Skip to content

Commit 9098e3a

Browse files
Fix Demand across Villages graph rendering issue
1 parent 34e525d commit 9098e3a

2 files changed

Lines changed: 91 additions & 73 deletions

File tree

src/components/LBDashboard/BarGraphs/CompareGraphs.jsx

Lines changed: 86 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ export function CompareBarGraph({
116116
height = 420,
117117
yCategoryWidth = 70,
118118
margins = { top: 16, right: 20, bottom: 46, left: 0 },
119-
maxBars,
120119
showYAxisTitle = true,
121120
yTickFormatter,
122121
darkMode = false,
@@ -165,75 +164,95 @@ export function CompareBarGraph({
165164
</div>
166165

167166
{/* chart */}
168-
<div className={styles.graphCanvas}>
169-
<ResponsiveContainer width="100%" height={height}>
170-
<BarChart
171-
data={data}
172-
layout={isHorizontal ? 'vertical' : 'horizontal'}
173-
margin={margins}
167+
<div
168+
className={styles.graphCanvas}
169+
style={{
170+
width: '100%',
171+
minHeight: `${height}px`,
172+
}}
173+
>
174+
{!data?.length ? (
175+
<div
176+
style={{
177+
height,
178+
display: 'flex',
179+
alignItems: 'center',
180+
justifyContent: 'center',
181+
color: darkMode ? '#e1e1e1' : '#666',
182+
}}
174183
>
175-
<CartesianGrid strokeDasharray="3 3" stroke={gridColor} />
176-
{isHorizontal
177-
? (() => {
178-
const axes = getHorizontalAxes({
179-
xDomain,
180-
xTicks,
181-
valueFormatter,
182-
tickColor,
183-
xLabel,
184-
nameKey,
185-
yCategoryWidth,
186-
yTickFormatter,
187-
showYAxisTitle,
188-
yLabel,
189-
});
190-
return (
191-
<>
192-
{axes.xAxis}
193-
{axes.yAxis}
194-
</>
195-
);
196-
})()
197-
: (() => {
198-
const axes = getVerticalAxes(
199-
nameKey,
200-
tickColor,
201-
xLabel,
202-
yDomain,
203-
yTicks,
204-
valueFormatter,
205-
yLabel,
206-
);
207-
return (
208-
<>
209-
{axes.xAxis}
210-
{axes.yAxis}
211-
</>
212-
);
213-
})()}
184+
No data available
185+
</div>
186+
) : (
187+
<ResponsiveContainer width="100%" height={height}>
188+
<BarChart
189+
data={data}
190+
layout={isHorizontal ? 'vertical' : 'horizontal'}
191+
margin={margins}
192+
>
193+
<CartesianGrid strokeDasharray="3 3" stroke={gridColor} />
194+
{isHorizontal
195+
? (() => {
196+
const axes = getHorizontalAxes({
197+
xDomain,
198+
xTicks,
199+
valueFormatter,
200+
tickColor,
201+
xLabel,
202+
nameKey,
203+
yCategoryWidth,
204+
yTickFormatter,
205+
showYAxisTitle,
206+
yLabel,
207+
});
208+
return (
209+
<>
210+
{axes.xAxis}
211+
{axes.yAxis}
212+
</>
213+
);
214+
})()
215+
: (() => {
216+
const axes = getVerticalAxes(
217+
nameKey,
218+
tickColor,
219+
xLabel,
220+
yDomain,
221+
yTicks,
222+
valueFormatter,
223+
yLabel,
224+
);
225+
return (
226+
<>
227+
{axes.xAxis}
228+
{axes.yAxis}
229+
</>
230+
);
231+
})()}
214232

215-
<Tooltip
216-
formatter={v => [valueFormatter(v), tooltipLabel || metricLabel || title]}
217-
labelFormatter={lbl => `${lbl}`}
218-
contentStyle={{
219-
background: darkMode ? '#1c2541' : '#fff',
220-
border: `1px solid ${darkMode ? '#3a506b' : '#ccc'}`,
221-
color: darkMode ? '#e1e1e1' : '#333',
222-
}}
223-
itemStyle={{ color: darkMode ? '#e1e1e1' : '#333' }}
224-
labelStyle={{ color: darkMode ? '#e1e1e1' : '#333', fontWeight: 600 }}
225-
/>
226-
<Bar dataKey={valueKey} radius={[4, 4, 4, 4]} fill={barColor} barSize={barSize}>
227-
<LabelList
228-
dataKey={valueKey}
229-
position={isHorizontal ? 'right' : 'top'}
230-
formatter={valueFormatter}
231-
style={{ fontSize: 15, fontWeight: 600 }}
232-
offset={8}
233+
<Tooltip
234+
formatter={v => [valueFormatter(v), tooltipLabel || metricLabel || title]}
235+
labelFormatter={lbl => `${lbl}`}
236+
contentStyle={{
237+
background: darkMode ? '#1c2541' : '#fff',
238+
border: `1px solid ${darkMode ? '#3a506b' : '#ccc'}`,
239+
color: darkMode ? '#e1e1e1' : '#333',
240+
}}
241+
itemStyle={{ color: darkMode ? '#e1e1e1' : '#333' }}
242+
labelStyle={{ color: darkMode ? '#e1e1e1' : '#333', fontWeight: 600 }}
233243
/>
234-
</Bar>
235-
</BarChart>
236-
</ResponsiveContainer>
244+
<Bar dataKey={valueKey} radius={[4, 4, 4, 4]} fill={barColor} barSize={barSize}>
245+
<LabelList
246+
dataKey={valueKey}
247+
position={isHorizontal ? 'right' : 'top'}
248+
formatter={valueFormatter}
249+
style={{ fontSize: 15, fontWeight: 600 }}
250+
offset={8}
251+
/>
252+
</Bar>
253+
</BarChart>
254+
</ResponsiveContainer>
255+
)}
237256
</div>
238257
</CardBody>
239258
</Card>
@@ -272,7 +291,6 @@ CompareBarGraph.propTypes = {
272291
bottom: PropTypes.number,
273292
left: PropTypes.number,
274293
}),
275-
maxBars: PropTypes.number,
276294
showYAxisTitle: PropTypes.bool,
277295
yTickFormatter: PropTypes.func,
278296
darkMode: PropTypes.bool,

src/components/LBDashboard/LBDashboard.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ export function LBDashboard() {
603603

604604
{compareType === 'villages' && (
605605
<AnalysisSection title="By Village" darkMode={darkMode}>
606-
<Row xs="1" md="3" className="g-3">
607-
<Col>
606+
<Row xs="1" lg="3" className="g-3">
607+
<Col lg="4" md="12">
608608
<DemandOverTime
609609
compareType="villages"
610610
metric={mappedMetric}
@@ -614,7 +614,7 @@ export function LBDashboard() {
614614
/>
615615
</Col>
616616

617-
<Col>
617+
<Col lg="4" md="12">
618618
{loadingVillages && (
619619
<div className={getClassNames('', styles.darkText, darkMode)}>
620620
Loading villages…
@@ -636,10 +636,10 @@ export function LBDashboard() {
636636
showYAxisTitle={true}
637637
yTickFormatter={stripVillageWord}
638638
yCategoryWidth={120}
639-
margins={{ top: 60, right: 110, bottom: 50, left: 20 }}
639+
margins={{ top: 40, right: 40, bottom: 50, left: 40 }}
640640
barSize={24}
641641
maxBars={6}
642-
height={480}
642+
height={420}
643643
valueFormatter={valueFormatter}
644644
darkMode={darkMode}
645645
headerChips={[

0 commit comments

Comments
 (0)