@devexperts/dxcharts-lite 2.1.0 → 2.3.0

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.
Files changed (31) hide show
  1. package/README.md +1 -1
  2. package/dist/chart/canvas/canvas-bounds-container.d.ts +2 -2
  3. package/dist/chart/canvas/canvas-bounds-container.js +2 -2
  4. package/dist/chart/chart.config.d.ts +17 -4
  5. package/dist/chart/chart.config.js +6 -2
  6. package/dist/chart/components/chart/chart-area-pan.handler.js +10 -5
  7. package/dist/chart/components/cross_tool/cross-tool.model.js +1 -1
  8. package/dist/chart/components/snapshot/snapshot.component.js +1 -0
  9. package/dist/chart/components/volumes/separate-volumes.component.js +2 -1
  10. package/dist/chart/components/volumes/volumes.formatter.d.ts +1 -1
  11. package/dist/chart/components/volumes/volumes.formatter.js +28 -25
  12. package/dist/chart/components/y_axis/y-axis-scale.handler.d.ts +5 -4
  13. package/dist/chart/components/y_axis/y-axis-scale.handler.js +9 -9
  14. package/dist/chart/components/y_axis/y-axis.component.js +1 -0
  15. package/dist/chart/drawers/data-series.drawer.js +1 -1
  16. package/dist/chart/inputhandlers/cross-event-producer.component.js +2 -1
  17. package/dist/chart/inputhandlers/hover-producer.component.js +1 -1
  18. package/dist/chart/inputlisteners/canvas-input-listener.component.d.ts +19 -3
  19. package/dist/chart/inputlisteners/canvas-input-listener.component.js +102 -44
  20. package/dist/chart/model/scale.model.d.ts +3 -2
  21. package/dist/chart/model/scale.model.js +23 -5
  22. package/dist/chart/model/scaling/constrait.functions.d.ts +1 -1
  23. package/dist/chart/model/scaling/constrait.functions.js +1 -2
  24. package/dist/chart/model/scaling/lock-ratio.model.d.ts +8 -2
  25. package/dist/chart/model/scaling/lock-ratio.model.js +18 -3
  26. package/dist/chart/utils/device/touchpad.utils.d.ts +3 -3
  27. package/dist/chart/utils/device/touchpad.utils.js +3 -5
  28. package/dist/chart/utils/math.utils.d.ts +0 -1
  29. package/dist/chart/utils/math.utils.js +1 -1
  30. package/dist/dxchart.min.js +4 -4
  31. package/package.json +4 -1
@@ -8,7 +8,7 @@ import { startViewportModelAnimation } from '../animation/viewport-model-animati
8
8
  import { cloneUnsafe } from '../utils/object.utils';
9
9
  import { AutoScaleViewportSubModel } from './scaling/auto-scale.model';
10
10
  import { zoomConstraint } from './scaling/constrait.functions';
11
- import { lockedYEndViewportCalculator, ratioFromZoomXY } from './scaling/lock-ratio.model';
11
+ import { changeXToKeepRatio, changeYToKeepRatio, ratioFromZoomXY } from './scaling/lock-ratio.model';
12
12
  import { moveXStart, moveYStart } from './scaling/move-chart.functions';
13
13
  import { ViewportModel, compareStates } from './scaling/viewport.model';
14
14
  import { zoomXToEndViewportCalculator, zoomXToPercentViewportCalculator } from './scaling/x-zooming.functions';
@@ -81,7 +81,7 @@ export class ScaleModel extends ViewportModel {
81
81
  * @param forceNoAnimation Whether to skip animation.
82
82
  * @param zoomSensitivity The sensitivity of the zoom.
83
83
  */
84
- zoomXToPercent(viewportPercent, zoomIn, forceNoAnimation = false, zoomSensitivity = this.config.scale.zoomSensitivity) {
84
+ zoomXToPercent(viewportPercent, zoomIn, forceNoAnimation = false, zoomSensitivity) {
85
85
  const disabledAnimations = this.config.scale.disableAnimations || forceNoAnimation;
86
86
  if (disabledAnimations) {
87
87
  this.haltAnimation();
@@ -96,7 +96,7 @@ export class ScaleModel extends ViewportModel {
96
96
  * @param zoomIn - If true, the chart will be zoomed in. If false, the chart will be zoomed out.
97
97
  * @param zoomSensitivity - The sensitivity of the zoom. Default value is taken from the configuration object.
98
98
  */
99
- zoomXToEnd(zoomIn, zoomSensitivity = this.config.scale.zoomSensitivity) {
99
+ zoomXToEnd(zoomIn, zoomSensitivity) {
100
100
  if (this.config.scale.disableAnimations) {
101
101
  this.haltAnimation();
102
102
  }
@@ -116,7 +116,7 @@ export class ScaleModel extends ViewportModel {
116
116
  const initialStateCopy = Object.assign({}, state);
117
117
  const constrainedState = this.scalePostProcessor(initialStateCopy, state);
118
118
  if (this.state.lockPriceToBarRatio) {
119
- lockedYEndViewportCalculator(constrainedState, this.zoomXYRatio);
119
+ changeYToKeepRatio(constrainedState, this.zoomXYRatio);
120
120
  }
121
121
  if (this.state.auto) {
122
122
  this.autoScaleModel.doAutoYScale(constrainedState);
@@ -142,13 +142,31 @@ export class ScaleModel extends ViewportModel {
142
142
  const state = this.export();
143
143
  const constrainedState = this.scalePostProcessor(initialState, state);
144
144
  if (this.state.lockPriceToBarRatio) {
145
- lockedYEndViewportCalculator(constrainedState, this.zoomXYRatio);
145
+ changeYToKeepRatio(constrainedState, this.zoomXYRatio);
146
146
  }
147
147
  if (this.state.auto) {
148
148
  this.autoScaleModel.doAutoYScale(constrainedState);
149
149
  }
150
150
  this.apply(constrainedState);
151
151
  }
152
+ setYScale(yStart, yEnd, fire = false) {
153
+ const initialState = this.export();
154
+ super.setYScale(yStart, yEnd, fire);
155
+ const state = this.export();
156
+ const constrainedState = this.scalePostProcessor(initialState, state);
157
+ if (this.state.lockPriceToBarRatio) {
158
+ changeXToKeepRatio(constrainedState, this.zoomXYRatio);
159
+ this.setXScale(constrainedState.xStart, constrainedState.xEnd);
160
+ // TODO: rewrite logic for applying constraints to consider both axes, now constraints on Y may not work correctly
161
+ return;
162
+ }
163
+ else {
164
+ if (this.state.auto) {
165
+ this.autoScaleModel.doAutoYScale(constrainedState);
166
+ }
167
+ this.apply(constrainedState);
168
+ }
169
+ }
152
170
  /**
153
171
  * Moves both xStart and xEnd without changing the viewport width (zoom).
154
172
  * Works without animation.
@@ -32,7 +32,7 @@ export declare const candleEdgesConstrait: (state: ViewportModelState, visualCan
32
32
  * @returns
33
33
  * @doc-tags viewport,zoom,scaling
34
34
  */
35
- export declare const zoomConstraint: (initialState: ViewportModelState, state: ViewportModelState, chartConfig: ChartConfigComponentsChart, boundsProvider: BoundsProvider) => {
35
+ export declare const zoomConstraint: (_: ViewportModelState, state: ViewportModelState, chartConfig: ChartConfigComponentsChart, boundsProvider: BoundsProvider) => {
36
36
  xStart: number;
37
37
  xEnd: number;
38
38
  yStart: number;
@@ -40,7 +40,7 @@ export const candleEdgesConstrait = (state, visualCandlesCoordinates, candleLimi
40
40
  * @returns
41
41
  * @doc-tags viewport,zoom,scaling
42
42
  */
43
- export const zoomConstraint = (initialState, state, chartConfig, boundsProvider) => {
43
+ export const zoomConstraint = (_, state, chartConfig, boundsProvider) => {
44
44
  const newState = Object.assign({}, state);
45
45
  const bounds = boundsProvider();
46
46
  // 1 - is an average candle width: newXEnd - newXStart = avg candles amount in the viewport
@@ -56,7 +56,6 @@ export const zoomConstraint = (initialState, state, chartConfig, boundsProvider)
56
56
  return newState;
57
57
  }
58
58
  if (minViewportReached) {
59
- newState.xEnd = initialState.xEnd;
60
59
  newState.xStart = newState.xEnd - chartConfig.minCandles;
61
60
  newState.zoomX = calculateZoom(newState.xEnd - newState.xStart, bounds.width);
62
61
  return newState;
@@ -9,8 +9,14 @@ export declare const ratioFromZoomXY: (zoomX: Zoom, zoomY: Zoom) => ZoomXToZoomY
9
9
  export declare const zoomXToZoomY: (zoomX: Zoom, ratio: ZoomXToZoomYRatio) => Zoom;
10
10
  export declare const zoomYToZoomX: (zoomY: Zoom, ratio: ZoomXToZoomYRatio) => Zoom;
11
11
  /**
12
- * Locks the zoomY with zoomX and moves yEnd according to ratio changes.
12
+ * Locks the zoomY with zoomX and zooms y-scale depending on x-scale.
13
13
  * @param state
14
14
  * @param zoomXYRatio
15
15
  */
16
- export declare const lockedYEndViewportCalculator: (state: ViewportModelState, zoomXYRatio: ZoomXToZoomYRatio) => void;
16
+ export declare const changeYToKeepRatio: (state: ViewportModelState, zoomXYRatio: ZoomXToZoomYRatio) => void;
17
+ /**
18
+ * Locks the zoomY with zoomX and zooms x-scale depending on y-scale.
19
+ * @param state
20
+ * @param zoomXYRatio
21
+ */
22
+ export declare const changeXToKeepRatio: (state: ViewportModelState, zoomXYRatio: ZoomXToZoomYRatio) => void;
@@ -7,16 +7,31 @@ export const ratioFromZoomXY = (zoomX, zoomY) => zoomX / zoomY;
7
7
  export const zoomXToZoomY = (zoomX, ratio) => zoomX / ratio;
8
8
  export const zoomYToZoomX = (zoomY, ratio) => zoomY * ratio;
9
9
  /**
10
- * Locks the zoomY with zoomX and moves yEnd according to ratio changes.
10
+ * Locks the zoomY with zoomX and zooms y-scale depending on x-scale.
11
11
  * @param state
12
12
  * @param zoomXYRatio
13
13
  */
14
- export const lockedYEndViewportCalculator = (state, zoomXYRatio) => {
14
+ export const changeYToKeepRatio = (state, zoomXYRatio) => {
15
15
  const prevZoomY = state.zoomY;
16
16
  state.zoomY = zoomXToZoomY(state.zoomX, zoomXYRatio);
17
17
  const zoomYMult = state.zoomY / prevZoomY;
18
18
  const lastYHeight = state.yEnd - state.yStart;
19
19
  const newYHeight = lastYHeight * zoomYMult;
20
20
  const delta = newYHeight - lastYHeight;
21
- state.yEnd = state.yEnd + delta;
21
+ state.yEnd = state.yEnd + delta / 2;
22
+ state.yStart = state.yStart - delta / 2;
23
+ };
24
+ /**
25
+ * Locks the zoomY with zoomX and zooms x-scale depending on y-scale.
26
+ * @param state
27
+ * @param zoomXYRatio
28
+ */
29
+ export const changeXToKeepRatio = (state, zoomXYRatio) => {
30
+ const prevZoomX = state.zoomX;
31
+ state.zoomX = zoomYToZoomX(state.zoomY, zoomXYRatio);
32
+ const zoomXMult = state.zoomX / prevZoomX;
33
+ const lastXWidth = state.xEnd - state.xStart;
34
+ const newXWidth = lastXWidth * zoomXMult;
35
+ const delta = newXWidth - lastXWidth;
36
+ state.xStart = state.xStart - delta;
22
37
  };
@@ -3,7 +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 { FullChartConfig } from '../../chart.config';
6
+ import { PriceAxisType } from '../../components/labels_generator/numeric-axis-labels.generator';
7
7
  export declare const isFirefox: boolean;
8
8
  /**
9
9
  * this function determines whether the event was triggered with the mouse or the touchpad
@@ -20,11 +20,11 @@ export declare const isFirefox: boolean;
20
20
  */
21
21
  export declare const touchpadDetector: (e: WheelEvent) => boolean;
22
22
  /**
23
- * this function returns different ящщь sensitivity for the percent axis and the others
23
+ * this function returns different zoom sensitivity for the percent axis and the others
24
24
  * @param config
25
25
  * @param isTouchpad
26
26
  * @returns {number}
27
27
  *
28
28
  * @doc-tags chart-core, zoom
29
29
  */
30
- export declare const getTouchpadSensitivity: (config: FullChartConfig) => number;
30
+ export declare const getTouchpadSensitivity: (type: PriceAxisType, zoomSensitivity: number) => number;
@@ -82,15 +82,13 @@ export const touchpadDetector = (e) => {
82
82
  return isTouchpad;
83
83
  };
84
84
  /**
85
- * this function returns different ящщь sensitivity for the percent axis and the others
85
+ * this function returns different zoom sensitivity for the percent axis and the others
86
86
  * @param config
87
87
  * @param isTouchpad
88
88
  * @returns {number}
89
89
  *
90
90
  * @doc-tags chart-core, zoom
91
91
  */
92
- export const getTouchpadSensitivity = (config) => {
93
- const isPercentAxisType = config.components.yAxis.type === 'percent';
94
- const zoomSensitivity = isPercentAxisType ? config.scale.zoomSensitivity / 4 : config.scale.zoomSensitivity;
95
- return zoomSensitivity;
92
+ export const getTouchpadSensitivity = (type, zoomSensitivity) => {
93
+ return type === 'percent' ? zoomSensitivity / 4 : zoomSensitivity;
96
94
  };
@@ -3,7 +3,6 @@
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
- export declare const MAX_DECIMAL_DIGITS = 14;
7
6
  export type NumberFormatLabels = 'K' | 'M' | 'B';
8
7
  export declare class MathUtils {
9
8
  static roundToNearest(value: number, precision: number): number;
@@ -3,7 +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
- export const MAX_DECIMAL_DIGITS = 14;
6
+ const MAX_DECIMAL_DIGITS = 14;
7
7
  // Array of powers of 10. Used in roundDecimal to walk through mantissa.
8
8
  const POW10 = [];
9
9
  for (let i = 0; i < MAX_DECIMAL_DIGITS + 1; i++) {