From c8bfc51946726a12d65b1c280cdc29dcfd09cdf7 Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Tue, 9 Apr 2024 07:38:25 -0400 Subject: [PATCH] Misc fixes: - Added check for zero bounds in fitOrCenter - Fixed broken dataset loader - Fixed re-drop handler when dataset view reset - Re-enabled fast speed slider during animation --- src/components/app.tsx | 2 +- src/components/graph.tsx | 5 +++++ src/components/speed-toggle.scss | 2 +- src/components/speed-toggle.tsx | 4 +--- src/hooks/use-codap.ts | 4 +++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/app.tsx b/src/components/app.tsx index 4c882f0..ecde6c7 100644 --- a/src/components/app.tsx +++ b/src/components/app.tsx @@ -390,7 +390,7 @@ export const App = () => { - +
diff --git a/src/components/graph.tsx b/src/components/graph.tsx index 7f387b4..b2467b5 100644 --- a/src/components/graph.tsx +++ b/src/components/graph.tsx @@ -808,6 +808,11 @@ export const Graph = (props: Props) => { const svg = d3.select(svgRef.current); const root = svg.select("g.root"); const bounds = (root.node() as SVGGElement).getBBox(); + + if (!bounds.width || !bounds.height) { + return false; + } + const center = { x: bounds.x + (bounds.width / 2), y: bounds.y + (bounds.height / 2), diff --git a/src/components/speed-toggle.scss b/src/components/speed-toggle.scss index 78a69b4..1c2c614 100644 --- a/src/components/speed-toggle.scss +++ b/src/components/speed-toggle.scss @@ -4,7 +4,7 @@ margin: 7px 0; display: flex; gap: 10px; - cursor: pointer; + cursor: default; &>div { width: 40px; diff --git a/src/components/speed-toggle.tsx b/src/components/speed-toggle.tsx index 33e3e51..2cbb836 100644 --- a/src/components/speed-toggle.tsx +++ b/src/components/speed-toggle.tsx @@ -4,11 +4,10 @@ import "./speed-toggle.scss"; interface Props { fastSimulation: boolean; - disabled: boolean; onChange: (newValue: boolean) => void; } -export const SpeedToggle = ({fastSimulation, disabled, onChange}: Props) => { +export const SpeedToggle = ({fastSimulation, onChange}: Props) => { const handleChange = (e: React.ChangeEvent) => { onChange(e.target.checked); }; @@ -28,7 +27,6 @@ export const SpeedToggle = ({fastSimulation, disabled, onChange}: Props) => { title={title} checked={fastSimulation} onChange={handleChange} - disabled={disabled} />
Fast
diff --git a/src/hooks/use-codap.ts b/src/hooks/use-codap.ts index 6a48c1b..9273fe7 100644 --- a/src/hooks/use-codap.ts +++ b/src/hooks/use-codap.ts @@ -77,7 +77,8 @@ export const useCODAP = ({onCODAPDataChanged, getGraph, setGraph, setInitialGrap const handleDataChanged = useCallback(async ({datasetName, collectionName, attributeName}: CODAPAttribute) => { const values = await getValuesForAttribute(datasetName, collectionName, attributeName); - if (viewMode === "dataset" && (JSON.stringify(values) !== JSON.stringify(valuesRef.current))) { + const valuesChanged = !valuesRef.current || (JSON.stringify(values) !== JSON.stringify(valuesRef.current)); + if (viewMode === "dataset" && valuesChanged) { onCODAPDataChanged(values); valuesRef.current = values; } @@ -127,6 +128,7 @@ export const useCODAP = ({onCODAPDataChanged, getGraph, setGraph, setInitialGrap collectionName: iMessage.values.collection.name, attributeName: iMessage.values.attribute.name }; + valuesRef.current = []; setAttribute(newAttribute); await handleDataChanged(newAttribute); await notifyStateIsDirty();