Skip to content

Commit

Permalink
Merge pull request #483 from Vizzuality/develop
Browse files Browse the repository at this point in the history
fix: Minor bug fixes of ASCOR pathway chart
  • Loading branch information
martintomas authored Dec 7, 2023
2 parents a7e49f2 + 9da98d5 commit a413b20
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/javascript/components/tpi/charts/ascor-emissions/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ import { options } from './options';
const EmissionsChart = ({ chartData }) => {
const { data, metadata } = chartData;

const hasNegative = useMemo(
const allNegative = useMemo(
() => data.every((series) => series.data?.every((point) => point?.y < 0)),
[data]
);

const allPositive = useMemo(
() => data.every((series) => series.data?.every((point) => point?.y >= 0)),
[data]
);

return (
<div className="emissions__chart">
<HighchartsReact
Expand All @@ -23,11 +28,11 @@ const EmissionsChart = ({ chartData }) => {
...options,
yAxis: {
...options.yAxis,
min: hasNegative ? null : 0,
max: hasNegative ? 0 : null,
min: allPositive ? 0 : null,
max: allNegative ? 0 : null,
title: { ...options.yAxis.title, text: metadata.unit }
},
series: data
series: data.filter(v => (v.data || []).length > 0)
}}
/>
</div>
Expand Down

0 comments on commit a413b20

Please sign in to comment.