@devexperts/dxcharts-lite 1.0.2 → 2.0.1

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 (258) 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.d.ts +2 -2
  81. package/dist/chart/components/pane/pane-hit-test.controller.js +55 -1
  82. package/dist/chart/components/pane/pane-manager.component.d.ts +12 -6
  83. package/dist/chart/components/pane/pane-manager.component.js +149 -1
  84. package/dist/chart/components/pane/pane.component.d.ts +16 -32
  85. package/dist/chart/components/pane/pane.component.js +278 -1
  86. package/dist/chart/components/resizer/bar-resizer.component.js +139 -1
  87. package/dist/chart/components/resizer/bar-resizer.drawer.js +46 -1
  88. package/dist/chart/components/snapshot/snapshot.component.js +48 -1
  89. package/dist/chart/components/volumes/separate-volumes.component.d.ts +6 -10
  90. package/dist/chart/components/volumes/separate-volumes.component.js +63 -1
  91. package/dist/chart/components/volumes/volume-color-resolvers.functions.js +18 -1
  92. package/dist/chart/components/volumes/volumes.component.d.ts +6 -7
  93. package/dist/chart/components/volumes/volumes.component.js +94 -1
  94. package/dist/chart/components/volumes/volumes.drawer.d.ts +5 -12
  95. package/dist/chart/components/volumes/volumes.drawer.js +140 -1
  96. package/dist/chart/components/volumes/volumes.formatter.js +31 -1
  97. package/dist/chart/components/volumes/volumes.model.d.ts +2 -2
  98. package/dist/chart/components/volumes/volumes.model.js +43 -1
  99. package/dist/chart/components/watermark/water-mark.component.js +103 -1
  100. package/dist/chart/components/watermark/water-mark.drawer.js +187 -1
  101. package/dist/chart/components/x_axis/numeric-x-axis-labels.generator.js +27 -1
  102. package/dist/chart/components/x_axis/time/parser/time-formats-matchers.functions.js +187 -1
  103. package/dist/chart/components/x_axis/time/parser/time-formats-parser.functions.js +76 -1
  104. package/dist/chart/components/x_axis/time/parser/time-formats-validators.functions.js +79 -1
  105. package/dist/chart/components/x_axis/time/parser/time-formats.model.js +14 -1
  106. package/dist/chart/components/x_axis/time/x-axis-weights.functions.d.ts +1 -1
  107. package/dist/chart/components/x_axis/time/x-axis-weights.functions.js +143 -1
  108. package/dist/chart/components/x_axis/time/x-axis-weights.generator.js +73 -1
  109. package/dist/chart/components/x_axis/x-axis-draw.functions.js +49 -1
  110. package/dist/chart/components/x_axis/x-axis-labels.drawer.js +70 -1
  111. package/dist/chart/components/x_axis/x-axis-labels.generator.d.ts +2 -2
  112. package/dist/chart/components/x_axis/x-axis-labels.generator.js +332 -1
  113. package/dist/chart/components/x_axis/x-axis-labels.model.js +35 -1
  114. package/dist/chart/components/x_axis/x-axis-scale.handler.d.ts +2 -2
  115. package/dist/chart/components/x_axis/x-axis-scale.handler.js +60 -1
  116. package/dist/chart/components/x_axis/x-axis-time-labels.drawer.js +82 -1
  117. package/dist/chart/components/x_axis/x-axis.component.d.ts +2 -2
  118. package/dist/chart/components/x_axis/x-axis.component.js +119 -1
  119. package/dist/chart/components/y_axis/label-color.functions.js +53 -1
  120. package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.d.ts +4 -4
  121. package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.js +33 -1
  122. package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.d.ts +3 -3
  123. package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.js +67 -1
  124. package/dist/chart/components/y_axis/price_labels/labels-positions-calculator.js +56 -1
  125. package/dist/chart/components/y_axis/price_labels/last-candle-labels.provider.d.ts +4 -3
  126. package/dist/chart/components/y_axis/price_labels/last-candle-labels.provider.js +96 -1
  127. package/dist/chart/components/y_axis/price_labels/price-label.drawer.d.ts +2 -2
  128. package/dist/chart/components/y_axis/price_labels/price-label.drawer.js +119 -1
  129. package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.d.ts +9 -8
  130. package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.js +201 -1
  131. package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.d.ts +6 -7
  132. package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.js +58 -1
  133. package/dist/chart/components/y_axis/y-axis-base-labels.model.d.ts +6 -4
  134. package/dist/chart/components/y_axis/y-axis-base-labels.model.js +47 -1
  135. package/dist/chart/components/y_axis/y-axis-labels.drawer.d.ts +4 -4
  136. package/dist/chart/components/y_axis/y-axis-labels.drawer.js +161 -1
  137. package/dist/chart/components/y_axis/y-axis-scale.handler.d.ts +2 -2
  138. package/dist/chart/components/y_axis/y-axis-scale.handler.js +72 -1
  139. package/dist/chart/components/y_axis/y-axis.component.d.ts +32 -41
  140. package/dist/chart/components/y_axis/y-axis.component.js +220 -1
  141. package/dist/chart/components/y_axis/y-axis.drawer.d.ts +9 -12
  142. package/dist/chart/components/y_axis/y-axis.drawer.js +96 -1
  143. package/dist/chart/components/y_axis/y-axis.model.d.ts +10 -17
  144. package/dist/chart/components/y_axis/y-axis.model.js +34 -1
  145. package/dist/chart/drawers/chart-background.drawer.js +69 -1
  146. package/dist/chart/drawers/chart-type-drawers/area.drawer.js +69 -1
  147. package/dist/chart/drawers/chart-type-drawers/bar.drawer.js +57 -1
  148. package/dist/chart/drawers/chart-type-drawers/baseline.drawer.js +84 -1
  149. package/dist/chart/drawers/chart-type-drawers/candle.drawer.js +162 -1
  150. package/dist/chart/drawers/chart-type-drawers/histogram.drawer.js +57 -1
  151. package/dist/chart/drawers/chart-type-drawers/line.drawer.js +38 -1
  152. package/dist/chart/drawers/chart-type-drawers/scatter-plot.drawer.js +19 -1
  153. package/dist/chart/drawers/clear-canvas.drawer.js +14 -1
  154. package/dist/chart/drawers/composite.drawer.js +67 -1
  155. package/dist/chart/drawers/data-series-drawers/candle-series-wrapper.js +50 -1
  156. package/dist/chart/drawers/data-series-drawers/color-candle.drawer.js +35 -1
  157. package/dist/chart/drawers/data-series-drawers/data-series-drawers.utils.js +16 -1
  158. package/dist/chart/drawers/data-series-drawers/difference-cloud.drawer.js +106 -1
  159. package/dist/chart/drawers/data-series-drawers/histogram.drawer.js +23 -1
  160. package/dist/chart/drawers/data-series-drawers/linear.drawer.js +19 -1
  161. package/dist/chart/drawers/data-series-drawers/points.drawer.js +19 -1
  162. package/dist/chart/drawers/data-series-drawers/rectangular-tool.drawer.js +7 -1
  163. package/dist/chart/drawers/data-series-drawers/text.drawer.js +25 -1
  164. package/dist/chart/drawers/data-series-drawers/trend-histogram.drawer.js +35 -1
  165. package/dist/chart/drawers/data-series-drawers/triangle.drawer.js +22 -1
  166. package/dist/chart/drawers/data-series.drawer.d.ts +5 -7
  167. package/dist/chart/drawers/data-series.drawer.js +56 -1
  168. package/dist/chart/drawers/drawing-manager.d.ts +1 -1
  169. package/dist/chart/drawers/drawing-manager.js +177 -1
  170. package/dist/chart/drawers/ht-data-series.drawer.js +37 -1
  171. package/dist/chart/events/event-bus.js +73 -1
  172. package/dist/chart/events/events.js +3 -1
  173. package/dist/chart/inputhandlers/candle-tap.handler.js +46 -1
  174. package/dist/chart/inputhandlers/chart-resize.handler.js +98 -1
  175. package/dist/chart/inputhandlers/cross-event-producer.component.js +67 -1
  176. package/dist/chart/inputhandlers/hover-producer.component.d.ts +2 -2
  177. package/dist/chart/inputhandlers/hover-producer.component.js +228 -1
  178. package/dist/chart/inputhandlers/main-canvas-touch.handler.d.ts +2 -2
  179. package/dist/chart/inputhandlers/main-canvas-touch.handler.js +80 -1
  180. package/dist/chart/inputlisteners/canvas-input-listener.component.js +629 -1
  181. package/dist/chart/model/baseline.model.js +88 -1
  182. package/dist/chart/model/bounds.model.js +1 -1
  183. package/dist/chart/model/candle-hover.js +70 -1
  184. package/dist/chart/model/candle-series-high-low.provider.js +45 -1
  185. package/dist/chart/model/candle-series.model.d.ts +3 -3
  186. package/dist/chart/model/candle-series.model.js +245 -1
  187. package/dist/chart/model/candle.model.js +69 -1
  188. package/dist/chart/model/canvas.model.js +228 -1
  189. package/dist/chart/model/chart-base-element.js +129 -1
  190. package/dist/chart/model/compare-series-hover.js +25 -1
  191. package/dist/chart/model/data-series-view.d.ts +5 -5
  192. package/dist/chart/model/data-series-view.js +111 -1
  193. package/dist/chart/model/data-series.config.js +14 -1
  194. package/dist/chart/model/data-series.model.d.ts +4 -4
  195. package/dist/chart/model/data-series.model.js +281 -1
  196. package/dist/chart/model/date-time.formatter.js +151 -1
  197. package/dist/chart/model/hit-test-canvas.model.d.ts +1 -1
  198. package/dist/chart/model/hit-test-canvas.model.js +256 -1
  199. package/dist/chart/model/main-candle-series.model.d.ts +1 -1
  200. package/dist/chart/model/main-candle-series.model.js +29 -1
  201. package/dist/chart/model/scale.model.d.ts +3 -2
  202. package/dist/chart/model/scale.model.js +316 -1
  203. package/dist/chart/model/scaling/auto-scale.model.d.ts +2 -4
  204. package/dist/chart/model/scaling/auto-scale.model.js +91 -1
  205. package/dist/chart/model/scaling/constrait.functions.js +61 -1
  206. package/dist/chart/model/scaling/lock-ratio.model.js +17 -1
  207. package/dist/chart/model/scaling/move-chart.functions.js +22 -1
  208. package/dist/chart/model/scaling/viewport.model.d.ts +2 -2
  209. package/dist/chart/model/scaling/viewport.model.js +279 -1
  210. package/dist/chart/model/scaling/x-zooming.functions.js +35 -1
  211. package/dist/chart/model/time-zone.model.js +109 -1
  212. package/dist/chart/model/visual-candle.js +134 -1
  213. package/dist/chart/utils/__tests__/array.utils.test.js +135 -1
  214. package/dist/chart/utils/__tests__/math.utils.test.js +14 -1
  215. package/dist/chart/utils/__tests__/object.utils.test.js +11 -1
  216. package/dist/chart/utils/__tests__/priceIncrementsUtils.test.js +29 -1
  217. package/dist/chart/utils/array.utils.d.ts +1 -1
  218. package/dist/chart/utils/array.utils.js +269 -1
  219. package/dist/chart/utils/auto-period-detector.utils.js +39 -1
  220. package/dist/chart/utils/candles-generator-ts.utils.js +20 -1
  221. package/dist/chart/utils/candles-generator.utils.js +161 -1
  222. package/dist/chart/utils/candles.utils.js +42 -1
  223. package/dist/chart/utils/canvas/canvas-drawing-functions.utils.js +144 -1
  224. package/dist/chart/utils/canvas/canvas-font-measure-tool.utils.js +51 -1
  225. package/dist/chart/utils/canvas/canvas-text-functions.utils.js +156 -1
  226. package/dist/chart/utils/color.utils.js +31 -1
  227. package/dist/chart/utils/device/browser.utils.js +10 -1
  228. package/dist/chart/utils/device/device-detector.utils.js +24 -1
  229. package/dist/chart/utils/device/device-pixel-ratio.utils.js +21 -1
  230. package/dist/chart/utils/device/touchpad.utils.js +91 -1
  231. package/dist/chart/utils/dom.utils.js +15 -1
  232. package/dist/chart/utils/function.utils.js +16 -1
  233. package/dist/chart/utils/linkedList.utils.d.ts +28 -0
  234. package/dist/chart/utils/linkedList.utils.js +138 -0
  235. package/dist/chart/utils/math.utils.js +115 -1
  236. package/dist/chart/utils/merge.utils.js +56 -1
  237. package/dist/chart/utils/object.utils.js +43 -1
  238. package/dist/chart/utils/performance/animation-frame-cache.utils.js +77 -0
  239. package/dist/chart/utils/{perfomance → performance}/debounce.utils.js +7 -1
  240. package/dist/chart/utils/performance/memoize.utils.js +74 -0
  241. package/dist/chart/utils/performance/request-animation-frame-throttle.utils.js +43 -0
  242. package/dist/chart/utils/performance/throttle.utils.js +26 -0
  243. package/dist/chart/utils/price-increments.utils.d.ts +1 -0
  244. package/dist/chart/utils/price-increments.utils.js +127 -1
  245. package/dist/chart/utils/uuid.utils.js +4 -1
  246. package/dist/dxchart.min.js +9 -12
  247. package/dist/index.d.ts +3 -3
  248. package/dist/index.js +20 -1
  249. package/package.json +4 -4
  250. package/dist/chart/utils/perfomance/animation-frame-cache.utils.js +0 -6
  251. package/dist/chart/utils/perfomance/memoize.utils.js +0 -6
  252. package/dist/chart/utils/perfomance/request-animation-frame-throttle.utils.js +0 -6
  253. package/dist/chart/utils/perfomance/throttle.utils.js +0 -6
  254. /package/dist/chart/utils/{perfomance → performance}/animation-frame-cache.utils.d.ts +0 -0
  255. /package/dist/chart/utils/{perfomance → performance}/debounce.utils.d.ts +0 -0
  256. /package/dist/chart/utils/{perfomance → performance}/memoize.utils.d.ts +0 -0
  257. /package/dist/chart/utils/{perfomance → performance}/request-animation-frame-throttle.utils.d.ts +0 -0
  258. /package/dist/chart/utils/{perfomance → performance}/throttle.utils.d.ts +0 -0
@@ -3,4 +3,101 @@
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 n}from"rxjs";import{EVENT_DRAW as h,EVENT_RESIZED as o}from"../events/events";import{uuid as a}from"../utils/uuid.utils";import{animationFrameThrottledPrior as m}from"../utils/perfomance/request-animation-frame-throttle.utils";export class ChartResizeHandler{constructor(e,i,s,t,r){this.frameElement=e,this.resizerElement=i,this.bus=s,this.canvasModels=t,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${a()}`,this.canvasResized=new n,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){m(this.animFrameId,()=>this.fireUpdates())}fireUpdates(){const e=this.resizerElement.getBoundingClientRect(),i={x:e.x,y:e.y,width:e.width,height:e.height};this.config||(this.frameElement.style.height=this.resizerElement.clientHeight+"px"),(this.previousBCR===void 0||this.isBCRDimensionsDiffer(this.previousBCR,i))&&(this.previousBCR=i,this.canvasModels.forEach(s=>this.previousBCR&&s.updateDPR(this.previousBCR)),this.canvasResized.next(i),this.bus.fire(o,i),this.bus.fire(h))}isBCRDimensionsDiffer(e,i){return e.height!==i.height||e.width!==i.width}unsubscribeAnimationUpdate(){if(this.resizerElement)try{this.elementResizeDetector.unobserve(this.resizerElement)}catch(e){console.warn("ChartResizeHandler.ts, unsubscribeAnimationUpdate failed")}}wasResized(){return this.previousBCR!==void 0}}
6
+ import { Subject } from 'rxjs';
7
+ import { EVENT_DRAW, EVENT_RESIZED } from '../events/events';
8
+ import { uuid } from '../utils/uuid.utils';
9
+ import { animationFrameThrottledPrior } from '../utils/performance/request-animation-frame-throttle.utils';
10
+ /**
11
+ * Tracks chart element size and emits events whenever it changes.
12
+ */
13
+ export class ChartResizeHandler {
14
+ constructor(frameElement, resizerElement, bus, canvasModels, config) {
15
+ this.frameElement = frameElement;
16
+ this.resizerElement = resizerElement;
17
+ this.bus = bus;
18
+ this.canvasModels = canvasModels;
19
+ this.config = config;
20
+ this.previousBCR = undefined;
21
+ this.animFrameId = `resize_${uuid()}`;
22
+ this.canvasResized = new Subject();
23
+ this.elementResizeDetector = new ResizeObserver(() => this.handleResize());
24
+ }
25
+ /**
26
+ * Subscribe to resize events
27
+ * Use it to update chart animations.
28
+ * TODO activate / deactivate cycle
29
+ */
30
+ subscribeResize() {
31
+ this.elementResizeDetector.observe(this.resizerElement);
32
+ }
33
+ /**
34
+ * Handles the resize event by throttling the animation frame and firing updates.
35
+ * @private
36
+ * @function
37
+ * @returns {void}
38
+ */
39
+ handleResize() {
40
+ animationFrameThrottledPrior(this.animFrameId, () => this.fireUpdates());
41
+ }
42
+ /**
43
+ * Updates the canvas models and fires events if the bounding client rectangle of the resizer element has changed.
44
+ * @function
45
+ * @name fireUpdates
46
+ * @memberof ClassName
47
+ * @returns {void}
48
+ */
49
+ fireUpdates() {
50
+ const resizerElementBCR = this.resizerElement.getBoundingClientRect();
51
+ const newBCR = {
52
+ x: resizerElementBCR.x,
53
+ y: resizerElementBCR.y,
54
+ width: resizerElementBCR.width,
55
+ height: resizerElementBCR.height,
56
+ };
57
+ if (!this.config) {
58
+ this.frameElement.style.height = this.resizerElement.clientHeight + 'px';
59
+ }
60
+ if (this.previousBCR === undefined || this.isBCRDimensionsDiffer(this.previousBCR, newBCR)) {
61
+ this.previousBCR = newBCR;
62
+ this.canvasModels.forEach(model => this.previousBCR && model.updateDPR(this.previousBCR));
63
+ this.canvasResized.next(newBCR);
64
+ this.bus.fire(EVENT_RESIZED, newBCR);
65
+ this.bus.fire(EVENT_DRAW);
66
+ }
67
+ }
68
+ /**
69
+ * Checks if the dimensions of two PickedDOMRect objects are different.
70
+ * @param {PickedDOMRect} previousBCR - The previous bounding client rectangle.
71
+ * @param {PickedDOMRect} newBCR - The new bounding client rectangle.
72
+ * @returns {boolean} - Returns true if the dimensions are different, false otherwise.
73
+ */
74
+ isBCRDimensionsDiffer(previousBCR, newBCR) {
75
+ return previousBCR.height !== newBCR.height || previousBCR.width !== newBCR.width;
76
+ }
77
+ /**
78
+ * Unsubscribes from the element resize detector to stop updating the chart animation.
79
+ * @function
80
+ * @name unsubscribeAnimationUpdate
81
+ * @memberof ChartResizeHandler
82
+ * @instance
83
+ * @returns {void}
84
+ */
85
+ unsubscribeAnimationUpdate() {
86
+ if (this.resizerElement) {
87
+ try {
88
+ this.elementResizeDetector.unobserve(this.resizerElement);
89
+ }
90
+ catch (e) {
91
+ console.warn('ChartResizeHandler.ts, unsubscribeAnimationUpdate failed');
92
+ }
93
+ }
94
+ }
95
+ // TODO a lot of unnecessary DRAW events fired before canvas has actual size
96
+ /**
97
+ * Checks if the canvas has been resized by comparing the previous bounding client rect with the current one.
98
+ * @returns {boolean} - Returns true if the canvas has been resized, false otherwise.
99
+ */
100
+ wasResized() {
101
+ return this.previousBCR !== undefined;
102
+ }
103
+ }
@@ -3,4 +3,70 @@
3
3
  * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
4
  * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
- import{BehaviorSubject as a,combineLatest as b,filter as v}from"rxjs";import{ChartBaseElement as p}from"../model/chart-base-element";export class CrossEventProducerComponent extends p{constructor(e,s){super(),this.canvasInputListener=e,this.canvasBoundsContainer=s,this.panesSubscriptions={},this.crossSubject=new a(null)}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(e){var s;(s=this.panesSubscriptions[e])===null||s===void 0||s.unsubscribe()}subscribeMouseOver(e,s,o){const i=s.map(r=>this.canvasBoundsContainer.getBoundsHitTest(r,o)),t=(r,n)=>i.some(u=>u(r,n));return this.subscribeMouseOverHT(e,t)}subscribeMouseOverHT(e,s){const o=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(s);let t=!1;const r=b([o,i]).pipe(v(([,n])=>!t||t&&n)).subscribe(([n,u])=>{if(u){const c=[n.x,n.y,e];this.crossSubject.next(c),t=!1}else this.crossSubject.next(null),t=!0});return this.panesSubscriptions[e]=r,()=>r.unsubscribe()}}
6
+ import { BehaviorSubject, combineLatest, filter } from 'rxjs';
7
+ import { ChartBaseElement } from '../model/chart-base-element';
8
+ export class CrossEventProducerComponent extends ChartBaseElement {
9
+ constructor(canvasInputListener, canvasBoundsContainer) {
10
+ super();
11
+ this.canvasInputListener = canvasInputListener;
12
+ this.canvasBoundsContainer = canvasBoundsContainer;
13
+ this.panesSubscriptions = {};
14
+ this.crossSubject = new BehaviorSubject(null);
15
+ }
16
+ doActivate() {
17
+ super.doActivate();
18
+ }
19
+ /**
20
+ * Emits a null value to the `cross` subject, effectively closing the current cross.
21
+ */
22
+ fireCrossClose() {
23
+ this.crossSubject.next(null);
24
+ }
25
+ /**
26
+ * Unsubscribes from the mouse over event for a specific pane.
27
+ * @param {string} uuid - The unique identifier of the pane.
28
+ * @returns {void}
29
+ */
30
+ unsubscribeMouseOver(uuid) {
31
+ var _a;
32
+ (_a = this.panesSubscriptions[uuid]) === null || _a === void 0 ? void 0 : _a.unsubscribe();
33
+ }
34
+ /**
35
+ * Subscribes to mouse over event on canvas elements.
36
+ * @param {string} uuid - Unique identifier for the subscription.
37
+ * @param {string[]} canvasElementNames - Array of canvas element names to subscribe to.
38
+ * @param {HitBoundsTestOptionsPartial} [options] - Optional hit bounds test options.
39
+ * @returns {Subscription} - Returns a subscription object.
40
+ */
41
+ subscribeMouseOver(uuid, canvasElementNames, options) {
42
+ const hts = canvasElementNames.map(canvasElementName => this.canvasBoundsContainer.getBoundsHitTest(canvasElementName, options));
43
+ const hitTest = (x, y) => hts.some(ht => ht(x, y));
44
+ return this.subscribeMouseOverHT(uuid, hitTest);
45
+ }
46
+ /**
47
+ * Subscribes to mouse over event on a hit test area identified by uuid.
48
+ * @param {string} uuid - The unique identifier of the hit test area.
49
+ * @param {HitBoundsTest} hitTest - The hit test area.
50
+ * @returns {Subscription} - The subscription object.
51
+ */
52
+ subscribeMouseOverHT(uuid, hitTest) {
53
+ const move$ = this.canvasInputListener.observeMouseMoveDocument();
54
+ const mouseEnter$ = this.canvasInputListener.observeMouseEnter(hitTest);
55
+ let closeHoverFired = false;
56
+ const subscription = combineLatest([move$, mouseEnter$])
57
+ .pipe(filter(([, enter]) => !closeHoverFired || (closeHoverFired && enter)))
58
+ .subscribe(([point, enter]) => {
59
+ if (enter) {
60
+ const cross = [point.x, point.y, uuid];
61
+ this.crossSubject.next(cross);
62
+ closeHoverFired = false;
63
+ }
64
+ else {
65
+ this.crossSubject.next(null);
66
+ closeHoverFired = true;
67
+ }
68
+ });
69
+ this.panesSubscriptions[uuid] = subscription;
70
+ return () => subscription.unsubscribe();
71
+ }
72
+ }
@@ -45,7 +45,7 @@ export interface HoverProducerParts {
45
45
  */
46
46
  export declare class HoverProducerComponent extends ChartBaseElement {
47
47
  private crossEventProducer;
48
- private scaleModel;
48
+ private scale;
49
49
  private config;
50
50
  private chartModel;
51
51
  private canvasInputListener;
@@ -58,7 +58,7 @@ export declare class HoverProducerComponent extends ChartBaseElement {
58
58
  private longTouchActivated;
59
59
  private hoverProducerParts;
60
60
  xFormatter: DateTimeFormatter;
61
- constructor(crossEventProducer: CrossEventProducerComponent, scaleModel: 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 | Date) => 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
@@ -3,4 +3,231 @@
3
3
  * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
4
  * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
- import{BehaviorSubject as l,merge as u}from"rxjs";import{CHART_UUID as v,CanvasElement as m}from"../canvas/canvas-bounds-container";import{CandleHoverProducerPart as b}from"../model/candle-hover";import{ChartBaseElement as p}from"../model/chart-base-element";import{CompareSeriesHoverProducerPart as C}from"../model/compare-series-hover";import{recalculateXFormatter as P}from"../model/date-time.formatter";import{isMobile as g}from"../utils/device/browser.utils";export class HoverProducerComponent extends p{get hover(){return this.hoverSubject.getValue()}constructor(t,e,r,s,o,i,c,n,a){super(),this.crossEventProducer=t,this.scaleModel=e,this.config=r,this.chartModel=s,this.canvasInputListener=o,this.canvasBoundsContainer=i,this.paneManager=c,this.timeZoneModel=n,this.formatterFactory=a,this.hoverSubject=new l(null),this.longTouchActivated=!1,this.xFormatter=()=>"";const h=new b(this.chartModel),d=new C(this.chartModel);this.hoverProducerParts={candleHover:h,compareSeriesHover:d}}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp===this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scaleModel.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{const r=e.touches[0].clientX,s=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.chartModel.candleFromX(r,!0)&&this.createAndFireHover([r,s,""])}));const t=this.canvasBoundsContainer.getBoundsHitTest(m.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouch(t).subscribe(e=>{this.paneManager.chartPanComponent.deactivatePanHandlers(),this.longTouchActivated=!0;const r=e.touches[0].clientX,s=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.createAndFireHover([r,s,""])})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(()=>{this.paneManager.chartPanComponent.activateChartPanHandlers(),this.longTouchActivated&&(this.longTouchActivated=!1,this.crossEventProducer.fireCrossClose())})),this.addRxSubscription(u(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter()))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=P(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.chartModel.scaleModel),r=this.chartModel.scaleModel.toY(t.close);return this.createHover(e,r,v)}createHover(t,e,r){if(this.chartModel.getCandles().length===0)return;const o=this.chartModel.candleFromX(t,!0).timestamp,i={x:t,y:e,timestamp:o,timeFormatted:this.xFormatter(o),paneId:r},c=Object.entries(this.hoverProducerParts).reduce((n,a)=>Object.assign(Object.assign({},n),{[a[0]]:a[1].getData(i)}),{});return Object.assign(Object.assign({},i),c)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const r=Object.assign(Object.assign({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(r)}}createAndFireHover([t,e,r]){const s=this.createHover(t,e,r);this.fireHover(s)}fireHover(t){var e;if(t){if(g()&&this.config.components.crossTool.type!=="none"){const r=(e=t.candleHover)===null||e===void 0?void 0:e.visualCandle.candle;r&&this.chartModel.mainCandleSeries.setActiveCandle(r)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=Object.assign(Object.assign({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}
6
+ import { BehaviorSubject, merge } from 'rxjs';
7
+ import { CHART_UUID, CanvasElement } from '../canvas/canvas-bounds-container';
8
+ import { CandleHoverProducerPart } from '../model/candle-hover';
9
+ import { ChartBaseElement } from '../model/chart-base-element';
10
+ import { CompareSeriesHoverProducerPart } from '../model/compare-series-hover';
11
+ import { recalculateXFormatter } from '../model/date-time.formatter';
12
+ import { isMobile } from '../utils/device/browser.utils';
13
+ /**
14
+ * Produces the Hover event.
15
+ * Hover is used for displaying values in legend and NOT related to displaying cross tool.
16
+ */
17
+ export class HoverProducerComponent extends ChartBaseElement {
18
+ get hover() {
19
+ return this.hoverSubject.getValue();
20
+ }
21
+ constructor(crossEventProducer, scale, config, chartModel, canvasInputListener, canvasBoundsContainer, paneManager, timeZoneModel, formatterFactory) {
22
+ super();
23
+ this.crossEventProducer = crossEventProducer;
24
+ this.scale = scale;
25
+ this.config = config;
26
+ this.chartModel = chartModel;
27
+ this.canvasInputListener = canvasInputListener;
28
+ this.canvasBoundsContainer = canvasBoundsContainer;
29
+ this.paneManager = paneManager;
30
+ this.timeZoneModel = timeZoneModel;
31
+ this.formatterFactory = formatterFactory;
32
+ this.hoverSubject = new BehaviorSubject(null);
33
+ this.longTouchActivated = false;
34
+ this.xFormatter = () => '';
35
+ const candleHoverProducerPart = new CandleHoverProducerPart(this.chartModel);
36
+ const compareSeriesHoverProducerPart = new CompareSeriesHoverProducerPart(this.chartModel);
37
+ this.hoverProducerParts = {
38
+ candleHover: candleHoverProducerPart,
39
+ compareSeriesHover: compareSeriesHoverProducerPart,
40
+ };
41
+ }
42
+ /**
43
+ * This method is responsible for activating the chart hover functionality. It subscribes to several observables to
44
+ * update the hover when the chart is updated or when the user interacts with it. It also handles special behavior
45
+ * for mobile devices, such as disabling panning and showing the cross tool on long touch.
46
+ *
47
+ * @protected
48
+ * @memberof ChartHover
49
+ * @returns {void}
50
+ */
51
+ doActivate() {
52
+ super.doActivate();
53
+ this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(() => {
54
+ // required for initial legend initialization, do not show cross tool
55
+ const lastCandle = this.chartModel.getLastVisualCandle();
56
+ lastCandle && this.createAndFireHoverFromCandle(lastCandle);
57
+ }));
58
+ this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(() => {
59
+ // update hover if it was the last candle
60
+ const lastCandle = this.chartModel.getLastVisualCandle();
61
+ if (this.hover !== null && lastCandle !== undefined) {
62
+ if (lastCandle.candle.timestamp === this.hover.timestamp) {
63
+ this.updateHover(lastCandle);
64
+ }
65
+ }
66
+ }));
67
+ this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe((cross) => {
68
+ if (cross === null) {
69
+ this.hoverSubject.next(null);
70
+ }
71
+ else {
72
+ this.createAndFireHover(cross);
73
+ }
74
+ }));
75
+ this.addRxSubscription(this.scale.xChanged.subscribe(() => this.fireLastCross()));
76
+ this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(event => {
77
+ const x = event.touches[0].clientX;
78
+ const y = event.touches[0].clientY - this.canvasBoundsContainer.canvasOnPageLocation.y;
79
+ const candle = this.chartModel.candleFromX(x, true);
80
+ if (candle) {
81
+ this.createAndFireHover([x, y, '']);
82
+ }
83
+ }));
84
+ // special handling for mobile
85
+ // on long touch - disable panning and show cross tool
86
+ const hitTest = this.canvasBoundsContainer.getBoundsHitTest(CanvasElement.ALL_PANES);
87
+ this.addRxSubscription(this.canvasInputListener.observeLongTouch(hitTest).subscribe(event => {
88
+ this.paneManager.chartPanComponent.deactivatePanHandlers();
89
+ this.longTouchActivated = true;
90
+ const x = event.touches[0].clientX;
91
+ const y = event.touches[0].clientY - this.canvasBoundsContainer.canvasOnPageLocation.y;
92
+ this.createAndFireHover([x, y, '']);
93
+ }));
94
+ this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(() => {
95
+ this.paneManager.chartPanComponent.activateChartPanHandlers();
96
+ if (this.longTouchActivated) {
97
+ this.longTouchActivated = false;
98
+ this.crossEventProducer.fireCrossClose();
99
+ }
100
+ }));
101
+ this.addRxSubscription(merge(this.chartModel.candlesSetSubject, this.timeZoneModel.observeTimeZoneChanged()).subscribe(() => this.recalculateCrossToolXFormatter()));
102
+ }
103
+ /**
104
+ * Recalculates the cross tool X formatter.
105
+ * @function
106
+ * @private
107
+ * @returns {void}
108
+ */
109
+ recalculateCrossToolXFormatter() {
110
+ const xAxisLabelFormat = this.config.components.crossTool.xAxisLabelFormat;
111
+ this.xFormatter = recalculateXFormatter(xAxisLabelFormat, this.chartModel.getPeriod(), this.formatterFactory);
112
+ }
113
+ /**
114
+ * Creates a hover object from a VisualCandle object.
115
+ * @param {VisualCandle} candle - The VisualCandle object to create the hover from.
116
+ * @returns {Hover | undefined} - The created hover object or undefined if the input is invalid.
117
+ */
118
+ createHoverFromCandle(candle) {
119
+ const x = candle.xCenter(this.scale);
120
+ const y = this.scale.toY(candle.close);
121
+ return this.createHover(x, y, CHART_UUID);
122
+ }
123
+ /**
124
+ * Creates a hover object based on the provided x and y coordinates.
125
+ * @param {number} x - The x coordinate of the hover.
126
+ * @param {number} y - The y coordinate of the hover.
127
+ * @returns {Hover | undefined} - The hover object or undefined if there are no candles in the chart model.
128
+ * @todo Check if uuid is still useful here.
129
+ */
130
+ createHover(x, y, uuid) {
131
+ if (this.chartModel.getCandles().length === 0) {
132
+ return;
133
+ }
134
+ const candle = this.chartModel.candleFromX(x, true);
135
+ const timestamp = candle.timestamp;
136
+ const hover = {
137
+ x,
138
+ y,
139
+ timestamp,
140
+ timeFormatted: this.xFormatter(timestamp),
141
+ paneId: uuid,
142
+ };
143
+ // eslint-disable-next-line no-restricted-syntax
144
+ const combinedHoverParts = Object.entries(this.hoverProducerParts).reduce((res, part) => (Object.assign(Object.assign({}, res), { [part[0]]: part[1].getData(hover) })),
145
+ // eslint-disable-next-line no-restricted-syntax
146
+ {});
147
+ return Object.assign(Object.assign({}, hover), combinedHoverParts);
148
+ }
149
+ /**
150
+ * Creates a hover from a VisualCandle object and fires it.
151
+ * @param {VisualCandle} candle - The VisualCandle object to create the hover from.
152
+ */
153
+ createAndFireHoverFromCandle(candle) {
154
+ const hover = this.createHoverFromCandle(candle);
155
+ this.fireHover(hover);
156
+ }
157
+ /**
158
+ * Update current hover using a VisualCandle and fires it.
159
+ * @param {VisualCandle} candle - The VisualCandle object to create the hover from.
160
+ */
161
+ updateHover(candle) {
162
+ const updatedHover = this.createHoverFromCandle(candle);
163
+ if (this.hover && updatedHover) {
164
+ const hover = Object.assign(Object.assign({}, updatedHover), { x: this.hover.x, y: this.hover.y });
165
+ this.fireHover(hover);
166
+ }
167
+ }
168
+ /**
169
+ * Creates a hover element at the specified coordinates and fires it with the option to show the cross tool
170
+ * @param {CrossEvent} [x,y] - The coordinates where the hover element will be created
171
+ * @param {boolean} [showCrossTool=true] - Whether to show the cross tool or not
172
+ * @returns {void}
173
+ */
174
+ createAndFireHover([x, y, uuid]) {
175
+ const hover = this.createHover(x, y, uuid);
176
+ this.fireHover(hover);
177
+ }
178
+ /**
179
+ * Private method that handles the hover event. If a hover event is provided, it sets the last hover to the provided hover.
180
+ * If the device is mobile and the cross tool type is not 'none', it sets the active candle to the hovered candle only when a long tap is detected.
181
+ * The showCrossToolOverride is set to true only when a long tap is detected on mobile devices, otherwise it is set to the value of showCrossTool parameter.
182
+ * Finally, it fires the EVENT_HOVER event with the provided hover and showCrossToolOverride.
183
+ * If no hover event is provided, it fires the EVENT_CLOSE_HOVER event.
184
+ *
185
+ * @param {Hover} [hover] - The hover event to handle.
186
+ * @param {boolean} [showCrossTool=true] - A boolean value indicating whether to show the cross tool or not.
187
+ * @returns {void}
188
+ */
189
+ fireHover(hover) {
190
+ var _a;
191
+ if (hover) {
192
+ // special handling for mobile
193
+ // set active candle + show cross tool only when long tap
194
+ if (isMobile() && this.config.components.crossTool.type !== 'none') {
195
+ const candle = (_a = hover.candleHover) === null || _a === void 0 ? void 0 : _a.visualCandle.candle;
196
+ candle && this.chartModel.mainCandleSeries.setActiveCandle(candle);
197
+ }
198
+ // const showCrossToolOverride = isMobile() ? this.longTouchActivated : showCrossTool;
199
+ this.hoverSubject.next(hover);
200
+ }
201
+ else {
202
+ this.crossEventProducer.fireCrossClose();
203
+ }
204
+ }
205
+ /**
206
+ * Fires the last hover update if there is a last cross.
207
+ */
208
+ fireLastCross() {
209
+ // fire last hover update
210
+ const lastCross = this.crossEventProducer.crossSubject.getValue();
211
+ if (lastCross) {
212
+ this.createAndFireHover(lastCross);
213
+ }
214
+ }
215
+ /**
216
+ * Registers a hover producer part with the given id.
217
+ *
218
+ * @param {string} id - The id of the hover producer part.
219
+ * @param {HoverProducerPart} hoverProducerPart - The hover producer part to register.
220
+ * @returns {void}
221
+ */
222
+ registerHoverProducerPart(id, hoverProducerPart) {
223
+ this.hoverProducerParts = Object.assign(Object.assign({}, this.hoverProducerParts), { [id]: hoverProducerPart });
224
+ }
225
+ /**
226
+ * Removes a hover producer part from the hoverProducerParts object.
227
+ * @param {string} id - The id of the hover producer part to be removed.
228
+ * @returns {void}
229
+ */
230
+ unregisterHoverProducerPart(id) {
231
+ delete this.hoverProducerParts[id];
232
+ }
233
+ }
@@ -10,11 +10,11 @@ import { ScaleModel } from '../model/scale.model';
10
10
  * Handles chart touch events.
11
11
  */
12
12
  export declare class MainCanvasTouchHandler extends ChartBaseElement {
13
- private scaleModel;
13
+ private scale;
14
14
  private canvasInputListeners;
15
15
  private mainCanvasParent;
16
16
  private touchedCandleIndexes;
17
- constructor(scaleModel: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, mainCanvasParent: Element);
17
+ constructor(scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, mainCanvasParent: Element);
18
18
  /**
19
19
  * Activates canvas input listeners for touch start and touch move events.
20
20
  * @protected
@@ -3,4 +3,83 @@
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{ChartBaseElement as c}from"../model/chart-base-element";export class MainCanvasTouchHandler extends c{constructor(t,e,s){super(),this.scaleModel=t,this.canvasInputListeners=e,this.mainCanvasParent=s,this.touchedCandleIndexes=[0,0]}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart().subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove().subscribe(t=>this.handleTouchMoveEvent(t)))}handleTouchStartEvent(t){t.touches.length===2&&(this.touchedCandleIndexes=this.getXPositions(t).map(e=>this.scaleModel.fromX(e)))}handleTouchMoveEvent(t){t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),s=[0,0],a=document.body.scrollLeft||document.documentElement.scrollLeft;for(let n=0,h=t.touches.length;n<h;n++){const o=t.touches[n];s[n]=o.pageX-e.left-a}return s}pinchHandler(t,e){const s=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),a=s+(t[0]-t[1])/(e[0]-e[1])*this.scaleModel.getBounds().width;this.scaleModel.setXScale(s,a)}}
6
+ import { ChartBaseElement } from '../model/chart-base-element';
7
+ /**
8
+ * Handles chart touch events.
9
+ */
10
+ export class MainCanvasTouchHandler extends ChartBaseElement {
11
+ constructor(scale, canvasInputListeners, mainCanvasParent) {
12
+ super();
13
+ this.scale = scale;
14
+ this.canvasInputListeners = canvasInputListeners;
15
+ this.mainCanvasParent = mainCanvasParent;
16
+ // 2 candles indexes touched by 2 fingers when pinching
17
+ this.touchedCandleIndexes = [0, 0];
18
+ }
19
+ /**
20
+ * Activates canvas input listeners for touch start and touch move events.
21
+ * @protected
22
+ * @returns {void}
23
+ */
24
+ doActivate() {
25
+ this.addRxSubscription(this.canvasInputListeners.observeTouchStart().subscribe(e => this.handleTouchStartEvent(e)));
26
+ this.addRxSubscription(this.canvasInputListeners.observeTouchMove().subscribe(e => this.handleTouchMoveEvent(e)));
27
+ }
28
+ /**
29
+ * Handles the touch start event.
30
+ * @param {TouchEvent} e - The touch event.
31
+ * @returns {void}
32
+ */
33
+ handleTouchStartEvent(e) {
34
+ if (e.touches.length === 2) {
35
+ // @ts-ignore
36
+ // TODO rework this
37
+ this.touchedCandleIndexes = this.getXPositions(e).map(x => this.scale.fromX(x));
38
+ }
39
+ }
40
+ /**
41
+ * Handles touch move event
42
+ * @param {TouchEvent} e - The touch event object
43
+ * @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
+ }*/
50
+ handleTouchMoveEvent(e) {
51
+ if (e.touches.length === 2) {
52
+ this.pinchHandler(this.touchedCandleIndexes, this.getXPositions(e));
53
+ }
54
+ }
55
+ /**
56
+ * Gets candle positions touched by user in pixels.
57
+ * @param e - touch event with "touches" array
58
+ * @return Array<number> - X coordinates of touches on the canvas
59
+ */
60
+ getXPositions(e) {
61
+ const rect = this.mainCanvasParent.getBoundingClientRect();
62
+ const result = [0, 0];
63
+ // TO DO: check if this body calculations can potentially works wrong in widget
64
+ const scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
65
+ for (let i = 0, l = e.touches.length; i < l; i++) {
66
+ const touch = e.touches[i];
67
+ result[i] = touch.pageX - rect.left - scrollLeft;
68
+ }
69
+ return result;
70
+ }
71
+ /**
72
+ * Handles the pinch gesture on the chart.
73
+ * @param {Array<number>} candleIndexes - An array of two numbers representing the indexes of the first and last visible candles on the chart.
74
+ * @param {number[]} touchPositions - An array of two numbers representing the touch positions on the screen.
75
+ * @returns {void}
76
+ */
77
+ pinchHandler(candleIndexes, touchPositions) {
78
+ const first = (touchPositions[0] * candleIndexes[1] - touchPositions[1] * candleIndexes[0]) /
79
+ (touchPositions[0] - touchPositions[1]);
80
+ const last = first +
81
+ ((candleIndexes[0] - candleIndexes[1]) / (touchPositions[0] - touchPositions[1])) *
82
+ this.scale.getBounds().width;
83
+ this.scale.setXScale(first, last);
84
+ }
85
+ }