@devexperts/dxcharts-lite 1.0.2 → 2.0.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 (255) hide show
  1. package/README.md +2 -2
  2. package/dist/chart/animation/canvas-animation.js +134 -1
  3. package/dist/chart/animation/types/animation.js +43 -1
  4. package/dist/chart/animation/types/color-alpha-animation.d.ts +1 -1
  5. package/dist/chart/animation/types/color-alpha-animation.js +60 -1
  6. package/dist/chart/animation/types/color-transition-animation.d.ts +1 -1
  7. package/dist/chart/animation/types/color-transition-animation.js +86 -1
  8. package/dist/chart/animation/types/viewport-movement-animation.js +63 -1
  9. package/dist/chart/animation/viewport-model-animation.js +20 -1
  10. package/dist/chart/bootstrap.d.ts +51 -48
  11. package/dist/chart/bootstrap.js +449 -1
  12. package/dist/chart/canvas/canvas-bounds-container.d.ts +0 -5
  13. package/dist/chart/canvas/canvas-bounds-container.js +815 -1
  14. package/dist/chart/canvas/canvas-chart-html.js +16 -18
  15. package/dist/chart/canvas/chart-elements.d.ts +1 -4
  16. package/dist/chart/canvas/chart-elements.js +22 -1
  17. package/dist/chart/canvas/cursor.handler.js +122 -1
  18. package/dist/chart/canvas/layout-creator.js +34 -1
  19. package/dist/chart/canvas/y-axis-bounds.container.d.ts +2 -2
  20. package/dist/chart/canvas/y-axis-bounds.container.js +67 -1
  21. package/dist/chart/chart-container.js +1 -1
  22. package/dist/chart/chart.config.d.ts +4 -5
  23. package/dist/chart/chart.config.js +645 -1
  24. package/dist/chart/chart.d.ts +62 -0
  25. package/dist/chart/chart.js +106 -0
  26. package/dist/chart/components/chart/basic-scale.d.ts +2 -2
  27. package/dist/chart/components/chart/basic-scale.js +31 -1
  28. package/dist/chart/components/chart/candle-transformer.functions.js +15 -1
  29. package/dist/chart/components/chart/candle-width-calculator.functions.js +2 -1
  30. package/dist/chart/components/chart/candle.functions.js +44 -1
  31. package/dist/chart/components/chart/chart-area-pan.handler.d.ts +3 -3
  32. package/dist/chart/components/chart/chart-area-pan.handler.js +197 -1
  33. package/dist/chart/components/chart/chart-base.model.js +66 -1
  34. package/dist/chart/components/chart/chart.component.d.ts +7 -3
  35. package/dist/chart/components/chart/chart.component.js +408 -1
  36. package/dist/chart/components/chart/chart.model.d.ts +4 -11
  37. package/dist/chart/components/chart/chart.model.js +954 -1
  38. package/dist/chart/components/chart/data-series.high-low-provider.js +34 -1
  39. package/dist/chart/components/chart/fake-candles.js +97 -1
  40. package/dist/chart/components/chart/price.formatter.js +35 -1
  41. package/dist/chart/components/chart/secondary-chart-colors-pool.js +68 -1
  42. package/dist/chart/components/cross_tool/cross-tool.component.js +85 -1
  43. package/dist/chart/components/cross_tool/cross-tool.drawer.js +32 -1
  44. package/dist/chart/components/cross_tool/cross-tool.model.js +107 -1
  45. package/dist/chart/components/cross_tool/types/cross-and-labels.drawer.js +137 -1
  46. package/dist/chart/components/cross_tool/types/none.drawer.js +3 -1
  47. package/dist/chart/components/dran-n-drop_helper/drag-n-drop-x.component.js +28 -1
  48. package/dist/chart/components/dran-n-drop_helper/drag-n-drop-y.component.js +24 -1
  49. package/dist/chart/components/dran-n-drop_helper/drag-n-drop.component.js +53 -1
  50. package/dist/chart/components/dynamic-objects/dynamic-objects.component.d.ts +13 -0
  51. package/dist/chart/components/dynamic-objects/dynamic-objects.component.js +20 -0
  52. package/dist/chart/components/dynamic-objects/dynamic-objects.drawer.d.ts +18 -0
  53. package/dist/chart/components/dynamic-objects/dynamic-objects.drawer.js +23 -0
  54. package/dist/chart/components/dynamic-objects/dynamic-objects.model.d.ts +63 -0
  55. package/dist/chart/components/dynamic-objects/dynamic-objects.model.js +136 -0
  56. package/dist/chart/components/events/events-hit-test.drawer.js +63 -1
  57. package/dist/chart/components/events/events.component.js +61 -1
  58. package/dist/chart/components/events/events.drawer.js +195 -1
  59. package/dist/chart/components/events/events.model.js +69 -1
  60. package/dist/chart/components/grid/grid.component.d.ts +2 -2
  61. package/dist/chart/components/grid/grid.component.js +31 -1
  62. package/dist/chart/components/grid/grid.drawer.d.ts +4 -3
  63. package/dist/chart/components/grid/grid.drawer.js +106 -1
  64. package/dist/chart/components/high_low/high-low.component.js +12 -1
  65. package/dist/chart/components/high_low/high-low.drawer.js +126 -1
  66. package/dist/chart/components/highlights/highlights.component.js +46 -1
  67. package/dist/chart/components/highlights/highlights.drawer.js +154 -1
  68. package/dist/chart/components/highlights/highlights.model.js +75 -1
  69. package/dist/chart/components/labels_generator/numeric-axis-labels.generator.d.ts +1 -1
  70. package/dist/chart/components/labels_generator/numeric-axis-labels.generator.js +199 -1
  71. package/dist/chart/components/navigation_map/navigation-map-move.handler.d.ts +2 -2
  72. package/dist/chart/components/navigation_map/navigation-map-move.handler.js +108 -1
  73. package/dist/chart/components/navigation_map/navigation-map.component.js +112 -1
  74. package/dist/chart/components/navigation_map/navigation-map.drawer.js +244 -1
  75. package/dist/chart/components/navigation_map/navigation-map.model.js +33 -2
  76. package/dist/chart/components/pan/chart-pan.component.d.ts +2 -2
  77. package/dist/chart/components/pan/chart-pan.component.js +51 -1
  78. package/dist/chart/components/pane/extent/y-extent-component.d.ts +12 -18
  79. package/dist/chart/components/pane/extent/y-extent-component.js +120 -1
  80. package/dist/chart/components/pane/pane-hit-test.controller.js +55 -1
  81. package/dist/chart/components/pane/pane-manager.component.d.ts +10 -5
  82. package/dist/chart/components/pane/pane-manager.component.js +148 -1
  83. package/dist/chart/components/pane/pane.component.d.ts +16 -32
  84. package/dist/chart/components/pane/pane.component.js +278 -1
  85. package/dist/chart/components/resizer/bar-resizer.component.js +139 -1
  86. package/dist/chart/components/resizer/bar-resizer.drawer.js +46 -1
  87. package/dist/chart/components/snapshot/snapshot.component.js +48 -1
  88. package/dist/chart/components/volumes/separate-volumes.component.d.ts +6 -10
  89. package/dist/chart/components/volumes/separate-volumes.component.js +63 -1
  90. package/dist/chart/components/volumes/volume-color-resolvers.functions.js +18 -1
  91. package/dist/chart/components/volumes/volumes.component.d.ts +6 -7
  92. package/dist/chart/components/volumes/volumes.component.js +94 -1
  93. package/dist/chart/components/volumes/volumes.drawer.d.ts +5 -12
  94. package/dist/chart/components/volumes/volumes.drawer.js +140 -1
  95. package/dist/chart/components/volumes/volumes.formatter.js +31 -1
  96. package/dist/chart/components/volumes/volumes.model.d.ts +2 -2
  97. package/dist/chart/components/volumes/volumes.model.js +43 -1
  98. package/dist/chart/components/watermark/water-mark.component.js +103 -1
  99. package/dist/chart/components/watermark/water-mark.drawer.js +187 -1
  100. package/dist/chart/components/x_axis/numeric-x-axis-labels.generator.js +27 -1
  101. package/dist/chart/components/x_axis/time/parser/time-formats-matchers.functions.js +187 -1
  102. package/dist/chart/components/x_axis/time/parser/time-formats-parser.functions.js +76 -1
  103. package/dist/chart/components/x_axis/time/parser/time-formats-validators.functions.js +79 -1
  104. package/dist/chart/components/x_axis/time/parser/time-formats.model.js +14 -1
  105. package/dist/chart/components/x_axis/time/x-axis-weights.functions.d.ts +1 -1
  106. package/dist/chart/components/x_axis/time/x-axis-weights.functions.js +143 -1
  107. package/dist/chart/components/x_axis/time/x-axis-weights.generator.js +73 -1
  108. package/dist/chart/components/x_axis/x-axis-draw.functions.js +49 -1
  109. package/dist/chart/components/x_axis/x-axis-labels.drawer.js +70 -1
  110. package/dist/chart/components/x_axis/x-axis-labels.generator.d.ts +2 -2
  111. package/dist/chart/components/x_axis/x-axis-labels.generator.js +332 -1
  112. package/dist/chart/components/x_axis/x-axis-labels.model.js +35 -1
  113. package/dist/chart/components/x_axis/x-axis-scale.handler.d.ts +2 -2
  114. package/dist/chart/components/x_axis/x-axis-scale.handler.js +60 -1
  115. package/dist/chart/components/x_axis/x-axis-time-labels.drawer.js +82 -1
  116. package/dist/chart/components/x_axis/x-axis.component.d.ts +2 -2
  117. package/dist/chart/components/x_axis/x-axis.component.js +119 -1
  118. package/dist/chart/components/y_axis/label-color.functions.js +53 -1
  119. package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.d.ts +4 -4
  120. package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.js +33 -1
  121. package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.d.ts +3 -3
  122. package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.js +67 -1
  123. package/dist/chart/components/y_axis/price_labels/labels-positions-calculator.js +56 -1
  124. package/dist/chart/components/y_axis/price_labels/last-candle-labels.provider.js +95 -1
  125. package/dist/chart/components/y_axis/price_labels/price-label.drawer.d.ts +2 -2
  126. package/dist/chart/components/y_axis/price_labels/price-label.drawer.js +119 -1
  127. package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.d.ts +9 -8
  128. package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.js +201 -1
  129. package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.d.ts +6 -7
  130. package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.js +58 -1
  131. package/dist/chart/components/y_axis/y-axis-base-labels.model.d.ts +6 -4
  132. package/dist/chart/components/y_axis/y-axis-base-labels.model.js +47 -1
  133. package/dist/chart/components/y_axis/y-axis-labels.drawer.d.ts +4 -4
  134. package/dist/chart/components/y_axis/y-axis-labels.drawer.js +161 -1
  135. package/dist/chart/components/y_axis/y-axis-scale.handler.d.ts +2 -2
  136. package/dist/chart/components/y_axis/y-axis-scale.handler.js +72 -1
  137. package/dist/chart/components/y_axis/y-axis.component.d.ts +32 -41
  138. package/dist/chart/components/y_axis/y-axis.component.js +220 -1
  139. package/dist/chart/components/y_axis/y-axis.drawer.d.ts +9 -12
  140. package/dist/chart/components/y_axis/y-axis.drawer.js +96 -1
  141. package/dist/chart/components/y_axis/y-axis.model.d.ts +9 -17
  142. package/dist/chart/components/y_axis/y-axis.model.js +33 -1
  143. package/dist/chart/drawers/chart-background.drawer.js +69 -1
  144. package/dist/chart/drawers/chart-type-drawers/area.drawer.js +69 -1
  145. package/dist/chart/drawers/chart-type-drawers/bar.drawer.js +57 -1
  146. package/dist/chart/drawers/chart-type-drawers/baseline.drawer.js +84 -1
  147. package/dist/chart/drawers/chart-type-drawers/candle.drawer.js +162 -1
  148. package/dist/chart/drawers/chart-type-drawers/histogram.drawer.js +57 -1
  149. package/dist/chart/drawers/chart-type-drawers/line.drawer.js +38 -1
  150. package/dist/chart/drawers/chart-type-drawers/scatter-plot.drawer.js +19 -1
  151. package/dist/chart/drawers/clear-canvas.drawer.js +14 -1
  152. package/dist/chart/drawers/composite.drawer.js +67 -1
  153. package/dist/chart/drawers/data-series-drawers/candle-series-wrapper.js +50 -1
  154. package/dist/chart/drawers/data-series-drawers/color-candle.drawer.js +35 -1
  155. package/dist/chart/drawers/data-series-drawers/data-series-drawers.utils.js +16 -1
  156. package/dist/chart/drawers/data-series-drawers/difference-cloud.drawer.js +106 -1
  157. package/dist/chart/drawers/data-series-drawers/histogram.drawer.js +23 -1
  158. package/dist/chart/drawers/data-series-drawers/linear.drawer.js +19 -1
  159. package/dist/chart/drawers/data-series-drawers/points.drawer.js +19 -1
  160. package/dist/chart/drawers/data-series-drawers/rectangular-tool.drawer.js +7 -1
  161. package/dist/chart/drawers/data-series-drawers/text.drawer.js +25 -1
  162. package/dist/chart/drawers/data-series-drawers/trend-histogram.drawer.js +35 -1
  163. package/dist/chart/drawers/data-series-drawers/triangle.drawer.js +22 -1
  164. package/dist/chart/drawers/data-series.drawer.d.ts +5 -7
  165. package/dist/chart/drawers/data-series.drawer.js +56 -1
  166. package/dist/chart/drawers/drawing-manager.d.ts +1 -1
  167. package/dist/chart/drawers/drawing-manager.js +177 -1
  168. package/dist/chart/drawers/ht-data-series.drawer.js +37 -1
  169. package/dist/chart/events/event-bus.js +73 -1
  170. package/dist/chart/events/events.js +3 -1
  171. package/dist/chart/inputhandlers/candle-tap.handler.js +46 -1
  172. package/dist/chart/inputhandlers/chart-resize.handler.js +98 -1
  173. package/dist/chart/inputhandlers/cross-event-producer.component.js +67 -1
  174. package/dist/chart/inputhandlers/hover-producer.component.d.ts +2 -2
  175. package/dist/chart/inputhandlers/hover-producer.component.js +228 -1
  176. package/dist/chart/inputhandlers/main-canvas-touch.handler.d.ts +2 -2
  177. package/dist/chart/inputhandlers/main-canvas-touch.handler.js +80 -1
  178. package/dist/chart/inputlisteners/canvas-input-listener.component.js +629 -1
  179. package/dist/chart/model/baseline.model.js +88 -1
  180. package/dist/chart/model/bounds.model.js +1 -1
  181. package/dist/chart/model/candle-hover.js +70 -1
  182. package/dist/chart/model/candle-series-high-low.provider.js +45 -1
  183. package/dist/chart/model/candle-series.model.d.ts +3 -3
  184. package/dist/chart/model/candle-series.model.js +245 -1
  185. package/dist/chart/model/candle.model.js +69 -1
  186. package/dist/chart/model/canvas.model.js +228 -1
  187. package/dist/chart/model/chart-base-element.js +129 -1
  188. package/dist/chart/model/compare-series-hover.js +25 -1
  189. package/dist/chart/model/data-series-view.d.ts +5 -5
  190. package/dist/chart/model/data-series-view.js +111 -1
  191. package/dist/chart/model/data-series.config.js +14 -1
  192. package/dist/chart/model/data-series.model.d.ts +4 -4
  193. package/dist/chart/model/data-series.model.js +281 -1
  194. package/dist/chart/model/date-time.formatter.js +151 -1
  195. package/dist/chart/model/hit-test-canvas.model.d.ts +1 -1
  196. package/dist/chart/model/hit-test-canvas.model.js +256 -1
  197. package/dist/chart/model/main-candle-series.model.d.ts +1 -1
  198. package/dist/chart/model/main-candle-series.model.js +29 -1
  199. package/dist/chart/model/scale.model.d.ts +2 -1
  200. package/dist/chart/model/scale.model.js +316 -1
  201. package/dist/chart/model/scaling/auto-scale.model.js +97 -1
  202. package/dist/chart/model/scaling/constrait.functions.js +61 -1
  203. package/dist/chart/model/scaling/lock-ratio.model.js +17 -1
  204. package/dist/chart/model/scaling/move-chart.functions.js +22 -1
  205. package/dist/chart/model/scaling/viewport.model.d.ts +2 -2
  206. package/dist/chart/model/scaling/viewport.model.js +279 -1
  207. package/dist/chart/model/scaling/x-zooming.functions.js +35 -1
  208. package/dist/chart/model/time-zone.model.js +109 -1
  209. package/dist/chart/model/visual-candle.js +134 -1
  210. package/dist/chart/utils/__tests__/array.utils.test.js +135 -1
  211. package/dist/chart/utils/__tests__/math.utils.test.js +14 -1
  212. package/dist/chart/utils/__tests__/object.utils.test.js +11 -1
  213. package/dist/chart/utils/__tests__/priceIncrementsUtils.test.js +29 -1
  214. package/dist/chart/utils/array.utils.d.ts +1 -1
  215. package/dist/chart/utils/array.utils.js +269 -1
  216. package/dist/chart/utils/auto-period-detector.utils.js +39 -1
  217. package/dist/chart/utils/candles-generator-ts.utils.js +20 -1
  218. package/dist/chart/utils/candles-generator.utils.js +161 -1
  219. package/dist/chart/utils/candles.utils.js +42 -1
  220. package/dist/chart/utils/canvas/canvas-drawing-functions.utils.js +144 -1
  221. package/dist/chart/utils/canvas/canvas-font-measure-tool.utils.js +51 -1
  222. package/dist/chart/utils/canvas/canvas-text-functions.utils.js +156 -1
  223. package/dist/chart/utils/color.utils.js +31 -1
  224. package/dist/chart/utils/device/browser.utils.js +10 -1
  225. package/dist/chart/utils/device/device-detector.utils.js +24 -1
  226. package/dist/chart/utils/device/device-pixel-ratio.utils.js +21 -1
  227. package/dist/chart/utils/device/touchpad.utils.js +91 -1
  228. package/dist/chart/utils/dom.utils.js +15 -1
  229. package/dist/chart/utils/function.utils.js +16 -1
  230. package/dist/chart/utils/linkedList.utils.d.ts +28 -0
  231. package/dist/chart/utils/linkedList.utils.js +138 -0
  232. package/dist/chart/utils/math.utils.js +115 -1
  233. package/dist/chart/utils/merge.utils.js +56 -1
  234. package/dist/chart/utils/object.utils.js +43 -1
  235. package/dist/chart/utils/performance/animation-frame-cache.utils.js +77 -0
  236. package/dist/chart/utils/{perfomance → performance}/debounce.utils.js +7 -1
  237. package/dist/chart/utils/performance/memoize.utils.js +74 -0
  238. package/dist/chart/utils/performance/request-animation-frame-throttle.utils.js +43 -0
  239. package/dist/chart/utils/performance/throttle.utils.js +26 -0
  240. package/dist/chart/utils/price-increments.utils.d.ts +1 -0
  241. package/dist/chart/utils/price-increments.utils.js +127 -1
  242. package/dist/chart/utils/uuid.utils.js +4 -1
  243. package/dist/dxchart.min.js +9 -12
  244. package/dist/index.d.ts +3 -3
  245. package/dist/index.js +20 -1
  246. package/package.json +4 -4
  247. package/dist/chart/utils/perfomance/animation-frame-cache.utils.js +0 -6
  248. package/dist/chart/utils/perfomance/memoize.utils.js +0 -6
  249. package/dist/chart/utils/perfomance/request-animation-frame-throttle.utils.js +0 -6
  250. package/dist/chart/utils/perfomance/throttle.utils.js +0 -6
  251. /package/dist/chart/utils/{perfomance → performance}/animation-frame-cache.utils.d.ts +0 -0
  252. /package/dist/chart/utils/{perfomance → performance}/debounce.utils.d.ts +0 -0
  253. /package/dist/chart/utils/{perfomance → performance}/memoize.utils.d.ts +0 -0
  254. /package/dist/chart/utils/{perfomance → performance}/request-animation-frame-throttle.utils.d.ts +0 -0
  255. /package/dist/chart/utils/{perfomance → performance}/throttle.utils.d.ts +0 -0
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright (C) 2019 - 2023 Devexperts Solutions IE Limited
3
+ * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
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
+ */
6
+ import ChartBootstrap from './bootstrap';
7
+ import { BarType, PartialChartConfig } from './chart.config';
8
+ import { CandleSeries } from './components/chart/chart.component';
9
+ import { PaneComponent, YExtentFormatters } from './components/pane/pane.component';
10
+ /**
11
+ * New shiny chart wrapper
12
+ */
13
+ export declare class Chart extends ChartBootstrap {
14
+ yAxis: import("./components/y_axis/y-axis.component").YAxisComponent;
15
+ xAxis: import("./components/x_axis/x-axis.component").XAxisComponent;
16
+ watermark: import("./components/watermark/water-mark.component").WaterMarkComponent;
17
+ highlights: import("./components/highlights/highlights.component").HighlightsComponent;
18
+ events: import("./components/events/events.component").EventsComponent;
19
+ snapshot: import("./components/snapshot/snapshot.component").SnapshotComponent;
20
+ crosshair: import("./components/cross_tool/cross-tool.component").CrossToolComponent;
21
+ navigationMap: import("./components/navigation_map/navigation-map.component").NavigationMapComponent;
22
+ volumes: import("./components/volumes/volumes.component").VolumesComponent;
23
+ cursors: import("./canvas/cursor.handler").CursorHandler;
24
+ data: import("./components/chart/chart.component").ChartComponent;
25
+ scale: import("./model/scale.model").ScaleModel;
26
+ panning: import("./components/pan/chart-pan.component").ChartPanComponent;
27
+ constructor(element: HTMLElement, config?: PartialChartConfig);
28
+ /**
29
+ * Registers number formatters for pane
30
+ * @param uuid - pane's id
31
+ * @param formatters - object, that contains 3 fileds: 'regular', 'percent', 'logarithmic'.
32
+ * Each filed must have it's own formatter.
33
+ * If 'percent' and 'logarithmic' formatters did not provided, 'regular' will be applied.
34
+ */
35
+ registerPaneFormatters(uuid: string, formatters: YExtentFormatters): void;
36
+ /**
37
+ * Contains tear-down logic for chart
38
+ * Use when you want to unmount the chart from the host app
39
+ */
40
+ destroy(): void;
41
+ /**
42
+ * Sets the visibility of the volumes separately and updates the yAxis width.
43
+ * @param {boolean} separate - A boolean value indicating whether to show the volumes separately or not. Default value is false.
44
+ */
45
+ showSeparateVolumes(separate?: boolean): void;
46
+ setData(data: CandleSeries | CandleSeries[]): void;
47
+ updateData(data: CandleSeries | CandleSeries[]): void;
48
+ /**
49
+ * Sets the auto scale property of the scale model.
50
+ * @param {boolean} auto - A boolean value indicating whether the auto scale is enabled or not. Default value is true.
51
+ */
52
+ setAutoScale(auto?: boolean): void;
53
+ /**
54
+ * Sets the right-to-left (RTL) configuration of the component.
55
+ *
56
+ * @param {boolean} rtl - A boolean value indicating whether the component should be displayed in RTL mode.
57
+ * @returns {void}
58
+ */
59
+ setRtl(rtl: boolean): void;
60
+ setChartType(type: BarType): void;
61
+ createPane(): PaneComponent;
62
+ }
@@ -0,0 +1,106 @@
1
+ /*
2
+ * Copyright (C) 2019 - 2023 Devexperts Solutions IE Limited
3
+ * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
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
+ */
6
+ import ChartBootstrap from './bootstrap';
7
+ /**
8
+ * New shiny chart wrapper
9
+ */
10
+ export class Chart extends ChartBootstrap {
11
+ constructor(element, config = {}) {
12
+ super(element, config);
13
+ this.yAxis = this.yAxisComponent;
14
+ this.xAxis = this.xAxisComponent;
15
+ this.watermark = this.watermarkComponent;
16
+ this.highlights = this.highlightsComponent;
17
+ this.events = this.eventsComponent;
18
+ this.snapshot = this.snapshotComponent;
19
+ this.crosshair = this.crossToolComponent;
20
+ this.navigationMap = this.navigationMapComponent;
21
+ this.volumes = this.volumesComponent;
22
+ this.cursors = this.cursorHandler;
23
+ this.data = this.chartComponent;
24
+ this.scale = this.scaleModel;
25
+ this.panning = this.chartPanComponent;
26
+ }
27
+ /**
28
+ * Registers number formatters for pane
29
+ * @param uuid - pane's id
30
+ * @param formatters - object, that contains 3 fileds: 'regular', 'percent', 'logarithmic'.
31
+ * Each filed must have it's own formatter.
32
+ * If 'percent' and 'logarithmic' formatters did not provided, 'regular' will be applied.
33
+ */
34
+ registerPaneFormatters(uuid, formatters) {
35
+ var _a;
36
+ (_a = this.paneManager.panes[uuid]) === null || _a === void 0 ? void 0 : _a.setPaneValueFormatters(formatters);
37
+ }
38
+ /**
39
+ * Contains tear-down logic for chart
40
+ * Use when you want to unmount the chart from the host app
41
+ */
42
+ destroy() {
43
+ this.bus.setMuted(true);
44
+ this.chartComponents.forEach(c => c.disable());
45
+ this.parentElement.childNodes.forEach(n => n.remove());
46
+ this.parentElement.style.width = '';
47
+ this.parentElement.style.height = '';
48
+ }
49
+ /**
50
+ * Sets the visibility of the volumes separately and updates the yAxis width.
51
+ * @param {boolean} separate - A boolean value indicating whether to show the volumes separately or not. Default value is false.
52
+ */
53
+ showSeparateVolumes(separate = false) {
54
+ if (this.volumes) {
55
+ this.volumes.setShowVolumesSeparatly(separate);
56
+ this.canvasBoundsContainer.updateYAxisWidths();
57
+ }
58
+ }
59
+ setData(data) {
60
+ if (Array.isArray(data)) {
61
+ if (data.length === 0) {
62
+ return;
63
+ }
64
+ const [mainSeries, ...restSeries] = data;
65
+ this.chartComponent.setAllSeries(mainSeries, restSeries);
66
+ }
67
+ else {
68
+ this.chartComponent.setMainSeries(data);
69
+ }
70
+ }
71
+ updateData(data) {
72
+ if (Array.isArray(data)) {
73
+ if (data.length === 0) {
74
+ return;
75
+ }
76
+ const [mainSeries, ...restSeries] = data;
77
+ this.chartComponent.updateAllSeries(mainSeries, restSeries);
78
+ }
79
+ else {
80
+ this.chartComponent.updateAllSeries(data);
81
+ }
82
+ }
83
+ /**
84
+ * Sets the auto scale property of the scale model.
85
+ * @param {boolean} auto - A boolean value indicating whether the auto scale is enabled or not. Default value is true.
86
+ */
87
+ setAutoScale(auto = true) {
88
+ this.scale.autoScale(auto);
89
+ }
90
+ /**
91
+ * Sets the right-to-left (RTL) configuration of the component.
92
+ *
93
+ * @param {boolean} rtl - A boolean value indicating whether the component should be displayed in RTL mode.
94
+ * @returns {void}
95
+ */
96
+ setRtl(rtl) {
97
+ this.config.rtl = rtl;
98
+ this.bus.fireDraw();
99
+ }
100
+ setChartType(type) {
101
+ this.chartComponent.setChartType(type);
102
+ }
103
+ createPane() {
104
+ return this.paneManager.createPane();
105
+ }
106
+ }
@@ -12,11 +12,11 @@ import { ChartModel } from './chart.model';
12
12
  * @param scaleModel
13
13
  * @doc-tags scaling,viewport
14
14
  */
15
- export declare const createBasicScaleViewportTransformer: (scaleModel: ScaleModel) => (visualCandleSource: VisualCandle[]) => void;
15
+ export declare const createBasicScaleViewportTransformer: (scale: ScaleModel) => (visualCandleSource: VisualCandle[]) => void;
16
16
  /**
17
17
  * Moves the viewport between 2 timestamps.
18
18
  * @param scaleModel
19
19
  * @param chartModel
20
20
  * @param canvasAnimationContainer
21
21
  */
22
- export declare const createTimeFrameViewportTransformer: (scaleModel: ScaleModel, chartModel: ChartModel) => (timeframe: [Timestamp, Timestamp], zoomIn?: boolean | null) => void;
22
+ export declare const createTimeFrameViewportTransformer: (scale: ScaleModel, chartModel: ChartModel) => (timeframe: [Timestamp, Timestamp], zoomIn?: boolean | null) => void;
@@ -3,4 +3,34 @@
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 createBasicScaleViewportTransformer=t=>n=>{if(n.length!==0){const a=n.slice(Math.max(n.length-t.state.defaultViewportItems,0)),e=a[0],i=a[a.length-1];t.setXScale(e.startUnit,i.startUnit+i.width+t.offsets.right),t.doAutoScale(!0),t.recalculateZoomXYRatio(),t.fireChanged()}},createTimeFrameViewportTransformer=(t,n)=>(a,e=null)=>{const[i,o]=a,r=n.candleFromTimestamp(i).startUnit,m=n.candleFromTimestamp(o).startUnit,s=e===null?0:n.mainCandleSeries.meanCandleWidth*2,c=e?r-s:r+s,f=e?m+s:m-s;t.setXScale(c,f)};
6
+ /**
7
+ * Calculates the initial viewport.
8
+ * @param scaleModel
9
+ * @doc-tags scaling,viewport
10
+ */
11
+ export const createBasicScaleViewportTransformer = (scale) => (visualCandleSource) => {
12
+ if (visualCandleSource.length !== 0) {
13
+ const vCandles = visualCandleSource.slice(Math.max(visualCandleSource.length - scale.state.defaultViewportItems, 0));
14
+ const startCandle = vCandles[0];
15
+ const endCandle = vCandles[vCandles.length - 1];
16
+ scale.setXScale(startCandle.startUnit, endCandle.startUnit + endCandle.width + scale.offsets.right);
17
+ scale.doAutoScale(true);
18
+ scale.recalculateZoomXYRatio();
19
+ scale.fireChanged();
20
+ }
21
+ };
22
+ /**
23
+ * Moves the viewport between 2 timestamps.
24
+ * @param scaleModel
25
+ * @param chartModel
26
+ * @param canvasAnimationContainer
27
+ */
28
+ export const createTimeFrameViewportTransformer = (scale, chartModel) => (timeframe, zoomIn = null) => {
29
+ const [firstTimestamp, lastTimestamp] = timeframe;
30
+ const xStart = chartModel.candleFromTimestamp(firstTimestamp).startUnit;
31
+ const xEnd = chartModel.candleFromTimestamp(lastTimestamp).startUnit;
32
+ const additionalAnimationWidth = zoomIn === null ? 0 : chartModel.mainCandleSeries.meanCandleWidth * 2;
33
+ const animationEffectXStart = zoomIn ? xStart - additionalAnimationWidth : xStart + additionalAnimationWidth;
34
+ const animationEffectXEnd = zoomIn ? xEnd + additionalAnimationWidth : xEnd - additionalAnimationWidth;
35
+ scale.setXScale(animationEffectXStart, animationEffectXEnd);
36
+ };
@@ -3,4 +3,18 @@
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{hollowDirection as p,nameDirection as m}from"../../model/candle.model";import u from"../../model/visual-candle";export const defaultCandleTransformer=(o,{x:s,width:r,activeCandle:e})=>new u(s,r,o.open,o.close,o.hi,o.lo,m(o.open,o.close),o,!0,getCandleIsActive(o,e)),hollowCandleTransformer=(o,{x:s,width:r,activeCandle:e,prevCandle:t})=>{var i;return new u(s,r,o.open,o.close,o.hi,o.lo,p((i=t==null?void 0:t.close)!==null&&i!==void 0?i:o.close,o.close),o,!0,getCandleIsActive(o,e),o.close>o.open)},trendCandleTransformer=(o,{x:s,width:r,activeCandle:e,prevCandle:t})=>{var i;return new u(s,r,o.open,o.close,o.hi,o.lo,m((i=t==null?void 0:t.close)!==null&&i!==void 0?i:o.close,o.close),o,!0,getCandleIsActive(o,e),o.close>o.open)},getCandleIsActive=(o,s)=>{const r=s&&s.idx===o.idx;return r!=null?r:!1};
6
+ import { hollowDirection, nameDirection } from '../../model/candle.model';
7
+ import VisualCandle from '../../model/visual-candle';
8
+ export const defaultCandleTransformer = (candle, { x, width, activeCandle }) => new VisualCandle(x, width, candle.open, candle.close, candle.hi, candle.lo, nameDirection(candle.open, candle.close), candle, true, getCandleIsActive(candle, activeCandle));
9
+ export const hollowCandleTransformer = (candle, { x, width, activeCandle, prevCandle }) => {
10
+ var _a;
11
+ return new VisualCandle(x, width, candle.open, candle.close, candle.hi, candle.lo, hollowDirection((_a = prevCandle === null || prevCandle === void 0 ? void 0 : prevCandle.close) !== null && _a !== void 0 ? _a : candle.close, candle.close), candle, true, getCandleIsActive(candle, activeCandle), candle.close > candle.open);
12
+ };
13
+ export const trendCandleTransformer = (candle, { x, width, activeCandle, prevCandle }) => {
14
+ var _a;
15
+ return new VisualCandle(x, width, candle.open, candle.close, candle.hi, candle.lo, nameDirection((_a = prevCandle === null || prevCandle === void 0 ? void 0 : prevCandle.close) !== null && _a !== void 0 ? _a : candle.close, candle.close), candle, true, getCandleIsActive(candle, activeCandle), candle.close > candle.open);
16
+ };
17
+ export const getCandleIsActive = (candle, activeCandle) => {
18
+ const isActive = activeCandle && activeCandle.idx === candle.idx;
19
+ return isActive !== null && isActive !== void 0 ? isActive : false;
20
+ };
@@ -3,4 +3,5 @@
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{BASIC_CANDLE_WIDTH as t}from"../../model/candle.model";export const calculateCandleWidth=()=>t;
6
+ import { BASIC_CANDLE_WIDTH } from '../../model/candle.model';
7
+ export const calculateCandleWidth = () => BASIC_CANDLE_WIDTH;
@@ -3,4 +3,47 @@
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{finite as t}from"../../utils/math.utils";export const prepareCandle=e=>{var o;const i=t(e.close,e.open,e.hi,e.lo);if(!isFinite(i))throw new Error("Received candle without any price");const p=t(e.hi,Math.max(e.open,e.close),i),r=t(e.lo,Math.min(e.open,e.close),i),s=t(e.open,e.lo,i),n=t(e.close,e.hi,i);return{hi:p,lo:r,open:s,close:n,timestamp:e.timestamp,volume:(o=e.volume)!==null&&o!==void 0?o:0,expansion:e.expansion,idx:e.idx,impVolatility:e.impVolatility}},reindexCandles=e=>{for(let o=0;o<e.length;++o)e[o].idx=o},deleteCandlesIndex=e=>{e.forEach(o=>{o.idx=void 0})};
6
+ import { finite } from '../../utils/math.utils';
7
+ /**
8
+ * In the early days of Futures contract there is no much trading,
9
+ * so there is not enough information to build a candle: only Open/Close value available.
10
+ * In this case Daily candle, which we receive, must be completed to full OHLC with equal values.
11
+ */
12
+ export const prepareCandle = (candle) => {
13
+ var _a;
14
+ const settlementPrice = finite(candle.close, candle.open, candle.hi, candle.lo);
15
+ if (!isFinite(settlementPrice)) {
16
+ throw new Error('Received candle without any price');
17
+ }
18
+ // @ts-ignore
19
+ const preparedCandleHi = finite(candle.hi, Math.max(candle.open, candle.close), settlementPrice);
20
+ // @ts-ignore
21
+ const preparedCandleLo = finite(candle.lo, Math.min(candle.open, candle.close), settlementPrice);
22
+ const preparedCandleOpen = finite(candle.open, candle.lo, settlementPrice);
23
+ const preparedCandleClose = finite(candle.close, candle.hi, settlementPrice);
24
+ return {
25
+ hi: preparedCandleHi,
26
+ lo: preparedCandleLo,
27
+ open: preparedCandleOpen,
28
+ close: preparedCandleClose,
29
+ timestamp: candle.timestamp,
30
+ volume: (_a = candle.volume) !== null && _a !== void 0 ? _a : 0,
31
+ expansion: candle.expansion,
32
+ idx: candle.idx,
33
+ impVolatility: candle.impVolatility,
34
+ };
35
+ };
36
+ /**
37
+ * Adds index to candles according to their array index.
38
+ * @param candles
39
+ */
40
+ export const reindexCandles = (candles) => {
41
+ for (let i = 0; i < candles.length; ++i) {
42
+ candles[i].idx = i;
43
+ }
44
+ };
45
+ export const deleteCandlesIndex = (candles) => {
46
+ candles.forEach(candle => {
47
+ candle.idx = undefined;
48
+ });
49
+ };
@@ -39,7 +39,7 @@ export interface ChartWheelEvent {
39
39
  export declare class ChartAreaPanHandler extends ChartBaseElement {
40
40
  private bus;
41
41
  private config;
42
- private scaleModel;
42
+ private scale;
43
43
  private mainCanvasParent;
44
44
  private canvasInputListener;
45
45
  private canvasBoundsContainer;
@@ -50,7 +50,7 @@ export declare class ChartAreaPanHandler extends ChartBaseElement {
50
50
  xDraggedCandlesDelta: number;
51
51
  lastXStart: number;
52
52
  wheelTrottleTime: number;
53
- constructor(bus: EventBus, config: FullChartConfig, scaleModel: ScaleModel, mainCanvasParent: Element, canvasInputListener: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, canvasAnimation: CanvasAnimation, chartPanComponent: ChartPanComponent);
53
+ constructor(bus: EventBus, config: FullChartConfig, scale: ScaleModel, mainCanvasParent: Element, canvasInputListener: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, canvasAnimation: CanvasAnimation, chartPanComponent: ChartPanComponent);
54
54
  /**
55
55
  * It observes the wheel event on all panes of the canvas and throttles it to the specified time.
56
56
  * It then calculates the zoom sensitivity based on whether the event was triggered by a touchpad or not.
@@ -74,7 +74,7 @@ export declare class ChartAreaPanHandler extends ChartBaseElement {
74
74
  * @param {HitBoundsTest} hitTest - The hit test of the pane.
75
75
  * @returns {DragNDropYComponent} - The drag and drop component for panning the chart along the Y-axis.
76
76
  */
77
- registerChartYPanHandler(scaleModel: ScaleModel, hitTest: HitBoundsTest): DragNDropYComponent;
77
+ registerChartYPanHandler(scale: ScaleModel, hitTest: HitBoundsTest): DragNDropYComponent;
78
78
  private onXDragStart;
79
79
  private onXDragTick;
80
80
  }
@@ -3,4 +3,200 @@
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{merge as C}from"rxjs";import{throttleTime as b}from"rxjs/operators";import{VIEWPORT_ANIMATION_ID as v}from"../../animation/canvas-animation";import{CanvasElement as m}from"../../canvas/canvas-bounds-container";import{MainCanvasTouchHandler as P}from"../../inputhandlers/main-canvas-touch.handler";import{ChartBaseElement as T}from"../../model/chart-base-element";import{pixelsToUnits as p}from"../../model/scaling/viewport.model";import{deviceDetector as X}from"../../utils/device/device-detector.utils";import{getTouchpadSensitivity as A,touchpadDetector as M}from"../../utils/device/touchpad.utils";import{DragNDropXComponent as x}from"../dran-n-drop_helper/drag-n-drop-x.component";import{DragNDropYComponent as w}from"../dran-n-drop_helper/drag-n-drop-y.component";export class ChartAreaPanHandler extends T{constructor(t,a,e,i,s,n,o,r){super(),this.bus=t,this.config=a,this.scaleModel=e,this.mainCanvasParent=i,this.canvasInputListener=s,this.canvasBoundsContainer=n,this.canvasAnimation=o,this.chartPanComponent=r,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelTrottleTime=15,this.zoomXHandler=h=>{const c=M(h),l=h.deltaY<0,f=c?A(this.config):this.config.scale.zoomSensitivity;if(this.config.scale.zoomToCursor){const D=this.canvasBoundsContainer.getBounds(m.CANVAS).width,S=h.offsetX/D;this.scaleModel.zoomXToPercent(S,l,!1,f)}else this.scaleModel.zoomXToEnd(l,f);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(v),this.xDraggedCandlesDelta=0,this.lastXStart=this.scaleModel.xStart},this.onXDragTick=h=>{const{delta:c}=h;this.currentPoint.x=c;const l=p(c,this.scaleModel.zoomX);this.scaleModel.moveXStart(this.lastXStart-l),this.bus.fireDraw()},this.touchHandler=new P(this.scaleModel,this.canvasInputListener,this.mainCanvasParent);const u=this.canvasBoundsContainer.getBoundsHitTest(m.ALL_PANES),g=new x(u,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick},this.canvasInputListener,this.chartPanComponent,{disableChartPanning:!1});this.addChildEntity(g)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(m.ALL_PANES);this.addRxSubscription(C(this.canvasInputListener.observeWheel(t),this.canvasInputListener.observePinch(t)).pipe(b(this.wheelTrottleTime,void 0,{trailing:!0,leading:!0})).subscribe(this.zoomXHandler)),this.addRxSubscription(this.canvasInputListener.observeScrollGesture().pipe(b(this.wheelTrottleTime,void 0,{trailing:!0,leading:!0})).subscribe(a=>{let e=-1;const i=X();(i==="apple"||i==="mobile")&&(e=1);let s=0,n=0;if(s+=a.deltaX*e,n+=a.deltaY*-e,s!==0&&Math.abs(s)>Math.abs(n)){const o=p(s,this.scaleModel.zoomX);this.scaleModel.moveXStart(this.scaleModel.xStart-o)}else n!==0&&Math.abs(n)>Math.abs(s)&&this.zoomXHandler(a);this.bus.fireDraw()})),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:a})=>{this.lastXStart+=a})),this.touchHandler.activate(),this.addSubscription(this.touchHandler.deactivate.bind(this.touchHandler))}registerChartYPanHandler(t,a){let e=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(v),this.currentPoint={x:0,y:0},e=t.yStart},s=o=>{const{delta:r}=o;if(this.currentPoint.y=r,t.state.auto)shouldDisableAutoScale(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const u=p(t.state.inverse?-r:r,t.zoomY);t.moveYStart(e+u)}},n=new w(a,{onDragTick:s,onDragStart:i},this.canvasInputListener,this.chartPanComponent,{disableChartPanning:!1});return this.addChildEntity(n),n}}export const shouldDisableAutoScale=(d,t)=>{if(!t.enabled)return!1;const a=Math.abs(d.y),e=Math.pow(Math.pow(Math.abs(d.x),2)+Math.pow(a,2),.5),i=Math.abs(Math.acos(a/e));return a>t.yDiff&&i<t.edgeAngle};
6
+ import { merge } from 'rxjs';
7
+ import { throttleTime } from 'rxjs/operators';
8
+ import { VIEWPORT_ANIMATION_ID } from '../../animation/canvas-animation';
9
+ import { CanvasElement } from '../../canvas/canvas-bounds-container';
10
+ import { MainCanvasTouchHandler } from '../../inputhandlers/main-canvas-touch.handler';
11
+ import { ChartBaseElement } from '../../model/chart-base-element';
12
+ import { pixelsToUnits } from '../../model/scaling/viewport.model';
13
+ import { deviceDetector } from '../../utils/device/device-detector.utils';
14
+ import { getTouchpadSensitivity, touchpadDetector } from '../../utils/device/touchpad.utils';
15
+ import { DragNDropXComponent } from '../dran-n-drop_helper/drag-n-drop-x.component';
16
+ import { DragNDropYComponent } from '../dran-n-drop_helper/drag-n-drop-y.component';
17
+ /**
18
+ * ChartAreaPanHandler is a class that handles the panning and zooming of the chart area.
19
+ * It extends the ChartBaseElement class and has the following properties:
20
+ * @property {MainCanvasTouchHandler} touchHandler - An instance of the MainCanvasTouchHandler class.
21
+ * @property {Point} currentPoint - An object that represents the current point of the chart area.
22
+ * @property {number} xDraggedCandlesDelta - A number that represents the number of candles delta changed during X dragging.
23
+ * @property {number} lastXStart - A number that represents the last X start position.
24
+ * @property {number} lastYStart - A number that represents the last Y start position.
25
+ * @property {number} wheelTrottleTime - A number that represents the time in ms for the wheel throttle.
26
+ * @constructor
27
+ * @param {EventBus} bus - An instance of the EventBus class.
28
+ * @param {FullChartConfig} config - An instance of the FullChartConfig class.
29
+ * @param {ScaleModel} scaleModel - An instance of the ScaleModel class.
30
+ * @param {Element} mainCanvasParent - The parent element of the main canvas.
31
+ * @param {CanvasInputListenerComponent} canvasInputListener - An instance of the CanvasInputListenerComponent class.
32
+ * @param {CanvasBoundsContainer} canvasBoundsContainer - An instance of the CanvasBoundsContainer class.
33
+ * @param {CanvasAnimation} canvasAnimation - An instance of the CanvasAnimation class.
34
+ * @param {ChartPanComponent} chartPanComponent - An instance of the ChartPanComponent class.
35
+
36
+ */
37
+ export class ChartAreaPanHandler extends ChartBaseElement {
38
+ constructor(bus, config, scale, mainCanvasParent, canvasInputListener, canvasBoundsContainer, canvasAnimation, chartPanComponent) {
39
+ super();
40
+ this.bus = bus;
41
+ this.config = config;
42
+ this.scale = scale;
43
+ this.mainCanvasParent = mainCanvasParent;
44
+ this.canvasInputListener = canvasInputListener;
45
+ this.canvasBoundsContainer = canvasBoundsContainer;
46
+ this.canvasAnimation = canvasAnimation;
47
+ this.chartPanComponent = chartPanComponent;
48
+ this.currentPoint = { x: 0, y: 0 };
49
+ // number of candles delta changed during X dragging: 1, 5 or -3 for ex.
50
+ this.xDraggedCandlesDelta = 0;
51
+ this.lastXStart = 0;
52
+ this.wheelTrottleTime = 15; // in ms
53
+ /**
54
+ * It observes the wheel event on all panes of the canvas and throttles it to the specified time.
55
+ * It then calculates the zoom sensitivity based on whether the event was triggered by a touchpad or not.
56
+ * If the zoomToCursor configuration is set to true, it calculates the viewport percentage based on the zoomCanvasOffset and canvas width.
57
+ * It then calls the zoomXToPercent method of the scaleModel to zoom in or out based on the zoomIn parameter.
58
+ * If the zoomToCursor configuration is set to false, it calls the zoomXToEnd method of the scaleModel to zoom in or out based on the zoomIn parameter.
59
+ * Finally, it fires the draw event of the bus to redraw the canvas.
60
+ * @param {WheelEvent} e - Wheel event
61
+ * @returns {void}
62
+ */
63
+ this.zoomXHandler = (e) => {
64
+ const isTouchpad = touchpadDetector(e);
65
+ const zoomIn = e.deltaY < 0;
66
+ const zoomSensitivity = isTouchpad ? getTouchpadSensitivity(this.config) : this.config.scale.zoomSensitivity;
67
+ if (this.config.scale.zoomToCursor) {
68
+ const b = this.canvasBoundsContainer.getBounds(CanvasElement.CANVAS);
69
+ const canvasW = b.width;
70
+ const zoomCanvasOffset = e.offsetX;
71
+ // 0.5 - zoom middle exactly
72
+ // 0..0.5 - zoom to left side
73
+ // 0.5..1 - zoom to right side
74
+ const viewportPercent = zoomCanvasOffset / canvasW;
75
+ this.scale.zoomXToPercent(viewportPercent, zoomIn, false, zoomSensitivity);
76
+ }
77
+ else {
78
+ this.scale.zoomXToEnd(zoomIn, zoomSensitivity);
79
+ }
80
+ this.bus.fireDraw();
81
+ };
82
+ this.onXDragStart = () => {
83
+ this.canvasAnimation.forceStopAnimation(VIEWPORT_ANIMATION_ID);
84
+ this.xDraggedCandlesDelta = 0;
85
+ this.lastXStart = this.scale.xStart;
86
+ };
87
+ this.onXDragTick = (dragInfo) => {
88
+ const { delta: absoluteXDelta } = dragInfo;
89
+ this.currentPoint.x = absoluteXDelta;
90
+ const unitsDelta = pixelsToUnits(absoluteXDelta, this.scale.zoomX);
91
+ this.scale.moveXStart(this.lastXStart - unitsDelta);
92
+ this.bus.fireDraw();
93
+ };
94
+ this.touchHandler = new MainCanvasTouchHandler(this.scale, this.canvasInputListener, this.mainCanvasParent);
95
+ const allPanesHitTest = this.canvasBoundsContainer.getBoundsHitTest(CanvasElement.ALL_PANES);
96
+ //#region drag-n-drop logic
97
+ const dragNDropXComponent = new DragNDropXComponent(allPanesHitTest, {
98
+ onDragStart: this.onXDragStart,
99
+ onDragTick: this.onXDragTick,
100
+ }, this.canvasInputListener, this.chartPanComponent, {
101
+ disableChartPanning: false,
102
+ });
103
+ this.addChildEntity(dragNDropXComponent);
104
+ //#endregion
105
+ }
106
+ /**
107
+ * This method is used to activate the zoom functionality of the canvas. It extends the doActivate method of the parent class.
108
+ * @protected
109
+ * @returns {void}
110
+ */
111
+ doActivate() {
112
+ super.doActivate();
113
+ //#region hit tests
114
+ const allPanesHitTest = this.canvasBoundsContainer.getBoundsHitTest(CanvasElement.ALL_PANES);
115
+ //#endregion
116
+ this.addRxSubscription(merge(this.canvasInputListener.observeWheel(allPanesHitTest), this.canvasInputListener.observePinch(allPanesHitTest))
117
+ .pipe(throttleTime(this.wheelTrottleTime, undefined, { trailing: true, leading: true }))
118
+ .subscribe(this.zoomXHandler));
119
+ this.addRxSubscription(this.canvasInputListener
120
+ .observeScrollGesture()
121
+ .pipe(throttleTime(this.wheelTrottleTime, undefined, { trailing: true, leading: true }))
122
+ .subscribe((e) => {
123
+ let direction = -1;
124
+ const device = deviceDetector();
125
+ if (device === 'apple' || device === 'mobile') {
126
+ direction = 1;
127
+ }
128
+ let deltaX = 0;
129
+ let deltaY = 0;
130
+ deltaX += e.deltaX * direction;
131
+ deltaY += e.deltaY * -direction;
132
+ if (deltaX !== 0 && Math.abs(deltaX) > Math.abs(deltaY)) {
133
+ const unitsDelta = pixelsToUnits(deltaX, this.scale.zoomX);
134
+ this.scale.moveXStart(this.scale.xStart - unitsDelta);
135
+ }
136
+ else if (deltaY !== 0 && Math.abs(deltaY) > Math.abs(deltaX)) {
137
+ this.zoomXHandler(e);
138
+ }
139
+ this.bus.fireDraw();
140
+ }));
141
+ this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject
142
+ .asObservable()
143
+ .subscribe(({ prependedCandlesWidth }) => {
144
+ this.lastXStart += prependedCandlesWidth;
145
+ }));
146
+ this.touchHandler.activate();
147
+ this.addSubscription(this.touchHandler.deactivate.bind(this.touchHandler));
148
+ }
149
+ /**
150
+ * Registers a handler for panning the chart along the Y-axis.
151
+ * @param {ScaleModel} scaleModel - The scale model of the extent.
152
+ * @param {HitBoundsTest} hitTest - The hit test of the pane.
153
+ * @returns {DragNDropYComponent} - The drag and drop component for panning the chart along the Y-axis.
154
+ */
155
+ registerChartYPanHandler(scale, hitTest) {
156
+ // we can have multiple extents which can have different yStarts, so we need to store last yStart for each extent
157
+ let lastYStart = scale.yStart;
158
+ // disable all pan handlers when hover data series
159
+ const onYDragStart = () => {
160
+ this.canvasAnimation.forceStopAnimation(VIEWPORT_ANIMATION_ID);
161
+ this.currentPoint = { x: 0, y: 0 };
162
+ lastYStart = scale.yStart;
163
+ };
164
+ const onYDragTick = (dragInfo) => {
165
+ const { delta: absoluteDelta } = dragInfo;
166
+ this.currentPoint.y = absoluteDelta;
167
+ if (scale.state.auto) {
168
+ if (shouldDisableAutoScale(this.currentPoint, scale.state.autoScaleDisableOnDrag)) {
169
+ scale.autoScale(false);
170
+ }
171
+ }
172
+ else {
173
+ const unitsDelta = pixelsToUnits(scale.state.inverse ? -absoluteDelta : absoluteDelta, scale.zoomY);
174
+ scale.moveYStart(lastYStart + unitsDelta);
175
+ }
176
+ };
177
+ const dragNDropYComponent = new DragNDropYComponent(hitTest, {
178
+ onDragTick: onYDragTick,
179
+ onDragStart: onYDragStart,
180
+ }, this.canvasInputListener, this.chartPanComponent, {
181
+ disableChartPanning: false,
182
+ });
183
+ this.addChildEntity(dragNDropYComponent);
184
+ return dragNDropYComponent;
185
+ }
186
+ }
187
+ /**
188
+ * This function calculates angle between current point and point(0, 0), and compares the result with config values
189
+ * @param point
190
+ * @param config
191
+ *
192
+ * @doc-tags chart-core,auto-scale,y-axis
193
+ */
194
+ export const shouldDisableAutoScale = (point, config) => {
195
+ if (!config.enabled) {
196
+ return false;
197
+ }
198
+ const absY = Math.abs(point.y);
199
+ const lenProduct = Math.pow((Math.pow(Math.abs(point.x), 2) + Math.pow(absY, 2)), 0.5);
200
+ const angle = Math.abs(Math.acos(absY / lenProduct));
201
+ return absY > config.yDiff && angle < config.edgeAngle;
202
+ };
@@ -3,4 +3,69 @@
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{Subject as a}from"rxjs";import{autoDetectPeriod as s}from"../../utils/auto-period-detector.utils";import{searchCandleIndex as n}from"../../utils/candles.utils";import{fakeVisualCandle as o,fakeVisualPoint as r}from"./fake-candles";export class ChartBaseModel{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new a,this.dataSetSubject=new a,this.dataRemovedSubject=new a,this.dataPrependSubject=new a,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,i=!0){const e=n(t,i,this.mainDataPoints,this.period);return this.dataFromIdx(e.index)}recalculatePeriod(){const t=s(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const i=this.mainVisualPoints[t];return i||(this.type==="candle"?o(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):r(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}
6
+ import { Subject } from 'rxjs';
7
+ import { autoDetectPeriod } from '../../utils/auto-period-detector.utils';
8
+ import { searchCandleIndex } from '../../utils/candles.utils';
9
+ import { fakeVisualCandle, fakeVisualPoint } from './fake-candles';
10
+ /**
11
+ * This model is an abstraction which describes manipulations tied to the main data series.
12
+ * For example, all x-scale is based on the main data series. If we add a new data series, we need to match its coordinates to the main data series.
13
+ */
14
+ export class ChartBaseModel {
15
+ constructor(type) {
16
+ this.type = type;
17
+ this.mainDataPoints = [];
18
+ this.mainVisualPoints = [];
19
+ this.dataUpdatedSubject = new Subject();
20
+ this.dataSetSubject = new Subject();
21
+ this.dataRemovedSubject = new Subject();
22
+ this.dataPrependSubject = new Subject();
23
+ /**
24
+ * Mean data point width in abstract units.
25
+ */
26
+ this.meanDataWidth = 1;
27
+ /**
28
+ * Candles aggregation period in ms. Required for future candles calculation.
29
+ */
30
+ this.period = 1;
31
+ }
32
+ /**
33
+ * For given timestamp finds the closest candle in dataset.
34
+ * @param timestamp
35
+ */
36
+ // TODO think how to make this function like candleFromX
37
+ dataFromTimestamp(timestamp, shouldExtrapolate = true) {
38
+ const result = searchCandleIndex(timestamp, shouldExtrapolate, this.mainDataPoints, this.period);
39
+ return this.dataFromIdx(result.index);
40
+ }
41
+ /**
42
+ * Recalculates the period of the main candle series based on the data points.
43
+ * If a period is detected, it is set as the new period.
44
+ */
45
+ recalculatePeriod() {
46
+ const naivePeriod = autoDetectPeriod(this.mainDataPoints);
47
+ if (naivePeriod) {
48
+ this.period = naivePeriod;
49
+ }
50
+ }
51
+ /**
52
+ * For given index returns the closest visual candle, or fake candle with correct X coordinate.
53
+ * @param idx - index of candle
54
+ */
55
+ dataFromIdx(idx) {
56
+ const vc = this.mainVisualPoints[idx];
57
+ if (vc) {
58
+ return vc;
59
+ }
60
+ // TODO think maybe to create fake candles in advance, maybe this will improve performance
61
+ if (this.type === 'candle') {
62
+ // TODO how to correctly infer type?
63
+ // @ts-ignore
64
+ return fakeVisualCandle(this.mainDataPoints, this.mainVisualPoints, this.meanDataWidth, idx, this.period);
65
+ }
66
+ else {
67
+ // @ts-ignore
68
+ return fakeVisualPoint(this.mainDataPoints, this.mainVisualPoints, this.meanDataWidth, idx, this.period);
69
+ }
70
+ }
71
+ }
@@ -23,6 +23,7 @@ import { ChartPanComponent } from '../pan/chart-pan.component';
23
23
  import { PaneManager } from '../pane/pane-manager.component';
24
24
  import { CandleWidthCalculator, ChartModel, LastCandleLabelHandler, VisualCandleCalculator } from './chart.model';
25
25
  import { PrependedCandlesData } from './chart-base.model';
26
+ import { DynamicObjectsComponent } from '../dynamic-objects/dynamic-objects.component';
26
27
  /**
27
28
  * Represents a financial instrument to be displayed on a chart
28
29
  * @class
@@ -51,16 +52,18 @@ export declare class ChartComponent extends ChartBaseElement {
51
52
  readonly chartModel: ChartModel;
52
53
  canvasModel: CanvasModel;
53
54
  private config;
54
- private scaleModel;
55
+ private scale;
55
56
  private canvasBoundsContainer;
56
57
  private drawingManager;
57
58
  private hitTestCanvasModel;
58
59
  private canvasInputListener;
60
+ private paneManager;
61
+ private dynamicObjects;
59
62
  readonly baselineModel: BaselineModel;
60
63
  private readonly backgroundDrawer;
61
- private readonly dataSeriesDrawers;
64
+ private readonly _dataSeriesDrawers;
62
65
  private readonly dataSeriesDrawer;
63
- constructor(chartModel: ChartModel, canvasModel: CanvasModel, config: FullChartConfig, scaleModel: ScaleModel, canvasBoundsContainer: CanvasBoundsContainer, drawingManager: DrawingManager, hitTestCanvasModel: HitTestCanvasModel, canvasInputListener: CanvasInputListenerComponent, backgroundCanvasModel: CanvasModel, chartPanComponent: ChartPanComponent, paneManager: PaneManager, cursorHandler: CursorHandler);
66
+ constructor(chartModel: ChartModel, canvasModel: CanvasModel, config: FullChartConfig, scale: ScaleModel, canvasBoundsContainer: CanvasBoundsContainer, drawingManager: DrawingManager, hitTestCanvasModel: HitTestCanvasModel, canvasInputListener: CanvasInputListenerComponent, backgroundCanvasModel: CanvasModel, chartPanComponent: ChartPanComponent, paneManager: PaneManager, cursorHandler: CursorHandler, dynamicObjects: DynamicObjectsComponent);
64
67
  /**
65
68
  * This method overrides the doActivate method of the parent class and calls it.
66
69
  * It does not take any parameters and does not return anything.
@@ -76,6 +79,7 @@ export declare class ChartComponent extends ChartBaseElement {
76
79
  */
77
80
  private registerDefaultCandlesTransformers;
78
81
  get barTypeValues(): Array<BarType>;
82
+ get dataSeriesDrawers(): Record<string, SeriesDrawer>;
79
83
  strToBarType: (str: string) => BarType;
80
84
  /**
81
85
  * You can use this method to determine logic of visual candle transformation for specified chart type.