Skip to content

Commit 8d1122a

Browse files
authored
Merge pull request #329 from bendichter/toggle-legend
Add toggle button for legend visibility in TimeseriesPlot component
2 parents e54ff94 + 4ad9542 commit 8d1122a

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/pages/NwbPage/plugins/simple-timeseries/TimeseriesPlot.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FunctionComponent, useMemo } from "react";
1+
import { FunctionComponent, useMemo, useState } from "react";
22
import Plot from "react-plotly.js";
33

44
import { TimeseriesPlotProps as Props } from "./types";
@@ -25,6 +25,9 @@ const TimeseriesPlot: FunctionComponent<Partial<Props>> = ({
2525
height = 300,
2626
zoomInRequired = false,
2727
}) => {
28+
// State for legend visibility
29+
const [showLegend, setShowLegend] = useState<boolean>(true);
30+
2831
// Memoize the transposed channel data
2932
const channelData = useMemo(() => {
3033
if (!data) return [];
@@ -111,9 +114,9 @@ const TimeseriesPlot: FunctionComponent<Partial<Props>> = ({
111114
showticklabels: true,
112115
showgrid: true,
113116
},
114-
showlegend: true,
117+
showlegend: showLegend,
115118
}),
116-
[channelSeparation, height, visibleEndTime, visibleStartTime, width],
119+
[channelSeparation, height, visibleEndTime, visibleStartTime, width, showLegend],
117120
);
118121

119122
const config = useMemo(
@@ -152,7 +155,26 @@ const TimeseriesPlot: FunctionComponent<Partial<Props>> = ({
152155
return <div>Loading...</div>;
153156
}
154157

155-
return <Plot data={plotData} layout={layout} config={config} />;
158+
return (
159+
<div>
160+
<div style={{ marginBottom: '10px', display: 'flex', justifyContent: 'flex-end' }}>
161+
<button
162+
onClick={() => setShowLegend(!showLegend)}
163+
style={{
164+
padding: '5px 10px',
165+
backgroundColor: '#f8f9fa',
166+
border: '1px solid #dee2e6',
167+
borderRadius: '4px',
168+
cursor: 'pointer',
169+
fontSize: '12px'
170+
}}
171+
>
172+
{showLegend ? 'Hide Legend' : 'Show Legend'}
173+
</button>
174+
</div>
175+
<Plot data={plotData} layout={layout} config={config} />
176+
</div>
177+
);
156178
};
157179

158180
export default TimeseriesPlot;

0 commit comments

Comments
 (0)