@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
@@ -3,4 +3,122 @@
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{CanvasElement as V,CHART_UUID as q}from"../../../canvas/canvas-bounds-container";import{getFontFromConfig as I}from"../../../chart.config";import{redrawBackgroundArea as z}from"../../../drawers/chart-background.drawer";import{avoidAntialiasing as J,drawLine as K}from"../../../utils/canvas/canvas-drawing-functions.utils";import{calculateSymbolHeight as N,calculateTextWidth as R}from"../../../utils/canvas/canvas-font-measure-tool.utils";import{floor as O}from"../../../utils/math.utils";import{drawBadgeLabel as Q,drawPlainLabel as Z,drawRectLabel as $}from"../y-axis-labels.drawer";export const DEFAULT_LABEL_APPEARANCE_TYPE="badge";const X=4;export const priceLabelDrawersMap={badge:Q,rectangle:$,plain:Z};export function drawLabel(o,n,e,m,t,B,l,_){var s,d,c,r,a;const p=t.y,f=t.labelText,T=(s=t.mode)!==null&&s!==void 0?s:"label",x=(d=t.labelType)!==null&&d!==void 0?d:DEFAULT_LABEL_APPEARANCE_TYPE,g=t.description,A=(c=t.textFont)!==null&&c!==void 0?c:I(l),w=t.bgColor,b=(r=t.lineColor)!==null&&r!==void 0?r:w,h=R(g!=null?g:"",o,A)+8,D=O(t.y),y=N(A,o),E=p-y/2,j=p+y/2-E;o.save(),o.fillStyle=w,o.strokeStyle=b;const i=B.getBounds(V.PANE_UUID(q)),G=priceLabelDrawersMap[x],C=l.labels.descriptions,M=v(e,D,j),Y=()=>C&&L(n,o,e,m,t,l.align,l);let F,P;const U=2;l.align==="right"?(F=i.x,P=C?i.x+i.width-h:i.x+i.width+U):(F=C?i.x+h:i.x-U,P=i.x+i.width);const k=(a=t.lineY)!==null&&a!==void 0?a:t.y,H=()=>M&&J(o,()=>K(o,F,k,P,k,1)),W=()=>G(o,e,f,p,t,l,_,!1,n);switch(T){case"line":H(),Y();break;case"line-label":H(),Y(),W();break;case"label":Y(),W();break;case"none":break}o.restore()}const v=(o,n,e)=>n>o.y+e/2&&n<o.y+o.height-e/2;function L(o,n,e,m,t,B="right",l){var _,s,d;const c=t.description;if(!c||c.length===0)return;const r=t.y,a=I(l),p=R(c,n,a),f=N(a,n),T=(_=t.paddingTop)!==null&&_!==void 0?_:X,x=(s=t.paddingBottom)!==null&&s!==void 0?s:X,g=r-f/2-T,w=r+f/2+x-g;if(r<e.y+w/2||r>e.y+e.height-w/2)return;n.save();const b=p+5,h=4,D=p+h*2,y=m.x+m.width,E=B==="right"?y-D:m.x+h;z(o,n,E,g,b,w,.8),n.fillStyle=(d=t.descColor)!==null&&d!==void 0?d:t.bgColor,n.font=a;const S=B==="right"?y-p-h*2:m.x+h*2;n.fillText(c,S,r+f/2-1),n.restore()}
6
+ import { CanvasElement, CHART_UUID } from '../../../canvas/canvas-bounds-container';
7
+ import { getFontFromConfig, } from '../../../chart.config';
8
+ import { redrawBackgroundArea } from '../../../drawers/chart-background.drawer';
9
+ import { avoidAntialiasing, drawLine } from '../../../utils/canvas/canvas-drawing-functions.utils';
10
+ import { calculateSymbolHeight, calculateTextWidth } from '../../../utils/canvas/canvas-font-measure-tool.utils';
11
+ import { floor } from '../../../utils/math.utils';
12
+ import { drawBadgeLabel, drawPlainLabel, drawRectLabel } from '../y-axis-labels.drawer';
13
+ export const DEFAULT_LABEL_APPEARANCE_TYPE = 'badge';
14
+ const DEFAULT_PADDING = 4;
15
+ export const priceLabelDrawersMap = {
16
+ badge: drawBadgeLabel,
17
+ rectangle: drawRectLabel,
18
+ plain: drawPlainLabel,
19
+ };
20
+ /**
21
+ * Draws label on Y axis with provided parameters.
22
+ * @param ctx - canvas 2D context to draw on
23
+ * @param bounds - bounds of Y axis
24
+ * @param visualLabel
25
+ * @param canvasBoundsContainer
26
+ * @param config
27
+ */
28
+ export function drawLabel(ctx, backgroundCtx, bounds, paneBounds, visualLabel, canvasBoundsContainer, config, colors) {
29
+ var _a, _b, _c, _d, _e;
30
+ const centralY = visualLabel.y;
31
+ const text = visualLabel.labelText;
32
+ const mode = (_a = visualLabel.mode) !== null && _a !== void 0 ? _a : 'label';
33
+ const appearanceType = (_b = visualLabel.labelType) !== null && _b !== void 0 ? _b : DEFAULT_LABEL_APPEARANCE_TYPE;
34
+ const description = visualLabel.description;
35
+ const textFont = (_c = visualLabel.textFont) !== null && _c !== void 0 ? _c : getFontFromConfig(config);
36
+ const bgColor = visualLabel.bgColor;
37
+ const lineColor = (_d = visualLabel.lineColor) !== null && _d !== void 0 ? _d : bgColor;
38
+ const descriptionWidth = calculateTextWidth(description !== null && description !== void 0 ? description : '', ctx, textFont) + 8;
39
+ const labelY = floor(visualLabel.y);
40
+ const fontHeight = calculateSymbolHeight(textFont, ctx);
41
+ const labelBoxTopY = centralY - fontHeight / 2;
42
+ const labelBoxBottomY = centralY + fontHeight / 2;
43
+ const labelBoxHeight = labelBoxBottomY - labelBoxTopY;
44
+ ctx.save();
45
+ ctx.fillStyle = bgColor;
46
+ ctx.strokeStyle = lineColor;
47
+ const chartBounds = canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID(CHART_UUID));
48
+ const drawLabel = priceLabelDrawersMap[appearanceType];
49
+ const showDescription = config.labels.descriptions;
50
+ const showLine = isLineVisible(bounds, labelY, labelBoxHeight);
51
+ const _drawDescription = () => showDescription && drawDescription(backgroundCtx, ctx, bounds, paneBounds, visualLabel, config.align, config);
52
+ let lineXStart;
53
+ let lineXEnd;
54
+ // line should touch the label
55
+ const lineStartAdjust = 2;
56
+ if (config.align === 'right') {
57
+ lineXStart = chartBounds.x;
58
+ lineXEnd = showDescription
59
+ ? chartBounds.x + chartBounds.width - descriptionWidth
60
+ : chartBounds.x + chartBounds.width + lineStartAdjust;
61
+ }
62
+ else {
63
+ lineXStart = showDescription ? chartBounds.x + descriptionWidth : chartBounds.x - lineStartAdjust;
64
+ lineXEnd = chartBounds.x + chartBounds.width;
65
+ }
66
+ const lineY = (_e = visualLabel.lineY) !== null && _e !== void 0 ? _e : visualLabel.y;
67
+ const _drawLine = () => showLine && avoidAntialiasing(ctx, () => drawLine(ctx, lineXStart, lineY, lineXEnd, lineY, 1));
68
+ const _drawLabel = () => drawLabel(ctx, bounds, text, centralY, visualLabel, config, colors, false, backgroundCtx);
69
+ switch (mode) {
70
+ case 'line':
71
+ _drawLine();
72
+ _drawDescription();
73
+ break;
74
+ case 'line-label':
75
+ _drawLine();
76
+ _drawDescription();
77
+ _drawLabel();
78
+ break;
79
+ case 'label':
80
+ _drawDescription();
81
+ _drawLabel();
82
+ break;
83
+ case 'none':
84
+ break;
85
+ }
86
+ ctx.restore();
87
+ }
88
+ const isLineVisible = (bounds, labelY, labelBoxHeight) => labelY > bounds.y + labelBoxHeight / 2 && labelY < bounds.y + bounds.height - labelBoxHeight / 2;
89
+ function drawDescription(backgroundCtx, ctx, labelBounds, paneBounds, visualLabel, align = 'right', yAxisState) {
90
+ var _a, _b, _c;
91
+ const description = visualLabel.description;
92
+ if (!description || description.length === 0) {
93
+ return;
94
+ }
95
+ const centralY = visualLabel.y;
96
+ const textFont = getFontFromConfig(yAxisState);
97
+ const descriptionWidth = calculateTextWidth(description, ctx, textFont);
98
+ const fontHeight = calculateSymbolHeight(textFont, ctx);
99
+ const paddingTop = (_a = visualLabel.paddingTop) !== null && _a !== void 0 ? _a : DEFAULT_PADDING;
100
+ const paddingBottom = (_b = visualLabel.paddingBottom) !== null && _b !== void 0 ? _b : DEFAULT_PADDING;
101
+ const labelBoxY = centralY - fontHeight / 2 - paddingTop;
102
+ const labelBoxBottom = centralY + fontHeight / 2 + paddingBottom;
103
+ const labelBoxHeight = labelBoxBottom - labelBoxY;
104
+ // do not draw, if description is out of bounds
105
+ if (centralY < labelBounds.y + labelBoxHeight / 2 ||
106
+ centralY > labelBounds.y + labelBounds.height - labelBoxHeight / 2) {
107
+ return;
108
+ }
109
+ ctx.save();
110
+ // overlay rect
111
+ const width = descriptionWidth + 5;
112
+ const descriptionPadding = 4;
113
+ const rectWidth = descriptionWidth + descriptionPadding * 2;
114
+ const boundsEnd = paneBounds.x + paneBounds.width;
115
+ const x = align === 'right' ? boundsEnd - rectWidth : paneBounds.x + descriptionPadding;
116
+ redrawBackgroundArea(backgroundCtx, ctx, x, labelBoxY, width, labelBoxHeight, 0.8);
117
+ ctx.fillStyle = (_c = visualLabel.descColor) !== null && _c !== void 0 ? _c : visualLabel.bgColor;
118
+ ctx.font = textFont;
119
+ const xTextBounds = align === 'right'
120
+ ? boundsEnd - descriptionWidth - descriptionPadding * 2
121
+ : paneBounds.x + descriptionPadding * 2;
122
+ ctx.fillText(description, xTextBounds, centralY + fontHeight / 2 - 1); // -1 for font height adjustment
123
+ ctx.restore();
124
+ }
@@ -5,13 +5,13 @@
5
5
  */
6
6
  import { Observable } from 'rxjs';
7
7
  import { CanvasBoundsContainer } from '../../../canvas/canvas-bounds-container';
8
- import { ChartConfigComponentsYAxis, FullChartConfig, YAxisLabelMode } from '../../../chart.config';
8
+ import { YAxisConfig, YAxisLabelMode } from '../../../chart.config';
9
9
  import EventBus from '../../../events/event-bus';
10
10
  import { Bounds } from '../../../model/bounds.model';
11
11
  import { CanvasModel } from '../../../model/canvas.model';
12
12
  import { ChartBaseElement } from '../../../model/chart-base-element';
13
+ import { ScaleModel } from '../../../model/scale.model';
13
14
  import { Unit } from '../../../model/scaling/viewport.model';
14
- import { ChartModel } from '../../chart/chart.model';
15
15
  import { YAxisLabelDrawConfig } from '../y-axis-labels.drawer';
16
16
  export type YAxisVisualLabelType = 'badge' | 'rectangle' | 'plain';
17
17
  export interface VisualYAxisLabel extends YAxisLabelDrawConfig {
@@ -27,7 +27,7 @@ export interface VisualYAxisLabel extends YAxisLabelDrawConfig {
27
27
  export interface LabelGroup {
28
28
  labels: VisualYAxisLabel[];
29
29
  bounds?: Bounds;
30
- axisState?: ChartConfigComponentsYAxis;
30
+ axisState?: YAxisConfig;
31
31
  }
32
32
  export type ProviderGroups = Record<string, YAxisLabelsProvider[]>;
33
33
  export declare const LabelsGroups: {
@@ -45,12 +45,13 @@ export declare const LabelsGroups: {
45
45
  * - ...
46
46
  * Anything but the base labels which are generated in other component {@link YAxisBaseLabelsModel}
47
47
  */
48
- export declare class YAxisLabelsModel extends ChartBaseElement {
48
+ export declare class FancyYAxisLabelsModel extends ChartBaseElement {
49
49
  eventBus: EventBus;
50
- private chartModel;
50
+ private scale;
51
51
  private canvasBoundsContainer;
52
- private config;
52
+ private state;
53
53
  private canvasModel;
54
+ private paneUUID;
54
55
  private updateYAxisWidth;
55
56
  orderedLabels: LabelGroup[];
56
57
  /**
@@ -60,7 +61,7 @@ export declare class YAxisLabelsModel extends ChartBaseElement {
60
61
  private labelsProviders;
61
62
  private labelsPositionRecalculatedSubject;
62
63
  private animFrameId;
63
- constructor(eventBus: EventBus, chartModel: ChartModel, canvasBoundsContainer: CanvasBoundsContainer, config: FullChartConfig, canvasModel: CanvasModel, updateYAxisWidth: () => void);
64
+ constructor(eventBus: EventBus, scale: ScaleModel, canvasBoundsContainer: CanvasBoundsContainer, state: YAxisConfig, canvasModel: CanvasModel, paneUUID: string, updateYAxisWidth: () => void);
64
65
  /**
65
66
  * This method is used to activate the chart and subscribe to the observables that will trigger the update of the labels.
66
67
  * It calls the parent method doActivate() and adds a new Rx subscription to the merge of the following observables:
@@ -68,7 +69,7 @@ export declare class YAxisLabelsModel extends ChartBaseElement {
68
69
  * - canvasBoundsContainer.observeBoundsChanged(CanvasElement.CHART)
69
70
  * - chartModel.nextCandleTimeStampSubject
70
71
  * - canvasBoundsContainer.barResizerChangedSubject
71
- * - chartModel.scaleModel.changed
72
+ * - chartModel.scale.changed
72
73
  * When any of these observables emit a new value, the updateLabels() method is called.
73
74
  * @protected
74
75
  */
@@ -3,4 +3,204 @@
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 h,Subject as b}from"rxjs";import{CanvasElement as c,CHART_UUID as v}from"../../../canvas/canvas-bounds-container";import{ChartBaseElement as u}from"../../../model/chart-base-element";import{animationFrameThrottledPrior as p}from"../../../utils/perfomance/request-animation-frame-throttle.utils";import{uuid as m}from"../../../utils/uuid.utils";import{calcLabelsYCoordinates as f}from"./labels-positions-calculator";import{flat as d}from"../../../utils/array.utils";export const LabelsGroups={MAIN:"MAIN"};export class YAxisLabelsModel extends u{constructor(e,s,t,i,r,l){super(),this.eventBus=e,this.chartModel=s,this.canvasBoundsContainer=t,this.config=i,this.canvasModel=r,this.updateYAxisWidth=l,this.orderedLabels=[],this.customLabels={},this.labelsProviders={},this.labelsPositionRecalculatedSubject=new b,this.animFrameId=`anim_cache_${m()}`,this.initModel()}doActivate(){super.doActivate(),this.addRxSubscription(h(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(c.PANE_UUID(v)),this.chartModel.nextCandleTimeStampSubject,this.canvasBoundsContainer.barResizerChangedSubject,this.chartModel.scaleModel.changed).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){if(Object.keys(this.labelsProviders).length!==0)for(const e of Object.keys(this.labelsProviders))this.createGroup(e),Object.entries(this.labelsProviders[e]).forEach(([s,t])=>{this.addToGroup(t,e,s)})}updateLabels(e=!1){this.recalculateLabels(),p(this.animFrameId,()=>{e&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var e,s;this.orderedLabels=[];const t=this.config.components.yAxis.fontSize+((e=this.config.components.yAxis.labelBoxMargin.top)!==null&&e!==void 0?e:0)+((s=this.config.components.yAxis.labelBoxMargin.bottom)!==null&&s!==void 0?s:0);for(const i of Object.values(this.labelsProviders)){const r=d(Object.values(i).map(a=>a.getUnorderedLabels())),l=d(r.map(a=>a.labels)).map(a=>{var o;return{y:a.y,weight:(o=a.labelWeight)!==null&&o!==void 0?o:Number.POSITIVE_INFINITY}}),n=f(l,t);r.forEach(a=>{const o=n.splice(0,a.labels.length);this.orderedLabels.push(this.updateLabelsCoordinates(a,o))})}this.orderedLabels=this.orderedLabels.reverse()}createGroup(e){!this.labelsProviders[e]&&(this.labelsProviders[e]={})}addToGroup(e,s,t){this.labelsProviders[s]&&(Object.values(this.labelsProviders[s]).includes(e)||(this.labelsProviders[s][t]=e))}updateLabelsCoordinates(e,s){return Object.assign(Object.assign({},e),{labels:e.labels.map((t,i)=>Object.assign(Object.assign({},t),{lineY:t.y,y:s[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(e,s,t){var i;const r=(i=this.labelsProviders[e])!==null&&i!==void 0?i:{};r[t]=s,this.labelsProviders[e]=r,this.initModel()}unregisterYAxisLabelsProvider(e,s){var t;const i=(t=this.labelsProviders[e])!==null&&t!==void 0?t:{};delete i[s],this.labelsProviders[e]&&Object.keys(this.labelsProviders[e]).length===0&&delete this.labelsProviders[e],this.initModel()}}
6
+ import { merge, Subject } from 'rxjs';
7
+ import { CanvasElement } from '../../../canvas/canvas-bounds-container';
8
+ import { ChartBaseElement } from '../../../model/chart-base-element';
9
+ import { flat } from '../../../utils/array.utils';
10
+ import { animationFrameThrottledPrior } from '../../../utils/performance/request-animation-frame-throttle.utils';
11
+ import { uuid } from '../../../utils/uuid.utils';
12
+ import { calcLabelsYCoordinates } from './labels-positions-calculator';
13
+ export const LabelsGroups = {
14
+ MAIN: 'MAIN',
15
+ };
16
+ /**
17
+ * Different labels on Y axis:
18
+ * - last candle price
19
+ * - bid/ask
20
+ * - countdown
21
+ * - prev.day price
22
+ * - high low in viewport
23
+ * - drawings
24
+ * - studies
25
+ * - ...
26
+ * Anything but the base labels which are generated in other component {@link YAxisBaseLabelsModel}
27
+ */
28
+ export class FancyYAxisLabelsModel extends ChartBaseElement {
29
+ constructor(eventBus, scale, canvasBoundsContainer, state, canvasModel, paneUUID, updateYAxisWidth) {
30
+ super();
31
+ this.eventBus = eventBus;
32
+ this.scale = scale;
33
+ this.canvasBoundsContainer = canvasBoundsContainer;
34
+ this.state = state;
35
+ this.canvasModel = canvasModel;
36
+ this.paneUUID = paneUUID;
37
+ this.updateYAxisWidth = updateYAxisWidth;
38
+ this.orderedLabels = [];
39
+ /**
40
+ * an easier way to manage custom y-axis labels, than y-axis labels providers, but doesn't support overlapping avoidance
41
+ */
42
+ this.customLabels = {};
43
+ this.labelsProviders = {};
44
+ this.labelsPositionRecalculatedSubject = new Subject();
45
+ this.animFrameId = `anim_cache_${uuid()}`;
46
+ this.initModel();
47
+ }
48
+ /**
49
+ * This method is used to activate the chart and subscribe to the observables that will trigger the update of the labels.
50
+ * It calls the parent method doActivate() and adds a new Rx subscription to the merge of the following observables:
51
+ * - chartModel.observeCandlesChanged()
52
+ * - canvasBoundsContainer.observeBoundsChanged(CanvasElement.CHART)
53
+ * - chartModel.nextCandleTimeStampSubject
54
+ * - canvasBoundsContainer.barResizerChangedSubject
55
+ * - chartModel.scale.changed
56
+ * When any of these observables emit a new value, the updateLabels() method is called.
57
+ * @protected
58
+ */
59
+ doActivate() {
60
+ super.doActivate();
61
+ this.addRxSubscription(merge(this.canvasBoundsContainer.observeBoundsChanged(CanvasElement.PANE_UUID(this.paneUUID)), this.canvasBoundsContainer.barResizerChangedSubject, this.scale.changed).subscribe(() => {
62
+ this.updateLabels();
63
+ }));
64
+ }
65
+ /**
66
+ * Initializes the model by calling the methods to initialize the label groups and recalculate the labels.
67
+ * Then, it fires the draw event on the canvas model.
68
+ * @private
69
+ */
70
+ initModel() {
71
+ this.initLabelsGroups();
72
+ this.recalculateLabels();
73
+ this.canvasModel.fireDraw();
74
+ }
75
+ /**
76
+ * Initializes the labels groups.
77
+ * If there are labels providers, it creates a group for each one and adds the providers to their respective groups.
78
+ * @returns {void}
79
+ */
80
+ initLabelsGroups() {
81
+ for (const groupName of Object.keys(this.labelsProviders)) {
82
+ this.createGroup(groupName);
83
+ Object.entries(this.labelsProviders[groupName]).forEach(([id, provider]) => {
84
+ this.addToGroup(provider, groupName, id);
85
+ });
86
+ }
87
+ }
88
+ /**
89
+ * Updates YAxis ordered labels.
90
+ * @param adjustYAxisWidth - provide "true", if you need to adjust width after new labels will be calculated.
91
+ */
92
+ updateLabels(adjustYAxisWidth = false) {
93
+ // Updating labels is an expensive operation, and depends on chart data.
94
+ // Animation frame is needed here, because recalculation can be proceeded while rendering, and make render process fregmented.
95
+ this.recalculateLabels();
96
+ animationFrameThrottledPrior(this.animFrameId, () => {
97
+ adjustYAxisWidth && this.updateYAxisWidth();
98
+ this.canvasModel.fireDraw();
99
+ });
100
+ }
101
+ /**
102
+ * Recalculates the labels based on the current configuration and label providers.
103
+ * It generates label groups and calculates their coordinates based on their weight and the label height.
104
+ * The coordinates are generated in the order they were passed to the generator.
105
+ * The ordered labels are then updated with the new coordinates and reversed.
106
+ * @returns {void}
107
+ */
108
+ recalculateLabels() {
109
+ var _a, _b;
110
+ this.orderedLabels = [];
111
+ const labelHeight = this.state.fontSize + ((_a = this.state.labelBoxMargin.top) !== null && _a !== void 0 ? _a : 0) + ((_b = this.state.labelBoxMargin.bottom) !== null && _b !== void 0 ? _b : 0);
112
+ for (const providers of Object.values(this.labelsProviders)) {
113
+ // generated label groups
114
+ const labelGroups = flat(Object.values(providers).map(c => c.getUnorderedLabels()));
115
+ const labelsPointsAndWeight = flat(labelGroups.map(g => g.labels)).map(label => {
116
+ var _a;
117
+ return ({
118
+ y: label.y,
119
+ weight: (_a = label.labelWeight) !== null && _a !== void 0 ? _a : Number.POSITIVE_INFINITY,
120
+ });
121
+ });
122
+ // coordinates are generated in order they were passed to generator
123
+ const updatedCoordinates = calcLabelsYCoordinates(labelsPointsAndWeight, labelHeight);
124
+ labelGroups.forEach(labelGroup => {
125
+ const points = updatedCoordinates.splice(0, labelGroup.labels.length);
126
+ this.orderedLabels.push(this.updateLabelsCoordinates(labelGroup, points));
127
+ });
128
+ }
129
+ this.orderedLabels = this.orderedLabels.reverse();
130
+ }
131
+ /**
132
+ * Creates a new group with the given name if it doesn't exist yet.
133
+ * @param {string} groupName - The name of the group to be created.
134
+ * @returns {void}
135
+ */
136
+ createGroup(groupName) {
137
+ !this.labelsProviders[groupName] && (this.labelsProviders[groupName] = {});
138
+ }
139
+ /**
140
+ * Adds a YAxisLabelsProvider component to a group.
141
+ *
142
+ * @param {YAxisLabelsProvider} component - The component to add to the group.
143
+ * @param {string} groupName - The name of the group to add the component to.
144
+ * @param {string} id - The id of the component to add to the group.
145
+ * @returns {void}
146
+ */
147
+ addToGroup(component, groupName, id) {
148
+ if (this.labelsProviders[groupName]) {
149
+ if (!Object.values(this.labelsProviders[groupName]).includes(component)) {
150
+ this.labelsProviders[groupName][id] = component;
151
+ }
152
+ }
153
+ }
154
+ /**
155
+ * Updates the coordinates of the labels in a LabelGroup object based on an array of points.
156
+ * @param {LabelGroup} labels - The LabelGroup object containing the labels to be updated.
157
+ * @param {number[]} points - An array of points to be used to update the y-coordinate of each label.
158
+ * @returns {LabelGroup} - A new LabelGroup object with updated label coordinates.
159
+ */
160
+ updateLabelsCoordinates(labels, points) {
161
+ return Object.assign(Object.assign({}, labels), { labels: labels.labels.map((label, idx) => (Object.assign(Object.assign({}, label), {
162
+ // save original y
163
+ lineY: label.y, y: points[idx] }))) });
164
+ }
165
+ /**
166
+ * Returns an Observable that emits a void value whenever the labels position is recalculated.
167
+ * The Observable is created from the labelsPositionRecalculatedSubject Subject.
168
+ * @returns {Observable<void>} An Observable that emits a void value whenever the labels position is recalculated.
169
+ */
170
+ observeLabelsPositionsRecalculated() {
171
+ return this.labelsPositionRecalculatedSubject.asObservable();
172
+ }
173
+ /**
174
+ * Registers a Y axis labels provider for a given group name and ID.
175
+ *
176
+ * @param {string} groupName - The name of the group to which the provider belongs.
177
+ * @param {YAxisLabelsProvider} provider - The provider to be registered.
178
+ * @param {string} id - The ID of the provider to be registered.
179
+ * @returns {void}
180
+ */
181
+ registerYAxisLabelsProvider(groupName, provider, id) {
182
+ var _a;
183
+ const providers = (_a = this.labelsProviders[groupName]) !== null && _a !== void 0 ? _a : {};
184
+ providers[id] = provider;
185
+ this.labelsProviders[groupName] = providers;
186
+ this.initModel();
187
+ }
188
+ /**
189
+ * Unregisters a Y axis labels provider.
190
+ *
191
+ * @param {string} groupName - The name of the group to which the provider belongs.
192
+ * @param {string} id - The ID of the provider to unregister.
193
+ *
194
+ * @returns {void}
195
+ */
196
+ unregisterYAxisLabelsProvider(groupName, id) {
197
+ var _a;
198
+ const providers = (_a = this.labelsProviders[groupName]) !== null && _a !== void 0 ? _a : {};
199
+ delete providers[id];
200
+ // if group is empty, delete it too
201
+ if (this.labelsProviders[groupName] && Object.keys(this.labelsProviders[groupName]).length === 0) {
202
+ delete this.labelsProviders[groupName];
203
+ }
204
+ this.initModel();
205
+ }
206
+ }
@@ -4,20 +4,19 @@
4
4
  * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
6
  import { CanvasBoundsContainer } from '../../../canvas/canvas-bounds-container';
7
- import { ChartConfigComponentsYAxis, FullChartColors } from '../../../chart.config';
7
+ import { FullChartColors } from '../../../chart.config';
8
8
  import { Drawer } from '../../../drawers/drawing-manager';
9
9
  import { CanvasModel } from '../../../model/canvas.model';
10
- import { LabelGroup, VisualYAxisLabel } from './y-axis-labels.model';
10
+ import { PaneManager } from '../../pane/pane-manager.component';
11
+ import { LabelGroup } from './y-axis-labels.model';
11
12
  export declare class YAxisPriceLabelsDrawer implements Drawer {
12
- private labelsProvider;
13
13
  private yAxisLabelsCanvasModel;
14
14
  private backgroundCanvasModel;
15
- private yAxisState;
16
15
  private canvasBoundsContainer;
17
16
  private yAxisColors;
18
- private readonly customLabels;
19
- constructor(labelsProvider: () => LabelGroup[], yAxisLabelsCanvasModel: CanvasModel, backgroundCanvasModel: CanvasModel, yAxisState: ChartConfigComponentsYAxis, canvasBoundsContainer: CanvasBoundsContainer, yAxisColors: FullChartColors['yAxis'], customLabels: Record<string, VisualYAxisLabel>);
17
+ private paneManager;
18
+ constructor(yAxisLabelsCanvasModel: CanvasModel, backgroundCanvasModel: CanvasModel, canvasBoundsContainer: CanvasBoundsContainer, yAxisColors: FullChartColors['yAxis'], paneManager: PaneManager);
20
19
  draw(): void;
21
- drawHighlightedBackgroundBetweenLabels(): void;
20
+ drawHighlightedBackgroundBetweenLabels(orderedLabels: LabelGroup[]): void;
22
21
  getCanvasIds(): Array<string>;
23
22
  }
@@ -3,4 +3,61 @@
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{CanvasElement as c,CHART_UUID as h,limitYToBounds as u}from"../../../canvas/canvas-bounds-container";import{fillRect as C}from"../../../utils/canvas/canvas-drawing-functions.utils";import{drawLabel as b}from"./price-label.drawer";export class YAxisPriceLabelsDrawer{constructor(t,d,e,i,r,o,a){this.labelsProvider=t,this.yAxisLabelsCanvasModel=d,this.backgroundCanvasModel=e,this.yAxisState=i,this.canvasBoundsContainer=r,this.yAxisColors=o,this.customLabels=a}draw(){const t=this.yAxisLabelsCanvasModel.ctx,d=this.backgroundCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(c.PANE_UUID_Y_AXIS(h)),i=this.canvasBoundsContainer.getBounds(c.ALL_PANES);this.drawHighlightedBackgroundBetweenLabels(),this.labelsProvider().forEach(o=>{var a;const l=(a=o.bounds)!==null&&a!==void 0?a:e;o.labels.forEach(s=>{var n;return b(t,d,l,i,s,this.canvasBoundsContainer,(n=o.axisState)!==null&&n!==void 0?n:this.yAxisState,this.yAxisColors)})}),Object.values(this.customLabels).forEach(o=>b(t,d,e,i,o,this.canvasBoundsContainer,this.yAxisState,this.yAxisColors))}drawHighlightedBackgroundBetweenLabels(){const t=this.yAxisLabelsCanvasModel.ctx,d=this.labelsProvider(),e={};d.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const s=(o=e[r.subGroupId])!==null&&o!==void 0?o:[];if(e[r.subGroupId]=s,s.push(r),s.length===2){const n=(a=i.bounds)!==null&&a!==void 0?a:this.canvasBoundsContainer.getBounds(c.PANE_UUID_Y_AXIS(h));t.save(),t.fillStyle=(l=s[0].highlightColor)!==null&&l!==void 0?l:s[0].bgColor;const[v,x]=s[0].y>s[1].y?[s[1].y,s[0].y]:[s[0].y,s[1].y];C(t,{x:n.x,y:u(v,n)},{x:n.x+n.width-6,y:u(x,n)}),t.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}
6
+ import { CanvasElement, CHART_UUID, limitYToBounds, } from '../../../canvas/canvas-bounds-container';
7
+ import { fillRect } from '../../../utils/canvas/canvas-drawing-functions.utils';
8
+ import { drawLabel } from './price-label.drawer';
9
+ export class YAxisPriceLabelsDrawer {
10
+ constructor(yAxisLabelsCanvasModel, backgroundCanvasModel, canvasBoundsContainer, yAxisColors, paneManager) {
11
+ this.yAxisLabelsCanvasModel = yAxisLabelsCanvasModel;
12
+ this.backgroundCanvasModel = backgroundCanvasModel;
13
+ this.canvasBoundsContainer = canvasBoundsContainer;
14
+ this.yAxisColors = yAxisColors;
15
+ this.paneManager = paneManager;
16
+ }
17
+ draw() {
18
+ const ctx = this.yAxisLabelsCanvasModel.ctx;
19
+ const backgroundCtx = this.backgroundCanvasModel.ctx;
20
+ this.paneManager.yExtents.forEach(extent => {
21
+ const yAxisBounds = extent.getYAxisBounds();
22
+ const paneBounds = this.canvasBoundsContainer.getBounds(CanvasElement.ALL_PANES);
23
+ const orderedLabels = extent.yAxis.model.fancyLabelsModel.orderedLabels;
24
+ this.drawHighlightedBackgroundBetweenLabels(orderedLabels);
25
+ orderedLabels.forEach(l => {
26
+ var _a;
27
+ const bounds = (_a = l.bounds) !== null && _a !== void 0 ? _a : yAxisBounds;
28
+ l.labels.forEach(vl => drawLabel(ctx, backgroundCtx, bounds, paneBounds, vl, this.canvasBoundsContainer, extent.yAxis.state, this.yAxisColors));
29
+ });
30
+ // TODO I added this as a simple mechanism to add custom labels, we need to review it
31
+ Object.values(extent.yAxis.model.fancyLabelsModel.customLabels).forEach(l => drawLabel(ctx, backgroundCtx, yAxisBounds, paneBounds, l, this.canvasBoundsContainer, extent.yAxis.state, this.yAxisColors));
32
+ });
33
+ }
34
+ // this is a very simple solution which matches 2 labels with same "subGroupId"
35
+ // in future we may want to change it, but for now it's enough
36
+ // and I guess it used only for drawings
37
+ drawHighlightedBackgroundBetweenLabels(orderedLabels) {
38
+ const ctx = this.yAxisLabelsCanvasModel.ctx;
39
+ const map = {};
40
+ orderedLabels.forEach(group => {
41
+ group.labels.forEach(label => {
42
+ var _a, _b, _c;
43
+ if (label.subGroupId) {
44
+ const labels = (_a = map[label.subGroupId]) !== null && _a !== void 0 ? _a : [];
45
+ map[label.subGroupId] = labels;
46
+ labels.push(label);
47
+ if (labels.length === 2) {
48
+ const bounds = (_b = group.bounds) !== null && _b !== void 0 ? _b : this.canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID_Y_AXIS(CHART_UUID));
49
+ ctx.save();
50
+ ctx.fillStyle = (_c = labels[0].highlightColor) !== null && _c !== void 0 ? _c : labels[0].bgColor;
51
+ // start and end are sorted in ascending order
52
+ const [startY, endY] = labels[0].y > labels[1].y ? [labels[1].y, labels[0].y] : [labels[0].y, labels[1].y];
53
+ fillRect(ctx, { x: bounds.x, y: limitYToBounds(startY, bounds) }, { x: bounds.x + bounds.width - 6, y: limitYToBounds(endY, bounds) });
54
+ ctx.restore();
55
+ }
56
+ }
57
+ });
58
+ });
59
+ }
60
+ getCanvasIds() {
61
+ return [this.yAxisLabelsCanvasModel.canvasId];
62
+ }
63
+ }
@@ -8,16 +8,18 @@ import { CanvasBoundsContainer } from '../../canvas/canvas-bounds-container';
8
8
  import { ChartBaseElement } from '../../model/chart-base-element';
9
9
  import { ScaleModel } from '../../model/scale.model';
10
10
  export declare class YAxisBaseLabelsModel extends ChartBaseElement {
11
- private scaleModel;
12
- private yAxisLabelsGenerator;
11
+ private scale;
12
+ private labelsGenerator;
13
13
  private canvasBoundsContainer;
14
+ private paneUUID;
15
+ private extentIdx;
14
16
  labels: Array<NumericAxisLabel>;
15
17
  private prevYAxisHeight;
16
18
  private animFrameId;
17
- constructor(scaleModel: ScaleModel, yAxisLabelsGenerator: NumericAxisLabelsGenerator, canvasBoundsContainer: CanvasBoundsContainer);
19
+ constructor(scale: ScaleModel, labelsGenerator: NumericAxisLabelsGenerator, canvasBoundsContainer: CanvasBoundsContainer, paneUUID: string, extentIdx: number);
18
20
  /**
19
21
  * This method is used to activate the component. It calls the parent's doActivate method and subscribes to the merge of two observables:
20
- * - this.scaleModel.yChanged
22
+ * - this.scale.yChanged
21
23
  * - this.canvasBoundsContainer.observeBoundsChanged
22
24
  * The merge of these two observables is used to update the labels of the component when either the y-axis scale model changes or the canvas bounds change.
23
25
  * If the height of the canvas bounds changes by more than 1.5 times the previous height, the labels cache is invalidated and the previous y-axis height is updated.
@@ -3,4 +3,50 @@
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 t}from"rxjs";import{filter as a,map as r,tap as o}from"rxjs/operators";import{CanvasElement as n}from"../../canvas/canvas-bounds-container";import{ChartBaseElement as h}from"../../model/chart-base-element";import{uuid as m}from"../../utils/uuid.utils";import{animationFrameThrottledPrior as l}from"../../utils/perfomance/request-animation-frame-throttle.utils";import{isDiffersBy as d}from"../../utils/math.utils";export class YAxisBaseLabelsModel extends h{constructor(e,s,i){super(),this.scaleModel=e,this.yAxisLabelsGenerator=s,this.canvasBoundsContainer=i,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${m()}`}doActivate(){super.doActivate(),this.addRxSubscription(t(this.scaleModel.yChanged,this.canvasBoundsContainer.observeBoundsChanged(n.Y_AXIS).pipe(r(e=>e.height),a(e=>d(e,this.prevYAxisHeight,1.5)),o(e=>{this.yAxisLabelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=e}))).subscribe(()=>this.updateLabels()))}updateLabels(){this.labels=this.yAxisLabelsGenerator.generateNumericLabels(),l(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}}
6
+ import { merge } from 'rxjs';
7
+ import { filter, map, tap } from 'rxjs/operators';
8
+ import { CanvasElement } from '../../canvas/canvas-bounds-container';
9
+ import { ChartBaseElement } from '../../model/chart-base-element';
10
+ import { uuid } from '../../utils/uuid.utils';
11
+ import { animationFrameThrottledPrior } from '../../utils/performance/request-animation-frame-throttle.utils';
12
+ import { isDiffersBy } from '../../utils/math.utils';
13
+ // TODO rework, make this the source of Y labels for main chart
14
+ export class YAxisBaseLabelsModel extends ChartBaseElement {
15
+ constructor(scale, labelsGenerator, canvasBoundsContainer, paneUUID, extentIdx) {
16
+ super();
17
+ this.scale = scale;
18
+ this.labelsGenerator = labelsGenerator;
19
+ this.canvasBoundsContainer = canvasBoundsContainer;
20
+ this.paneUUID = paneUUID;
21
+ this.extentIdx = extentIdx;
22
+ this.labels = [];
23
+ this.prevYAxisHeight = 0;
24
+ this.animFrameId = `anim_cache_${uuid()}`;
25
+ }
26
+ /**
27
+ * This method is used to activate the component. It calls the parent's doActivate method and subscribes to the merge of two observables:
28
+ * - this.scale.yChanged
29
+ * - this.canvasBoundsContainer.observeBoundsChanged
30
+ * The merge of these two observables is used to update the labels of the component when either the y-axis scale model changes or the canvas bounds change.
31
+ * If the height of the canvas bounds changes by more than 1.5 times the previous height, the labels cache is invalidated and the previous y-axis height is updated.
32
+ */
33
+ doActivate() {
34
+ super.doActivate();
35
+ this.addRxSubscription(merge(this.scale.yChanged, this.canvasBoundsContainer
36
+ .observeBoundsChanged(CanvasElement.PANE_UUID_Y_AXIS(this.paneUUID, this.extentIdx))
37
+ .pipe(map(bounds => bounds.height),
38
+ // do not recalculate height every time bounds is changed, recalculate only if it differs by 1.5 times
39
+ filter(height => isDiffersBy(height, this.prevYAxisHeight, 1.5)), tap(height => {
40
+ this.labelsGenerator.labelsCache.invalidate();
41
+ this.prevYAxisHeight = height;
42
+ }))).subscribe(() => this.updateLabels()));
43
+ }
44
+ /**
45
+ * Updates the labels of the chart's y-axis by generating new numeric labels using the yAxisLabelsGenerator object.
46
+ * Then, it calls the updateYAxisWidth method to update the width of the y-axis.
47
+ */
48
+ updateLabels() {
49
+ this.labels = this.labelsGenerator.generateNumericLabels();
50
+ animationFrameThrottledPrior(this.animFrameId, () => this.canvasBoundsContainer.updateYAxisWidths());
51
+ }
52
+ }
@@ -3,7 +3,7 @@
3
3
  * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
4
  * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
- import { ChartConfigComponentsYAxis, FullChartColors } from '../../chart.config';
6
+ import { YAxisConfig, FullChartColors } from '../../chart.config';
7
7
  import { Bounds } from '../../model/bounds.model';
8
8
  export interface YAxisLabelDrawProps {
9
9
  ctx: CanvasRenderingContext2D;
@@ -37,7 +37,7 @@ export declare const DEFAULT_PRICE_LABEL_PADDING = 4;
37
37
  * @param align
38
38
  * @param yAxisState
39
39
  */
40
- export declare function drawBadgeLabel(ctx: CanvasRenderingContext2D, bounds: Bounds, text: string, centralY: number, config: YAxisLabelDrawConfig, yAxisState: ChartConfigComponentsYAxis, yAxisColors: FullChartColors['yAxis'], drawOutside?: boolean): void;
40
+ export declare function drawBadgeLabel(ctx: CanvasRenderingContext2D, bounds: Bounds, text: string, centralY: number, config: YAxisLabelDrawConfig, yAxisState: YAxisConfig, yAxisColors: FullChartColors['yAxis'], drawOutside?: boolean): void;
41
41
  /**
42
42
  * Draws rectangle label on Y axis with provided parameters.
43
43
  * @param ctx - canvas 2D context to draw on
@@ -48,7 +48,7 @@ export declare function drawBadgeLabel(ctx: CanvasRenderingContext2D, bounds: Bo
48
48
  * @param align
49
49
  * @param yAxisState
50
50
  */
51
- export declare function drawRectLabel(ctx: CanvasRenderingContext2D, bounds: Bounds, text: string, centralY: number, config: YAxisLabelDrawConfig, yAxisState: ChartConfigComponentsYAxis, yAxisColors: FullChartColors['yAxis'], drawOutside?: boolean): void;
51
+ export declare function drawRectLabel(ctx: CanvasRenderingContext2D, bounds: Bounds, text: string, centralY: number, config: YAxisLabelDrawConfig, yAxisState: YAxisConfig, yAxisColors: FullChartColors['yAxis'], drawOutside?: boolean): void;
52
52
  /**
53
53
  * Draws rectangle label on Y axis with provided parameters but with transparent background.
54
54
  * @param ctx - canvas 2D context to draw on
@@ -59,7 +59,7 @@ export declare function drawRectLabel(ctx: CanvasRenderingContext2D, bounds: Bou
59
59
  * @param align
60
60
  * @param yAxisState
61
61
  */
62
- export declare function drawPlainLabel(ctx: CanvasRenderingContext2D, bounds: Bounds, text: string, centralY: number, config: YAxisLabelDrawConfig, yAxisState: ChartConfigComponentsYAxis, yAxisColors: FullChartColors['yAxis'], drawOutside?: boolean, backgroundCtx?: CanvasRenderingContext2D): void;
62
+ export declare function drawPlainLabel(ctx: CanvasRenderingContext2D, bounds: Bounds, text: string, centralY: number, config: YAxisLabelDrawConfig, yAxisState: YAxisConfig, yAxisColors: FullChartColors['yAxis'], drawOutside?: boolean, backgroundCtx?: CanvasRenderingContext2D): void;
63
63
  /**
64
64
  * Offset from the center of label to the top/bottom.
65
65
  *