diff --git a/components/CircularPlot.tsx b/components/CircularPlot.tsx index d54898c..da061ca 100644 --- a/components/CircularPlot.tsx +++ b/components/CircularPlot.tsx @@ -11,6 +11,7 @@ interface CircularPlotProps { imageProperties: ImagePropertiesConfig; onViewStateChange?: (state: PlotViewState) => void; squarePlot?: boolean; + centreViewSignal?: number; } interface TooltipInfo extends PlotTooltip { @@ -18,7 +19,7 @@ interface TooltipInfo extends PlotTooltip { y: number; } -export default function CircularPlot({ data, imageProperties, onViewStateChange, squarePlot = false }: CircularPlotProps) { +export default function CircularPlot({ data, imageProperties, onViewStateChange, squarePlot = false, centreViewSignal = 0 }: CircularPlotProps) { const canvasRef = useRef(null); const rendererRef = useRef(null); const [tooltip, setTooltip] = useState(null); @@ -40,6 +41,7 @@ export default function CircularPlot({ data, imageProperties, onViewStateChange, panRef.current = pan; const onViewStateChangeRef = useRef(onViewStateChange); + const previousCentreViewSignal = useRef(centreViewSignal); onViewStateChangeRef.current = onViewStateChange; /** Emit current view state to parent (for SVG export). */ @@ -130,6 +132,15 @@ export default function CircularPlot({ data, imageProperties, onViewStateChange, emitViewState(); }, [zoom, pan, emitViewState]); + // A fullscreen transition should not preserve a plot dragged partly off-canvas. + // Keep the user's zoom and legend placement, but centre the circular map. + useEffect(() => { + if (previousCentreViewSignal.current === centreViewSignal) return; + previousCentreViewSignal.current = centreViewSignal; + setPan({ x: 0, y: 0 }); + setTooltip(null); + }, [centreViewSignal]); + const getCanvasCoords = (e: React.MouseEvent) => { const canvas = canvasRef.current; if (!canvas) return { canvasX: 0, canvasY: 0 }; @@ -274,11 +285,13 @@ export default function CircularPlot({ data, imageProperties, onViewStateChange, onMouseUp={handleMouseUp} onMouseLeave={handleMouseLeave} onWheel={handleWheel} - style={{ cursor: draggingLegend ? 'move' : isDragging ? 'grabbing' : 'grab', background: 'white' }} + data-plot-pan-x={Math.round(pan.x)} + data-plot-pan-y={Math.round(pan.y)} + style={{ cursor: draggingLegend ? 'move' : isDragging ? 'grabbing' : 'grab', background: 'var(--gx-bg-alt)' }} > {tooltip && tooltip.x != null && tooltip.y != null && (
(null); const [plotViewState, setPlotViewState] = useReactState(null); + const [plotCentreSignal, setPlotCentreSignal] = useReactState(0); const [bugReportOpen, setBugReportOpen] = useReactState(false); const handleViewStateChange = useCallback((state: PlotViewState) => { setPlotViewState(previous => samePlotViewState(previous, state) ? previous : state); @@ -78,6 +79,10 @@ export default function Home() { loadedSessionUrlRef.current = sessionUrl; void handleLoadSessionUrl(sessionUrl); }, [handleLoadSessionUrl, sessionUrl]); + const togglePlotExpanded = () => { + if (!plotExpanded) setPlotCentreSignal(signal => signal + 1); + setPlotExpanded(value => !value); + }; return ( <> @@ -116,7 +121,7 @@ export default function Home() {

Circular Plot

-