diff --git a/src/components/NetworkChart.tsx b/src/components/NetworkChart.tsx index a48420e..2049add 100644 --- a/src/components/NetworkChart.tsx +++ b/src/components/NetworkChart.tsx @@ -111,13 +111,27 @@ export const NetworkChartClient = React.memo(function NetworkChart({ const defaultChart = "All"; - const [activeChart, setActiveChart] = React.useState(defaultChart); + const [activeCharts, setActiveCharts] = React.useState([defaultChart]); const handleButtonClick = useCallback( (chart: string) => { - setActiveChart((prev) => (prev === chart ? defaultChart : chart)); + setActiveCharts((prev) => { + if (chart === defaultChart) { + return [defaultChart]; + } + + const newCharts = prev.filter(c => c !== defaultChart); + const chartIndex = newCharts.indexOf(chart); + + if (chartIndex === -1) { + return newCharts.length === 0 ? [chart] : [...newCharts, chart]; + } else { + const result = newCharts.filter(c => c !== chart); + return result.length === 0 ? [defaultChart] : result; + } + }); }, - [defaultChart], + [], ); const getColorByIndex = useCallback( @@ -133,7 +147,7 @@ export const NetworkChartClient = React.memo(function NetworkChart({ chartDataKey.map((key) => ( )), - [chartDataKey, activeChart, chartData, handleButtonClick], + [chartDataKey, activeCharts, chartData, handleButtonClick], ); const chartLines = useMemo(() => { - if (activeChart !== defaultChart) { - return ( + if (activeCharts.includes(defaultChart)) { + return chartDataKey.map((key) => ( - ); + )); } - return chartDataKey.map((key) => ( + + return activeCharts.map((chart) => ( )); - }, [activeChart, defaultChart, chartDataKey, getColorByIndex]); + }, [activeCharts, chartDataKey, getColorByIndex]); return ( @@ -196,9 +213,9 @@ export const NetworkChartClient = React.memo(function NetworkChart({ @@ -231,7 +248,7 @@ export const NetworkChartClient = React.memo(function NetworkChart({ /> } /> - {activeChart === defaultChart && ( + {activeCharts.includes(defaultChart) && ( } /> )} {chartLines}