source: node_modules/recharts/es6/animation/AnimationManager.js@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * Represents a single item in the ReactSmoothQueue.
3 * The item can be:
4 * - A number representing a delay in milliseconds.
5 * - An object representing a style change
6 * - A StartAnimationFunction that starts eased transition and calls different render
7 * because of course in Recharts we have to have three ways to do everything
8 * - An arbitrary function to be executed
9 */
10
11export function createAnimateManager(timeoutController) {
12 var currStyle;
13 var handleChange = () => null;
14 var shouldStop = false;
15 var cancelTimeout = null;
16 var setStyle = _style => {
17 if (shouldStop) {
18 return;
19 }
20 if (Array.isArray(_style)) {
21 if (!_style.length) {
22 return;
23 }
24 var styles = _style;
25 var [curr, ...restStyles] = styles;
26 if (typeof curr === 'number') {
27 cancelTimeout = timeoutController.setTimeout(setStyle.bind(null, restStyles), curr);
28 return;
29 }
30 setStyle(curr);
31 cancelTimeout = timeoutController.setTimeout(setStyle.bind(null, restStyles));
32 return;
33 }
34 if (typeof _style === 'string') {
35 currStyle = _style;
36 handleChange(currStyle);
37 }
38 if (typeof _style === 'object') {
39 currStyle = _style;
40 handleChange(currStyle);
41 }
42 if (typeof _style === 'function') {
43 _style();
44 }
45 };
46 return {
47 stop: () => {
48 shouldStop = true;
49 },
50 start: style => {
51 shouldStop = false;
52 if (cancelTimeout) {
53 cancelTimeout();
54 cancelTimeout = null;
55 }
56 setStyle(style);
57 },
58 subscribe: _handleChange => {
59 handleChange = _handleChange;
60 return () => {
61 handleChange = () => null;
62 };
63 },
64 getTimeoutController: () => timeoutController
65 };
66}
Note: See TracBrowser for help on using the repository browser.