@devexperts/dxcharts-lite 2.4.5 → 2.5.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 (59) hide show
  1. package/dist/chart/__tests__/model/date-time.formatter.test.d.ts +6 -0
  2. package/dist/chart/__tests__/model/date-time.formatter.test.js +30 -0
  3. package/dist/chart/bootstrap.js +1 -1
  4. package/dist/chart/canvas/canvas-bounds-container.d.ts +7 -3
  5. package/dist/chart/canvas/canvas-bounds-container.js +149 -105
  6. package/dist/chart/canvas/y-axis-bounds.container.js +4 -0
  7. package/dist/chart/chart.config.d.ts +4 -10
  8. package/dist/chart/chart.config.js +4 -6
  9. package/dist/chart/components/chart/chart-area-pan.handler.d.ts +9 -6
  10. package/dist/chart/components/chart/chart-area-pan.handler.js +41 -38
  11. package/dist/chart/components/chart/chart.model.d.ts +0 -1
  12. package/dist/chart/components/chart/chart.model.js +0 -1
  13. package/dist/chart/components/dran-n-drop_helper/drag-n-drop-x.component.d.ts +0 -6
  14. package/dist/chart/components/dran-n-drop_helper/drag-n-drop-x.component.js +0 -8
  15. package/dist/chart/components/dran-n-drop_helper/drag-n-drop-y.component.d.ts +0 -5
  16. package/dist/chart/components/dran-n-drop_helper/drag-n-drop-y.component.js +0 -7
  17. package/dist/chart/components/dran-n-drop_helper/drag-n-drop.component.d.ts +1 -12
  18. package/dist/chart/components/dran-n-drop_helper/drag-n-drop.component.js +19 -30
  19. package/dist/chart/components/dynamic-objects/dynamic-objects.model.d.ts +6 -3
  20. package/dist/chart/components/dynamic-objects/dynamic-objects.model.js +14 -3
  21. package/dist/chart/components/hit-test/hit-test.component.d.ts +3 -1
  22. package/dist/chart/components/hit-test/hit-test.component.js +6 -1
  23. package/dist/chart/components/pan/chart-pan.component.d.ts +4 -14
  24. package/dist/chart/components/pan/chart-pan.component.js +10 -21
  25. package/dist/chart/components/pane/extent/y-extent-component.d.ts +2 -0
  26. package/dist/chart/components/pane/pane-manager.component.d.ts +29 -0
  27. package/dist/chart/components/pane/pane-manager.component.js +71 -8
  28. package/dist/chart/components/pane/pane.component.d.ts +5 -17
  29. package/dist/chart/components/pane/pane.component.js +13 -29
  30. package/dist/chart/components/resizer/bar-resizer.component.d.ts +1 -1
  31. package/dist/chart/components/resizer/bar-resizer.component.js +8 -5
  32. package/dist/chart/components/x_axis/x-axis-scale.handler.js +1 -1
  33. package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.d.ts +1 -3
  34. package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.js +1 -3
  35. package/dist/chart/components/y_axis/y-axis-scale.handler.js +6 -8
  36. package/dist/chart/components/y_axis/y-axis.component.d.ts +1 -1
  37. package/dist/chart/components/y_axis/y-axis.component.js +7 -4
  38. package/dist/chart/inputhandlers/hover-producer.component.d.ts +1 -1
  39. package/dist/chart/inputhandlers/main-canvas-touch.handler.d.ts +11 -7
  40. package/dist/chart/inputhandlers/main-canvas-touch.handler.js +34 -7
  41. package/dist/chart/inputlisteners/canvas-input-listener.component.d.ts +0 -14
  42. package/dist/chart/inputlisteners/canvas-input-listener.component.js +1 -35
  43. package/dist/chart/model/baseline.model.d.ts +3 -0
  44. package/dist/chart/model/baseline.model.js +5 -0
  45. package/dist/chart/model/candle-series.model.d.ts +10 -1
  46. package/dist/chart/model/candle-series.model.js +20 -2
  47. package/dist/chart/model/chart-base-element.d.ts +2 -0
  48. package/dist/chart/model/chart-base-element.js +2 -0
  49. package/dist/chart/model/data-series.model.js +5 -3
  50. package/dist/chart/model/date-time.formatter.d.ts +20 -3
  51. package/dist/chart/model/date-time.formatter.js +62 -14
  52. package/dist/chart/model/scale.model.d.ts +5 -0
  53. package/dist/chart/model/scale.model.js +9 -1
  54. package/dist/chart/model/scaling/constrait.functions.d.ts +5 -7
  55. package/dist/chart/model/scaling/constrait.functions.js +3 -3
  56. package/dist/chart/model/time-zone.model.js +3 -1
  57. package/dist/chart/utils/timezone.utils.js +3 -3
  58. package/dist/dxchart.min.js +4 -4
  59. package/package.json +1 -1
@@ -12,7 +12,7 @@ import { BarResizerComponent } from '../resizer/bar-resizer.component';
12
12
  import { createDefaultYExtentHighLowProvider, } from './extent/y-extent-component';
13
13
  import { PaneHitTestController } from './pane-hit-test.controller';
14
14
  import { PaneComponent } from './pane.component';
15
- import { flatMap } from '../../utils/array.utils';
15
+ import { firstOf, flatMap, lastOf } from '../../utils/array.utils';
16
16
  export class PaneManager extends ChartBaseElement {
17
17
  /**
18
18
  * Returns order of panes in the chart from top to bottom.
@@ -53,7 +53,7 @@ export class PaneManager extends ChartBaseElement {
53
53
  }
54
54
  addBounds(uuid, order) {
55
55
  this.canvasBoundsContainer.addPaneBounds(uuid, order);
56
- return () => this.canvasBoundsContainer.removedPaneBounds(uuid);
56
+ return () => this.canvasBoundsContainer.removePaneBounds(uuid);
57
57
  }
58
58
  /**
59
59
  * Adds a resizer to the canvas bounds container for the given uuid.
@@ -110,19 +110,82 @@ export class PaneManager extends ChartBaseElement {
110
110
  this.paneAddedSubject.next(this.panes);
111
111
  return paneComponent;
112
112
  }
113
+ /**
114
+ * Moves the canvas bounds container up by calling the movePaneUp method with the uuid of the current object.
115
+ * @returns {void}
116
+ */
117
+ movePaneUp(uuid) {
118
+ this.canvasBoundsContainer.movePaneUp(uuid);
119
+ }
120
+ /**
121
+ * Moves the canvas bounds container down by calling the movePaneDown method with the uuid of the current object.
122
+ * @returns {void}
123
+ */
124
+ movePaneDown(uuid) {
125
+ this.canvasBoundsContainer.movePaneDown(uuid);
126
+ }
127
+ /**
128
+ * Checks if the current pane can move up.
129
+ * @returns {boolean} - Returns true if the current pane can move up, otherwise false.
130
+ */
131
+ canMovePaneUp(uuid) {
132
+ var _a, _b;
133
+ const firstVisiblePane = firstOf(this.canvasBoundsContainer.panesOrder.filter(uuid => { var _a, _b; return (_b = (_a = this.panes[uuid]) === null || _a === void 0 ? void 0 : _a.visible) !== null && _b !== void 0 ? _b : false; }));
134
+ return uuid !== firstVisiblePane && ((_b = (_a = this.panes[uuid]) === null || _a === void 0 ? void 0 : _a.visible) !== null && _b !== void 0 ? _b : false);
135
+ }
136
+ /**
137
+ * Checks if the current pane can move down.
138
+ *
139
+ * @returns {boolean} - Returns true if the current pane is not the last one in the canvasBoundsContainer, otherwise returns false.
140
+ */
141
+ canMovePaneDown(uuid) {
142
+ var _a, _b;
143
+ const lastVisiblePane = lastOf(this.canvasBoundsContainer.panesOrder.filter(uuid => { var _a, _b; return (_b = (_a = this.panes[uuid]) === null || _a === void 0 ? void 0 : _a.visible) !== null && _b !== void 0 ? _b : false; }));
144
+ return uuid !== lastVisiblePane && ((_b = (_a = this.panes[uuid]) === null || _a === void 0 ? void 0 : _a.visible) !== null && _b !== void 0 ? _b : false);
145
+ }
113
146
  /**
114
147
  * Removes pane from the chart and all related components
115
148
  * @param uuid
116
149
  */
117
150
  removePane(uuid) {
118
151
  const pane = this.panes[uuid];
119
- if (pane !== undefined) {
120
- this.paneRemovedSubject.next(pane);
121
- pane.disable();
122
- pane.yExtentComponents.forEach(yExtentComponent => yExtentComponent.disable());
123
- delete this.panes[uuid];
124
- this.recalculateState();
152
+ if (pane === undefined) {
153
+ return;
154
+ }
155
+ this.paneRemovedSubject.next(pane);
156
+ pane.disable();
157
+ pane.yExtentComponents.forEach(yExtentComponent => yExtentComponent.disable());
158
+ delete this.panes[uuid];
159
+ this.recalculateState();
160
+ }
161
+ /**
162
+ * Hides a pane from the chart and all related components
163
+ */
164
+ hidePane(paneUUID) {
165
+ const pane = this.panes[paneUUID];
166
+ // hide pane only if we have more than one visible pane
167
+ if (pane === undefined || !pane.visible) {
168
+ return;
125
169
  }
170
+ const paneResizerId = CanvasElement.PANE_UUID_RESIZER(paneUUID);
171
+ const resizer = this.userInputListenerComponents.find(el => el instanceof BarResizerComponent && el.id === paneResizerId);
172
+ resizer === null || resizer === void 0 ? void 0 : resizer.disable();
173
+ this.canvasBoundsContainer.hidePaneBounds(paneUUID);
174
+ this.recalculateState();
175
+ }
176
+ /**
177
+ * Shows a pane, use if the pane is hidden
178
+ */
179
+ showPane(paneUUID) {
180
+ const pane = this.panes[paneUUID];
181
+ const paneResizerId = CanvasElement.PANE_UUID_RESIZER(paneUUID);
182
+ if (pane === undefined || pane.visible) {
183
+ return;
184
+ }
185
+ const resizer = this.userInputListenerComponents.find(el => el instanceof BarResizerComponent && el.id === paneResizerId);
186
+ resizer === null || resizer === void 0 ? void 0 : resizer.enable();
187
+ this.canvasBoundsContainer.showPaneBounds(paneUUID);
188
+ this.recalculateState();
126
189
  }
127
190
  /**
128
191
  * Adds cursors to the chart elements based on the provided uuid and cursor type.
@@ -44,7 +44,6 @@ export declare class PaneComponent extends ChartBaseElement {
44
44
  seriesAddedSubject: Subject<DataSeriesModel>;
45
45
  seriesRemovedSubject: Subject<DataSeriesModel>;
46
46
  private hitTestCanvasModel;
47
- private _paneOrder;
48
47
  /**
49
48
  * Pane hit test (without Y-Axis and resizer)
50
49
  */
@@ -53,6 +52,7 @@ export declare class PaneComponent extends ChartBaseElement {
53
52
  get scale(): ScaleModel;
54
53
  get yAxis(): YAxisComponent;
55
54
  get dataSeries(): DataSeriesModel<import("../../model/data-series.model").DataSeriesPoint, import("../../model/data-series.model").VisualSeriesPoint>[];
55
+ get visible(): boolean;
56
56
  mainExtent: YExtentComponent;
57
57
  constructor(chartBaseModel: ChartBaseModel<'candle'>, mainCanvasModel: CanvasModel, yAxisLabelsCanvasModel: CanvasModel, dynamicObjectsCanvasModel: CanvasModel, hitTestController: PaneHitTestController, config: FullChartConfig, mainScale: ScaleModel, drawingManager: DrawingManager, chartPanComponent: ChartPanComponent, canvasInputListener: CanvasInputListenerComponent, canvasAnimation: CanvasAnimation, cursorHandler: CursorHandler, eventBus: EventBus, canvasBoundsContainer: CanvasBoundsContainer, uuid: string, seriesAddedSubject: Subject<DataSeriesModel>, seriesRemovedSubject: Subject<DataSeriesModel>, hitTestCanvasModel: HitTestCanvasModel, options?: AtLeastOne<YExtentCreationOptions>);
58
58
  /**
@@ -96,22 +96,6 @@ export declare class PaneComponent extends ChartBaseElement {
96
96
  * Returns the bounds of the pane component.
97
97
  */
98
98
  getBounds(): Bounds;
99
- /**
100
- * Hides the pane by removing its bounds from the canvasBoundsContainer and firing a draw event.
101
- * @function
102
- * @name hide
103
- * @memberof PaneComponent
104
- * @returns {void}
105
- */
106
- hide(): void;
107
- /**
108
- * Adds the bounds of the pane to the canvas bounds container and fires a draw event.
109
- * @function
110
- * @name show
111
- * @memberof PaneComponent
112
- * @returns {void}
113
- */
114
- show(): void;
115
99
  /**
116
100
  * Creates a new DataSeriesModel object.
117
101
  * @returns {DataSeriesModel} - The newly created DataSeriesModel object.
@@ -140,22 +124,26 @@ export declare class PaneComponent extends ChartBaseElement {
140
124
  /**
141
125
  * Moves the canvas bounds container up by calling the movePaneUp method with the uuid of the current object.
142
126
  * @returns {void}
127
+ * @deprecated Use `paneManager.movePaneUp()` instead
143
128
  */
144
129
  moveUp(): void;
145
130
  /**
146
131
  * Moves the canvas bounds container down by calling the movePaneDown method with the uuid of the current object.
147
132
  * @returns {void}
133
+ * @deprecated Use `paneManager.movePaneDown()` instead
148
134
  */
149
135
  moveDown(): void;
150
136
  /**
151
137
  * Checks if the current pane can move up.
152
138
  * @returns {boolean} - Returns true if the current pane can move up, otherwise false.
139
+ * @deprecated Use `paneManager.canMovePaneUp()` instead
153
140
  */
154
141
  canMoveUp(): boolean;
155
142
  /**
156
143
  * Checks if the current pane can move down.
157
144
  *
158
145
  * @returns {boolean} - Returns true if the current pane is not the last one in the canvasBoundsContainer, otherwise returns false.
146
+ * @deprecated Use `paneManager.canMovePaneDown()` instead
159
147
  */
160
148
  canMoveDown(): boolean;
161
149
  valueFormatter: (value: Unit, dataSeries?: DataSeriesModel) => string;
@@ -22,6 +22,9 @@ export class PaneComponent extends ChartBaseElement {
22
22
  get dataSeries() {
23
23
  return flatMap(this.yExtentComponents, c => Array.from(c.dataSeries));
24
24
  }
25
+ get visible() {
26
+ return this.canvasBoundsContainer.graphsHeightRatio[this.uuid] > 0;
27
+ }
25
28
  constructor(chartBaseModel, mainCanvasModel, yAxisLabelsCanvasModel, dynamicObjectsCanvasModel, hitTestController, config, mainScale, drawingManager, chartPanComponent, canvasInputListener, canvasAnimation, cursorHandler, eventBus, canvasBoundsContainer, uuid, seriesAddedSubject, seriesRemovedSubject, hitTestCanvasModel, options) {
26
29
  super();
27
30
  this.chartBaseModel = chartBaseModel;
@@ -42,7 +45,6 @@ export class PaneComponent extends ChartBaseElement {
42
45
  this.seriesAddedSubject = seriesAddedSubject;
43
46
  this.seriesRemovedSubject = seriesRemovedSubject;
44
47
  this.hitTestCanvasModel = hitTestCanvasModel;
45
- this._paneOrder = 0;
46
48
  this.yExtentComponents = [];
47
49
  this.getYAxisBounds = () => {
48
50
  return this.canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID_Y_AXIS(this.uuid));
@@ -119,10 +121,11 @@ export class PaneComponent extends ChartBaseElement {
119
121
  const chartPaneId = CanvasElement.PANE_UUID(this.uuid);
120
122
  const getBounds = () => this.canvasBoundsContainer.getBounds(chartPaneId);
121
123
  const scaleModel = (_a = options === null || options === void 0 ? void 0 : options.scale) !== null && _a !== void 0 ? _a : new SyncedByXScaleModel(this.mainScale, this.config, getBounds, this.canvasAnimation);
124
+ const initialYAxisState = options === null || options === void 0 ? void 0 : options.initialYAxisState;
122
125
  const [unsub, dragNDrop] = this.createYPanHandler(this.uuid, scaleModel);
123
126
  // creating partially resolved constructor except formatter & dataSeriesProvider - bcs it's not possible to provide formatter
124
127
  // before y-extent is created
125
- const createYAxisComponent = (formatter, dataSeriesProvider) => new YAxisComponent(this.eventBus, this.config, this.yAxisLabelsCanvasModel, scaleModel, this.canvasInputListener, this.canvasBoundsContainer, this.chartPanComponent, this.cursorHandler, formatter, dataSeriesProvider, this.uuid, extentIdx, this.hitTestCanvasModel);
128
+ const createYAxisComponent = (formatter, dataSeriesProvider) => new YAxisComponent(this.eventBus, this.config, this.yAxisLabelsCanvasModel, scaleModel, this.canvasInputListener, this.canvasBoundsContainer, this.chartPanComponent, this.cursorHandler, formatter, dataSeriesProvider, this.uuid, extentIdx, this.hitTestCanvasModel, initialYAxisState);
126
129
  const yExtentComponent = new YExtentComponent(this.uuid, extentIdx, this, this.chartBaseModel, this.canvasBoundsContainer, this.hitTestController, this.dynamicObjectsCanvasModel, scaleModel, createYAxisComponent, dragNDrop);
127
130
  yExtentComponent.addSubscription(unsub);
128
131
  yExtentComponent.addSubscription(this.addCursors(extentIdx, yExtentComponent.yAxis));
@@ -175,29 +178,6 @@ export class PaneComponent extends ChartBaseElement {
175
178
  getBounds() {
176
179
  return this.mainExtent.getBounds();
177
180
  }
178
- /**
179
- * Hides the pane by removing its bounds from the canvasBoundsContainer and firing a draw event.
180
- * @function
181
- * @name hide
182
- * @memberof PaneComponent
183
- * @returns {void}
184
- */
185
- hide() {
186
- this._paneOrder = this.canvasBoundsContainer.panesOrder.indexOf(this.uuid);
187
- this.canvasBoundsContainer.removedPaneBounds(this.uuid);
188
- this.eventBus.fireDraw();
189
- }
190
- /**
191
- * Adds the bounds of the pane to the canvas bounds container and fires a draw event.
192
- * @function
193
- * @name show
194
- * @memberof PaneComponent
195
- * @returns {void}
196
- */
197
- show() {
198
- this.canvasBoundsContainer.addPaneBounds(this.uuid, this._paneOrder);
199
- this.eventBus.fireDraw();
200
- }
201
181
  /**
202
182
  * Creates a new DataSeriesModel object.
203
183
  * @returns {DataSeriesModel} - The newly created DataSeriesModel object.
@@ -238,6 +218,7 @@ export class PaneComponent extends ChartBaseElement {
238
218
  /**
239
219
  * Moves the canvas bounds container up by calling the movePaneUp method with the uuid of the current object.
240
220
  * @returns {void}
221
+ * @deprecated Use `paneManager.movePaneUp()` instead
241
222
  */
242
223
  moveUp() {
243
224
  this.canvasBoundsContainer.movePaneUp(this.uuid);
@@ -245,6 +226,7 @@ export class PaneComponent extends ChartBaseElement {
245
226
  /**
246
227
  * Moves the canvas bounds container down by calling the movePaneDown method with the uuid of the current object.
247
228
  * @returns {void}
229
+ * @deprecated Use `paneManager.movePaneDown()` instead
248
230
  */
249
231
  moveDown() {
250
232
  this.canvasBoundsContainer.movePaneDown(this.uuid);
@@ -252,19 +234,21 @@ export class PaneComponent extends ChartBaseElement {
252
234
  /**
253
235
  * Checks if the current pane can move up.
254
236
  * @returns {boolean} - Returns true if the current pane can move up, otherwise false.
237
+ * @deprecated Use `paneManager.canMovePaneUp()` instead
255
238
  */
256
239
  canMoveUp() {
257
- const firstPane = firstOf(this.canvasBoundsContainer.panesOrder);
258
- return this.uuid !== firstPane;
240
+ const firstVisiblePane = firstOf(this.canvasBoundsContainer.panesOrder.filter(uuid => this.canvasBoundsContainer.graphsHeightRatio[uuid] > 0));
241
+ return this.uuid !== firstVisiblePane && this.visible;
259
242
  }
260
243
  /**
261
244
  * Checks if the current pane can move down.
262
245
  *
263
246
  * @returns {boolean} - Returns true if the current pane is not the last one in the canvasBoundsContainer, otherwise returns false.
247
+ * @deprecated Use `paneManager.canMovePaneDown()` instead
264
248
  */
265
249
  canMoveDown() {
266
- const lastPane = lastOf(this.canvasBoundsContainer.panesOrder);
267
- return this.uuid !== lastPane;
250
+ const lastVisiblePane = lastOf(this.canvasBoundsContainer.panesOrder.filter(uuid => this.canvasBoundsContainer.graphsHeightRatio[uuid] > 0));
251
+ return this.uuid !== lastVisiblePane && this.visible;
268
252
  }
269
253
  get regularFormatter() {
270
254
  return this.mainExtent.formatters.regular;
@@ -22,7 +22,7 @@ import { HitTestCanvasModel } from '../../model/hit-test-canvas.model';
22
22
  * @doc-tags chart-core,resizer
23
23
  */
24
24
  export declare class BarResizerComponent extends ChartBaseElement {
25
- private id;
25
+ readonly id: string;
26
26
  private boundsProvider;
27
27
  private hitTest;
28
28
  private dragTickCb;
@@ -39,6 +39,7 @@ export class BarResizerComponent extends ChartBaseElement {
39
39
  this.initialY = this.boundsProvider().y;
40
40
  // Stop redrawing hit test
41
41
  this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(false);
42
+ this.chartPanComponent.deactivatePanHandlers();
42
43
  };
43
44
  this.onYDragEnd = () => {
44
45
  this.config.components.crossTool.type = 'cross-and-labels';
@@ -46,6 +47,7 @@ export class BarResizerComponent extends ChartBaseElement {
46
47
  this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio);
47
48
  // Continue redrawing hit test
48
49
  this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(true);
50
+ this.chartPanComponent.activateChartPanHandlers();
49
51
  };
50
52
  this.onYDragTick = (dragInfo) => {
51
53
  const { delta: yDelta, draggedPixels } = dragInfo;
@@ -73,10 +75,12 @@ export class BarResizerComponent extends ChartBaseElement {
73
75
  const fixedMode = this.config.components.paneResizer.fixedMode;
74
76
  if (!fixedMode) {
75
77
  const dragNDropYComponent = new DragNDropYComponent(this.hitTest, {
76
- onDragTick: callIfPredicateTrue(this.onYDragTick, this.dragPredicate),
77
- onDragStart: callIfPredicateTrue(this.onYDragStart, this.dragPredicate),
78
- onDragEnd: callIfPredicateTrue(this.onYDragEnd, this.dragPredicate)
79
- }, this.canvasInputListener, this.chartPanComponent);
78
+ onDragTick: this.onYDragTick,
79
+ onDragStart: this.onYDragStart,
80
+ onDragEnd: this.onYDragEnd,
81
+ }, this.canvasInputListener, this.chartPanComponent, {
82
+ dragPredicate: this.dragPredicate,
83
+ });
80
84
  this.addChildEntity(dragNDropYComponent);
81
85
  if (this.config.animation.paneResizer.enabled) {
82
86
  this.addRxSubscription(this.canvasInputListener
@@ -148,4 +152,3 @@ export class BarResizerComponent extends ChartBaseElement {
148
152
  }
149
153
  }
150
154
  }
151
- const callIfPredicateTrue = (fun, predicate) => (...args) => predicate() && fun(...args);
@@ -51,7 +51,7 @@ export class XAxisScaleHandler extends ChartBaseElement {
51
51
  onDragTick: this.onXDragTick,
52
52
  onDragEnd: this.onXDragEnd,
53
53
  }, this.canvasInputListener, this.chartPanComponent, {
54
- disableChartPanning: false,
54
+ dragPredicate: () => chartPanComponent.chartAreaPanHandler.chartPanningOptions.horizontal,
55
55
  });
56
56
  this.addChildEntity(dragNDropXComponent);
57
57
  }
@@ -65,11 +65,9 @@ export declare class FancyYAxisLabelsModel extends ChartBaseElement {
65
65
  /**
66
66
  * This method is used to activate the chart and subscribe to the observables that will trigger the update of the labels.
67
67
  * It calls the parent method doActivate() and adds a new Rx subscription to the merge of the following observables:
68
- * - chartModel.observeCandlesChanged()
69
68
  * - canvasBoundsContainer.observeBoundsChanged(CanvasElement.CHART)
70
- * - chartModel.nextCandleTimeStampSubject
71
69
  * - canvasBoundsContainer.barResizerChangedSubject
72
- * - chartModel.scale.changed
70
+ * - scale changed
73
71
  * When any of these observables emit a new value, the updateLabels() method is called.
74
72
  * @protected
75
73
  */
@@ -48,11 +48,9 @@ export class FancyYAxisLabelsModel extends ChartBaseElement {
48
48
  /**
49
49
  * This method is used to activate the chart and subscribe to the observables that will trigger the update of the labels.
50
50
  * It calls the parent method doActivate() and adds a new Rx subscription to the merge of the following observables:
51
- * - chartModel.observeCandlesChanged()
52
51
  * - canvasBoundsContainer.observeBoundsChanged(CanvasElement.CHART)
53
- * - chartModel.nextCandleTimeStampSubject
54
52
  * - canvasBoundsContainer.barResizerChangedSubject
55
- * - chartModel.scale.changed
53
+ * - scale changed
56
54
  * When any of these observables emit a new value, the updateLabels() method is called.
57
55
  * @protected
58
56
  */
@@ -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 { Subject } from 'rxjs';
7
- import { CanvasElement } from '../../canvas/canvas-bounds-container';
7
+ import { CanvasElement, DEFAULT_MIN_PANE_HEIGHT } from '../../canvas/canvas-bounds-container';
8
8
  import { ChartBaseElement } from '../../model/chart-base-element';
9
9
  import { DragNDropYComponent } from '../dran-n-drop_helper/drag-n-drop-y.component';
10
10
  // if you drag full Y height from top to bottom - you will have x3 zoom, and vice-versa
@@ -35,7 +35,7 @@ export class YAxisScaleHandler extends ChartBaseElement {
35
35
  this.lastYStart = this.scale.yStart;
36
36
  this.lastYEnd = this.scale.yEnd;
37
37
  this.lastYHeight = this.scale.yEnd - this.scale.yStart;
38
- this.lastYPxHeight = this.bounds.getBounds(CanvasElement.Y_AXIS).height;
38
+ this.lastYPxHeight = Math.max(this.bounds.getBounds(CanvasElement.Y_AXIS).height, DEFAULT_MIN_PANE_HEIGHT);
39
39
  // Stop redrawing hit test
40
40
  this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(false);
41
41
  };
@@ -68,13 +68,12 @@ export class YAxisScaleHandler extends ChartBaseElement {
68
68
  };
69
69
  // drag to Y-scale and double click to auto scale
70
70
  if (config.customScale) {
71
- const dragPredicate = () => config.type !== 'percent' && config.visible;
72
71
  const dragNDropYComponent = new DragNDropYComponent(hitTest, {
73
- onDragTick: callIfPredicateTrue(this.onYDragTick, dragPredicate),
74
- onDragStart: callIfPredicateTrue(this.onYDragStart, dragPredicate),
75
- onDragEnd: callIfPredicateTrue(this.onYDragEnd, dragPredicate),
72
+ onDragTick: this.onYDragTick,
73
+ onDragStart: this.onYDragStart,
74
+ onDragEnd: this.onYDragEnd,
76
75
  }, canvasInputListener, panning, {
77
- disableChartPanning: false,
76
+ dragPredicate: () => panning.chartAreaPanHandler.chartPanningOptions.vertical && config.type !== 'percent',
78
77
  });
79
78
  this.addChildEntity(dragNDropYComponent);
80
79
  }
@@ -88,4 +87,3 @@ export class YAxisScaleHandler extends ChartBaseElement {
88
87
  }
89
88
  }
90
89
  }
91
- const callIfPredicateTrue = (fun, predicate) => (...args) => predicate() && fun(...args);
@@ -40,7 +40,7 @@ export declare class YAxisComponent extends ChartBaseElement {
40
40
  model: YAxisModel;
41
41
  axisTypeSetSubject: Subject<PriceAxisType>;
42
42
  readonly state: YAxisConfig;
43
- constructor(eventBus: EventBus, config: FullChartConfig, canvasModel: CanvasModel, scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, chartPanComponent: ChartPanComponent, cursors: CursorHandler, valueFormatter: (value: number) => string, dataSeriesProvider: () => DataSeriesModel | undefined, paneUUID: string, extentIdx: number, hitTestCanvasModel: HitTestCanvasModel);
43
+ constructor(eventBus: EventBus, config: FullChartConfig, canvasModel: CanvasModel, scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, chartPanComponent: ChartPanComponent, cursors: CursorHandler, valueFormatter: (value: number) => string, dataSeriesProvider: () => DataSeriesModel | undefined, paneUUID: string, extentIdx: number, hitTestCanvasModel: HitTestCanvasModel, initialState?: YAxisConfig);
44
44
  /**
45
45
  * Registers default label color resolvers for different chart types.
46
46
  * @private
@@ -6,17 +6,17 @@
6
6
  import { Subject } from 'rxjs';
7
7
  import { CanvasElement } from '../../canvas/canvas-bounds-container';
8
8
  import { ChartBaseElement } from '../../model/chart-base-element';
9
- import { cloneUnsafe } from '../../utils/object.utils';
10
9
  import { uuid } from '../../utils/uuid.utils';
11
10
  import { resolveColorForArea, resolveColorForBar, resolveColorForBaseLine, resolveColorForCandle, resolveColorForHistogram, resolveColorForLine, resolveColorForScatterPlot, resolveColorForTrendAndHollow, resolveDefaultColorForLabel, } from './label-color.functions';
12
11
  import { LabelsGroups } from './price_labels/y-axis-labels.model';
13
12
  import { YAxisScaleHandler } from './y-axis-scale.handler';
14
13
  import { YAxisModel } from './y-axis.model';
14
+ import { merge as mergeObj } from '../../utils/merge.utils';
15
15
  /**
16
16
  * Y axis component. Contains all Y axis related logic.
17
17
  */
18
18
  export class YAxisComponent extends ChartBaseElement {
19
- constructor(eventBus, config, canvasModel, scale, canvasInputListeners, canvasBoundsContainer, chartPanComponent, cursors, valueFormatter, dataSeriesProvider, paneUUID, extentIdx, hitTestCanvasModel) {
19
+ constructor(eventBus, config, canvasModel, scale, canvasInputListeners, canvasBoundsContainer, chartPanComponent, cursors, valueFormatter, dataSeriesProvider, paneUUID, extentIdx, hitTestCanvasModel, initialState) {
20
20
  super();
21
21
  this.eventBus = eventBus;
22
22
  this.config = config;
@@ -28,7 +28,10 @@ export class YAxisComponent extends ChartBaseElement {
28
28
  this.extentIdx = extentIdx;
29
29
  this.labelsColorByChartTypeMap = {};
30
30
  this.axisTypeSetSubject = new Subject();
31
- this.state = cloneUnsafe(config.components.yAxis);
31
+ this.state = mergeObj(initialState !== null && initialState !== void 0 ? initialState : {}, config.components.yAxis, {
32
+ overrideExisting: false,
33
+ addIfMissing: true,
34
+ });
32
35
  //#region init yAxisScaleHandler
33
36
  this.yAxisScaleHandler = new YAxisScaleHandler(eventBus, this.state, chartPanComponent, scale, canvasInputListeners, canvasBoundsContainer, canvasBoundsContainer.getBoundsHitTest(CanvasElement.PANE_UUID_Y_AXIS(paneUUID, extentIdx)), auto => scale.autoScale(auto), hitTestCanvasModel);
34
37
  this.addChildEntity(this.yAxisScaleHandler);
@@ -173,7 +176,7 @@ export class YAxisComponent extends ChartBaseElement {
173
176
  setVisible(isVisible) {
174
177
  this.state.visible = isVisible;
175
178
  this.config.components.yAxis.visible = isVisible;
176
- isVisible ? this.enable() : this.disable();
179
+ isVisible ? this.activate() : this.deactivate();
177
180
  this.model.fancyLabelsModel.updateLabels();
178
181
  this.model.baseLabelsModel.updateLabels();
179
182
  }
@@ -58,7 +58,7 @@ export declare class HoverProducerComponent extends ChartBaseElement {
58
58
  private longTouchActivatedSubject;
59
59
  private hoverProducerParts;
60
60
  xFormatter: DateTimeFormatter;
61
- constructor(crossEventProducer: CrossEventProducerComponent, scale: ScaleModel, config: FullChartConfig, chartModel: ChartModel, canvasInputListener: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, paneManager: PaneManager, timeZoneModel: TimeZoneModel, formatterFactory: (format: string) => (timestamp: number | Date) => string);
61
+ constructor(crossEventProducer: CrossEventProducerComponent, scale: ScaleModel, config: FullChartConfig, chartModel: ChartModel, canvasInputListener: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, paneManager: PaneManager, timeZoneModel: TimeZoneModel, formatterFactory: (format: string) => (timestamp: number) => string);
62
62
  /**
63
63
  * This method is responsible for activating the chart hover functionality. It subscribes to several observables to
64
64
  * update the hover when the chart is updated or when the user interacts with it. It also handles special behavior
@@ -6,15 +6,19 @@
6
6
  import { ChartBaseElement } from '../model/chart-base-element';
7
7
  import { CanvasInputListenerComponent } from '../inputlisteners/canvas-input-listener.component';
8
8
  import { ScaleModel } from '../model/scale.model';
9
+ import { ChartAreaPanHandler } from '../components/chart/chart-area-pan.handler';
9
10
  /**
10
11
  * Handles chart touch events.
11
12
  */
12
13
  export declare class MainCanvasTouchHandler extends ChartBaseElement {
14
+ private chartAreaPanHandler;
13
15
  private scale;
14
16
  private canvasInputListeners;
15
17
  private mainCanvasParent;
16
18
  private touchedCandleIndexes;
17
- constructor(scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, mainCanvasParent: Element);
19
+ private pinchDistance;
20
+ private isDraggable;
21
+ constructor(chartAreaPanHandler: ChartAreaPanHandler, scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, mainCanvasParent: Element);
18
22
  /**
19
23
  * Activates canvas input listeners for touch start and touch move events.
20
24
  * @protected
@@ -31,13 +35,13 @@ export declare class MainCanvasTouchHandler extends ChartBaseElement {
31
35
  * Handles touch move event
32
36
  * @param {TouchEvent} e - The touch event object
33
37
  * @returns {void}
34
-
35
- private handleTouchMoveEvent(e: TouchEvent): void {
36
- if (e.touches.length === 2) {
37
- this.pinchHandler(this.touchedCandleIndexes, this.getXPositions(e));
38
- }
39
- }*/
38
+ */
40
39
  private handleTouchMoveEvent;
40
+ /**
41
+ * Handles touch end event
42
+ * @returns {void}
43
+ */
44
+ private handleTouchEndEvent;
41
45
  /**
42
46
  * Gets candle positions touched by user in pixels.
43
47
  * @param e - touch event with "touches" array
@@ -4,17 +4,23 @@
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 { ChartBaseElement } from '../model/chart-base-element';
7
+ const MIN_PINCH_DISTANCE = 30;
7
8
  /**
8
9
  * Handles chart touch events.
9
10
  */
10
11
  export class MainCanvasTouchHandler extends ChartBaseElement {
11
- constructor(scale, canvasInputListeners, mainCanvasParent) {
12
+ constructor(chartAreaPanHandler, scale, canvasInputListeners, mainCanvasParent) {
12
13
  super();
14
+ this.chartAreaPanHandler = chartAreaPanHandler;
13
15
  this.scale = scale;
14
16
  this.canvasInputListeners = canvasInputListeners;
15
17
  this.mainCanvasParent = mainCanvasParent;
16
18
  // 2 candles indexes touched by 2 fingers when pinching
17
19
  this.touchedCandleIndexes = [0, 0];
20
+ // number of px between touch events
21
+ this.pinchDistance = 0;
22
+ // used when maximum zoom in/out reached, can't use deactivate because it unsubscribes from all touch events
23
+ this.isDraggable = true;
18
24
  }
19
25
  /**
20
26
  * Activates canvas input listeners for touch start and touch move events.
@@ -24,6 +30,7 @@ export class MainCanvasTouchHandler extends ChartBaseElement {
24
30
  doActivate() {
25
31
  this.addRxSubscription(this.canvasInputListeners.observeTouchStart().subscribe(e => this.handleTouchStartEvent(e)));
26
32
  this.addRxSubscription(this.canvasInputListeners.observeTouchMove().subscribe(e => this.handleTouchMoveEvent(e)));
33
+ this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(e => this.handleTouchEndEvent(e)));
27
34
  }
28
35
  /**
29
36
  * Handles the touch start event.
@@ -32,6 +39,8 @@ export class MainCanvasTouchHandler extends ChartBaseElement {
32
39
  */
33
40
  handleTouchStartEvent(e) {
34
41
  if (e.touches.length === 2) {
42
+ this.isDraggable = true;
43
+ this.chartAreaPanHandler.deactivate();
35
44
  // @ts-ignore
36
45
  // TODO rework this
37
46
  this.touchedCandleIndexes = this.getXPositions(e).map(x => this.scale.fromX(x));
@@ -41,17 +50,22 @@ export class MainCanvasTouchHandler extends ChartBaseElement {
41
50
  * Handles touch move event
42
51
  * @param {TouchEvent} e - The touch event object
43
52
  * @returns {void}
44
-
45
- private handleTouchMoveEvent(e: TouchEvent): void {
46
- if (e.touches.length === 2) {
47
- this.pinchHandler(this.touchedCandleIndexes, this.getXPositions(e));
48
- }
49
- }*/
53
+ */
50
54
  handleTouchMoveEvent(e) {
51
55
  if (e.touches.length === 2) {
52
56
  this.pinchHandler(this.touchedCandleIndexes, this.getXPositions(e));
53
57
  }
54
58
  }
59
+ /**
60
+ * Handles touch end event
61
+ * @returns {void}
62
+ */
63
+ handleTouchEndEvent(e) {
64
+ // zero touches means the user stopped resizing completely (both fingers are up)
65
+ if (e.touches.length === 0) {
66
+ this.chartAreaPanHandler.activate();
67
+ }
68
+ }
55
69
  /**
56
70
  * Gets candle positions touched by user in pixels.
57
71
  * @param e - touch event with "touches" array
@@ -75,11 +89,24 @@ export class MainCanvasTouchHandler extends ChartBaseElement {
75
89
  * @returns {void}
76
90
  */
77
91
  pinchHandler(candleIndexes, touchPositions) {
92
+ const diff = Math.abs(touchPositions[0]) - Math.abs(touchPositions[1]);
93
+ const pinchDistance = Math.abs(diff);
94
+ const zoomIn = pinchDistance > this.pinchDistance;
95
+ if (this.scale.isMaxZoomXReached(zoomIn)) {
96
+ this.isDraggable = false;
97
+ }
98
+ if (!this.isDraggable || pinchDistance < MIN_PINCH_DISTANCE) {
99
+ return;
100
+ }
101
+ this.pinchDistance = pinchDistance;
78
102
  const first = (touchPositions[0] * candleIndexes[1] - touchPositions[1] * candleIndexes[0]) /
79
103
  (touchPositions[0] - touchPositions[1]);
80
104
  const last = first +
81
105
  ((candleIndexes[0] - candleIndexes[1]) / (touchPositions[0] - touchPositions[1])) *
82
106
  this.scale.getBounds().width;
107
+ if (first >= last) {
108
+ return;
109
+ }
83
110
  this.scale.setXScale(first, last);
84
111
  }
85
112
  }
@@ -51,8 +51,6 @@ export declare class CanvasInputListenerComponent extends ChartBaseElement {
51
51
  private longTouchStartSubject;
52
52
  private longTouchEndSubject;
53
53
  private contextMenuSubject;
54
- private pinchSubject;
55
- private scrollGestureSubject;
56
54
  private fastTouchScroll;
57
55
  mouseLeavesCanvasSubject: Subject<boolean>;
58
56
  dragStartPoint: Point;
@@ -242,18 +240,6 @@ export declare class CanvasInputListenerComponent extends ChartBaseElement {
242
240
  * @returns {Observable<WheelEvent>} - An Observable that emits WheelEvent objects.
243
241
  */
244
242
  observeWheel(hitBoundsTest?: HitBoundsTest): Observable<WheelEvent>;
245
- /**
246
- * Returns an Observable that emits WheelEvent when a pinch event occurs and the hitBoundsTest function returns true for the current point.
247
- * @param {HitBoundsTest} hitBoundsTest - A function that takes the current point's x and y coordinates as arguments and returns a boolean indicating whether the point is within the desired bounds.
248
- * @returns {Observable<WheelEvent>} - An Observable that emits WheelEvent when a pinch event occurs and the hitBoundsTest function returns true for the current point.
249
- */
250
- observePinch(hitBoundsTest?: HitBoundsTest): Observable<WheelEvent>;
251
- /**
252
- * Returns an Observable that emits a WheelEvent whenever a scroll gesture is detected.
253
- * The Observable is created from a Subject that is subscribed to by the component's template.
254
- * @returns {Observable<WheelEvent>} An Observable that emits a WheelEvent whenever a scroll gesture is detected.
255
- */
256
- observeScrollGesture(): Observable<WheelEvent>;
257
243
  /**
258
244
  * Returns an Observable that emits TouchEvent when a touchstart event occurs within the bounds of the current point.
259
245
  * @param {HitBoundsTest} [hitBoundsTest=() => true] - A function that tests if the touch event occurred within the bounds of the current point.