diff --git a/lib/strokeAlphabetText.ts b/lib/strokeAlphabetText.ts index 83de469..596dd95 100644 --- a/lib/strokeAlphabetText.ts +++ b/lib/strokeAlphabetText.ts @@ -45,7 +45,7 @@ export function getAlphabetAdvanceWidth( const advanceRatio = getAdvanceRatio(char) const letterSpacingRatio = nextChar ? textMetrics.letterSpacingRatio : 0 const kerningAdjustmentRatio = nextChar - ? (kerningRatio[char]?.[nextChar] ?? 0) + ? kerningRatio[char]?.[nextChar] ?? 0 : 0 return fontSize * (advanceRatio + letterSpacingRatio + kerningAdjustmentRatio) diff --git a/site/components/InteractiveGraphics/InteractiveGraphics.tsx b/site/components/InteractiveGraphics/InteractiveGraphics.tsx index de014e1..825c2ff 100644 --- a/site/components/InteractiveGraphics/InteractiveGraphics.tsx +++ b/site/components/InteractiveGraphics/InteractiveGraphics.tsx @@ -59,11 +59,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) @@ -359,6 +363,10 @@ export const InteractiveGraphics = ({ } const showToolbar = true + const stepTitle = + maxStep > 0 + ? stepMetadata?.[showLastStep ? maxStep : activeStep ?? -1]?.title + : undefined // Use custom hooks for visibility checks and filtering const isPointOnScreen = useIsPointOnScreen(realToScreen, size) @@ -576,6 +584,12 @@ export const InteractiveGraphics = ({ /> Enable Object Interation + + {maxStep > 0 && stepTitle && ( +
+ {stepTitle} +
+ )} )} diff --git a/site/components/InteractiveGraphics/Point.tsx b/site/components/InteractiveGraphics/Point.tsx index c4a1971..1f114b4 100644 --- a/site/components/InteractiveGraphics/Point.tsx +++ b/site/components/InteractiveGraphics/Point.tsx @@ -57,7 +57,7 @@ export const Point = ({ 0.2, color ?? defaultColors[index % defaultColors.length], ) - : (color ?? defaultColors[index % defaultColors.length]) + : color ?? defaultColors[index % defaultColors.length] }`, cursor: "pointer", transition: "border-color 0.2s", diff --git a/site/components/InteractiveGraphicsCanvas.tsx b/site/components/InteractiveGraphicsCanvas.tsx index 1954485..7987efa 100644 --- a/site/components/InteractiveGraphicsCanvas.tsx +++ b/site/components/InteractiveGraphicsCanvas.tsx @@ -16,13 +16,18 @@ interface InteractiveGraphicsCanvasProps { showGrid?: boolean height?: number | string width?: number | string + stepMetadata?: Array<{ title: string }> + alwaysShowToolbar?: boolean } export function InteractiveGraphicsCanvas({ graphics, + showLabelsByDefault = true, showGrid = true, height = 500, width = "100%", + stepMetadata, + alwaysShowToolbar = false, }: InteractiveGraphicsCanvasProps) { const canvasRef = useRef(null) const containerRef = useRef(null) @@ -43,6 +48,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, { @@ -254,66 +264,80 @@ 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} +
+ )}
-
+ )}
{