Skip to content

Commit

Permalink
Add min Y axis value and change X axis ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
barbara-chaves committed Oct 30, 2023
1 parent 8dea066 commit 395ae05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/javascript/components/tpi/charts/ascor-emissions/Chart.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<div className="emissions__chart">
<HighchartsReact
Expand All @@ -18,8 +25,13 @@ const EmissionsChart = ({ chartData }) => {
...options,
yAxis: {
...options.yAxis,
min: hasNegative ? null : 0,
title: { ...options.yAxis.title, text: metadata.unit }
},
xAxis: {
...options.xAxis,
min: minTickInterval
},
series: data,
title: { text: '' }
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const options = {
lineWidth: 1,
tickColor: '#595B5D',
tickInterval: 5,
startOnTick: true,
labels: {
style: {
color: '#0A4BDC',
Expand Down

0 comments on commit 395ae05

Please sign in to comment.