Skip to content

Commit

Permalink
fix(data): Handle spaced data name for label bg color
Browse files Browse the repository at this point in the history
Suffix data id value to handle spaced data ids.

fix #2160
  • Loading branch information
netil committed Jun 28, 2021
1 parent 2b813aa commit 4ffb654
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ChartInternal/internals/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default {
}

ids.forEach(v => {
const id = `${state.datetimeId}-labels-bg-${v}`;
const id = `${state.datetimeId}-labels-bg${$$.getTargetSelectorSuffix(v)}`;

$el.defs.append("filter")
.attr("x", "0")
Expand Down
4 changes: 2 additions & 2 deletions src/ChartInternal/internals/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ export default {
let color: string = "";

if (isString(backgroundColor) || isObject(backgroundColor)) {
const id = isString(backgroundColor) ? "" : ("id" in d ? d.id : d.data.id);
const filter = $el.defs.select(["filter[id*='labels-bg-", "']"].join(id));
const id = isString(backgroundColor) ? "" : $$.getTargetSelectorSuffix(("id" in d ? d.id : d.data.id));
const filter = $el.defs.select(["filter[id*='labels-bg", "']"].join(id));

if (filter.size()) {
color = `url(#${filter.attr("id")})`;
Expand Down
8 changes: 4 additions & 4 deletions test/internals/data-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ describe("DATA", () => {
args = {
data: {
columns: [
["data1", 30, 200, 100],
["data 1 2 3", 30, 200, 100],
["data2", 430, 300, 500]
],
labels: {
Expand Down Expand Up @@ -1888,19 +1888,19 @@ describe("DATA", () => {
it("set options data.type='pie'", () => {
args.data.type = "line";
args.data.labels.backgroundColors = {
data1: "red"
"data 1": "red"
};
});

it("should set filter definition and text nodes for line type", () => {
const {$el} = chart.internal;
const filter = $el.defs.select("filter[id*='labels-bg-data1']");
const filter = $el.defs.select("filter[id*='labels-bg-data-1']");
const filterId = filter.attr("id");

expect(filter.size()).to.be.equal(1);

$el.text.each(function(d) {
if (d.id === "data1") {
if (d.id === "data-1") {
expect(this.getAttribute("filter").indexOf(filterId) > -1).to.be.ok;
} else {
expect(this.getAttribute("filter")).to.be.null;
Expand Down

0 comments on commit 4ffb654

Please sign in to comment.