Skip to content

Commit

Permalink
🐛 (slope) use correct domains when facetted and axis is shared
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 11, 2024
1 parent 92800ef commit f7aaf16
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ export class SlopeChart
}

@computed private get yDomainDefault(): [number, number] {
return domainExtent(this.allYValues, this.yScaleType)
const defaultDomain: [number, number] = [Infinity, -Infinity]
return domainExtent(this.allYValues, this.yScaleType) ?? defaultDomain
}

@computed private get yDomain(): [number, number] {
Expand Down
6 changes: 3 additions & 3 deletions packages/@ourworldindata/utils/src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export const domainExtent = (
numValues: number[],
scaleType: ScaleType,
maxValueMultiplierForPadding = 1
): [number, number] => {
): [number, number] | undefined => {
const filterValues =
scaleType === ScaleType.log ? numValues.filter((v) => v > 0) : numValues
const [minValue, maxValue] = extent(filterValues)
Expand All @@ -439,9 +439,9 @@ export const domainExtent = (
? [minValue / 10, minValue * 10]
: [minValue - 1, maxValue + 1]
}
} else {
return scaleType === ScaleType.log ? [1, 100] : [-1, 1]
}

return undefined
}

// Compound annual growth rate
Expand Down

0 comments on commit f7aaf16

Please sign in to comment.