Animation events sanity (#7629)

This commit is contained in:
Jukka Kurkela
2020-07-16 20:30:07 +03:00
committed by Evert Timberg
parent eff5c696dd
commit 3f9ddade9c
2 changed files with 42 additions and 3 deletions

View File

@@ -40,7 +40,7 @@ export class Animator {
callbacks.forEach(fn => fn({
chart,
numSteps,
currentStep: date - anims.start
currentStep: Math.min(date - anims.start, numSteps)
}));
}
@@ -98,14 +98,13 @@ export class Animator {
if (draw) {
chart.draw();
me._notify(chart, anims, date, 'progress');
}
if (chart.options.animation.debug) {
drawFPS(chart, items.length, date, me._lastDate);
}
me._notify(chart, anims, date, 'progress');
if (!items.length) {
anims.running = false;
me._notify(chart, anims, date, 'complete');

View File

@@ -0,0 +1,40 @@
describe('Chart.animator', function() {
it('should fire onProgress for each draw', function(done) {
let count = 0;
let drawCount = 0;
const progress = (animation) => {
count++;
expect(animation.numSteps).toEqual(250);
expect(animation.currentStep <= 250).toBeTrue();
};
acquireChart({
type: 'bar',
data: {
datasets: [
{data: [10, 5, 0, 25, 78, -10]}
],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
},
options: {
animation: {
duration: 250,
onProgress: progress,
onComplete: function() {
expect(count).toEqual(drawCount);
done();
}
}
},
plugins: [{
afterDraw() {
drawCount++;
}
}]
}, {
canvas: {
height: 150,
width: 250
},
});
});
});