Skip to content

Commit

Permalink
🔨 work on facetting
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Jan 9, 2025
1 parent 3851b23 commit b7638b8
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3032,6 +3032,30 @@ export class GrapherState {
(question) => !!getErrorMessageRelatedQuestionUrl(question)
)
}
set facetStrategy(facet: FacetStrategy) {
this.selectedFacetStrategy = facet
}
set staticFormat(format: GrapherStaticFormat) {
this._staticFormat = format
}
set baseFontSize(val: number) {
this._baseFontSize = val
}
set isInFullScreenMode(newValue: boolean) {
// prevent scrolling when in full-screen mode
if (newValue) {
document.documentElement.classList.add("no-scroll")
} else {
document.documentElement.classList.remove("no-scroll")
}

// dismiss the share menu
this.isShareMenuActive = false

this._isInFullScreenMode = newValue
}

@observable isShareMenuActive = false
}

export interface GrapherProps {
Expand All @@ -3058,7 +3082,6 @@ export class Grapher extends React.Component<GrapherProps> {
@observable private hasBeenVisible = false
@observable private uncaughtError?: Error
@observable slideShow?: SlideShowController<any>
@observable isShareMenuActive = false

/**
* Whether the chart is rendered in an Admin context (e.g. on owid.cloud).
Expand Down Expand Up @@ -3125,7 +3148,7 @@ export class Grapher extends React.Component<GrapherProps> {
}

@computed get hideFullScreenButton(): boolean {
if (this.isInFullScreenMode) return false
if (this.grapherState.isInFullScreenMode) return false
// hide the full screen button if the full screen height
// is barely larger than the current chart height
const fullScreenHeight = this.grapherState.windowInnerHeight!
Expand Down Expand Up @@ -3293,10 +3316,6 @@ export class Grapher extends React.Component<GrapherProps> {
)?.column
}

set staticFormat(format: GrapherStaticFormat) {
this.grapherState._staticFormat = format
}

get staticSVG(): string {
return this.grapherState.generateStaticSvg()
}
Expand Down Expand Up @@ -3542,10 +3561,6 @@ export class Grapher extends React.Component<GrapherProps> {
)
}

set facetStrategy(facet: FacetStrategy) {
this.grapherState.selectedFacetStrategy = facet
}

@action.bound randomSelection(num: number): void {
// Continent, Population, GDP PC, GDP, PopDens, UN, Language, etc.
this.clearErrors()
Expand All @@ -3561,34 +3576,24 @@ export class Grapher extends React.Component<GrapherProps> {
)
}

set isInFullScreenMode(newValue: boolean) {
// prevent scrolling when in full-screen mode
if (newValue) {
document.documentElement.classList.add("no-scroll")
} else {
document.documentElement.classList.remove("no-scroll")
}

// dismiss the share menu
this.isShareMenuActive = false

this.grapherState._isInFullScreenMode = newValue
}

@action.bound toggleFullScreenMode(): void {
this.isInFullScreenMode = !this.isInFullScreenMode
this.grapherState.isInFullScreenMode =
!this.grapherState.isInFullScreenMode
}

@action.bound dismissFullScreen(): void {
// if a modal is open, dismiss it instead of exiting full-screen mode
if (this.grapherState.isModalOpen || this.isShareMenuActive) {
if (
this.grapherState.isModalOpen ||
this.grapherState.isShareMenuActive
) {
this.grapherState.isEntitySelectorModalOrDrawerOpen = false
this.grapherState.isSourcesModalOpen = false
this.grapherState.isEmbedModalOpen = false
this.grapherState.isDownloadModalOpen = false
this.isShareMenuActive = false
this.grapherState.isShareMenuActive = false
} else {
this.isInFullScreenMode = false
this.grapherState.isInFullScreenMode = false
}
}

Expand Down Expand Up @@ -3675,7 +3680,7 @@ export class Grapher extends React.Component<GrapherProps> {
if (this.grapherState.isExportingToSvgOrPng)
return <CaptionedChart manager={this.grapherState} />

if (this.isInFullScreenMode) {
if (this.grapherState.isInFullScreenMode) {
return (
<FullScreen
onDismiss={this.dismissFullScreen}
Expand Down Expand Up @@ -3803,14 +3808,11 @@ export class Grapher extends React.Component<GrapherProps> {
}
}

set baseFontSize(val: number) {
this.grapherState._baseFontSize = val
}

@action.bound private setBaseFontSize(): void {
this.baseFontSize = this.grapherState.computeBaseFontSizeFromWidth(
this.grapherState.captionedChartBounds
)
this.grapherState.baseFontSize =
this.grapherState.computeBaseFontSizeFromWidth(
this.grapherState.captionedChartBounds
)
}

// Binds chart properties to global window title and URL. This should only
Expand Down Expand Up @@ -3869,7 +3871,7 @@ export class Grapher extends React.Component<GrapherProps> {
}
),
reaction(
() => this.facetStrategy,
() => this.grapherState.facetStrategy,
() => this.grapherState.focusArray.clear()
)
)
Expand Down

0 comments on commit b7638b8

Please sign in to comment.