From f18ae0b121da6ffe4b4fb7f2d3174d87c8a136a9 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Wed, 8 Mar 2023 16:38:23 +0100 Subject: [PATCH 1/6] Move default init animation logic to each annotation element --- src/helpers/helpers.chart.js | 4 ++-- src/helpers/helpers.options.js | 24 ++++++++++++------------ src/types/box.js | 7 ++++++- src/types/ellipse.js | 7 ++++++- src/types/label.js | 7 ++++++- src/types/line.js | 7 ++++++- src/types/point.js | 7 ++++++- src/types/polygon.js | 7 ++++++- test/specs/animation.spec.js | 2 +- 9 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/helpers/helpers.chart.js b/src/helpers/helpers.chart.js index 0d976604d..99d3b7a8c 100644 --- a/src/helpers/helpers.chart.js +++ b/src/helpers/helpers.chart.js @@ -177,9 +177,9 @@ export function resolveLineProperties(chart, options) { * @param {boolean} [centerBased=false] * @returns {AnnotationBoxModel} */ -export function resolveBoxAndLabelProperties(chart, options, centerBased) { +export function resolveBoxAndLabelProperties(chart, options, element) { const properties = resolveBoxProperties(chart, options); - properties.initProperties = initAnimationProperties(chart, properties, options, centerBased); + properties.initProperties = initAnimationProperties(chart, properties, options, element); properties.elements = [{ type: 'label', optionScope: 'label', diff --git a/src/helpers/helpers.options.js b/src/helpers/helpers.options.js index 8fffd084d..742a3e09d 100644 --- a/src/helpers/helpers.options.js +++ b/src/helpers/helpers.options.js @@ -1,4 +1,4 @@ -import {isObject, isFunction, valueOrDefault, defined, callback} from 'chart.js/helpers'; +import {isObject, isFunction, valueOrDefault, defined, callback as invoke} from 'chart.js/helpers'; import {clamp} from './helpers.core'; const isPercentString = (s) => typeof s === 'string' && s.endsWith('%'); @@ -8,6 +8,7 @@ const toPositivePercent = (s) => clamp(toPercent(s), 0, 1); /** * @typedef { import("chart.js").Chart } Chart * @typedef { import('../../types/element').AnnotationBoxModel } AnnotationBoxModel + * @typedef { import('../../types/element').AnnotationElement } AnnotationElement * @typedef { import('../../types/options').AnnotationPointCoordinates } AnnotationPointCoordinates * @typedef { import('../../types/label').CoreLabelOptions } CoreLabelOptions * @typedef { import('../../types/label').LabelPositionObject } LabelPositionObject @@ -93,17 +94,17 @@ export function isBoundToPoint(options) { * @param {Chart} chart * @param {AnnotationBoxModel} properties * @param {CoreAnnotationOptions} options - * @param {boolean} [centerBased=false] + * @param {AnnotationElement} element * @returns {AnnotationBoxModel} */ -export function initAnimationProperties(chart, properties, options, centerBased = false) { +export function initAnimationProperties(chart, properties, options, element) { const initAnim = options.init; if (!initAnim) { return; } else if (initAnim === true) { - return applyDefault(properties, centerBased); + return applyDefault(chart, properties, options, element); } - return checkCallbackResult(properties, centerBased, callback(initAnim, [{chart, properties, options}])); + return execCallback(chart, properties, options, element); } /** @@ -125,17 +126,16 @@ export function loadHooks(options, hooks, hooksContainer) { return activated; } -function applyDefault({centerX, centerY}, centerBased) { - if (centerBased) { - return {centerX, centerY, radius: 0, width: 0, height: 0}; - } - return {x: centerX, y: centerY, x2: centerX, y2: centerY, width: 0, height: 0}; +function applyDefault(chart, properties, options, element) { + return element.getInitAnimationProperties(chart, properties, options); } -function checkCallbackResult(properties, centerBased, result) { +function execCallback(chart, properties, options, element) { + const result = invoke(options.init, [{chart, properties, options}]); if (result === true) { - return applyDefault(properties, centerBased); + return applyDefault(chart, properties, options, element); } else if (isObject(result)) { return result; } + return; } diff --git a/src/types/box.js b/src/types/box.js index 66d02ae95..5543476d4 100644 --- a/src/types/box.js +++ b/src/types/box.js @@ -20,12 +20,17 @@ export default class BoxAnnotation extends Element { ctx.restore(); } + getInitAnimationProperties(chart, properties) { + const {centerX, centerY} = properties; + return {x: centerX, y: centerY, x2: centerX, y2: centerY, width: 0, height: 0}; + } + get label() { return this.elements && this.elements[0]; } resolveElementProperties(chart, options) { - return resolveBoxAndLabelProperties(chart, options); + return resolveBoxAndLabelProperties(chart, options, this); } } diff --git a/src/types/ellipse.js b/src/types/ellipse.js index 0721f1ee2..1ce659302 100644 --- a/src/types/ellipse.js +++ b/src/types/ellipse.js @@ -22,6 +22,11 @@ export default class EllipseAnnotation extends Element { return getElementCenterPoint(this, useFinalPosition); } + getInitAnimationProperties(chart, properties) { + const {centerX, centerY} = properties; + return {centerX, centerY, radius: 0, width: 0, height: 0}; + } + draw(ctx) { const {width, height, centerX, centerY, options} = this; ctx.save(); @@ -44,7 +49,7 @@ export default class EllipseAnnotation extends Element { } resolveElementProperties(chart, options) { - return resolveBoxAndLabelProperties(chart, options, true); + return resolveBoxAndLabelProperties(chart, options, this); } } diff --git a/src/types/label.js b/src/types/label.js index f1c03ce2a..7b270d3d4 100644 --- a/src/types/label.js +++ b/src/types/label.js @@ -29,6 +29,11 @@ export default class LabelAnnotation extends Element { ctx.restore(); } + getInitAnimationProperties(chart, properties) { + const {centerX, centerY} = properties; + return {x: centerX, y: centerY, x2: centerX, y2: centerY, width: 0, height: 0}; + } + resolveElementProperties(chart, options) { let point; if (!isBoundToPoint(options)) { @@ -41,7 +46,7 @@ export default class LabelAnnotation extends Element { const labelSize = measureLabelSize(chart.ctx, options); const boxSize = measureRect(point, labelSize, options, padding); return { - initProperties: initAnimationProperties(chart, boxSize, options), + initProperties: initAnimationProperties(chart, boxSize, options, this), pointX: point.x, pointY: point.y, ...boxSize, diff --git a/src/types/line.js b/src/types/line.js index ba0aaf874..a9ee2fc19 100644 --- a/src/types/line.js +++ b/src/types/line.js @@ -40,6 +40,11 @@ export default class LineAnnotation extends Element { return getElementCenterPoint(this, useFinalPosition); } + getInitAnimationProperties(chart, properties) { + const {x, y} = properties; + return {x, y, x2: x, y2: y, width: 0, height: 0}; + } + draw(ctx) { const {x, y, x2, y2, cp, options} = this; @@ -82,7 +87,7 @@ export default class LineAnnotation extends Element { : {x, y, x2, y2, width: Math.abs(x2 - x), height: Math.abs(y2 - y)}; properties.centerX = (x2 + x) / 2; properties.centerY = (y2 + y) / 2; - properties.initProperties = initAnimationProperties(chart, properties, options); + properties.initProperties = initAnimationProperties(chart, properties, options, this); if (options.curve) { const p1 = {x: properties.x, y: properties.y}; const p2 = {x: properties.x2, y: properties.y2}; diff --git a/src/types/point.js b/src/types/point.js index 696ddf4d8..b6911cc5c 100644 --- a/src/types/point.js +++ b/src/types/point.js @@ -18,6 +18,11 @@ export default class PointAnnotation extends Element { return getElementCenterPoint(this, useFinalPosition); } + getInitAnimationProperties(chart, properties) { + const {centerX, centerY} = properties; + return {centerX, centerY, radius: 0, width: 0, height: 0}; + } + draw(ctx) { const options = this.options; const borderWidth = options.borderWidth; @@ -39,7 +44,7 @@ export default class PointAnnotation extends Element { resolveElementProperties(chart, options) { const properties = resolvePointProperties(chart, options); - properties.initProperties = initAnimationProperties(chart, properties, options, true); + properties.initProperties = initAnimationProperties(chart, properties, options, this); return properties; } } diff --git a/src/types/polygon.js b/src/types/polygon.js index 2d622a7c5..041977272 100644 --- a/src/types/polygon.js +++ b/src/types/polygon.js @@ -19,6 +19,11 @@ export default class PolygonAnnotation extends Element { return getElementCenterPoint(this, useFinalPosition); } + getInitAnimationProperties(chart, properties) { + const {centerX, centerY} = properties; + return {x: centerX, y: centerY, x2: centerX, y2: centerY, width: 0, height: 0}; + } + draw(ctx) { const {elements, options} = this; ctx.save(); @@ -53,7 +58,7 @@ export default class PolygonAnnotation extends Element { let rad = rotation * RAD_PER_DEG; for (let i = 0; i < sides; i++, rad += angle) { const elProps = buildPointElement(properties, options, rad); - elProps.initProperties = initAnimationProperties(chart, properties, options); + elProps.initProperties = initAnimationProperties(chart, properties, options, this); elements.push(elProps); } properties.elements = elements; diff --git a/test/specs/animation.spec.js b/test/specs/animation.spec.js index 7d2bb4e0c..669672d7d 100644 --- a/test/specs/animation.spec.js +++ b/test/specs/animation.spec.js @@ -4,7 +4,7 @@ describe('Initial animation', function() { box: 'x', ellipse: 'width', label: 'x', - line: 'x', + line: 'x2', point: 'radius', polygon: 'y' }; From 696dd7c8a147903f1e3627205041629a37275651 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Wed, 8 Mar 2023 17:34:08 +0100 Subject: [PATCH 2/6] move defaults in an inner object of helpers --- src/helpers/helpers.chart.js | 4 ++-- src/helpers/helpers.options.js | 27 +++++++++++++++++---------- src/types/box.js | 5 ----- src/types/ellipse.js | 5 ----- src/types/label.js | 7 +------ src/types/line.js | 7 +------ src/types/point.js | 7 +------ src/types/polygon.js | 7 +------ 8 files changed, 23 insertions(+), 46 deletions(-) diff --git a/src/helpers/helpers.chart.js b/src/helpers/helpers.chart.js index 99d3b7a8c..76ab085c6 100644 --- a/src/helpers/helpers.chart.js +++ b/src/helpers/helpers.chart.js @@ -177,9 +177,9 @@ export function resolveLineProperties(chart, options) { * @param {boolean} [centerBased=false] * @returns {AnnotationBoxModel} */ -export function resolveBoxAndLabelProperties(chart, options, element) { +export function resolveBoxAndLabelProperties(chart, options) { const properties = resolveBoxProperties(chart, options); - properties.initProperties = initAnimationProperties(chart, properties, options, element); + properties.initProperties = initAnimationProperties(chart, properties, options); properties.elements = [{ type: 'label', optionScope: 'label', diff --git a/src/helpers/helpers.options.js b/src/helpers/helpers.options.js index 742a3e09d..0a33ef3cf 100644 --- a/src/helpers/helpers.options.js +++ b/src/helpers/helpers.options.js @@ -5,10 +5,18 @@ const isPercentString = (s) => typeof s === 'string' && s.endsWith('%'); const toPercent = (s) => parseFloat(s) / 100; const toPositivePercent = (s) => clamp(toPercent(s), 0, 1); +const defaultInitAnimation = { + box: (properties) => ({x: properties.centerX, y: properties.centerY, x2: properties.centerX, y2: properties.centerY, width: 0, height: 0}), + ellipse: (properties) => ({centerX: properties.centerX, centerY: properties.centerX, radius: 0, width: 0, height: 0}), + label: (properties) => ({x: properties.centerX, y: properties.centerY, x2: properties.centerX, y2: properties.centerY, width: 0, height: 0}), + line: (properties) => ({x: properties.x, y: properties.y, x2: properties.x, y2: properties.y, width: 0, height: 0}), + point: (properties) => ({centerX: properties.centerX, centerY: properties.centerY, radius: 0, width: 0, height: 0}), + polygon: (properties) => ({x: properties.centerX, y: properties.centerY, x2: properties.centerX, y2: properties.centerY, width: 0, height: 0}) +}; + /** * @typedef { import("chart.js").Chart } Chart * @typedef { import('../../types/element').AnnotationBoxModel } AnnotationBoxModel - * @typedef { import('../../types/element').AnnotationElement } AnnotationElement * @typedef { import('../../types/options').AnnotationPointCoordinates } AnnotationPointCoordinates * @typedef { import('../../types/label').CoreLabelOptions } CoreLabelOptions * @typedef { import('../../types/label').LabelPositionObject } LabelPositionObject @@ -95,16 +103,15 @@ export function isBoundToPoint(options) { * @param {AnnotationBoxModel} properties * @param {CoreAnnotationOptions} options * @param {AnnotationElement} element - * @returns {AnnotationBoxModel} */ -export function initAnimationProperties(chart, properties, options, element) { +export function initAnimationProperties(chart, properties, options) { const initAnim = options.init; if (!initAnim) { return; } else if (initAnim === true) { - return applyDefault(chart, properties, options, element); + return applyDefault(properties, options); } - return execCallback(chart, properties, options, element); + return execCallback(chart, properties, options); } /** @@ -126,16 +133,16 @@ export function loadHooks(options, hooks, hooksContainer) { return activated; } -function applyDefault(chart, properties, options, element) { - return element.getInitAnimationProperties(chart, properties, options); +function applyDefault(properties, options) { + const type = options.type || 'line'; + return defaultInitAnimation[type](properties); } -function execCallback(chart, properties, options, element) { +function execCallback(chart, properties, options) { const result = invoke(options.init, [{chart, properties, options}]); if (result === true) { - return applyDefault(chart, properties, options, element); + return applyDefault(properties, options); } else if (isObject(result)) { return result; } - return; } diff --git a/src/types/box.js b/src/types/box.js index 5543476d4..a022b4908 100644 --- a/src/types/box.js +++ b/src/types/box.js @@ -20,11 +20,6 @@ export default class BoxAnnotation extends Element { ctx.restore(); } - getInitAnimationProperties(chart, properties) { - const {centerX, centerY} = properties; - return {x: centerX, y: centerY, x2: centerX, y2: centerY, width: 0, height: 0}; - } - get label() { return this.elements && this.elements[0]; } diff --git a/src/types/ellipse.js b/src/types/ellipse.js index 1ce659302..9422beb5b 100644 --- a/src/types/ellipse.js +++ b/src/types/ellipse.js @@ -22,11 +22,6 @@ export default class EllipseAnnotation extends Element { return getElementCenterPoint(this, useFinalPosition); } - getInitAnimationProperties(chart, properties) { - const {centerX, centerY} = properties; - return {centerX, centerY, radius: 0, width: 0, height: 0}; - } - draw(ctx) { const {width, height, centerX, centerY, options} = this; ctx.save(); diff --git a/src/types/label.js b/src/types/label.js index 7b270d3d4..f1c03ce2a 100644 --- a/src/types/label.js +++ b/src/types/label.js @@ -29,11 +29,6 @@ export default class LabelAnnotation extends Element { ctx.restore(); } - getInitAnimationProperties(chart, properties) { - const {centerX, centerY} = properties; - return {x: centerX, y: centerY, x2: centerX, y2: centerY, width: 0, height: 0}; - } - resolveElementProperties(chart, options) { let point; if (!isBoundToPoint(options)) { @@ -46,7 +41,7 @@ export default class LabelAnnotation extends Element { const labelSize = measureLabelSize(chart.ctx, options); const boxSize = measureRect(point, labelSize, options, padding); return { - initProperties: initAnimationProperties(chart, boxSize, options, this), + initProperties: initAnimationProperties(chart, boxSize, options), pointX: point.x, pointY: point.y, ...boxSize, diff --git a/src/types/line.js b/src/types/line.js index a9ee2fc19..ba0aaf874 100644 --- a/src/types/line.js +++ b/src/types/line.js @@ -40,11 +40,6 @@ export default class LineAnnotation extends Element { return getElementCenterPoint(this, useFinalPosition); } - getInitAnimationProperties(chart, properties) { - const {x, y} = properties; - return {x, y, x2: x, y2: y, width: 0, height: 0}; - } - draw(ctx) { const {x, y, x2, y2, cp, options} = this; @@ -87,7 +82,7 @@ export default class LineAnnotation extends Element { : {x, y, x2, y2, width: Math.abs(x2 - x), height: Math.abs(y2 - y)}; properties.centerX = (x2 + x) / 2; properties.centerY = (y2 + y) / 2; - properties.initProperties = initAnimationProperties(chart, properties, options, this); + properties.initProperties = initAnimationProperties(chart, properties, options); if (options.curve) { const p1 = {x: properties.x, y: properties.y}; const p2 = {x: properties.x2, y: properties.y2}; diff --git a/src/types/point.js b/src/types/point.js index b6911cc5c..8fd9549d6 100644 --- a/src/types/point.js +++ b/src/types/point.js @@ -18,11 +18,6 @@ export default class PointAnnotation extends Element { return getElementCenterPoint(this, useFinalPosition); } - getInitAnimationProperties(chart, properties) { - const {centerX, centerY} = properties; - return {centerX, centerY, radius: 0, width: 0, height: 0}; - } - draw(ctx) { const options = this.options; const borderWidth = options.borderWidth; @@ -44,7 +39,7 @@ export default class PointAnnotation extends Element { resolveElementProperties(chart, options) { const properties = resolvePointProperties(chart, options); - properties.initProperties = initAnimationProperties(chart, properties, options, this); + properties.initProperties = initAnimationProperties(chart, properties, options); return properties; } } diff --git a/src/types/polygon.js b/src/types/polygon.js index 041977272..2d622a7c5 100644 --- a/src/types/polygon.js +++ b/src/types/polygon.js @@ -19,11 +19,6 @@ export default class PolygonAnnotation extends Element { return getElementCenterPoint(this, useFinalPosition); } - getInitAnimationProperties(chart, properties) { - const {centerX, centerY} = properties; - return {x: centerX, y: centerY, x2: centerX, y2: centerY, width: 0, height: 0}; - } - draw(ctx) { const {elements, options} = this; ctx.save(); @@ -58,7 +53,7 @@ export default class PolygonAnnotation extends Element { let rad = rotation * RAD_PER_DEG; for (let i = 0; i < sides; i++, rad += angle) { const elProps = buildPointElement(properties, options, rad); - elProps.initProperties = initAnimationProperties(chart, properties, options, this); + elProps.initProperties = initAnimationProperties(chart, properties, options); elements.push(elProps); } properties.elements = elements; From 6d8870bff2a60924139782b944b86370e38e9804 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Wed, 8 Mar 2023 17:35:26 +0100 Subject: [PATCH 3/6] remove element passed argument --- src/types/box.js | 2 +- src/types/ellipse.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/box.js b/src/types/box.js index a022b4908..66d02ae95 100644 --- a/src/types/box.js +++ b/src/types/box.js @@ -25,7 +25,7 @@ export default class BoxAnnotation extends Element { } resolveElementProperties(chart, options) { - return resolveBoxAndLabelProperties(chart, options, this); + return resolveBoxAndLabelProperties(chart, options); } } diff --git a/src/types/ellipse.js b/src/types/ellipse.js index 9422beb5b..bddb9511f 100644 --- a/src/types/ellipse.js +++ b/src/types/ellipse.js @@ -44,7 +44,7 @@ export default class EllipseAnnotation extends Element { } resolveElementProperties(chart, options) { - return resolveBoxAndLabelProperties(chart, options, this); + return resolveBoxAndLabelProperties(chart, options); } } From 64d5162d180790c9c5072c71ec83b64549b1aad9 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Wed, 8 Mar 2023 17:37:08 +0100 Subject: [PATCH 4/6] fixes JS doc --- src/helpers/helpers.options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/helpers.options.js b/src/helpers/helpers.options.js index 0a33ef3cf..194180aec 100644 --- a/src/helpers/helpers.options.js +++ b/src/helpers/helpers.options.js @@ -102,7 +102,7 @@ export function isBoundToPoint(options) { * @param {Chart} chart * @param {AnnotationBoxModel} properties * @param {CoreAnnotationOptions} options - * @param {AnnotationElement} element + * @returns {AnnotationBoxModel} */ export function initAnimationProperties(chart, properties, options) { const initAnim = options.init; From bcb83108281e0b2b9791ac27bca1eae1122630b2 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Wed, 8 Mar 2023 18:10:23 +0100 Subject: [PATCH 5/6] CC duplications --- src/helpers/helpers.options.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/helpers/helpers.options.js b/src/helpers/helpers.options.js index 194180aec..ad3966ed9 100644 --- a/src/helpers/helpers.options.js +++ b/src/helpers/helpers.options.js @@ -5,13 +5,14 @@ const isPercentString = (s) => typeof s === 'string' && s.endsWith('%'); const toPercent = (s) => parseFloat(s) / 100; const toPositivePercent = (s) => clamp(toPercent(s), 0, 1); +const boxAppering = (x, y) => ({x, y, x2: x, y2: y, width: 0, height: 0}); const defaultInitAnimation = { - box: (properties) => ({x: properties.centerX, y: properties.centerY, x2: properties.centerX, y2: properties.centerY, width: 0, height: 0}), + box: (properties) => boxAppering(properties.centerX, properties.centerY), ellipse: (properties) => ({centerX: properties.centerX, centerY: properties.centerX, radius: 0, width: 0, height: 0}), - label: (properties) => ({x: properties.centerX, y: properties.centerY, x2: properties.centerX, y2: properties.centerY, width: 0, height: 0}), - line: (properties) => ({x: properties.x, y: properties.y, x2: properties.x, y2: properties.y, width: 0, height: 0}), + label: (properties) => boxAppering(properties.centerX, properties.centerY), + line: (properties) => boxAppering(properties.x, properties.y), point: (properties) => ({centerX: properties.centerX, centerY: properties.centerY, radius: 0, width: 0, height: 0}), - polygon: (properties) => ({x: properties.centerX, y: properties.centerY, x2: properties.centerX, y2: properties.centerY, width: 0, height: 0}) + polygon: (properties) => boxAppering(properties.centerX, properties.centerY) }; /** From f65267a67acddfababaee65f67db571f58510309 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Thu, 9 Mar 2023 17:05:38 +0100 Subject: [PATCH 6/6] Returned value could be AnnotationElement to animate options --- docs/guide/configuration.md | 2 +- src/helpers/helpers.options.js | 3 ++- types/options.d.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/guide/configuration.md b/docs/guide/configuration.md index d05fe0ca8..c2291d63e 100644 --- a/docs/guide/configuration.md +++ b/docs/guide/configuration.md @@ -73,7 +73,7 @@ The `init` option is scriptable but it doesn't get the [options context](./optio This is the signature of the scriptable option: ```javascript -({chart, properties, options}) => void | boolean | AnnotationBoxModel +({chart, properties, options}) => void | boolean | AnnotationElement ``` where the properties is the element model diff --git a/src/helpers/helpers.options.js b/src/helpers/helpers.options.js index ad3966ed9..f0e7f0225 100644 --- a/src/helpers/helpers.options.js +++ b/src/helpers/helpers.options.js @@ -18,6 +18,7 @@ const defaultInitAnimation = { /** * @typedef { import("chart.js").Chart } Chart * @typedef { import('../../types/element').AnnotationBoxModel } AnnotationBoxModel + * @typedef { import('../../types/element').AnnotationElement } AnnotationElement * @typedef { import('../../types/options').AnnotationPointCoordinates } AnnotationPointCoordinates * @typedef { import('../../types/label').CoreLabelOptions } CoreLabelOptions * @typedef { import('../../types/label').LabelPositionObject } LabelPositionObject @@ -103,7 +104,7 @@ export function isBoundToPoint(options) { * @param {Chart} chart * @param {AnnotationBoxModel} properties * @param {CoreAnnotationOptions} options - * @returns {AnnotationBoxModel} + * @returns {AnnotationElement} */ export function initAnimationProperties(chart, properties, options) { const initAnim = options.init; diff --git a/types/options.d.ts b/types/options.d.ts index fb1c9cf1c..4a73ca499 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -1,7 +1,7 @@ import { Chart, Color, PointStyle, BorderRadius, CoreInteractionOptions } from 'chart.js'; import { AnnotationEvents, PartialEventContext, EventContext } from './events'; import { LabelOptions, BoxLabelOptions, LabelTypeOptions } from './label'; -import { AnnotationBoxModel } from './element'; +import { AnnotationBoxModel, AnnotationElement } from './element'; export type DrawTime = 'afterDraw' | 'afterDatasetsDraw' | 'beforeDraw' | 'beforeDatasetsDraw'; @@ -42,7 +42,7 @@ export interface CoreAnnotationOptions extends AnnotationEvents, ShadowOptions, borderWidth?: Scriptable, display?: Scriptable, drawTime?: Scriptable, - init: boolean | ((chart: Chart, properties: AnnotationBoxModel, options: AnnotationOptions) => void | boolean | AnnotationBoxModel), + init: boolean | ((chart: Chart, properties: AnnotationBoxModel, options: AnnotationOptions) => void | boolean | AnnotationElement), id?: string, xMax?: Scriptable, xMin?: Scriptable,