Skip to content

Commit d4c8eb1

Browse files
authored
fix(axis): Correct on tick count display
Make the interval of tick value to be rounded for x Axis category type. Ref #1077
1 parent e5ddb73 commit d4c8eb1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

spec/internals/axis-spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ describe("AXIS", function() {
2323
]
2424
},
2525
axis: {
26+
x: {
27+
tick: {
28+
count: undefined
29+
}
30+
},
2631
y: {
2732
tick: {
2833
values: null,
@@ -42,6 +47,25 @@ describe("AXIS", function() {
4247
chart = util.generate(args);
4348
});
4449

50+
describe("axis.x.tick.count", () => {
51+
after(() => {
52+
args.axis.x.type = "indexed";
53+
args.axis.x.tick.count = undefined;
54+
});
55+
56+
it("set options axis.x.tick.count=3", () => {
57+
args.axis.x.type = "category";
58+
args.axis.x.tick.count = 3;
59+
});
60+
61+
it("should have only 3 tick on x axis", () => {
62+
const ticks = chart.$.main.select(`.${CLASS.axisX}`).selectAll("g.tick");
63+
64+
expect(ticks.size()).to.be.equal(3);
65+
expect(ticks.data()).to.be.deep.equal([0,3,5]);
66+
});
67+
});
68+
4569
describe("axis.y.tick.count", () => {
4670
it("set options axis.y.tick.count=1", () => {
4771
args.axis.y.tick.count = 1;

src/axis/Axis.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ export default class Axis {
605605
} else if (targetCount === 2) {
606606
tickValues = [values[0], values[values.length - 1]];
607607
} else if (targetCount > 2) {
608+
const isCategorized = this.owner.isCategorized();
609+
608610
count = targetCount - 2;
609611
start = values[0];
610612
end = values[values.length - 1];
@@ -615,7 +617,11 @@ export default class Axis {
615617

616618
for (i = 0; i < count; i++) {
617619
tickValue = +start + interval * (i + 1);
618-
tickValues.push(forTimeSeries ? new Date(tickValue) : tickValue);
620+
tickValues.push(
621+
forTimeSeries ? new Date(tickValue) : (
622+
isCategorized ? Math.round(tickValue) : tickValue
623+
)
624+
);
619625
}
620626

621627
tickValues.push(end);

0 commit comments

Comments
 (0)