Skip to content

Commit

Permalink
fix(arc): Fix shape rendering when data id equivalent of color string
Browse files Browse the repository at this point in the history
For interpolation, make sure to be applied only necessary values.
Issue happened because colorish string were interpolated, which transformed
id values as interpolated color string.

Fix #3321
  • Loading branch information
netil authored and netil committed Aug 9, 2023
1 parent 0bc03d2 commit 047d1db
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/ChartInternal/shape/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,24 @@ function getRadiusFn(expandRate = 0) {
*/
function getAttrTweenFn(fn: (d: IArcData) => string) {
return function(d: IArcData): (t: number) => string {
const interpolate = d3Interpolate(this._current, d);
const getAngleKeyValue = ({startAngle = 0, endAngle = 0, padAngle = 0}) => ({
startAngle, endAngle, padAngle
});

// d3.interpolate interpolates id value, if id is given as color string(ex. gold, silver, etc)
// to avoid unexpected behavior, interpolate only angle values
// https://github.com/naver/billboard.js/issues/3321
const interpolate = d3Interpolate(
getAngleKeyValue(this._current), getAngleKeyValue(d)
);

this._current = d;

return function(t: number): string {
const interpolated = interpolate(t);
const interpolated = interpolate(t) as IArcData;
const {data, index, value} = d;

return fn(interpolated);
return fn({...interpolated, data, index, value});
};
};
}
Expand Down Expand Up @@ -310,7 +320,7 @@ export default {
.innerRadius(inner)
.outerRadius(outer);

const newArc = function(d, withoutUpdate) {
const newArc = function(d: IArcData, withoutUpdate) {
let path: string | null = "M 0 0";

if (d.value || d.data) {
Expand Down
26 changes: 26 additions & 0 deletions test/shape/arc-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,5 +879,31 @@ describe("SHAPE ARC", () => {
i++;
}, 15);
});

it("when colorish string value is used as data name", done => {
const chart = util.generate({
data: {
columns: [
["data1", 30],
["red", 120]
],
type: "donut"
},
onafterinit: function() {
setTimeout(() => {
this.focus("red");
}, 300);

setTimeout(() => {
const d = this.$.arc.select(".bb-arc-red").attr("d");

// shape shouldn't be an empty path
expect(d).to.not.be.equal("M 0 0");

done();
}, 500);
}
});
});
});
});

0 comments on commit 047d1db

Please sign in to comment.