-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin): Intent to ship TextOverlap
- Split data.labels.overlap into TextOverlap plugin - Update head license comments & describe name for stanford diagram Fix #1048
- Loading branch information
Showing
13 changed files
with
328 additions
and
172 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
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
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
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,95 @@ | ||
/** | ||
* Copyright (c) 2017 ~ present NAVER Corp. | ||
* billboard.js project is licensed under the MIT license | ||
*/ | ||
/* eslint-disable */ | ||
import util from "../../assets/util"; | ||
import CLASS from "../../../src/config/classes"; | ||
import TextOverlap from "../../../src/plugin/textoverlap"; | ||
|
||
describe("PLUGIN: TEXTOVERLAP", () => { | ||
let chart; | ||
let args = { | ||
padding: { | ||
left: 50 | ||
}, | ||
data: { | ||
columns: [ | ||
["data1", 1030, 2200, 2100], | ||
["data2", 1150, 2010, 1200], | ||
["data3", -1150, -2010, -1200], | ||
["data4", -1030, -2200, -2100] | ||
], | ||
type: "line", | ||
labels: true, | ||
groups: [ | ||
["data1", "data2"], | ||
["data3", "data4"] | ||
] | ||
}, | ||
plugins: [ | ||
new TextOverlap() | ||
] | ||
}; | ||
|
||
beforeEach(() => { | ||
chart = util.generate(args); | ||
}); | ||
|
||
it("should move data labels into correct position", () => { | ||
const expectedTextDy = { | ||
data1: ["0.35em", "0.71em", "0.71em"], | ||
data2: ["0.35em", "0.35em", "0.71em"], | ||
data3: ["0.71em", "0.71em", "0.35em"], | ||
data4: ["0.71em", "0.35em", "0.35em"] | ||
}; | ||
const expectedTextTransform = { | ||
data1: ["translate(-1, -1)", "translate(-1, 6)", "translate(-1, 6)"], | ||
data2: ["translate(-1, -1)", "translate(-1, -1)", "translate(-1, 6)"], | ||
data3: ["translate(-1, 6)", "translate(-1, 6)", "translate(-1, -1)"], | ||
data4: ["translate(-1, 6)", "translate(-1, -1)", "translate(-1, -1)"] | ||
}; | ||
|
||
Object.keys(expectedTextDy).forEach(key => { | ||
chart.internal.main.selectAll(`.${CLASS.texts}-${key} text.${CLASS.text}`).each(function(d, i) { | ||
const text = d3.select(this); | ||
|
||
expect(text.attr("dy")).to.be.equal(expectedTextDy[key][i]); | ||
expect(text.attr("transform")).to.be.equal(expectedTextTransform[key][i]); | ||
}); | ||
}); | ||
}); | ||
|
||
it("set options extent & area options", () => { | ||
args.plugins = [ | ||
new TextOverlap({ | ||
extent: 8, | ||
area: 3 | ||
}) | ||
]; | ||
}); | ||
|
||
it("should move data labels into correct position with specified extent and area", () => { | ||
const expectedTextDy = { | ||
data1: ["0.35em", "0.71em", "0.71em"], | ||
data2: ["0.35em", "0.35em", "0.71em"], | ||
data3: ["0.71em", "0.71em", "0.35em"], | ||
data4: ["0.71em", "0.35em", "0.35em"] | ||
}; | ||
const expectedTextTransform = { | ||
data1: ["translate(-8, -8)", "translate(-8, 13)", "translate(-8, 13)"], | ||
data2: ["translate(-8, -8)", "translate(-8, -8)", "translate(-8, 13)"], | ||
data3: ["translate(-8, 13)", "translate(-8, 13)", "translate(-8, -8)"], | ||
data4: ["translate(-8, 13)", "translate(-8, -8)", "translate(-8, -8)"] | ||
}; | ||
|
||
Object.keys(expectedTextDy).forEach(key => { | ||
chart.internal.main.selectAll(`.${CLASS.texts}-${key} text.${CLASS.text}`).each(function(d, i) { | ||
const text = d3.select(this); | ||
|
||
expect(text.attr("dy")).to.be.equal(expectedTextDy[key][i]); | ||
expect(text.attr("transform")).to.be.equal(expectedTextTransform[key][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
Oops, something went wrong.