Skip to content

Commit

Permalink
fix(axis): Fix indexed x axis order (#879)
Browse files Browse the repository at this point in the history
Correct domain array ascending order.
Side effect caused by #714

Fix #877
  • Loading branch information
netil committed May 10, 2019
1 parent cbe95b7 commit df8d385
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
18 changes: 18 additions & 0 deletions demo/demo.js
Expand Up @@ -805,6 +805,24 @@ var demos = {
}
}
},
IndexedAxis: {
options: {
data: {
x: "x",
columns: [
["x", 495, 940, 1500, 3000, 4500, 6000, 7500, 9000, 10500, 12000, 13500, 15000],
["data", 47.911, 47.915, 48.437, 49.117, 49.583, 50.28, 51.712, 53.103, 54.456, 55.955, 56.752, 56.851]
]
},
axis: {
x: {
tick: {
culling: false
}
}
}
}
},
MultiAxes: [
{
options: {
Expand Down
27 changes: 27 additions & 0 deletions spec/internals/axis-spec.js
Expand Up @@ -132,6 +132,33 @@ describe("AXIS", function() {
});
});

describe("tick values less than 0", () => {
before(() => {
args = {
data: {
x: "x",
columns: [
["x", 495, 740, 1500, 3000, 4500, 6000, 7500, 9000, 10500, 12000, 13500, 15000],
["data", 47.911, 47.915, 48.437, 49.117, 49.583, 50.28, 51.712, 53.103, 54.456, 55.955, 56.752, 56.851]
]
},
axis: {
x: {
tick: {
culling: false
}
}
}
};
});

it("Indexed x axis should scale correct order", () => {
chart.$.main.selectAll(".bb-axis-x .tick tspan").each(function(d, i) {
expect(+this.textContent).to.be.equal(args.data.columns[0][i + 1]);
});
});
});

describe("axis y timeseries", () => {
before(() => {
args = {
Expand Down
8 changes: 6 additions & 2 deletions src/internals/util.js
Expand Up @@ -213,8 +213,12 @@ const sortValue = (data, isAsc = true) => {

if (data[0] instanceof Date) {
fn = isAsc ? (a, b) => a - b : (a, b) => b - a;
} else if (!isAsc) {
fn = (a, b) => (a > b && -1) || (a < b && 1) || (a === b && 0);
} else {
if (isAsc && data.every(Number)) {
fn = (a, b) => a - b;
} else if (!isAsc) {
fn = (a, b) => (a > b && -1) || (a < b && 1) || (a === b && 0);
}
}

return data.concat().sort(fn);
Expand Down

0 comments on commit df8d385

Please sign in to comment.