Skip to content

Commit

Permalink
fix(shape): Correct newly added points transition position
Browse files Browse the repository at this point in the history
Check for the cx attribute for newly added point element to exclude
from the transition

Fix #648
Close #659
  • Loading branch information
netil authored Nov 19, 2018
1 parent a9159a2 commit d9dc75a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
44 changes: 44 additions & 0 deletions spec/shape/shape.point-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,48 @@ describe("SHAPE POINT", () => {
});
});
});

describe("point transition", () => {
before(() => {
args = {
data: {
columns: [
["data1", 30, 200, 100],
["data2", 130, 100, 140]
]
}
};
});

it("newly added points shouldn't be transitioning from the top/left", done => {
const main = chart.$.main;
const pos = [];
let point;
let interval;

setTimeout(() => {
interval = setInterval(() => {
point = main.select(`.${CLASS.circles}-data2 .${CLASS.circle}-3`);
pos.push(+point.attr("cx"));
}, 20);

chart.load({
columns: [
["data2", 44, 134, 98, 170]
],
done: function () {
setTimeout(() => {
clearInterval(interval);
const currPos = +point.attr("cx");

expect(Math.round(pos[0])).to.not.equal(0);
expect(pos.every(v => v === currPos)).to.be.true;

done();
}, 500);
}
});
}, 500);
});
})
});
12 changes: 7 additions & 5 deletions src/shape/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ extend(ChartInternal.prototype, {
.attr("cx", xPosFn);
}

mainCircles = mainCircles
.transition(transitionName)
.attr("cx", xPosFn)
.attr("cy", yPosFn)
.transition(transitionName);
mainCircles = element.attr("cx") ?
mainCircles.transition(transitionName)
.attr("cx", xPosFn)
.attr("cy", yPosFn)
.transition(transitionName) :
mainCircles.attr("cx", xPosFn)
.attr("cy", yPosFn);

selectedCircles.transition($$.getTransitionName());
} else {
Expand Down

0 comments on commit d9dc75a

Please sign in to comment.