/** * @format */ import React, {FC, useEffect, useState} from 'react' import { XAxis, YAxis, CartesianGrid, Tooltip, Brush, LineChart, Line, ResponsiveContainer, Label, Legend, LabelList } from 'recharts' import {formatLineChartData, groupArrayBy, nFormatter, setChartTicks, tickFormatter} from '../../common/utils' import { useChartActiveDataPoints } from '../../hooks/useChartActiveDataPoints' import { chartColors_blue, LineChartOptions, TimePeriods } from '../../types/types' import {CustomLabel, CustomTooltipDouble} from './ChartElemets' export const LineChartComponent: FC = ({ data, xAxisLabeL, yAxisLabeL, currentTimePeriod }) => { // a perm solution to group data by regions for different lines const [activeLegends, handleDotClick] = useChartActiveDataPoints() const [processedData, setProcessedData] = useState(data) const [dataKeys, setDataKeys] = useState(new Set()) useEffect(()=> { const {processedData, dataKeys} = formatLineChartData(groupArrayBy('X_AXIS_VALUE', data)) setProcessedData(processedData) setDataKeys(dataKeys) }, [data]) return ( { handleDotClick(chartState, event) }} > tickFormatter(tick, currentTimePeriod)}> nFormatter(tick, 3)}> } /> }> {Array.from(dataKeys).map((item, index) => ( {index === dataKeys.size - 1 && ( )} />} ))} ({ value: item, type: 'circle', color: chartColors_blue[index] }))} wrapperStyle={{position: 'absolute', bottom: '-40px'}} /> ) }