Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions src/views/CityScopeJS/VisContainer/BarChart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ export const noData = {
export default function BarChart() {
const cityIOdata = useSelector((state) => state.cityIOdataState.cityIOdata);
const [barChartData, setBarChartData] = useState();
const [givenOptions, setOptions] = useState(options);

useEffect(() => {
if (!cityIOdata.indicators) {
setBarChartData(noData);
} else {
const d = createBarChartData(cityIOdata.indicators);
const { d, o } = createBarChartData(cityIOdata.indicators);
setBarChartData(d);
setOptions({ ...o });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [cityIOdata]);
Expand All @@ -124,7 +126,7 @@ export default function BarChart() {
},
],
};

let new_options = { ...options };
for (let i = 0; i < indicators.length; i++) {
if (indicators[i].viz_type === "bar") {
barChartData.labels.push(indicators[i].name);
Expand All @@ -146,14 +148,42 @@ export default function BarChart() {
"No description available"
);
}
if (indicators[i].viz_config === "bar") {
if (indicators[i].style === "raw") {
new_options = {
...new_options,
plugins: {
...new_options.plugins,
tooltip: {},
},
scales: {
...new_options.scales,
y: {
...new_options.scales.y,
ticks: {
...new_options.scales.y.ticks,
format: {
style: "decimal",
},
},
},
},
};
}
}
}
return barChartData;

return { d: barChartData, o: new_options };
};

return (
<>
{barChartData && (
<Bar options={options} data={barChartData ? barChartData : noData} />
<Bar
options={givenOptions}
data={barChartData ? barChartData : noData}
key={JSON.stringify(givenOptions)} // to force re-render on options change
/>
)}
</>
);
Expand Down