// Update Line
line.points = points;
+
// In resize mode only point locations change, so no need to set the options.
if (mode !== 'resize') {
- me.updateElement(line, undefined, {options: me.resolveDatasetElementOptions()}, mode);
+ me.updateElement(line, undefined, {
+ animated: !animationsDisabled,
+ options: me.resolveDatasetElementOptions()
+ }, mode);
}
// Update Points
import {_computeSegments, _boundSegments} from '../helpers/helpers.segment';
import {_steppedLineTo, _bezierCurveTo} from '../helpers/helpers.canvas';
import {_updateBezierControlPoints} from '../helpers/helpers.curve';
-import {_coordsAnimated} from '../helpers/helpers.extras';
/**
* @typedef { import("./element.point").default } PointElement
constructor(cfg) {
super();
+ this.animated = true;
this.options = undefined;
this._loop = undefined;
this._fullLoop = undefined;
* @param {number} [count]
*/
draw(ctx, chartArea, start, count) {
- const options = this.options || {};
- const points = this.points || [];
+ const me = this;
+ const options = me.options || {};
+ const points = me.points || [];
if (!points.length || !options.borderWidth) {
return;
setStyle(ctx, options);
- let path = this._path;
+ let path = me._path;
if (!path) {
- path = this._path = new Path2D();
- if (this.path(path, start, count)) {
+ path = me._path = new Path2D();
+ if (me.path(path, start, count)) {
path.closePath();
}
}
ctx.restore();
- if (_coordsAnimated(points[0]) || _coordsAnimated(points[points.length - 1])) {
- // When point coordinates are animating, we need to recalculate the
- // path (and control points when beziers are used). Only coordinates
- // matter, other animations are ignored.
- this._pointsUpdated = false;
- this._path = undefined;
+ if (me.animated) {
+ // When line is animated, the control points and path are not cached.
+ me._pointsUpdated = false;
+ me._path = undefined;
}
}
}
* @private
*/
export const _alignStartEnd = (align, start, end) => align === 'start' ? start : align === 'end' ? end : (start + end) / 2;
-
-/**
- * Return true if `x` or `y` property (coordinates) of the element is currently animated.
- * @param {object} element
- * @returns {boolean}
- * @private
- */
-export function _coordsAnimated(element) {
- const anims = element && element.$animations;
- return anims && ((anims.x && anims.x.active()) || (anims.y && anims.y.active()));
-}
expect(line).not.toBe(undefined);
expect(line.points).toEqual([1, 2, 3, 4]);
});
+
+ it('should not cache path when animations are enabled', function(done) {
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [0, -1, 0],
+ label: 'dataset1',
+ }],
+ labels: ['label1', 'label2', 'label3']
+ },
+ options: {
+ animation: {
+ duration: 50,
+ onComplete: () => {
+ expect(chart.getDatasetMeta(0).dataset._path).toBeUndefined();
+ done();
+ }
+ }
+ }
+ });
+ });
});