Skip to content

Commit

Permalink
🔨 tweaks to extracted state logic
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Jan 6, 2025
1 parent 13270fe commit cc0b8c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
7 changes: 3 additions & 4 deletions site/DataPageV2Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,10 @@ export const DataPageV2Content = ({
(grapher2State.chartInstance as MapChart).projection
)

const focusedEntity = (
grapher2State.chartInstance as MapChart
).projection
const projection = (grapher2State.chartInstance as MapChart)
.projection
grapher1State.selection.clearSelection()
if (focusedEntity)
if (projection)
grapher1State.selection.addToSelection([projection])
}
)
Expand Down
29 changes: 15 additions & 14 deletions site/GrapherFigureView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useRef } from "react"

import { Grapher, GrapherProgrammaticInterface } from "@ourworldindata/grapher"
import {
Grapher,
GrapherProgrammaticInterface,
GrapherState,
} from "@ourworldindata/grapher"
import {
ADMIN_BASE_URL,
BAKED_GRAPHER_URL,
Expand All @@ -19,28 +23,25 @@ export const GrapherFigureView = ({
const base = useRef<HTMLDivElement>(null)
const bounds = useElementBounds(base)

const grapherProps: GrapherProgrammaticInterface = {
...grapher.toObject(),
isEmbeddedInADataPage: grapher.isEmbeddedInADataPage,
bindUrlToWindow: grapher.props.bindUrlToWindow,
queryStr: grapher.props.bindUrlToWindow
const grapherState: GrapherState = new GrapherState({
...grapher.grapherState.toObject(),
isEmbeddedInADataPage: grapher.grapherState.isEmbeddedInADataPage,
bindUrlToWindow: grapher.grapherState.initialOptions.bindUrlToWindow,
queryStr: grapher.grapherState.initialOptions.bindUrlToWindow
? window.location.search
: undefined,
: "", // TODO: 2025-01-03 changed this from undefined to empty string - is this a problem?
bounds,
dataApiUrl: DATA_API_URL,
enableKeyboardShortcuts: true,
adminBaseUrl: ADMIN_BASE_URL,
bakedGrapherURL: BAKED_GRAPHER_URL,
...extraProps,
}
})
return (
// They key= in here makes it so that the chart is re-loaded when the slug changes.
<figure data-grapher-src ref={base}>
{bounds && (
<Grapher
key={grapherProps.slug}
{...grapherProps}
adminBaseUrl={ADMIN_BASE_URL}
bakedGrapherURL={BAKED_GRAPHER_URL}
/>
<Grapher key={grapherState.slug} grapherState={grapherState} />
)}
</figure>
)
Expand Down

0 comments on commit cc0b8c2

Please sign in to comment.