Skip to content

Commit

Permalink
🎉 (slope) support facetting
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 11, 2024
1 parent d95d75e commit 92800ef
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 57 deletions.
3 changes: 2 additions & 1 deletion packages/@ourworldindata/grapher/src/chart/ChartManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface ChartManager {

hidePoints?: boolean // for line options
startHandleTimeBound?: TimeBound // for relative-to-first-year line chart
hideNoDataSection?: boolean // for slope charts

// we need endTime so DiscreteBarCharts and StackedDiscreteBarCharts can
// know what date the timeline is set to. and let's pass startTime in, too.
Expand All @@ -78,7 +79,7 @@ export interface ChartManager {
seriesStrategy?: SeriesStrategy

sortConfig?: SortConfig
showNoDataArea?: boolean
showNoDataArea?: boolean // No data area in Marimekko charts

externalLegendHoverBin?: ColorScaleBin | undefined
disableIntroAnimation?: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export class SettingsMenu extends React.Component<{
StackedBar,
StackedDiscreteBar,
LineChart,
SlopeChart,
].includes(this.chartType as any)

const hasProjection = filledDimensions.some(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ export class FacetChart
return series.map((series, index) => {
const { bounds } = gridBoundsArr[index]
const showLegend = !this.hideFacetLegends

const hidePoints = true
const hideNoDataSection = true

// NOTE: The order of overrides is important!
// We need to preserve most config coming in.
Expand All @@ -319,6 +321,7 @@ export class FacetChart
endTime,
missingDataStrategy,
backgroundColor,
hideNoDataSection,
...series.manager,
xAxisConfig: {
...globalXAxisConfig,
Expand Down Expand Up @@ -756,7 +759,8 @@ export class FacetChart
)
if (this.facetStrategy === FacetStrategy.metric && newBins.length <= 1)
return []
return newBins
const sortedBins = sortBy(newBins, (bin) => bin.label)
return sortedBins
}

@observable.ref private legendHoverBin: ColorScaleBin | undefined =
Expand Down
11 changes: 11 additions & 0 deletions packages/@ourworldindata/grapher/src/lineLegend/LineLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ export class LineLegend extends React.Component<LineLegendProps> {
return test.stableWidth
}

static width(props: LineLegendProps): number {
const test = new LineLegend(props)
return test.width
}

static fontSize(props: Partial<LineLegendProps>): number {
const test = new LineLegend(props as LineLegendProps)
return test.fontSize
Expand Down Expand Up @@ -449,6 +454,12 @@ export class LineLegend extends React.Component<LineLegendProps> {
return this.maxLabelWidth + DEFAULT_CONNECTOR_LINE_WIDTH + MARKER_MARGIN
}

@computed get width(): number {
return this.needsLines
? this.stableWidth
: this.maxLabelWidth + MARKER_MARGIN
}

@computed get onMouseOver(): any {
return this.props.onMouseOver ?? noop
}
Expand Down
Loading

0 comments on commit 92800ef

Please sign in to comment.