Skip to content

Commit fffe736

Browse files
committed
When the interval option is applied on a quantitative scale, generate the ticks with the interval; also set the tickFormat so that we don't show 1.0, 2.0, 3.0 if the interval is an integer.
1 parent 759c46f commit fffe736

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/axes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {extent} from "d3";
22
import {AxisX, AxisY} from "./axis.js";
33
import {isOrdinalScale, isTemporalScale, scaleOrder} from "./scales.js";
44
import {position, registry} from "./scales/index.js";
5+
import {maybeInterval} from "./transforms/interval.js";
56

67
export function Axes(
78
{x: xScale, y: yScale, fx: fxScale, fy: fyScale},
@@ -33,12 +34,22 @@ export function autoAxisTicks({x, y, fx, fy}, {x: xAxis, y: yAxis, fx: fxAxis, f
3334
}
3435

3536
function autoAxisTicksK(scale, axis, k) {
37+
tickInterval(scale, axis);
3638
if (axis.ticks === undefined) {
3739
const [min, max] = extent(scale.scale.range());
3840
axis.ticks = (max - min) / k;
3941
}
4042
}
4143

44+
function tickInterval(scale, axis) {
45+
const interval = maybeInterval(scale.interval);
46+
if (interval != null) {
47+
const [min, max] = extent(scale.scale.domain());
48+
if (axis.ticks === undefined) axis.ticks = interval.range(interval.floor(min), interval.offset(interval.floor(max)));
49+
if (scale.type !== "point" && scale.type !== "band" && axis.tickFormat === undefined && typeof scale.interval === "number") axis.tickFormat = ",";
50+
}
51+
}
52+
4253
// Mutates axis.{label,labelAnchor,labelOffset} and scale.label!
4354
export function autoScaleLabels(channels, scales, {x, y, fx, fy}, dimensions, options) {
4455
if (fx) {

0 commit comments

Comments
 (0)