Skip to content

Commit

Permalink
refactor(grid): update threshold for grid interval (#2812)
Browse files Browse the repository at this point in the history
Adjust interval for grid lines display when grid.y.ticks is given
  • Loading branch information
netil authored Aug 4, 2022
1 parent 4818e44 commit e7bdbbc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ChartInternal/Axis/AxisRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export default class AxisRenderer {
let res = this.generatedTicks;

if (len > count) {
const interval = Math.round((len / count) - 0.1);
const interval = Math.round((len / count) + 0.1);

res = this.generatedTicks
.map((v, i) => (i % interval === 0 ? v : null))
Expand Down
30 changes: 30 additions & 0 deletions test/internals/grid-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,36 @@ describe("GRID", function() {
});
});

it("set options", () => {
args = {
data: {
columns: [
["data1", 130, 340, 200, 500, 250, 350]
],
type: "line"
},
axis: {
y: {
min: 0
}
},
grid: {
y: {
show: true,
ticks: 5
}
}
};
});

it("y grid showed with nice intervals?", () => {
const yPos = [426, 320, 214, 108, 1];

chart.$.grid.y.each(function(d, i) {
expect(+this.getAttribute("y1")).to.be.equal(yPos[i]);
});
});

it("set options", () => {
args = {
data: {
Expand Down

0 comments on commit e7bdbbc

Please sign in to comment.