Skip to content

Commit

Permalink
fix(data): mitigate bar/bubble ranged data to handle data length than…
Browse files Browse the repository at this point in the history
… needed

Remove the strict length check to determine ranged data type
to mitigate unexpected error when data length exceed.

Fix #3096
  • Loading branch information
netil authored Feb 16, 2023
1 parent 9a172c6 commit 51603ec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ChartInternal/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ export default {

return $$.isBubbleType(d) && (
(isObject(d.value) && ("z" in d.value || "y" in d.value)) ||
(isArray(d.value) && d.value.length === 2)
(isArray(d.value) && d.value.length >= 2)
);
},

Expand All @@ -1021,7 +1021,7 @@ export default {
const $$ = this;
const {value} = d;

return $$.isBarType(d) && isArray(value) && value.length === 2 && value.every(v => isNumber(v));
return $$.isBarType(d) && isArray(value) && value.length >= 2 && value.every(v => isNumber(v));
},

/**
Expand Down
29 changes: 29 additions & 0 deletions test/internals/data-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,4 +1290,33 @@ describe("DATA", () => {
});
});
});

describe("ranged data", () => {
before(() => {
args = {
data: {
type: "bar",
columns: [,
["data1", [350, 70, 60], [230, 290], [200, 500]]
]
}
};
});

it("when bar ranged type data contains additional value than needed.", () => {
const path = chart.$.bar.bars.attr("d");

expect(/^M\d+/.test(path)).to.be.true;
});

it("set options: data.type='bubble'", () => {
args.data.type = "bubble";
});

it("when bubble dimension type data contains additional value than needed.", () => {
const r = +chart.$.circles.attr("r");

expect(r > 0).to.be.true;
});
});
});

0 comments on commit 51603ec

Please sign in to comment.