-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): Correct .x()/.xs() to work properly
- Update on correct .x() update for indexed type - Added to check argument data types - Added test code Fix #634 Close #635
- Loading branch information
Showing
3 changed files
with
140 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* Copyright (c) 2017 NAVER Corp. | ||
* billboard.js project is licensed under the MIT license | ||
*/ | ||
/* eslint-disable */ | ||
import util from "../assets/util"; | ||
import CLASS from "../../src/config/classes"; | ||
|
||
describe("API x", () => { | ||
let chart; | ||
let args; | ||
|
||
beforeEach(() => { | ||
chart = util.generate(args); | ||
}); | ||
|
||
describe(".x()", () => { | ||
before(() => { | ||
args = { | ||
data: { | ||
columns: [ | ||
["data1", 30, 200, 100], | ||
["data2", 130, 100, 140] | ||
] | ||
} | ||
}; | ||
}); | ||
|
||
it("check for: indexed Axis", () => { | ||
const x = chart.x(); | ||
let xValue = [0, 1, 2]; | ||
const checkFn = v => { | ||
expect(x[v]).to.deep.equal(xValue); | ||
}; | ||
|
||
Object.keys(x).forEach(checkFn); | ||
|
||
// update x value | ||
xValue = [2,5,8]; | ||
Object.keys(chart.x(xValue)).forEach(checkFn); | ||
|
||
chart.$.main.selectAll(`.${CLASS.axisX} .tick tspan`).each(function(v, i) { | ||
expect(+this.textContent).to.be.equal(xValue[i]); | ||
}); | ||
}); | ||
|
||
it("set options for category Axis", () => { | ||
args = { | ||
data: { | ||
x: "x", | ||
columns: [ | ||
["x", "a", "b", "c"], | ||
["data1", 30, 200, 100], | ||
["data2", 130, 100, 140] | ||
] | ||
}, | ||
axis: { | ||
x: { | ||
type: "category" | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
it("check for: category Axis", () => { | ||
const x = chart.x(); | ||
let xValue = ["a", "b", "c"]; | ||
|
||
expect(x).to.be.deep.equal(xValue); | ||
|
||
xValue = ["d", "e", "f"]; | ||
expect(chart.x(xValue)).to.be.deep.equal(xValue); | ||
|
||
chart.$.main.selectAll(`.${CLASS.axisX} .tick tspan`).each(function(v, i) { | ||
expect(this.textContent).to.be.equal(xValue[i]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe(".xs()", () => { | ||
let xs = { | ||
x1: [10, 30, 45], | ||
x2: [30, 50, 75] | ||
}; | ||
|
||
before(() => { | ||
args = { | ||
data: { | ||
xs: { | ||
data1: "x1", | ||
data2: "x2" | ||
}, | ||
columns: [ | ||
["x1"].concat(xs.x1), | ||
["x2"].concat(xs.x2), | ||
["data1", 30, 200, 100], | ||
["data2", 20, 180, 240] | ||
] | ||
} | ||
}; | ||
}); | ||
|
||
it("should return & update xs values", () => { | ||
let xsValue = chart.xs(); | ||
|
||
Object.keys(xs).forEach((v, i) => { | ||
expect(xsValue[`data${i + 1}`]).to.deep.equal(xs[v]); | ||
}); | ||
|
||
xs = { | ||
data1: [15, 35, 58], | ||
data2: [33, 55, 82] | ||
}; | ||
|
||
xsValue = chart.xs(xs); | ||
expect(xsValue).to.be.deep.equal(xs); | ||
|
||
xsValue = xsValue.data1.concat(xsValue.data2).sort(); | ||
|
||
chart.$.main.selectAll(`.${CLASS.axisX} .tick tspan`).each(function(v, i) { | ||
expect(+this.textContent).to.be.equal(xsValue[i]); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters