diff --git a/site/components/InteractiveGraphics/InteractiveGraphics.tsx b/site/components/InteractiveGraphics/InteractiveGraphics.tsx index 0b0063c..b862b20 100644 --- a/site/components/InteractiveGraphics/InteractiveGraphics.tsx +++ b/site/components/InteractiveGraphics/InteractiveGraphics.tsx @@ -45,11 +45,15 @@ export const InteractiveGraphics = ({ onObjectClicked, objectLimit, height = 600, + stepMetadata, + alwaysShowToolbar = false, }: { graphics: GraphicsObject onObjectClicked?: (event: GraphicsObjectClickEvent) => void objectLimit?: number height?: number + stepMetadata?: Array<{ title: string }> + alwaysShowToolbar?: boolean }) => { const [activeLayers, setActiveLayers] = useState(null) const [activeStep, setActiveStep] = useState(null) @@ -287,7 +291,13 @@ export const InteractiveGraphics = ({ onObjectClicked: onObjectClicked, } - const showToolbar = availableLayers.length > 1 || maxStep > 0 + const showToolbar = + alwaysShowToolbar || availableLayers.length > 1 || maxStep > 0 + + const stepTitle = + maxStep > 0 + ? stepMetadata?.[showLastStep ? maxStep : (activeStep ?? -1)]?.title + : undefined // Use custom hooks for visibility checks and filtering const isPointOnScreen = useIsPointOnScreen(realToScreen, size) @@ -386,72 +396,86 @@ export const InteractiveGraphics = ({ return (
{showToolbar && ( -
- {availableLayers.length > 1 && ( - - )} - - {maxStep > 0 && ( -
- Step: - +
+ {availableLayers.length > 1 && ( + + )} + + {maxStep > 0 && ( +
+ Step: { + const value = parseInt(e.target.value) setShowLastStep(false) - setActiveStep(e.target.checked ? 0 : null) - }} - /> - Filter by step - - - {isLimitReached && ( - - Display limited to {objectLimit} objects. Received:{" "} - {totalFilteredObjects}. - - )} + + + {isLimitReached && ( + + Display limited to {objectLimit} objects. Received:{" "} + {totalFilteredObjects}. + + )} +
+ )} +
+ {maxStep > 0 && stepTitle && ( +
+ {stepTitle}
)}
diff --git a/site/components/InteractiveGraphicsCanvas.tsx b/site/components/InteractiveGraphicsCanvas.tsx index 3cb5cd2..14a8a14 100644 --- a/site/components/InteractiveGraphicsCanvas.tsx +++ b/site/components/InteractiveGraphicsCanvas.tsx @@ -13,6 +13,8 @@ interface InteractiveGraphicsCanvasProps { showGrid?: boolean height?: number | string width?: number | string + stepMetadata?: Array<{ title: string }> + alwaysShowToolbar?: boolean } export function InteractiveGraphicsCanvas({ @@ -21,6 +23,8 @@ export function InteractiveGraphicsCanvas({ showGrid = true, height = 500, width = "100%", + stepMetadata, + alwaysShowToolbar = false, }: InteractiveGraphicsCanvasProps) { const canvasRef = useRef(null) const containerRef = useRef(null) @@ -31,6 +35,11 @@ export function InteractiveGraphicsCanvas({ // Calculate the maximum step value from all graphics objects const maxStep = getMaxStep(graphics) + const showToolbar = alwaysShowToolbar || maxStep > 0 || showLabelsByDefault + const stepTitle = + maxStep > 0 + ? stepMetadata?.[showLastStep ? maxStep : (activeStep ?? -1)]?.title + : undefined // Filter graphics objects based on step const filteredGraphics = getGraphicsFilteredByStep(graphics, { @@ -176,62 +185,78 @@ export function InteractiveGraphicsCanvas({ return (
-
-
- - - { - const value = parseInt(e.target.value) - setShowLastStep(false) - setActiveStep(Number.isNaN(value) ? 0 : Math.min(value, maxStep)) - }} - disabled={activeStep === null} - style={{ width: "60px" }} - /> - - -
- -
- + {showToolbar && ( +
+
+ {maxStep > 0 && ( + <> + + + { + const value = parseInt(e.target.value) + setShowLastStep(false) + setActiveStep( + Number.isNaN(value) ? 0 : Math.min(value, maxStep), + ) + }} + disabled={activeStep === null} + style={{ width: "60px" }} + /> + + + + )} + +
+ {maxStep > 0 && stepTitle && ( +
+ {stepTitle} +
+ )}
-
+ )}
{