@devexperts/dxcharts-lite 2.7.1 → 2.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chart/animation/canvas-animation.d.ts +19 -21
- package/dist/chart/animation/canvas-animation.js +19 -19
- package/dist/chart/animation/types/animation.d.ts +5 -17
- package/dist/chart/animation/types/animation.js +12 -17
- package/dist/chart/animation/types/color-alpha-animation.js +11 -21
- package/dist/chart/animation/types/viewport-movement-animation.d.ts +1 -1
- package/dist/chart/animation/viewport-model-animation.js +2 -2
- package/dist/chart/bootstrap.js +7 -4
- package/dist/chart/canvas/canvas-chart-html.js +1 -0
- package/dist/chart/canvas/chart-elements.d.ts +1 -0
- package/dist/chart/chart.config.d.ts +7 -0
- package/dist/chart/chart.config.js +4 -0
- package/dist/chart/components/chart/chart.component.d.ts +19 -6
- package/dist/chart/components/chart/chart.component.js +27 -8
- package/dist/chart/components/pane/pane.component.js +5 -1
- package/dist/chart/components/x_axis/x-axis-time-labels.drawer.js +4 -1
- package/dist/chart/components/y_axis/price_labels/price-label.drawer.d.ts +1 -1
- package/dist/chart/components/y_axis/price_labels/price-label.drawer.js +3 -2
- package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.d.ts +2 -1
- package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.js +5 -3
- package/dist/chart/components/y_axis/y-axis-base-labels.model.d.ts +5 -0
- package/dist/chart/components/y_axis/y-axis-base-labels.model.js +9 -0
- package/dist/chart/components/y_axis/y-axis.component.d.ts +6 -1
- package/dist/chart/components/y_axis/y-axis.component.js +14 -5
- package/dist/chart/components/y_axis/y-axis.drawer.js +5 -3
- package/dist/chart/components/y_axis/y-axis.model.d.ts +1 -1
- package/dist/chart/drawers/chart-background.drawer.d.ts +1 -0
- package/dist/chart/drawers/chart-background.drawer.js +2 -1
- package/dist/chart/drawers/chart-type-drawers/area.drawer.d.ts +2 -2
- package/dist/chart/drawers/chart-type-drawers/area.drawer.js +5 -5
- package/dist/chart/drawers/chart-type-drawers/bar.drawer.d.ts +2 -2
- package/dist/chart/drawers/chart-type-drawers/bar.drawer.js +6 -6
- package/dist/chart/drawers/chart-type-drawers/baseline.drawer.d.ts +2 -2
- package/dist/chart/drawers/chart-type-drawers/baseline.drawer.js +8 -8
- package/dist/chart/drawers/chart-type-drawers/candle.drawer.d.ts +3 -3
- package/dist/chart/drawers/chart-type-drawers/candle.drawer.js +20 -16
- package/dist/chart/drawers/chart-type-drawers/histogram.drawer.d.ts +2 -2
- package/dist/chart/drawers/chart-type-drawers/histogram.drawer.js +5 -5
- package/dist/chart/drawers/chart-type-drawers/line.drawer.d.ts +2 -2
- package/dist/chart/drawers/chart-type-drawers/line.drawer.js +5 -5
- package/dist/chart/drawers/chart-type-drawers/scatter-plot.drawer.d.ts +2 -2
- package/dist/chart/drawers/chart-type-drawers/scatter-plot.drawer.js +4 -3
- package/dist/chart/drawers/data-series-drawers/candle-series-wrapper.d.ts +2 -2
- package/dist/chart/drawers/data-series-drawers/candle-series-wrapper.js +2 -2
- package/dist/chart/drawers/data-series-drawers/color-candle.drawer.d.ts +2 -2
- package/dist/chart/drawers/data-series-drawers/color-candle.drawer.js +4 -4
- package/dist/chart/drawers/data-series-drawers/difference-cloud.drawer.d.ts +2 -2
- package/dist/chart/drawers/data-series-drawers/difference-cloud.drawer.js +9 -9
- package/dist/chart/drawers/data-series-drawers/histogram.drawer.d.ts +2 -2
- package/dist/chart/drawers/data-series-drawers/histogram.drawer.js +3 -3
- package/dist/chart/drawers/data-series-drawers/linear.drawer.d.ts +2 -2
- package/dist/chart/drawers/data-series-drawers/linear.drawer.js +3 -3
- package/dist/chart/drawers/data-series-drawers/points.drawer.d.ts +2 -2
- package/dist/chart/drawers/data-series-drawers/points.drawer.js +3 -3
- package/dist/chart/drawers/data-series-drawers/text.drawer.d.ts +2 -2
- package/dist/chart/drawers/data-series-drawers/text.drawer.js +2 -2
- package/dist/chart/drawers/data-series-drawers/trend-histogram.drawer.d.ts +2 -2
- package/dist/chart/drawers/data-series-drawers/trend-histogram.drawer.js +16 -13
- package/dist/chart/drawers/data-series-drawers/triangle.drawer.d.ts +2 -2
- package/dist/chart/drawers/data-series-drawers/triangle.drawer.js +2 -2
- package/dist/chart/drawers/data-series.drawer.d.ts +5 -5
- package/dist/chart/drawers/data-series.drawer.js +3 -3
- package/dist/chart/drawers/ht-data-series.drawer.js +2 -2
- package/dist/chart/model/scale.model.js +4 -0
- package/dist/chart/utils/numeric-constants.utils.d.ts +6 -0
- package/dist/chart/utils/numeric-constants.utils.js +6 -0
- package/dist/dxchart.min.js +5 -4
- package/package.json +1 -1
|
@@ -4,18 +4,16 @@
|
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
6
|
import EventBus from '../events/event-bus';
|
|
7
|
-
import { Animation } from './types/animation';
|
|
8
|
-
import { ColorAlphaAnimationConfig, ColorAlphaAnimation } from './types/color-alpha-animation';
|
|
9
|
-
import { ColorTransitionAnimationConfig, ColorTransitionAnimation } from './types/color-transition-animation';
|
|
10
|
-
import { ViewportMovementAnimationConfig, ViewportMovementAnimation } from './types/viewport-movement-animation';
|
|
11
|
-
import { ViewportModel } from '../model/scaling/viewport.model';
|
|
12
|
-
import { StringTMap } from '../utils/object.utils';
|
|
13
7
|
import { BehaviorSubject } from 'rxjs';
|
|
8
|
+
import { ViewportModel } from '../model/scaling/viewport.model';
|
|
9
|
+
import { ColorAlphaAnimation, ColorAlphaAnimationConfig } from './types/color-alpha-animation';
|
|
10
|
+
import { ColorTransitionAnimation, ColorTransitionAnimationConfig } from './types/color-transition-animation';
|
|
11
|
+
import { ViewportMovementAnimation, ViewportMovementAnimationConfig } from './types/viewport-movement-animation';
|
|
12
|
+
export declare const VIEWPORT_ANIMATION_ID = "VIEWPORT_ANIMATION";
|
|
14
13
|
export interface AnimationConfig {
|
|
15
14
|
duration: number;
|
|
16
15
|
timeLeft?: number;
|
|
17
16
|
}
|
|
18
|
-
export declare const VIEWPORT_ANIMATION_ID = "VIEWPORT_ANIMATION";
|
|
19
17
|
/**
|
|
20
18
|
* Singleton animation container for all chart animations.
|
|
21
19
|
* Does the following things:
|
|
@@ -28,10 +26,10 @@ export declare const VIEWPORT_ANIMATION_ID = "VIEWPORT_ANIMATION";
|
|
|
28
26
|
* @doc-tags chart-core,animation
|
|
29
27
|
*/
|
|
30
28
|
export declare class CanvasAnimation {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
animations: StringTMap<Animation>;
|
|
29
|
+
eventBus: EventBus;
|
|
30
|
+
animations: Record<string, any>;
|
|
34
31
|
animationInProgressSubject: BehaviorSubject<boolean>;
|
|
32
|
+
animFrameId: string;
|
|
35
33
|
constructor(eventBus: EventBus);
|
|
36
34
|
/**
|
|
37
35
|
* Starts a viewport movement animation with the given configuration and adds it to the list of animations.
|
|
@@ -41,7 +39,10 @@ export declare class CanvasAnimation {
|
|
|
41
39
|
* @param {Function} [onTickFunction] - The function to be called on each tick of the animation.
|
|
42
40
|
* @returns {ViewportMovementAnimation} The container for the created animation.
|
|
43
41
|
*/
|
|
44
|
-
startViewportMovementAnimation(viewportModel: ViewportModel, config: ViewportMovementAnimationConfig, uniqueAnimationId
|
|
42
|
+
startViewportMovementAnimation(viewportModel: ViewportModel, config: ViewportMovementAnimationConfig, uniqueAnimationId: string | undefined, onTickFunction: {
|
|
43
|
+
(): boolean;
|
|
44
|
+
(): void;
|
|
45
|
+
}): ViewportMovementAnimation;
|
|
45
46
|
/**
|
|
46
47
|
* Starts a color alpha animation with the given configuration and adds it to the list of animations.
|
|
47
48
|
* @param {string} uniqueAnimationId - A unique identifier for the animation.
|
|
@@ -50,7 +51,7 @@ export declare class CanvasAnimation {
|
|
|
50
51
|
* @param {Partial<ACAnimationConfig>} [animationConfig] - An optional configuration for the animation.
|
|
51
52
|
* @returns {ColorAlphaAnimation} - The created animation container.
|
|
52
53
|
*/
|
|
53
|
-
startColorAlphaAnimation(uniqueAnimationId: string, colorConfigs: Array<ColorAlphaAnimationConfig>, onTickFunction?: () => void, animationConfig?:
|
|
54
|
+
startColorAlphaAnimation(uniqueAnimationId: string, colorConfigs: Array<ColorAlphaAnimationConfig>, onTickFunction?: (() => void) | undefined, animationConfig?: AnimationConfig): ColorAlphaAnimation;
|
|
54
55
|
/**
|
|
55
56
|
* Starts a color transition animation with the given configurations and duration.
|
|
56
57
|
* @param {string} uniqueAnimationId - A unique identifier for the animation.
|
|
@@ -63,20 +64,20 @@ export declare class CanvasAnimation {
|
|
|
63
64
|
/**
|
|
64
65
|
* This function takes an id as a string and returns an animation container object of type T. It retrieves the animation container object from the animations object using the provided id. The @ts-ignore comment is used to ignore any TypeScript errors that may occur due to the dynamic nature of the function.
|
|
65
66
|
*/
|
|
66
|
-
getAnimation
|
|
67
|
+
getAnimation(id: string | number): any;
|
|
67
68
|
/**
|
|
68
69
|
* Returns a ColorAlphaAnimation object for the given animation ID.
|
|
69
70
|
*
|
|
70
71
|
* @param {string} id - The ID of the animation to retrieve.
|
|
71
72
|
* @returns {ColorAlphaAnimation} - The ColorAlphaAnimation object for the given ID.
|
|
72
73
|
*/
|
|
73
|
-
getColorAlphaAnimation(id: string):
|
|
74
|
+
getColorAlphaAnimation(id: string): any;
|
|
74
75
|
/**
|
|
75
76
|
* Returns a ColorTransitionAnimation object for the given id.
|
|
76
77
|
* @param {string} id - The id of the animation to retrieve.
|
|
77
78
|
* @returns {ColorTransitionAnimation} - The ColorTransitionAnimation object for the given id.
|
|
78
79
|
*/
|
|
79
|
-
getColorTransitionAnimation(id: string):
|
|
80
|
+
getColorTransitionAnimation(id: string): any;
|
|
80
81
|
/**
|
|
81
82
|
* Stops the animation with the given ID.
|
|
82
83
|
* @param {string} id - The ID of the animation to be stopped.
|
|
@@ -86,13 +87,10 @@ export declare class CanvasAnimation {
|
|
|
86
87
|
/**
|
|
87
88
|
* This method ensures that the animation interval is started. If the animation interval ID is not set, it sets it to a new interval ID using `window.setInterval()` with a callback function of `this.tick()` and a delay of 20 milliseconds.
|
|
88
89
|
*/
|
|
89
|
-
|
|
90
|
+
processAnimation(): void;
|
|
90
91
|
/**
|
|
91
92
|
* This is a private method that iterates through all the animations in the container and calls their tick method. If any animation is still in progress, it sets the allCompleted flag to false. If all animations are completed, it stops the interval. If not, it fires the draw event.
|
|
92
93
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
* Stops the interval for the animation.
|
|
96
|
-
*/
|
|
97
|
-
private stopInterval;
|
|
94
|
+
tick(): void;
|
|
95
|
+
stopInterval(): void;
|
|
98
96
|
}
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
+
import { BehaviorSubject } from 'rxjs';
|
|
7
|
+
import { animationFrameThrottledPrior, cancelThrottledAnimationFrame, } from '../utils/performance/request-animation-frame-throttle.utils';
|
|
8
|
+
import { uuid } from '../utils/uuid.utils';
|
|
6
9
|
import { ColorAlphaAnimation } from './types/color-alpha-animation';
|
|
7
10
|
import { ColorTransitionAnimation } from './types/color-transition-animation';
|
|
8
11
|
import { ViewportMovementAnimation } from './types/viewport-movement-animation';
|
|
9
|
-
|
|
10
|
-
const DEFAULT_ANIMATION_TIME = 10;
|
|
12
|
+
const DEFAULT_ANIMATION_TIME_MS = 400;
|
|
11
13
|
export const VIEWPORT_ANIMATION_ID = 'VIEWPORT_ANIMATION';
|
|
12
14
|
/**
|
|
13
15
|
* Singleton animation container for all chart animations.
|
|
@@ -22,9 +24,10 @@ export const VIEWPORT_ANIMATION_ID = 'VIEWPORT_ANIMATION';
|
|
|
22
24
|
*/
|
|
23
25
|
export class CanvasAnimation {
|
|
24
26
|
constructor(eventBus) {
|
|
25
|
-
this.eventBus = eventBus;
|
|
26
27
|
this.animations = {};
|
|
27
28
|
this.animationInProgressSubject = new BehaviorSubject(false);
|
|
29
|
+
this.animFrameId = `canvas_animation_${uuid()}`;
|
|
30
|
+
this.eventBus = eventBus;
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
30
33
|
* Starts a viewport movement animation with the given configuration and adds it to the list of animations.
|
|
@@ -37,7 +40,7 @@ export class CanvasAnimation {
|
|
|
37
40
|
startViewportMovementAnimation(viewportModel, config, uniqueAnimationId = VIEWPORT_ANIMATION_ID, onTickFunction) {
|
|
38
41
|
const animation = new ViewportMovementAnimation(viewportModel, config, onTickFunction);
|
|
39
42
|
this.animations[uniqueAnimationId] = animation;
|
|
40
|
-
this.
|
|
43
|
+
this.processAnimation();
|
|
41
44
|
return animation;
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
@@ -49,9 +52,9 @@ export class CanvasAnimation {
|
|
|
49
52
|
* @returns {ColorAlphaAnimation} - The created animation container.
|
|
50
53
|
*/
|
|
51
54
|
startColorAlphaAnimation(uniqueAnimationId, colorConfigs, onTickFunction, animationConfig) {
|
|
52
|
-
const animation = new ColorAlphaAnimation(Object.assign(Object.assign({}, animationConfig), { duration: (animationConfig && animationConfig.duration) ||
|
|
55
|
+
const animation = new ColorAlphaAnimation(Object.assign(Object.assign({}, animationConfig), { duration: (animationConfig && animationConfig.duration) || DEFAULT_ANIMATION_TIME_MS }), colorConfigs, onTickFunction);
|
|
53
56
|
this.animations[uniqueAnimationId] = animation;
|
|
54
|
-
this.
|
|
57
|
+
this.processAnimation();
|
|
55
58
|
return animation;
|
|
56
59
|
}
|
|
57
60
|
/**
|
|
@@ -62,10 +65,10 @@ export class CanvasAnimation {
|
|
|
62
65
|
* @param {Function} [onTickFunction] - A function to be called on each tick of the animation.
|
|
63
66
|
* @returns {ColorTransitionAnimation} - The created animation container.
|
|
64
67
|
*/
|
|
65
|
-
startColorTransitionAnimation(uniqueAnimationId, colorConfigs, duration =
|
|
68
|
+
startColorTransitionAnimation(uniqueAnimationId, colorConfigs, duration = DEFAULT_ANIMATION_TIME_MS, onTickFunction) {
|
|
66
69
|
const animation = new ColorTransitionAnimation({ duration }, colorConfigs, onTickFunction);
|
|
67
70
|
this.animations[uniqueAnimationId] = animation;
|
|
68
|
-
this.
|
|
71
|
+
this.processAnimation();
|
|
69
72
|
return animation;
|
|
70
73
|
}
|
|
71
74
|
/**
|
|
@@ -100,17 +103,15 @@ export class CanvasAnimation {
|
|
|
100
103
|
forceStopAnimation(id) {
|
|
101
104
|
const animation = this.animations[id];
|
|
102
105
|
if (animation) {
|
|
103
|
-
animation.animationTimeLeft = -1;
|
|
104
106
|
animation.animationInProgress = false;
|
|
107
|
+
animation.animationStartTime = 0;
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
/**
|
|
108
111
|
* This method ensures that the animation interval is started. If the animation interval ID is not set, it sets it to a new interval ID using `window.setInterval()` with a callback function of `this.tick()` and a delay of 20 milliseconds.
|
|
109
112
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.animationIntervalId = window.setInterval(() => this.tick(), 20);
|
|
113
|
-
}
|
|
113
|
+
processAnimation() {
|
|
114
|
+
animationFrameThrottledPrior(this.animFrameId, () => this.tick());
|
|
114
115
|
}
|
|
115
116
|
/**
|
|
116
117
|
* This is a private method that iterates through all the animations in the container and calls their tick method. If any animation is still in progress, it sets the allCompleted flag to false. If all animations are completed, it stops the interval. If not, it fires the draw event.
|
|
@@ -126,17 +127,16 @@ export class CanvasAnimation {
|
|
|
126
127
|
}
|
|
127
128
|
this.animationInProgressSubject.next(!allCompleted);
|
|
128
129
|
if (!allCompleted) {
|
|
129
|
-
|
|
130
|
+
queueMicrotask(() => {
|
|
131
|
+
this.processAnimation();
|
|
132
|
+
this.eventBus.fireDraw();
|
|
133
|
+
});
|
|
130
134
|
}
|
|
131
135
|
else {
|
|
132
136
|
this.stopInterval();
|
|
133
137
|
}
|
|
134
138
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Stops the interval for the animation.
|
|
137
|
-
*/
|
|
138
139
|
stopInterval() {
|
|
139
|
-
|
|
140
|
-
this.animationIntervalId = undefined;
|
|
140
|
+
cancelThrottledAnimationFrame(this.animFrameId);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
@@ -4,32 +4,20 @@
|
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
6
|
import { AnimationConfig } from '../canvas-animation';
|
|
7
|
-
|
|
8
|
-
tick: () => void;
|
|
9
|
-
}
|
|
7
|
+
type OnTickFunction = () => void;
|
|
10
8
|
/**
|
|
11
9
|
* Basic animation. Holds current state: inProgress, timeLeft.
|
|
12
10
|
* Additional params are useful to pass data which helps animating.
|
|
13
11
|
*/
|
|
14
|
-
export declare class Animation
|
|
15
|
-
private onTickFunction?;
|
|
12
|
+
export declare class Animation {
|
|
16
13
|
animationTime: number;
|
|
17
14
|
animationTimeLeft: number;
|
|
15
|
+
animationStartTime: number;
|
|
18
16
|
animationInProgress: boolean;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* Decrements the animation time left and executes the onTickFunction if it exists.
|
|
22
|
-
* If the animation time left reaches zero, sets the animationInProgress flag to false.
|
|
23
|
-
*/
|
|
17
|
+
onTickFunction?: OnTickFunction;
|
|
18
|
+
constructor(animationConfig: AnimationConfig, onTickFunction: OnTickFunction);
|
|
24
19
|
tick(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Calculates the normalized progress of an animation.
|
|
27
|
-
* @returns {number} A value between 0 and 1 representing the progress of the animation.
|
|
28
|
-
*/
|
|
29
20
|
getProgress(): number;
|
|
30
|
-
/**
|
|
31
|
-
* Sets the animationInProgress flag to false and resets the animationTimeLeft to 0.
|
|
32
|
-
*/
|
|
33
21
|
finishAnimation(): void;
|
|
34
22
|
}
|
|
35
23
|
export {};
|
|
@@ -9,40 +9,35 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export class Animation {
|
|
11
11
|
constructor(animationConfig, onTickFunction) {
|
|
12
|
-
this.onTickFunction = onTickFunction;
|
|
13
12
|
this.animationTimeLeft = 0;
|
|
14
|
-
this.
|
|
13
|
+
this.onTickFunction = onTickFunction;
|
|
15
14
|
this.animationTime = animationConfig.duration;
|
|
16
|
-
this.
|
|
17
|
-
animationConfig.timeLeft === undefined ? animationConfig.duration : animationConfig.timeLeft;
|
|
15
|
+
this.animationStartTime = Date.now();
|
|
18
16
|
this.animationInProgress = true;
|
|
19
17
|
}
|
|
20
|
-
|
|
18
|
+
/*
|
|
21
19
|
* Decrements the animation time left and executes the onTickFunction if it exists.
|
|
22
20
|
* If the animation time left reaches zero, sets the animationInProgress flag to false.
|
|
23
21
|
*/
|
|
24
22
|
tick() {
|
|
25
|
-
|
|
23
|
+
var _a;
|
|
24
|
+
if (Date.now() > this.animationStartTime + this.animationTime) {
|
|
26
25
|
this.animationInProgress = false;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
this.animationTimeLeft--;
|
|
30
|
-
}
|
|
31
|
-
this.onTickFunction && this.onTickFunction();
|
|
27
|
+
(_a = this.onTickFunction) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* Calculates the normalized progress of an animation.
|
|
29
|
+
/*
|
|
30
|
+
* Gets the normalized progress of the animation.
|
|
36
31
|
* @returns {number} A value between 0 and 1 representing the progress of the animation.
|
|
37
32
|
*/
|
|
38
33
|
getProgress() {
|
|
39
|
-
return
|
|
34
|
+
return Math.min((Date.now() - this.animationStartTime) / this.animationTime, 1);
|
|
40
35
|
}
|
|
41
|
-
|
|
42
|
-
* Sets the animationInProgress flag to false and resets the
|
|
36
|
+
/*
|
|
37
|
+
* Sets the animationInProgress flag to false and resets the animationStartTime to 0.
|
|
43
38
|
*/
|
|
44
39
|
finishAnimation() {
|
|
45
40
|
this.animationInProgress = false;
|
|
46
|
-
this.
|
|
41
|
+
this.animationStartTime = 0;
|
|
47
42
|
}
|
|
48
43
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
+
import { clamp } from '../../utils/math.utils';
|
|
6
7
|
import { Animation } from './animation';
|
|
7
8
|
import Color from 'color';
|
|
8
9
|
/**
|
|
@@ -24,19 +25,13 @@ export class ColorAlphaAnimation extends Animation {
|
|
|
24
25
|
*/
|
|
25
26
|
tick() {
|
|
26
27
|
super.tick();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
else if (config.type === 'appearing') {
|
|
36
|
-
config.currentAnimationColor = config.rgbColor.alpha(config.initialAlpha * (1 - this.animationTimeLeft / this.animationTime));
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
28
|
+
this.colorConfigs.forEach(config => {
|
|
29
|
+
if (config.initialAlpha === undefined || config.rgbColor === undefined) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const alpha = config.initialAlpha * (config.type === 'fading' ? 1 - this.getProgress() : this.getProgress());
|
|
33
|
+
config.currentAnimationColor = config.rgbColor.alpha(alpha);
|
|
34
|
+
});
|
|
40
35
|
}
|
|
41
36
|
/**
|
|
42
37
|
* Returns the color of the current animation for a given index.
|
|
@@ -51,15 +46,10 @@ export class ColorAlphaAnimation extends Animation {
|
|
|
51
46
|
* This function reverts the animation by changing the type of color configurations from 'fading' to 'appearing' and vice versa. It also ensures that the animationTimeLeft is not zero to avoid getting stuck in the middle of the animation.
|
|
52
47
|
*/
|
|
53
48
|
revert() {
|
|
54
|
-
|
|
55
|
-
this.
|
|
49
|
+
const timePassed = clamp(Date.now() - this.animationStartTime, 0, this.animationTime);
|
|
50
|
+
this.animationStartTime = Date.now() - this.animationTime + timePassed;
|
|
56
51
|
this.colorConfigs.forEach(config => {
|
|
57
|
-
|
|
58
|
-
config.type = 'appearing';
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
config.type = 'fading';
|
|
62
|
-
}
|
|
52
|
+
config.type = config.type === 'fading' ? 'appearing' : 'fading';
|
|
63
53
|
});
|
|
64
54
|
}
|
|
65
55
|
}
|
|
@@ -32,7 +32,7 @@ export declare class ViewportMovementAnimation extends Animation {
|
|
|
32
32
|
readonly zoomY: number;
|
|
33
33
|
readonly easingFn: easingFn;
|
|
34
34
|
readonly id: string;
|
|
35
|
-
constructor(viewportModel: ViewportModel, animationConfig: ViewportMovementAnimationConfig, onTickFunction
|
|
35
|
+
constructor(viewportModel: ViewportModel, animationConfig: ViewportMovementAnimationConfig, onTickFunction: () => void);
|
|
36
36
|
/**
|
|
37
37
|
* Updates the viewport model's properties based on the animation configuration and easing function. If an animation is in progress, the properties are updated based on the current progress of the animation. The updated properties include the start and end coordinates for the x and y axes, as well as the zoom level for both axes. The updated properties are then applied to the viewport model.
|
|
38
38
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
6
|
import { VIEWPORT_ANIMATION_ID } from './canvas-animation';
|
|
7
|
-
const
|
|
7
|
+
const VIEWPORT_ANIMATION_DURATION_MS = 400;
|
|
8
8
|
/**
|
|
9
9
|
* Starts the animation for chart viewport movement.
|
|
10
10
|
* @param canvasAnimation
|
|
@@ -14,7 +14,7 @@ const VIEWPORT_ANIMATION_DURATION = 20;
|
|
|
14
14
|
*/
|
|
15
15
|
export const startViewportModelAnimation = (canvasAnimation, viewportModel, state) => {
|
|
16
16
|
const animation = canvasAnimation.startViewportMovementAnimation(viewportModel, {
|
|
17
|
-
duration:
|
|
17
|
+
duration: VIEWPORT_ANIMATION_DURATION_MS,
|
|
18
18
|
targetXStart: state.xStart,
|
|
19
19
|
targetXEnd: state.xEnd,
|
|
20
20
|
targetYStart: state.yStart,
|
package/dist/chart/bootstrap.js
CHANGED
|
@@ -88,6 +88,7 @@ export default class ChartBootstrap {
|
|
|
88
88
|
const dataSeriesCanvasClearDrawer = new ClearCanvasDrawer(this.dynamicObjectsCanvasModel);
|
|
89
89
|
drawingManager.addDrawer(dataSeriesCanvasClearDrawer, 'SERIES_CLEAR');
|
|
90
90
|
const yAxisLabelsCanvasModel = createCanvasModel(eventBus, elements.yAxisLabelsCanvas, config, drawingManager, this.canvasModels, elements.chartResizer);
|
|
91
|
+
const yAxisDescriptionsCanvasModel = createCanvasModel(eventBus, elements.yAxisDescriptionsCanvas, config, drawingManager, this.canvasModels, elements.chartResizer);
|
|
91
92
|
const canvasBoundsContainer = new CanvasBoundsContainer(config, eventBus, mainCanvasModel, formatterFactory, chartResizeHandler);
|
|
92
93
|
this.canvasBoundsContainer = canvasBoundsContainer;
|
|
93
94
|
//#region main canvas user input listeners
|
|
@@ -172,7 +173,7 @@ export default class ChartBootstrap {
|
|
|
172
173
|
// high low component
|
|
173
174
|
const highLowComponent = new HighLowComponent(config, this.dynamicObjectsCanvasModel, chartModel, canvasBoundsContainer, drawingManager);
|
|
174
175
|
this.chartComponents.push(highLowComponent);
|
|
175
|
-
this.initYAxisDrawer(yAxisLabelsCanvasModel);
|
|
176
|
+
this.initYAxisDrawer(yAxisLabelsCanvasModel, yAxisDescriptionsCanvasModel);
|
|
176
177
|
this.yAxisComponent = mainPane.mainExtent.yAxis;
|
|
177
178
|
// default labels provider
|
|
178
179
|
const lastCandleLabelsProvider = new LastCandleLabelsProvider(this.chartModel, this.config, mainPane.mainExtent.yAxis.state, this.chartModel.lastCandleLabelsByChartType, this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));
|
|
@@ -201,15 +202,17 @@ export default class ChartBootstrap {
|
|
|
201
202
|
drawingManager.reorderDrawers(config.drawingOrder);
|
|
202
203
|
this.clearer = clearerSafe(this.components);
|
|
203
204
|
}
|
|
204
|
-
initYAxisDrawer(yAxisLabelsCanvasModel) {
|
|
205
|
+
initYAxisDrawer(yAxisLabelsCanvasModel, yAxisDescriptionsCanvasModel) {
|
|
205
206
|
const yAxisCompositeDrawer = new CompositeDrawer();
|
|
206
207
|
const clearYAxis = new ClearCanvasDrawer(yAxisLabelsCanvasModel);
|
|
208
|
+
const clearYAxisDescriptions = new ClearCanvasDrawer(yAxisDescriptionsCanvasModel);
|
|
207
209
|
yAxisCompositeDrawer.addDrawer(clearYAxis, 'YAXIS_CLEAR');
|
|
210
|
+
yAxisCompositeDrawer.addDrawer(clearYAxisDescriptions, 'Y_AXIS_DESCRIPTIONS_CLEAR');
|
|
208
211
|
this.drawingManager.addDrawer(yAxisCompositeDrawer, 'Y_AXIS');
|
|
209
212
|
const yAxisDrawer = new YAxisDrawer(this.config, yAxisLabelsCanvasModel, this.paneManager);
|
|
210
213
|
yAxisCompositeDrawer.addDrawer(yAxisDrawer);
|
|
211
|
-
const
|
|
212
|
-
|
|
214
|
+
const yAxisPriceLabelsDrawer = new YAxisPriceLabelsDrawer(yAxisLabelsCanvasModel, yAxisDescriptionsCanvasModel, this.backgroundCanvasModel, this.canvasBoundsContainer, this.config, this.paneManager);
|
|
215
|
+
this.drawingManager.addDrawer(yAxisPriceLabelsDrawer, 'Y_AXIS_PRICE_LABELS');
|
|
213
216
|
}
|
|
214
217
|
// TODO remove chartModel dependency, put period to global config somewhere
|
|
215
218
|
/**
|
|
@@ -11,6 +11,7 @@ export default (devexpertsPromoLink) => '<div data-element="chartResizer" style=
|
|
|
11
11
|
'\t\t\t<canvas data-element="mainCanvas"></canvas>\n' +
|
|
12
12
|
'\t\t\t<canvas data-element="yAxisLabelsCanvas"></canvas>\n' +
|
|
13
13
|
'\t\t\t<canvas data-element="dynamicObjectsCanvas"></canvas>\n' +
|
|
14
|
+
'\t\t\t<canvas data-element="yAxisDescriptionsCanvas"></canvas>\n' +
|
|
14
15
|
'\t\t\t<canvas data-element="crossToolCanvas"></canvas>\n' +
|
|
15
16
|
'\t\t\t<canvas data-element="hitTestCanvas"></canvas>\n' +
|
|
16
17
|
`${devexpertsPromoLink
|
|
@@ -10,6 +10,7 @@ export interface ChartElements {
|
|
|
10
10
|
mainCanvas?: HTMLCanvasElement;
|
|
11
11
|
dynamicObjectsCanvas?: HTMLCanvasElement;
|
|
12
12
|
yAxisLabelsCanvas?: HTMLCanvasElement;
|
|
13
|
+
yAxisDescriptionsCanvas?: HTMLCanvasElement;
|
|
13
14
|
crossToolCanvas?: HTMLCanvasElement;
|
|
14
15
|
hitTestCanvas?: HTMLCanvasElement;
|
|
15
16
|
chartResizer?: HTMLElement;
|
|
@@ -322,6 +322,13 @@ export interface ChartConfigComponentsChart {
|
|
|
322
322
|
* The maximum amount of Y axis scales on a single chart
|
|
323
323
|
*/
|
|
324
324
|
maxYAxisScalesAmount: number;
|
|
325
|
+
/**
|
|
326
|
+
* Background color will be also applied to the chart axes
|
|
327
|
+
*/
|
|
328
|
+
applyBackgroundToAxes: {
|
|
329
|
+
x: boolean;
|
|
330
|
+
y: boolean;
|
|
331
|
+
};
|
|
325
332
|
sortCandles?: (candles: Candle[]) => Candle[];
|
|
326
333
|
}
|
|
327
334
|
export interface ChartConfigComponentsEvents {
|
|
@@ -117,6 +117,7 @@ export declare class ChartComponent extends ChartBaseElement {
|
|
|
117
117
|
* Sets the timestamp range of the chart by setting the x-axis scale.
|
|
118
118
|
* @param {Timestamp} start - The start timestamp of the range.
|
|
119
119
|
* @param {Timestamp} end - The end timestamp of the range.
|
|
120
|
+
* @param {boolean} forceNoAnimation - true by default
|
|
120
121
|
* @returns {void}
|
|
121
122
|
*/
|
|
122
123
|
setTimestampRange(start: Timestamp, end: Timestamp, forceNoAnimation?: boolean): void;
|
|
@@ -124,6 +125,7 @@ export declare class ChartComponent extends ChartBaseElement {
|
|
|
124
125
|
* Moves the viewport to exactly xStart..xEnd place.
|
|
125
126
|
* @param xStart - viewport start in units
|
|
126
127
|
* @param xEnd - viewport end in units
|
|
128
|
+
* @param {boolean} forceNoAnimation - true by default
|
|
127
129
|
*/
|
|
128
130
|
setXScale(xStart: Unit, xEnd: Unit, forceNoAnimation?: boolean): void;
|
|
129
131
|
/**
|
|
@@ -132,6 +134,17 @@ export declare class ChartComponent extends ChartBaseElement {
|
|
|
132
134
|
* @returns {void}
|
|
133
135
|
*/
|
|
134
136
|
setShowWicks(isShow: boolean): void;
|
|
137
|
+
/**
|
|
138
|
+
* Sets the options for the background color applying to the chart axes
|
|
139
|
+
* @param {Object} options - options for both axes
|
|
140
|
+
* @param {boolean} options.x - should the background color apply to the x axis
|
|
141
|
+
* @param {boolean} options.y - should the background color apply to the y axis
|
|
142
|
+
* @returns {void}
|
|
143
|
+
*/
|
|
144
|
+
setApplyBackgroundToAxes(options: {
|
|
145
|
+
x: boolean;
|
|
146
|
+
y: boolean;
|
|
147
|
+
}): void;
|
|
135
148
|
/**
|
|
136
149
|
* Used to set the main series to chart.
|
|
137
150
|
* @param series
|
|
@@ -171,12 +184,12 @@ export declare class ChartComponent extends ChartBaseElement {
|
|
|
171
184
|
/**
|
|
172
185
|
* Removes all data points from the main candle series that are newer than the given timestamp.
|
|
173
186
|
* Can be useful for data replay.
|
|
174
|
-
* @param
|
|
187
|
+
* @param {Timestamp } timestamp
|
|
175
188
|
*/
|
|
176
189
|
removeDataFrom(timestamp: Timestamp): void;
|
|
177
190
|
/**
|
|
178
191
|
* Removes chart candles series.
|
|
179
|
-
* @param
|
|
192
|
+
* @param {CandleSeriesModel} series
|
|
180
193
|
*/
|
|
181
194
|
removeSecondarySeries(series: CandleSeriesModel): void;
|
|
182
195
|
/**
|
|
@@ -223,13 +236,13 @@ export declare class ChartComponent extends ChartBaseElement {
|
|
|
223
236
|
/**
|
|
224
237
|
* Updates last candle value
|
|
225
238
|
* @param candle - updated candle
|
|
226
|
-
* @param instrumentSymbol - name of the instrument to update
|
|
239
|
+
* @param {string} instrumentSymbol - name of the instrument to update
|
|
227
240
|
*/
|
|
228
241
|
updateLastCandle(candle: Candle, instrumentSymbol?: string): void;
|
|
229
242
|
/**
|
|
230
243
|
* Updates candle series for instrument. By default takes main instrument.
|
|
231
|
-
* @param candles
|
|
232
|
-
* @param instrument
|
|
244
|
+
* @param {Array<Candle>} candles
|
|
245
|
+
* @param {string} instrumentSymbol - name of the instrument to update
|
|
233
246
|
*/
|
|
234
247
|
updateCandles(candles: Array<Candle>, instrumentSymbol?: string): void;
|
|
235
248
|
/**
|
|
@@ -246,7 +259,7 @@ export declare class ChartComponent extends ChartBaseElement {
|
|
|
246
259
|
/**
|
|
247
260
|
* Registers a new chart type drawer or overrides default drawer if drawerType is {BarType}.
|
|
248
261
|
* @param drawerType {string} - a unique name for the drawer, could be {BarType} - in this case will override default drawer for the type
|
|
249
|
-
* @param drawer {
|
|
262
|
+
* @param drawer {SeriesDrawer} - an implementation of the drawer
|
|
250
263
|
*/
|
|
251
264
|
registerDataSeriesTypeDrawer(drawerType: DataSeriesType, drawer: SeriesDrawer): void;
|
|
252
265
|
/**
|
|
@@ -27,10 +27,12 @@ import { HIT_TEST_PREFIX } from '../../drawers/drawing-manager';
|
|
|
27
27
|
import { HTDataSeriesDrawer } from '../../drawers/ht-data-series.drawer';
|
|
28
28
|
import { BaselineModel } from '../../model/baseline.model';
|
|
29
29
|
import { keys } from '../../utils/object.utils';
|
|
30
|
+
import { ONE_FRAME_MS } from '../../utils/numeric-constants.utils';
|
|
30
31
|
import { PriceIncrementsUtils } from '../../utils/price-increments.utils';
|
|
31
32
|
import { defaultCandleTransformer, hollowCandleTransformer, lineCandleTransformer, trendCandleTransformer, } from './candle-transformer.functions';
|
|
32
33
|
import { deleteCandlesIndex } from './candle.functions';
|
|
33
34
|
import { TrendHistogramDrawer } from '../../drawers/data-series-drawers/trend-histogram.drawer';
|
|
35
|
+
import { debounce } from '../../utils/performance/debounce.utils';
|
|
34
36
|
/**
|
|
35
37
|
* Represents a financial instrument to be displayed on a chart
|
|
36
38
|
* @class
|
|
@@ -109,9 +111,13 @@ export class ChartComponent extends ChartBaseElement {
|
|
|
109
111
|
this.dynamicObjects.model.removeObject(series.id);
|
|
110
112
|
}));
|
|
111
113
|
// redraw background only when chart is resized
|
|
112
|
-
this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(() => {
|
|
114
|
+
this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(debounce(() => {
|
|
115
|
+
// there is multiple calls on this bounds change on lots of sources,
|
|
116
|
+
// and sometimes this calls mixes with this.chartResizeHandler.canvasResized
|
|
117
|
+
// and this leads to change of background in situations when it's not needed,
|
|
118
|
+
// so on multiple calls in one frame we debounced it to avoid that collisions and steam races
|
|
113
119
|
this.backgroundDrawerPredicateSubject.next(false);
|
|
114
|
-
}));
|
|
120
|
+
}, ONE_FRAME_MS)));
|
|
115
121
|
this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(() => {
|
|
116
122
|
this.backgroundDrawerPredicateSubject.next(true);
|
|
117
123
|
}));
|
|
@@ -206,6 +212,7 @@ export class ChartComponent extends ChartBaseElement {
|
|
|
206
212
|
* Sets the timestamp range of the chart by setting the x-axis scale.
|
|
207
213
|
* @param {Timestamp} start - The start timestamp of the range.
|
|
208
214
|
* @param {Timestamp} end - The end timestamp of the range.
|
|
215
|
+
* @param {boolean} forceNoAnimation - true by default
|
|
209
216
|
* @returns {void}
|
|
210
217
|
*/
|
|
211
218
|
setTimestampRange(start, end, forceNoAnimation = true) {
|
|
@@ -215,6 +222,7 @@ export class ChartComponent extends ChartBaseElement {
|
|
|
215
222
|
* Moves the viewport to exactly xStart..xEnd place.
|
|
216
223
|
* @param xStart - viewport start in units
|
|
217
224
|
* @param xEnd - viewport end in units
|
|
225
|
+
* @param {boolean} forceNoAnimation - true by default
|
|
218
226
|
*/
|
|
219
227
|
setXScale(xStart, xEnd, forceNoAnimation = true) {
|
|
220
228
|
return this.scale.setXScale(xStart, xEnd, forceNoAnimation);
|
|
@@ -228,6 +236,17 @@ export class ChartComponent extends ChartBaseElement {
|
|
|
228
236
|
this.config.components.chart.showWicks = isShow;
|
|
229
237
|
this.canvasModel.fireDraw();
|
|
230
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Sets the options for the background color applying to the chart axes
|
|
241
|
+
* @param {Object} options - options for both axes
|
|
242
|
+
* @param {boolean} options.x - should the background color apply to the x axis
|
|
243
|
+
* @param {boolean} options.y - should the background color apply to the y axis
|
|
244
|
+
* @returns {void}
|
|
245
|
+
*/
|
|
246
|
+
setApplyBackgroundToAxes(options) {
|
|
247
|
+
this.config.components.chart.applyBackgroundToAxes = Object.assign({}, options);
|
|
248
|
+
this.chartModel.bus.fireDraw();
|
|
249
|
+
}
|
|
231
250
|
/**
|
|
232
251
|
* Used to set the main series to chart.
|
|
233
252
|
* @param series
|
|
@@ -314,14 +333,14 @@ export class ChartComponent extends ChartBaseElement {
|
|
|
314
333
|
/**
|
|
315
334
|
* Removes all data points from the main candle series that are newer than the given timestamp.
|
|
316
335
|
* Can be useful for data replay.
|
|
317
|
-
* @param
|
|
336
|
+
* @param {Timestamp } timestamp
|
|
318
337
|
*/
|
|
319
338
|
removeDataFrom(timestamp) {
|
|
320
339
|
this.chartModel.removeDataFrom(timestamp);
|
|
321
340
|
}
|
|
322
341
|
/**
|
|
323
342
|
* Removes chart candles series.
|
|
324
|
-
* @param
|
|
343
|
+
* @param {CandleSeriesModel} series
|
|
325
344
|
*/
|
|
326
345
|
removeSecondarySeries(series) {
|
|
327
346
|
this.chartModel.removeSecondaryCandleSeries(series);
|
|
@@ -382,15 +401,15 @@ export class ChartComponent extends ChartBaseElement {
|
|
|
382
401
|
/**
|
|
383
402
|
* Updates last candle value
|
|
384
403
|
* @param candle - updated candle
|
|
385
|
-
* @param instrumentSymbol - name of the instrument to update
|
|
404
|
+
* @param {string} instrumentSymbol - name of the instrument to update
|
|
386
405
|
*/
|
|
387
406
|
updateLastCandle(candle, instrumentSymbol) {
|
|
388
407
|
this.chartModel.updateLastCandle(candle, instrumentSymbol);
|
|
389
408
|
}
|
|
390
409
|
/**
|
|
391
410
|
* Updates candle series for instrument. By default takes main instrument.
|
|
392
|
-
* @param candles
|
|
393
|
-
* @param instrument
|
|
411
|
+
* @param {Array<Candle>} candles
|
|
412
|
+
* @param {string} instrumentSymbol - name of the instrument to update
|
|
394
413
|
*/
|
|
395
414
|
updateCandles(candles, instrumentSymbol) {
|
|
396
415
|
this.chartModel.updateCandles(candles, instrumentSymbol);
|
|
@@ -413,7 +432,7 @@ export class ChartComponent extends ChartBaseElement {
|
|
|
413
432
|
/**
|
|
414
433
|
* Registers a new chart type drawer or overrides default drawer if drawerType is {BarType}.
|
|
415
434
|
* @param drawerType {string} - a unique name for the drawer, could be {BarType} - in this case will override default drawer for the type
|
|
416
|
-
* @param drawer {
|
|
435
|
+
* @param drawer {SeriesDrawer} - an implementation of the drawer
|
|
417
436
|
*/
|
|
418
437
|
registerDataSeriesTypeDrawer(drawerType, drawer) {
|
|
419
438
|
this._dataSeriesDrawers[drawerType] = drawer;
|