diff --git a/packages/@ourworldindata/grapher/src/axis/Axis.ts b/packages/@ourworldindata/grapher/src/axis/Axis.ts index eb9f2e9159..604284d9d3 100644 --- a/packages/@ourworldindata/grapher/src/axis/Axis.ts +++ b/packages/@ourworldindata/grapher/src/axis/Axis.ts @@ -210,10 +210,11 @@ abstract class AbstractAxis { } @computed private get d3_scale(): Scale { - const d3Scale = - this.scaleType === ScaleType.log ? scaleLog : scaleLinear + const isLogScale = this.scaleType === ScaleType.log + const d3Scale = isLogScale ? scaleLog : scaleLinear let scale = d3Scale().domain(this.domain).range(this.range) - scale = this.nice ? scale.nice(this.totalTicksTarget) : scale + scale = + this.nice && !isLogScale ? scale.nice(this.totalTicksTarget) : scale if (this.config.domainValues) { // compute bandwidth and adjust the scale diff --git a/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx b/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx index dd54175a66..80c0fc1896 100644 --- a/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx +++ b/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx @@ -1410,9 +1410,9 @@ export class LineChart } @computed private get yAxisConfig(): AxisConfig { - // TODO: enable nice axis ticks for linear scales return new AxisConfig( { + nice: true, // if we only have a single y value (probably 0), we want the // horizontal axis to be at the bottom of the chart. // see https://github.com/owid/owid-grapher/pull/975#issuecomment-890798547 diff --git a/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx b/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx index 5b40a3086b..812da2c381 100644 --- a/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx +++ b/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx @@ -253,8 +253,13 @@ export class AbstractStackedChart } @computed private get yAxisConfig(): AxisConfig { - // TODO: enable nice axis ticks for linear scales - return new AxisConfig(this.manager.yAxisConfig, this) + return new AxisConfig( + { + nice: true, + ...this.manager.yAxisConfig, + }, + this + ) } // implemented in subclasses