From 395ae056e878bbc51534aab0769ccc6ec093b2c4 Mon Sep 17 00:00:00 2001 From: barbara-chaves Date: Mon, 30 Oct 2023 10:44:12 +0100 Subject: [PATCH] Add min Y axis value and change X axis ticks --- .../components/tpi/charts/ascor-emissions/Chart.js | 14 +++++++++++++- .../tpi/charts/ascor-emissions/options.js | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/javascript/components/tpi/charts/ascor-emissions/Chart.js b/app/javascript/components/tpi/charts/ascor-emissions/Chart.js index 21ff57afb..0e8b2c830 100644 --- a/app/javascript/components/tpi/charts/ascor-emissions/Chart.js +++ b/app/javascript/components/tpi/charts/ascor-emissions/Chart.js @@ -1,6 +1,6 @@ import PropTypes from 'prop-types'; -import React from 'react'; +import React, { useMemo } from 'react'; import Highcharts from 'highcharts'; import HighchartsReact from 'highcharts-react-official'; @@ -10,6 +10,13 @@ import { options } from './options'; const EmissionsChart = ({ chartData }) => { const { data, metadata } = chartData; + const hasNegative = useMemo( + () => data.some((series) => series.data?.some((point) => point?.y < 0)), + [data] + ); + + const minTickInterval = useMemo(() => data?.[0]?.data?.[0]?.x, [data]); + return (
{ ...options, yAxis: { ...options.yAxis, + min: hasNegative ? null : 0, title: { ...options.yAxis.title, text: metadata.unit } }, + xAxis: { + ...options.xAxis, + min: minTickInterval + }, series: data, title: { text: '' } }} diff --git a/app/javascript/components/tpi/charts/ascor-emissions/options.js b/app/javascript/components/tpi/charts/ascor-emissions/options.js index 9f2ac1acc..02839f8cc 100644 --- a/app/javascript/components/tpi/charts/ascor-emissions/options.js +++ b/app/javascript/components/tpi/charts/ascor-emissions/options.js @@ -49,6 +49,7 @@ export const options = { lineWidth: 1, tickColor: '#595B5D', tickInterval: 5, + startOnTick: true, labels: { style: { color: '#0A4BDC',