import React, { useState } from 'react'; import CustomTooltip from "../CustomChartTooltip"; import { Styles } from '../../common'; import { ResponsiveContainer, XAxis, YAxis, CartesianGrid, Tooltip, LineChart, Line, Legend, } from 'recharts'; import { observer } from 'mobx-react-lite'; interface Props { data: any; compData: any | null; params: any; colors: any; onClick?: (event, index) => void; yaxis?: any; label?: string; hideLegend?: boolean; inGrid?: boolean; } function CustomMetricLineChart(props: Props) { const { data = { chart: [], namesMap: [] }, compData = { chart: [], namesMap: [] }, colors, onClick = () => null, yaxis = { ...Styles.yaxis }, label = 'Number of Sessions', hideLegend = false, inGrid, } = props; const [hoveredSeries, setHoveredSeries] = useState(null); const handleMouseOver = (key) => () => { setHoveredSeries(key); }; const handleMouseLeave = () => { setHoveredSeries(null); }; // const resultChart = data.chart.map((item, i) => { // if (compData && compData.chart[i]) return { ...compData.chart[i], ...item }; // return item; // }); const resultChart = data.chart.map((item, i) => { if (compData && compData.chart[i]) { const comparisonItem: Record = {}; Object.keys(compData.chart[i]).forEach(key => { if (key !== 'time') { comparisonItem[`${key}_comparison`] = (compData.chart[i] as any)[key]; } }); return { ...item, ...comparisonItem }; } return item; }); return ( {!hideLegend && ( ({ value: key, type: 'line', color: colors[index], id: key, })) } /> )} Styles.tickFormatter(val)} label={{ ...Styles.axisLabelLeft, value: label || 'Number of Sessions' }} /> } /> {Array.isArray(data.namesMap) && data.namesMap.map((key, index) => key ? ( ) : null )} {compData?.namesMap?.map((key, i) => data.namesMap[i] ? ( ) : null )} ); } export default observer(CustomMetricLineChart);