From: Jukka Kurkela Date: Thu, 16 Jul 2020 17:30:07 +0000 (+0300) Subject: Animation events sanity (#7629) X-Git-Tag: v3.0.0-beta.2~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc5f88b62020c686ccf012aba5d87873989c7661;p=thirdparty%2FChart.js.git Animation events sanity (#7629) --- diff --git a/src/core/core.animator.js b/src/core/core.animator.js index 18afeaaa3..bed5e2854 100644 --- a/src/core/core.animator.js +++ b/src/core/core.animator.js @@ -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'); diff --git a/test/specs/core.animator.tests.js b/test/specs/core.animator.tests.js new file mode 100644 index 000000000..ea68235a7 --- /dev/null +++ b/test/specs/core.animator.tests.js @@ -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 + }, + }); + }); +});