Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 (slope) support facetting / TAS-734 #4247

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -1144,10 +1144,16 @@ export class ScatterPlotChart
// domains across the entire timeline
private domainDefault(property: "x" | "y"): [number, number] {
const scaleType = property === "x" ? this.xScaleType : this.yScaleType
return domainExtent(
this.pointsForAxisDomains.map((point) => point[property]),
scaleType,
this.manager.zoomToSelection && this.selectedPoints.length ? 1.1 : 1
const defaultDomain: [number, number] =
scaleType === ScaleType.log ? [1, 100] : [-1, 1]
return (
domainExtent(
this.pointsForAxisDomains.map((point) => point[property]),
scaleType,
this.manager.zoomToSelection && this.selectedPoints.length
? 1.1
: 1
) ?? defaultDomain
)
}

Expand Down
Loading
Loading