Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove debug option from animation #8512

Merged
merged 3 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/docs/configuration/animations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/core/core.animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
}
Expand Down
20 changes: 1 addition & 19 deletions src/core/core.animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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({
Expand Down Expand Up @@ -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');
Expand Down
61 changes: 46 additions & 15 deletions test/specs/core.animations.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}});

Expand Down Expand Up @@ -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}});

Expand Down Expand Up @@ -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}});

Expand Down Expand Up @@ -184,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();
}
}
}
}
});
});
});
});
});