PageSourceSearch

https://www.creusotmontceautourisme.fr/app/dist/creusotmontceau/ad…/Core/Animation/AnimationUtilities.js

js creusotmontceautourisme.fr collected 2026-09-28 12:16:54 UTC 6,043 bytes, 200 lines download raw bytes

1/* *
2 *
3 *  (c) 2010-2024 Torstein Honsi
4 *
5 *  License: www.highcharts.com/license
6 *
7 *  !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
8 *
9 * */
10'use strict';
11import Fx from './Fx.js';
12import U from '../Utilities.js';
13const { defined, getStyle, isArray, isNumber, isObject, merge, objectEach, pick } = U;
14/* *
15 *
16 *  Functions
17 *
18 * */
19/**
20 * Set the global animation to either a given value, or fall back to the given
21 * chart's animation option.
22 *
23 * @function Highcharts.setAnimation
24 *
25 * @param {boolean|Partial<Highcharts.AnimationOptionsObject>|undefined} animation
26 *        The animation object.
27 *
28 * @param {Highcharts.Chart} chart
29 *        The chart instance.
30 *
31 * @todo
32 * This function always relates to a chart, and sets a property on the renderer,
33 * so it should be moved to the SVGRenderer.
34 */
35function setAnimation(animation, chart) {
36    chart.renderer.globalAnimation = pick(animation, chart.options.chart.animation, true);
37}
38/**
39 * Get the animation in object form, where a disabled animation is always
40 * returned as `{ duration: 0 }`.
41 *
42 * @function Highcharts.animObject
43 *
44 * @param {boolean|Highcharts.AnimationOptionsObject} [animation=0]
45 *        An animation setting. Can be an object with duration, complete and
46 *        easing properties, or a boolean to enable or disable.
47 *
48 * @return {Highcharts.AnimationOptionsObject}
49 *         An object with at least a duration property.
50 */
51function animObject(animation) {
52    return isObject(animation) ?
53        merge({ duration: 500, defer: 0 }, animation) :
54        { duration: animation ? 500 : 0, defer: 0 };
55}
56/**
57 * Get the defer as a number value from series animation options.
58 *
59 * @function Highcharts.getDeferredAnimation
60 *
61 * @param {Highcharts.Chart} chart
62 *        The chart instance.
63 *
64 * @param {boolean|Highcharts.AnimationOptionsObject} animation
65 *        An animation setting. Can be an object with duration, complete and
66 *        easing properties, or a boolean to enable or disable.
67 *
68 * @param {Highcharts.Series} [series]
69 *        Series to defer animation.
70 *
71 * @return {number}
72 *        The numeric value.
73 */
74function getDeferredAnimation(chart, animation, series) {
75    const labelAnimation = animObject(animation), s = series ? [series] : chart.series;
76    let defer = 0, duration = 0;
77    s.forEach((series) => {
78        const seriesAnim = animObject(series.options.animation);
79        defer = isObject(animation) && defined(animation.defer) ?
80            labelAnimation.defer :
81            Math.max(defer, seriesAnim.duration + seriesAnim.defer);
82        duration = Math.min(labelAnimation.duration, seriesAnim.duration);
83    });
84    // Disable defer for exporting
85    if (chart.renderer.forExport) {
86        defer = 0;
87    }
88    const anim = {
89        defer: Math.max(0, defer - duration),
90        duration: Math.min(defer, duration)
91    };
92    return anim;
93}
94/**
95 * The global animate method, which uses Fx to create individual animators.
96 *
97 * @function Highcharts.animate
98 *
99 * @param {Highcharts.HTMLDOMElement|Highcharts.SVGElement} el
100 *        The element to animate.
101 *
102 * @param {Highcharts.CSSObject|Highcharts.SVGAttributes} params
103 *        An object containing key-value pairs of the properties to animate.
104 *        Supports numeric as pixel-based CSS properties for HTML objects and
105 *        attributes for SVGElements.
106 *
107 * @param {Partial<Highcharts.AnimationOptionsObject>} [opt]
108 *        Animation options.
109 *
110 * @return {void}
111 */
112function animate(el, params, opt) {
113    let start, unit = '', end, fx, args;
114    if (!isObject(opt)) { // Number or undefined/null
115        args = arguments;
116        opt = {
117            duration: args[2],
118            easing: args[3],
119            complete: args[4]
120        };
121    }
122    if (!isNumber(opt.duration)) {
123        opt.duration = 400;
124    }
125    opt.easing = typeof opt.easing === 'function' ?
126        opt.easing :
127        (Math[opt.easing] || Math.easeInOutSine);
128    opt.curAnim = merge(params);
129    objectEach(params, function (val, prop) {
130        // Stop current running animation of this property
131        stop(el, prop);
132        fx = new Fx(el, opt, prop);
133        end = void 0;
134        if (prop === 'd' && isArray(params.d)) {
135            fx.paths = fx.initPath(el, el.pathArray, params.d);
136            fx.toD = params.d;
137            start = 0;
138            end = 1;
139        }
140        else if (el.attr) {
141            start = el.attr(prop);
142        }
143        else {
144            start = parseFloat(getStyle(el, prop)) || 0;
145            if (prop !== 'opacity') {
146                unit = 'px';
147            }
148        }
149        if (!end) {
150            end = val;
151        }
152        if (typeof end === 'string' && end.match('px')) {
153            end = end.replace(/px/g, ''); // #4351
154        }
155        fx.run(start, end, unit);
156    });
157}
158/**
159 * Stop running animation.
160 *
161 * @function Highcharts.stop
162 *
163 * @param {Highcharts.SVGElement} el
164 *        The SVGElement to stop animation on.
165 *
166 * @param {string} [prop]
167 *        The property to stop animating. If given, the stop method will stop a
168 *        single property from animating, while others continue.
169 *
170 * @return {void}
171 *
172 * @todo
173 * A possible extension to this would be to stop a single property, when
174 * we want to continue animating others. Then assign the prop to the timer
175 * in the Fx.run method, and check for the prop here. This would be an
176 * improvement in all cases where we stop the animation from .attr. Instead of
177 * stopping everything, we can just stop the actual attributes we're setting.
178 */
179function stop(el, prop) {
180    let i = Fx.timers.length;
181    // Remove timers related to this element (#4519)
182    while (i--) {
183        if (Fx.timers[i].elem === el && (!prop || prop === Fx.timers[i].prop)) {
184            Fx.timers[i].stopped = true; // #4667
185        }
186    }
187}
188const animationExports = {
189    animate,
190    animObject,
191    getDeferredAnimation,
192    setAnimation,
193    stop
194};
195/* *
196 *
197 *  Default Export
198 *
199 * */
200export default animationExports;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.