From 22d5e9f929a38157af869af7755be8e5cf7f671f Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Wed, 24 Feb 2021 16:46:20 +0200 Subject: [PATCH 1/3] Remove debug option from animation --- docs/docs/configuration/animations.mdx | 1 - src/core/core.animator.js | 20 +------------------- test/specs/core.animations.tests.js | 18 +++--------------- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/docs/docs/configuration/animations.mdx b/docs/docs/configuration/animations.mdx index f3ca5e30b51..dc816121f2a 100644 --- a/docs/docs/configuration/animations.mdx +++ b/docs/docs/configuration/animations.mdx @@ -136,7 +136,6 @@ Namespace: `options.animation` | ---- | ---- | ------- | ----------- | `duration` | `number` | `1000` | The number of milliseconds an animation takes. | `easing` | `string` | `'easeOutQuart'` | Easing function to use. [more...](#easing) -| `debug` | `boolean` | `undefined` | Running animation count + FPS display in upper left corner of the chart. | `delay` | `number` | `undefined` | Delay before starting the animations. | `loop` | `boolean` | `undefined` | If set to `true`, the animations loop endlessly. diff --git a/src/core/core.animator.js b/src/core/core.animator.js index e06651474fe..918eddad747 100644 --- a/src/core/core.animator.js +++ b/src/core/core.animator.js @@ -5,20 +5,6 @@ import {requestAnimFrame} from '../helpers/helpers.extras'; * @typedef { import("./core.controller").default } Chart */ -function drawFPS(chart, count, date, lastDate) { - const fps = (1000 / (date - lastDate)) | 0; - const ctx = chart.ctx; - ctx.save(); - ctx.clearRect(0, 0, 50, 24); - ctx.fillStyle = 'black'; - ctx.textAlign = 'right'; - if (count) { - ctx.fillText(count, 50, 8); - ctx.fillText(fps + ' fps', 50, 18); - } - ctx.restore(); -} - /** * Please use the module's default export which provides a singleton instance * Note: class is export for typedoc @@ -35,7 +21,7 @@ export class Animator { * @private */ _notify(chart, anims, date, type) { - const callbacks = anims.listeners[type] || []; + const callbacks = anims.listeners[type]; const numSteps = anims.duration; callbacks.forEach(fn => fn({ @@ -101,10 +87,6 @@ export class Animator { me._notify(chart, anims, date, 'progress'); } - if (chart.options.animation.debug) { - drawFPS(chart, items.length, date, me._lastDate); - } - if (!items.length) { anims.running = false; me._notify(chart, anims, date, 'complete'); diff --git a/test/specs/core.animations.tests.js b/test/specs/core.animations.tests.js index 6cb2d3aac4d..6b1d26fd1a7 100644 --- a/test/specs/core.animations.tests.js +++ b/test/specs/core.animations.tests.js @@ -64,11 +64,7 @@ describe('Chart.animations', function() { it('should assign shared options to target after animations complete', function(done) { const chart = { draw: function() {}, - options: { - animation: { - debug: false - } - } + options: {} }; const anims = new Chart.Animations(chart, {value: {duration: 100}, option: {duration: 200}}); @@ -100,11 +96,7 @@ describe('Chart.animations', function() { it('should not assign shared options to target when animations are cancelled', function(done) { const chart = { draw: function() {}, - options: { - animation: { - debug: false - } - } + options: {} }; const anims = new Chart.Animations(chart, {value: {duration: 100}, option: {duration: 200}}); @@ -141,11 +133,7 @@ describe('Chart.animations', function() { it('should assign final shared options to target after animations complete', function(done) { const chart = { draw: function() {}, - options: { - animation: { - debug: false - } - } + options: {} }; const anims = new Chart.Animations(chart, {value: {duration: 100}, option: {duration: 200}}); From d2e3e1ca40fafedd1e1bc2e600c69a7540b9b45b Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Wed, 24 Feb 2021 17:23:48 +0200 Subject: [PATCH 2/3] Add converage for visible animation --- test/specs/core.animations.tests.js | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/specs/core.animations.tests.js b/test/specs/core.animations.tests.js index 6b1d26fd1a7..fc2cf24297c 100644 --- a/test/specs/core.animations.tests.js +++ b/test/specs/core.animations.tests.js @@ -172,4 +172,47 @@ describe('Chart.animations', function() { }, 250); }, 50); }); + + describe('default transitions', function() { + describe('hide', function() { + it('should keep dataset visible through the animation', function(done) { + let test = false; + let count = 0; + window.acquireChart({ + type: 'line', + data: { + labels: [0], + datasets: [ + {data: [1]}, + ] + }, + options: { + animation: { + duration: 100, + onProgress: (args) => { + if (test) { + if (args.currentStep < args.numSteps) { + // while animating, visible should be truthly + expect(args.chart.getDatasetMeta(0).visible).toBeTruthy(); + count++; + } + } + }, + onComplete: (args) => { + if (!test) { + test = true; + setTimeout(() => args.chart.hide(0), 1); + } else { + // and when finished, it should be false + expect(args.chart.getDatasetMeta(0).visible).toBeFalsy(); + expect(count).toBeGreaterThan(0); + done(); + } + } + } + } + }); + }); + }); + }); }); From ef6db7350f31142fc004f8ec2273ce4f410affcf Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Wed, 24 Feb 2021 17:38:16 +0200 Subject: [PATCH 3/3] Update visible animation fn --- src/core/core.animations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/core.animations.js b/src/core/core.animations.js index 600aa71e1b6..28c0830682a 100644 --- a/src/core/core.animations.js +++ b/src/core/core.animations.js @@ -69,7 +69,7 @@ defaults.set('transitions', { }, visible: { type: 'boolean', - fn: v => v < 1 ? 0 : 1 // for keeping the dataset visible all the way through the animation + fn: v => v | 0 // for keeping the dataset visible all the way through the animation }, } }