Skip to content

Commit

Permalink
fix: Minor bug fixes of ASCOR pathway chart
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomas committed Dec 7, 2023
1 parent 25b6e6c commit 9da98d5
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 9da98d5

Please sign in to comment.