| ---- | ---- | ------- | -----------
| `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.
},
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
},
}
}
* @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
* @private
*/
_notify(chart, anims, date, type) {
- const callbacks = anims.listeners[type] || [];
+ const callbacks = anims.listeners[type];
const numSteps = anims.duration;
callbacks.forEach(fn => fn({
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');
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}});
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}});
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}});
}, 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();
+ }
+ }
+ }
+ }
+ });
+ });
+ });
+ });
});