billboard.js 4.1.4 → 4.2.0-next.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 (352) hide show
  1. package/dist/billboard.css +87 -1
  2. package/dist/billboard.js +11129 -7032
  3. package/dist/billboard.min.css +2 -2
  4. package/dist/billboard.min.js +20 -20
  5. package/dist/billboard.pkgd.js +22703 -14154
  6. package/dist/billboard.pkgd.min.js +37 -37
  7. package/dist/billboard.react.js +5 -5
  8. package/dist/billboard.react.min.js +2 -2
  9. package/dist/billboard.worker.js +1 -1
  10. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-sparkline.js +21 -4
  13. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  14. package/dist/plugin/billboardjs-plugin-stanford.js +22 -13
  15. package/dist/plugin/billboardjs-plugin-stanford.min.js +4 -4
  16. package/dist/plugin/billboardjs-plugin-tableview.js +20 -3
  17. package/dist/plugin/billboardjs-plugin-tableview.min.js +4 -4
  18. package/dist/plugin/billboardjs-plugin-textoverlap.js +2 -2
  19. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  20. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +1689 -1252
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +8 -8
  22. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2288 -1012
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +10 -10
  24. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6350 -2390
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -18
  26. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +1310 -1006
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +10 -10
  28. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +1293 -1006
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
  30. package/dist/theme/dark.css +90 -1
  31. package/dist/theme/dark.min.css +2 -2
  32. package/dist/theme/datalab.css +87 -1
  33. package/dist/theme/datalab.min.css +2 -2
  34. package/dist/theme/graph.css +87 -1
  35. package/dist/theme/graph.min.css +2 -2
  36. package/dist/theme/insight.css +87 -1
  37. package/dist/theme/insight.min.css +2 -2
  38. package/dist/theme/modern.css +87 -1
  39. package/dist/theme/modern.min.css +2 -2
  40. package/dist-esm/Chart/Chart.js +5 -5
  41. package/dist-esm/Chart/api/axis.js +2 -3
  42. package/dist-esm/Chart/api/category.js +2 -3
  43. package/dist-esm/Chart/api/chart.js +3 -4
  44. package/dist-esm/Chart/api/color.js +2 -3
  45. package/dist-esm/Chart/api/data.js +3 -4
  46. package/dist-esm/Chart/api/export.js +3 -4
  47. package/dist-esm/Chart/api/flow.js +15 -9
  48. package/dist-esm/Chart/api/focus.js +5 -3
  49. package/dist-esm/Chart/api/grid.js +2 -3
  50. package/dist-esm/Chart/api/group.js +2 -3
  51. package/dist-esm/Chart/api/legend.js +1 -2
  52. package/dist-esm/Chart/api/load.js +3 -4
  53. package/dist-esm/Chart/api/regions.js +3 -4
  54. package/dist-esm/Chart/api/selection.js +3 -4
  55. package/dist-esm/Chart/api/show.js +2 -3
  56. package/dist-esm/Chart/api/stubs.js +3 -4
  57. package/dist-esm/Chart/api/subchart.js +4 -5
  58. package/dist-esm/Chart/api/tooltip.js +28 -9
  59. package/dist-esm/Chart/api/x.js +2 -3
  60. package/dist-esm/Chart/api/zoom.js +6 -7
  61. package/dist-esm/ChartInternal/Axis/Axis.js +5 -6
  62. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +26 -17
  63. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +40 -12
  64. package/dist-esm/ChartInternal/ChartInternal.js +39 -24
  65. package/dist-esm/ChartInternal/data/convert.helper.js +2 -3
  66. package/dist-esm/ChartInternal/data/convert.js +3 -4
  67. package/dist-esm/ChartInternal/data/data.js +18 -11
  68. package/dist-esm/ChartInternal/data/load.js +4 -5
  69. package/dist-esm/ChartInternal/interactions/drag.js +3 -4
  70. package/dist-esm/ChartInternal/interactions/eventrect.js +4 -5
  71. package/dist-esm/ChartInternal/interactions/flow.js +25 -19
  72. package/dist-esm/ChartInternal/interactions/interaction.js +14 -13
  73. package/dist-esm/ChartInternal/interactions/subchart.js +5 -6
  74. package/dist-esm/ChartInternal/interactions/zoom.js +4 -5
  75. package/dist-esm/ChartInternal/internals/category.js +2 -3
  76. package/dist-esm/ChartInternal/internals/class.js +5 -5
  77. package/dist-esm/ChartInternal/internals/clip.js +2 -3
  78. package/dist-esm/ChartInternal/internals/color.js +4 -5
  79. package/dist-esm/ChartInternal/internals/domain.js +7 -7
  80. package/dist-esm/ChartInternal/internals/format.js +3 -4
  81. package/dist-esm/ChartInternal/internals/grid.js +4 -5
  82. package/dist-esm/ChartInternal/internals/legend.js +7 -7
  83. package/dist-esm/ChartInternal/internals/redraw.js +13 -13
  84. package/dist-esm/ChartInternal/internals/region.js +4 -5
  85. package/dist-esm/ChartInternal/internals/scale.js +2 -3
  86. package/dist-esm/ChartInternal/internals/selection.js +3 -4
  87. package/dist-esm/ChartInternal/internals/size.axis.js +2 -3
  88. package/dist-esm/ChartInternal/internals/size.js +8 -9
  89. package/dist-esm/ChartInternal/internals/style.js +4 -5
  90. package/dist-esm/ChartInternal/internals/subchart.util.js +2 -3
  91. package/dist-esm/ChartInternal/internals/text.arc.js +3 -4
  92. package/dist-esm/ChartInternal/internals/text.js +22 -23
  93. package/dist-esm/ChartInternal/internals/text.util.js +4 -5
  94. package/dist-esm/ChartInternal/internals/title.js +4 -5
  95. package/dist-esm/ChartInternal/internals/tooltip.js +42 -23
  96. package/dist-esm/ChartInternal/internals/transform.js +5 -6
  97. package/dist-esm/ChartInternal/internals/type.js +78 -11
  98. package/dist-esm/ChartInternal/shape/arc.js +5 -6
  99. package/dist-esm/ChartInternal/shape/area.js +4 -5
  100. package/dist-esm/ChartInternal/shape/bar.js +5 -6
  101. package/dist-esm/ChartInternal/shape/boxplot.js +111 -0
  102. package/dist-esm/ChartInternal/shape/bubble.js +2 -3
  103. package/dist-esm/ChartInternal/shape/bullet.js +213 -0
  104. package/dist-esm/ChartInternal/shape/candlestick.js +5 -6
  105. package/dist-esm/ChartInternal/shape/core/barRadius.js +2 -3
  106. package/dist-esm/ChartInternal/shape/core/boxplot.js +192 -0
  107. package/dist-esm/ChartInternal/shape/core/bubble.js +4 -5
  108. package/dist-esm/ChartInternal/shape/core/bullet.js +528 -0
  109. package/dist-esm/ChartInternal/shape/core/candlestick.js +2 -3
  110. package/dist-esm/ChartInternal/shape/core/dataRegion.js +2 -3
  111. package/dist-esm/ChartInternal/shape/core/geometry.js +2 -3
  112. package/dist-esm/ChartInternal/shape/core/heatmap.js +453 -0
  113. package/dist-esm/ChartInternal/shape/core/path.js +2 -3
  114. package/dist-esm/ChartInternal/shape/core/point.js +2 -3
  115. package/dist-esm/ChartInternal/shape/core/sankey.js +576 -0
  116. package/dist-esm/ChartInternal/shape/core/treemap.js +2 -3
  117. package/dist-esm/ChartInternal/shape/funnel.js +45 -6
  118. package/dist-esm/ChartInternal/shape/gauge.js +3 -4
  119. package/dist-esm/ChartInternal/shape/heatmap.js +144 -0
  120. package/dist-esm/ChartInternal/shape/line.js +7 -8
  121. package/dist-esm/ChartInternal/shape/point.js +9 -9
  122. package/dist-esm/ChartInternal/shape/polar.js +3 -4
  123. package/dist-esm/ChartInternal/shape/radar.js +19 -7
  124. package/dist-esm/ChartInternal/shape/sankey.js +154 -0
  125. package/dist-esm/ChartInternal/shape/shape.js +15 -11
  126. package/dist-esm/ChartInternal/shape/treemap.js +8 -5
  127. package/dist-esm/canvas/CanvasAxisRenderer.js +28 -328
  128. package/dist-esm/canvas/CanvasEngine.js +2 -3
  129. package/dist-esm/canvas/CanvasPainter.js +2 -3
  130. package/dist-esm/canvas/CanvasRenderer.js +38 -408
  131. package/dist-esm/canvas/CanvasTheme.js +28 -8
  132. package/dist-esm/canvas/HitDetector.js +20 -24
  133. package/dist-esm/canvas/axisTicks.js +5 -6
  134. package/dist-esm/canvas/boxplot.js +201 -0
  135. package/dist-esm/canvas/bullet.js +212 -0
  136. package/dist-esm/canvas/classes.js +2 -3
  137. package/dist-esm/canvas/color.js +2 -3
  138. package/dist-esm/canvas/flow.js +190 -0
  139. package/dist-esm/canvas/geometry.js +2 -3
  140. package/dist-esm/canvas/grid.js +206 -0
  141. package/dist-esm/canvas/heatmap.js +141 -0
  142. package/dist-esm/canvas/labels.js +3 -4
  143. package/dist-esm/canvas/pointPattern.js +2 -3
  144. package/dist-esm/canvas/sankey.js +137 -0
  145. package/dist-esm/canvas/selection.js +473 -0
  146. package/dist-esm/canvas/subchart.js +814 -0
  147. package/dist-esm/canvas/treemap.js +100 -0
  148. package/dist-esm/canvas/util.js +2 -3
  149. package/dist-esm/config/Options/Options.js +3 -4
  150. package/dist-esm/config/Options/axis/axis.js +2 -3
  151. package/dist-esm/config/Options/axis/x.js +2 -3
  152. package/dist-esm/config/Options/axis/y.js +2 -3
  153. package/dist-esm/config/Options/axis/y2.js +14 -3
  154. package/dist-esm/config/Options/common/boost.js +2 -3
  155. package/dist-esm/config/Options/common/color.js +2 -3
  156. package/dist-esm/config/Options/common/grid.js +2 -3
  157. package/dist-esm/config/Options/common/legend.js +2 -3
  158. package/dist-esm/config/Options/common/main.js +2 -3
  159. package/dist-esm/config/Options/common/point.js +2 -3
  160. package/dist-esm/config/Options/common/title.js +2 -3
  161. package/dist-esm/config/Options/common/tooltip.js +2 -3
  162. package/dist-esm/config/Options/data/axis.js +2 -3
  163. package/dist-esm/config/Options/data/data.js +49 -4
  164. package/dist-esm/config/Options/data/selection.js +2 -3
  165. package/dist-esm/config/Options/interaction/interaction.js +2 -3
  166. package/dist-esm/config/Options/interaction/subchart.js +6 -3
  167. package/dist-esm/config/Options/interaction/zoom.js +2 -3
  168. package/dist-esm/config/Options/shape/arc.js +2 -3
  169. package/dist-esm/config/Options/shape/area.js +2 -3
  170. package/dist-esm/config/Options/shape/bar.js +2 -3
  171. package/dist-esm/config/Options/shape/boxplot.js +106 -0
  172. package/dist-esm/config/Options/shape/bubble.js +2 -3
  173. package/dist-esm/config/Options/shape/bullet.js +177 -0
  174. package/dist-esm/config/Options/shape/candlestick.js +2 -3
  175. package/dist-esm/config/Options/shape/donut.js +2 -3
  176. package/dist-esm/config/Options/shape/funnel.js +2 -3
  177. package/dist-esm/config/Options/shape/gauge.js +2 -3
  178. package/dist-esm/config/Options/shape/heatmap.js +137 -0
  179. package/dist-esm/config/Options/shape/line.js +2 -3
  180. package/dist-esm/config/Options/shape/pie.js +2 -3
  181. package/dist-esm/config/Options/shape/polar.js +2 -3
  182. package/dist-esm/config/Options/shape/radar.js +2 -3
  183. package/dist-esm/config/Options/shape/sankey.js +116 -0
  184. package/dist-esm/config/Options/shape/scatter.js +2 -3
  185. package/dist-esm/config/Options/shape/spline.js +2 -3
  186. package/dist-esm/config/Options/shape/treemap.js +2 -3
  187. package/dist-esm/config/Store/Element.js +2 -3
  188. package/dist-esm/config/Store/State.js +4 -4
  189. package/dist-esm/config/Store/Store.js +2 -3
  190. package/dist-esm/config/classes.js +2 -4
  191. package/dist-esm/config/config.js +2 -3
  192. package/dist-esm/config/const.js +31 -23
  193. package/dist-esm/config/resolver/axis.core.js +4 -5
  194. package/dist-esm/config/resolver/axis.js +2 -3
  195. package/dist-esm/config/resolver/canvas.js +113 -900
  196. package/dist-esm/config/resolver/canvasBoxplot.js +49 -0
  197. package/dist-esm/config/resolver/canvasBullet.js +29 -0
  198. package/dist-esm/config/resolver/canvasFlow.js +28 -0
  199. package/dist-esm/config/resolver/canvasGrid.js +27 -0
  200. package/dist-esm/config/resolver/canvasHeatmap.js +31 -0
  201. package/dist-esm/config/resolver/canvasSankey.js +31 -0
  202. package/dist-esm/config/resolver/canvasSelection.js +30 -0
  203. package/dist-esm/config/resolver/canvasShape.js +13 -12
  204. package/dist-esm/config/resolver/canvasSubchart.js +30 -0
  205. package/dist-esm/config/resolver/canvasType.js +48 -0
  206. package/dist-esm/config/resolver/category.js +3 -4
  207. package/dist-esm/config/resolver/customType.js +58 -0
  208. package/dist-esm/config/resolver/export.js +3 -4
  209. package/dist-esm/config/resolver/flow.js +5 -6
  210. package/dist-esm/config/resolver/grid.js +6 -7
  211. package/dist-esm/config/resolver/interaction/selection.js +6 -7
  212. package/dist-esm/config/resolver/interaction/subchart.js +6 -7
  213. package/dist-esm/config/resolver/interaction/zoom.js +6 -7
  214. package/dist-esm/config/resolver/regions.js +5 -6
  215. package/dist-esm/config/resolver/shape/arc.helpers.js +5 -6
  216. package/dist-esm/config/resolver/shape/area.js +3 -4
  217. package/dist-esm/config/resolver/shape/axis.helpers.js +2 -3
  218. package/dist-esm/config/resolver/shape/bar.js +5 -6
  219. package/dist-esm/config/resolver/shape/boxplot.js +30 -0
  220. package/dist-esm/config/resolver/shape/bubble.js +5 -6
  221. package/dist-esm/config/resolver/shape/bullet.js +23 -0
  222. package/dist-esm/config/resolver/shape/candlestick.js +5 -6
  223. package/dist-esm/config/resolver/shape/donut.js +2 -3
  224. package/dist-esm/config/resolver/shape/funnel.js +7 -6
  225. package/dist-esm/config/resolver/shape/gauge.js +4 -5
  226. package/dist-esm/config/resolver/shape/heatmap.js +23 -0
  227. package/dist-esm/config/resolver/shape/line.js +2 -3
  228. package/dist-esm/config/resolver/shape/pie.js +3 -4
  229. package/dist-esm/config/resolver/shape/polar.js +4 -5
  230. package/dist-esm/config/resolver/shape/radar.js +5 -6
  231. package/dist-esm/config/resolver/shape/sankey.js +23 -0
  232. package/dist-esm/config/resolver/shape/scatter.js +4 -5
  233. package/dist-esm/config/resolver/shape/treemap.js +4 -5
  234. package/dist-esm/core.js +5 -6
  235. package/dist-esm/index.canvas.js +13 -9
  236. package/dist-esm/index.esm.js +6 -2
  237. package/dist-esm/module/Cache.js +2 -3
  238. package/dist-esm/module/browser.js +2 -3
  239. package/dist-esm/module/dsv.js +2 -3
  240. package/dist-esm/module/error.js +23 -16
  241. package/dist-esm/module/generator.js +3 -4
  242. package/dist-esm/module/sanitize.js +2 -3
  243. package/dist-esm/module/util/brush.js +2 -3
  244. package/dist-esm/module/util/dom.js +3 -4
  245. package/dist-esm/module/util/object.js +13 -6
  246. package/dist-esm/module/util/type-checks.js +2 -3
  247. package/dist-esm/module/worker.js +2 -3
  248. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +6 -10
  249. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +10 -18
  250. package/dist-esm/plugin/billboardjs-plugin-stanford.js +17 -45
  251. package/dist-esm/plugin/billboardjs-plugin-tableview.js +10 -18
  252. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +9 -16
  253. package/dist-esm/react/index.js +2 -3
  254. package/package.json +44 -44
  255. package/src/Chart/Chart.ts +1 -0
  256. package/src/Chart/api/chart.ts +2 -1
  257. package/src/Chart/api/flow.ts +20 -7
  258. package/src/Chart/api/focus.ts +3 -0
  259. package/src/Chart/api/subchart.ts +1 -1
  260. package/src/Chart/api/tooltip.ts +54 -15
  261. package/src/ChartInternal/Axis/AxisRenderer.ts +29 -20
  262. package/src/ChartInternal/Axis/AxisRendererHelper.ts +45 -9
  263. package/src/ChartInternal/ChartInternal.ts +46 -19
  264. package/src/ChartInternal/data/IData.ts +13 -0
  265. package/src/ChartInternal/data/data.ts +26 -5
  266. package/src/ChartInternal/data/load.ts +2 -2
  267. package/src/ChartInternal/interactions/flow.ts +50 -19
  268. package/src/ChartInternal/interactions/interaction.ts +15 -11
  269. package/src/ChartInternal/internals/class.ts +3 -2
  270. package/src/ChartInternal/internals/domain.ts +4 -2
  271. package/src/ChartInternal/internals/format.ts +3 -1
  272. package/src/ChartInternal/internals/legend.ts +2 -1
  273. package/src/ChartInternal/internals/redraw.ts +18 -12
  274. package/src/ChartInternal/internals/size.ts +5 -3
  275. package/src/ChartInternal/internals/text.ts +24 -28
  276. package/src/ChartInternal/internals/tooltip.ts +59 -20
  277. package/src/ChartInternal/internals/transform.ts +2 -2
  278. package/src/ChartInternal/internals/type.ts +101 -9
  279. package/src/ChartInternal/shape/boxplot.ts +172 -0
  280. package/src/ChartInternal/shape/bullet.ts +323 -0
  281. package/src/ChartInternal/shape/core/boxplot.ts +241 -0
  282. package/src/ChartInternal/shape/core/bullet.ts +734 -0
  283. package/src/ChartInternal/shape/core/heatmap.ts +665 -0
  284. package/src/ChartInternal/shape/core/sankey.ts +782 -0
  285. package/src/ChartInternal/shape/funnel.ts +73 -2
  286. package/src/ChartInternal/shape/heatmap.ts +236 -0
  287. package/src/ChartInternal/shape/point.ts +6 -3
  288. package/src/ChartInternal/shape/radar.ts +30 -1
  289. package/src/ChartInternal/shape/sankey.ts +242 -0
  290. package/src/ChartInternal/shape/shape.ts +16 -4
  291. package/src/ChartInternal/shape/treemap.ts +10 -0
  292. package/src/Plugin/stanford/index.ts +1 -28
  293. package/src/canvas/CanvasAxisRenderer.ts +54 -596
  294. package/src/canvas/CanvasRenderer.ts +68 -640
  295. package/src/canvas/CanvasTheme.ts +92 -6
  296. package/src/canvas/HitDetector.ts +30 -28
  297. package/src/canvas/boxplot.ts +230 -0
  298. package/src/canvas/bullet.ts +269 -0
  299. package/src/canvas/flow.ts +237 -0
  300. package/src/canvas/grid.ts +359 -0
  301. package/src/canvas/heatmap.ts +147 -0
  302. package/src/canvas/labels.ts +3 -1
  303. package/src/canvas/sankey.ts +151 -0
  304. package/src/canvas/selection.ts +626 -0
  305. package/src/canvas/subchart.ts +1292 -0
  306. package/src/canvas/treemap.ts +142 -0
  307. package/src/config/Options/axis/y2.ts +13 -0
  308. package/src/config/Options/data/data.ts +47 -1
  309. package/src/config/Options/interaction/subchart.ts +4 -0
  310. package/src/config/Options/shape/boxplot.ts +95 -0
  311. package/src/config/Options/shape/bullet.ts +170 -0
  312. package/src/config/Options/shape/heatmap.ts +125 -0
  313. package/src/config/Options/shape/sankey.ts +108 -0
  314. package/src/config/Store/State.ts +2 -1
  315. package/src/config/classes.ts +0 -1
  316. package/src/config/const.ts +30 -21
  317. package/src/config/resolver/canvas.ts +147 -1293
  318. package/src/config/resolver/canvasBoxplot.ts +42 -0
  319. package/src/config/resolver/canvasBullet.ts +20 -0
  320. package/src/config/resolver/canvasFlow.ts +18 -0
  321. package/src/config/resolver/canvasGrid.ts +17 -0
  322. package/src/config/resolver/canvasHeatmap.ts +23 -0
  323. package/src/config/resolver/canvasSankey.ts +23 -0
  324. package/src/config/resolver/canvasSelection.ts +20 -0
  325. package/src/config/resolver/canvasShape.ts +6 -1
  326. package/src/config/resolver/canvasSubchart.ts +20 -0
  327. package/src/config/resolver/canvasType.ts +51 -0
  328. package/src/config/resolver/customType.ts +69 -0
  329. package/src/config/resolver/shape/boxplot.ts +31 -0
  330. package/src/config/resolver/shape/bullet.ts +18 -0
  331. package/src/config/resolver/shape/funnel.ts +8 -2
  332. package/src/config/resolver/shape/heatmap.ts +18 -0
  333. package/src/config/resolver/shape/index.ts +4 -0
  334. package/src/config/resolver/shape/sankey.ts +18 -0
  335. package/src/index.canvas.ts +9 -3
  336. package/src/index.esm.ts +4 -0
  337. package/src/index.ts +34 -0
  338. package/src/module/error.ts +32 -18
  339. package/src/module/util/object.ts +26 -1
  340. package/src/scss/billboard.scss +106 -0
  341. package/src/scss/theme/dark.scss +110 -0
  342. package/src/scss/theme/datalab.scss +106 -0
  343. package/src/scss/theme/graph.scss +106 -0
  344. package/src/scss/theme/insight.scss +106 -0
  345. package/src/scss/theme/modern.scss +106 -0
  346. package/types/bb.d.ts +4 -0
  347. package/types/canvas.d.ts +3 -0
  348. package/types/chart.d.ts +5 -0
  349. package/types/index.d.ts +4 -0
  350. package/types/options.d.ts +13 -1
  351. package/types/options.shape.d.ts +431 -0
  352. package/types/types.d.ts +4 -0
@@ -3,20 +3,17 @@
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
5
  import type {AxisTickFormat, AxisTickValue} from "../../types/axis";
6
- import type {GridLineOptions, RegionOptions} from "../../types/options";
6
+ import type {RegionOptions} from "../../types/options";
7
7
  import type {AxisType} from "../../types/types";
8
- import {AXIS_TICK_PADDING, AXIS_TICK_SIZE} from "../config/const";
8
+ import {AXIS_TICK_LENGTH, AXIS_TICK_PADDING, AXIS_TICK_SIZE} from "../config/const";
9
9
  import {
10
10
  getAdditionalAxisScale,
11
11
  getAdditionalAxisTickFormat,
12
12
  getAdditionalAxisTickValues,
13
- getSubXTickLineValues,
14
- getSubXTickValues,
15
13
  getXScale,
16
14
  getXTickLinePosition,
17
15
  getXTickLineValues,
18
16
  getXTickValues,
19
- getYGridTickValues,
20
17
  getYTickValues,
21
18
  isSameTickValue,
22
19
  normalizeXValue,
@@ -24,12 +21,10 @@ import {
24
21
  type YAxisId
25
22
  } from "./axisTicks";
26
23
  import CanvasEngine from "./CanvasEngine";
27
- import CanvasPainter, {CanvasRect, type CanvasStyle} from "./CanvasPainter";
28
- import CanvasTheme, {type CanvasGridLineThemeStyle} from "./CanvasTheme";
24
+ import CanvasPainter, {CanvasRect} from "./CanvasPainter";
25
+ import CanvasTheme from "./CanvasTheme";
29
26
  import {getFontSize} from "./util";
30
27
 
31
- type GridLine = Partial<GridLineOptions>;
32
- type GridAxis = "x" | "y";
33
28
  type AdditionalAxisOptions = {
34
29
  scale: any,
35
30
  ticks: AxisTickValue[],
@@ -54,7 +49,7 @@ const X_AXIS_TICK_TEXT_VERTICAL_CLIP_PADDING = 15;
54
49
  * @returns {number} Text direction multiplier
55
50
  * @private
56
51
  */
57
- function getXTickTextDirection(isRotated: boolean): number {
52
+ export function getXTickTextDirection(isRotated: boolean): number {
58
53
  return isRotated ? -1 : 1;
59
54
  }
60
55
 
@@ -69,57 +64,6 @@ function getYTickTextDirection(isRotated: boolean, isY2: boolean): number {
69
64
  return isRotated ? (isY2 ? -1 : 1) : (isY2 ? 1 : -1);
70
65
  }
71
66
 
72
- /**
73
- * Get tick formatter for the canvas subchart y/y2 axis.
74
- * @param {object} $$ ChartInternal context
75
- * @param {string} id Axis id
76
- * @returns {function} Tick formatter
77
- * @private
78
- */
79
- function getSubYTickFormat($$, id: YAxisId): AxisTickFormat {
80
- const subAxisId = id === "y2" ? "subY2" : "subY";
81
- const axisFormat = $$.axis?.[subAxisId]?.tickFormat?.();
82
- const configFormat = $$.config[`subchart_axis_${id}_tick_format`] ||
83
- $$.config[`axis_${id}_tick_format`];
84
-
85
- if (axisFormat) {
86
- return axisFormat;
87
- }
88
-
89
- return typeof configFormat === "function" ? configFormat.bind($$.api) : (v => v);
90
- }
91
-
92
- /**
93
- * Convert resolved grid line style to painter line style.
94
- * @param {object} style Grid line style
95
- * @returns {object|undefined} Canvas line style
96
- * @private
97
- */
98
- function getGridLineCanvasStyle(style?: CanvasGridLineThemeStyle): CanvasStyle | undefined {
99
- return style ?
100
- {
101
- stroke: style.lineColor,
102
- lineWidth: style.lineWidth,
103
- lineDash: style.dashArray
104
- } :
105
- undefined;
106
- }
107
-
108
- /**
109
- * Convert resolved grid text style to painter text style.
110
- * @param {object} style Grid text style
111
- * @returns {object|undefined} Canvas text style
112
- * @private
113
- */
114
- function getGridTextCanvasStyle(style?: CanvasGridLineThemeStyle): CanvasStyle | undefined {
115
- return style ?
116
- {
117
- fill: style.labelColor,
118
- font: style.labelFont
119
- } :
120
- undefined;
121
- }
122
-
123
67
  /**
124
68
  * Get horizontal x-axis clip rect with small text overflow tolerance.
125
69
  * @param {object} margin Chart margin
@@ -128,7 +72,7 @@ function getGridTextCanvasStyle(style?: CanvasGridLineThemeStyle): CanvasStyle |
128
72
  * @returns {object} Clip rectangle
129
73
  * @private
130
74
  */
131
- function getHorizontalXAxisClipRect(margin, width: number, height: number): CanvasRect {
75
+ export function getHorizontalXAxisClipRect(margin, width: number, height: number): CanvasRect {
132
76
  return {
133
77
  x: margin.left - X_AXIS_TICK_TEXT_HORIZONTAL_CLIP_PADDING,
134
78
  y: 0,
@@ -145,7 +89,7 @@ function getHorizontalXAxisClipRect(margin, width: number, height: number): Canv
145
89
  * @returns {object} Clip rectangle
146
90
  * @private
147
91
  */
148
- function getRotatedXAxisClipRect(margin, width: number, height: number): CanvasRect {
92
+ export function getRotatedXAxisClipRect(margin, width: number, height: number): CanvasRect {
149
93
  return {
150
94
  x: 0,
151
95
  y: margin.top - X_AXIS_TICK_TEXT_VERTICAL_CLIP_PADDING,
@@ -273,7 +217,7 @@ function formatTick(format: AxisTickFormat, tick: AxisTickValue): string {
273
217
  * @returns {string} Canvas font shorthand
274
218
  * @private
275
219
  */
276
- function getAxisTickFont(axisStyle, id: AxisType): string {
220
+ export function getAxisTickFont(axisStyle, id: AxisType): string {
277
221
  return axisStyle[`${id}TickFont`] || axisStyle.labelFont;
278
222
  }
279
223
 
@@ -284,7 +228,7 @@ function getAxisTickFont(axisStyle, id: AxisType): string {
284
228
  * @returns {number} Line height
285
229
  * @private
286
230
  */
287
- function getXTickTextLineHeight(painter: CanvasPainter, fontSize: number): number {
231
+ export function getXTickTextLineHeight(painter: CanvasPainter, fontSize: number): number {
288
232
  const metrics = painter.measureText("0");
289
233
  const fontBoxHeight = (metrics.fontBoundingBoxAscent || 0) +
290
234
  (metrics.fontBoundingBoxDescent || 0);
@@ -356,36 +300,33 @@ function splitTickTextByWidth(text: string, width: number, painter: CanvasPainte
356
300
  }
357
301
 
358
302
  const charWidth = painter.measureText("0").width || 5.5;
303
+ const lines: string[] = [];
304
+ let start = 0;
359
305
 
360
- /**
361
- * Split a text fragment recursively.
362
- * @param {Array} lines Accumulated text lines
363
- * @param {string} value Remaining text fragment
364
- * @returns {Array} Text lines
365
- * @private
366
- */
367
- function split(lines: string[], value: string): string[] {
306
+ // iterate rather than recurse per line, so a very long label cannot overflow the stack
307
+ while (true) {
368
308
  let spaceIndex: number | undefined;
309
+ let splitAt = -1;
369
310
 
370
- for (let i = 1; i < value.length; i++) {
371
- if (value.charAt(i) === " ") {
311
+ for (let i = 1; start + i < text.length; i++) {
312
+ if (text.charAt(start + i) === " ") {
372
313
  spaceIndex = i;
373
314
  }
374
315
 
375
316
  if (width < charWidth * (i + 1)) {
376
- const splitIndex = spaceIndex || i;
377
-
378
- return split(
379
- lines.concat(value.slice(0, splitIndex)),
380
- value.slice(spaceIndex ? spaceIndex + 1 : i)
381
- );
317
+ splitAt = i;
318
+ break;
382
319
  }
383
320
  }
384
321
 
385
- return lines.concat(value);
386
- }
322
+ if (splitAt === -1) {
323
+ lines.push(text.slice(start));
324
+ return lines;
325
+ }
387
326
 
388
- return split([], text);
327
+ lines.push(text.slice(start, start + (spaceIndex || splitAt)));
328
+ start += spaceIndex ? spaceIndex + 1 : splitAt;
329
+ }
389
330
  }
390
331
 
391
332
  /**
@@ -397,7 +338,8 @@ function splitTickTextByWidth(text: string, width: number, painter: CanvasPainte
397
338
  * @returns {number} Max tick text width
398
339
  * @private
399
340
  */
400
- function getXTickTextWidth($$, ticks: AxisTickValue[], isRotated: boolean, targetScale): number {
341
+ export function getXTickTextWidth($$, ticks: AxisTickValue[], isRotated: boolean,
342
+ targetScale): number {
401
343
  const configured = $$.config.axis_x_tick_width;
402
344
 
403
345
  if (configured && configured > 0) {
@@ -431,9 +373,9 @@ function getXTickTextWidth($$, ticks: AxisTickValue[], isRotated: boolean, targe
431
373
  * @returns {Array} Tick text lines
432
374
  * @private
433
375
  */
434
- function getXTickTextLines($$, painter: CanvasPainter, format: AxisTickFormat, tick: AxisTickValue,
435
- ticks: AxisTickValue[] = [], isRotated = false, targetScale = getXScale($$),
436
- maxWidth?: number): string[] {
376
+ export function getXTickTextLines($$, painter: CanvasPainter, format: AxisTickFormat,
377
+ tick: AxisTickValue, ticks: AxisTickValue[] = [], isRotated = false,
378
+ targetScale = getXScale($$), maxWidth?: number): string[] {
437
379
  const value = format ? format(tick) : tick;
438
380
 
439
381
  if (value == null) {
@@ -518,7 +460,7 @@ function getTitleTextPosition(position: string | undefined,
518
460
  * @returns {boolean} Whether coordinate is finite
519
461
  * @private
520
462
  */
521
- function isDrawable(value: number): boolean {
463
+ export function isDrawable(value: number): boolean {
522
464
  return Number.isFinite(value);
523
465
  }
524
466
 
@@ -530,7 +472,7 @@ function isDrawable(value: number): boolean {
530
472
  * @returns {boolean} Whether coordinate is finite and in range
531
473
  * @private
532
474
  */
533
- function isInAxisRange(value: number, start: number, end: number): boolean {
475
+ export function isInAxisRange(value: number, start: number, end: number): boolean {
534
476
  return isDrawable(value) &&
535
477
  value >= Math.min(start, end) &&
536
478
  value <= Math.max(start, end);
@@ -542,7 +484,7 @@ function isInAxisRange(value: number, start: number, end: number): boolean {
542
484
  * @returns {number} Outer tick direction
543
485
  * @private
544
486
  */
545
- function getXOuterTickDirection(isRotated: boolean): number {
487
+ export function getXOuterTickDirection(isRotated: boolean): number {
546
488
  return isRotated ? -1 : 1;
547
489
  }
548
490
 
@@ -570,7 +512,7 @@ function getYOuterTickDirection(config, isRotated: boolean, isY2: boolean): numb
570
512
  * @returns {number} Pixel coordinate relative to plot area
571
513
  * @private
572
514
  */
573
- function getXPosition($$, value: AxisTickValue, targetScale = getXScale($$)): number {
515
+ export function getXPosition($$, value: AxisTickValue, targetScale = getXScale($$)): number {
574
516
  return targetScale(normalizeXValue($$, value));
575
517
  }
576
518
 
@@ -639,47 +581,6 @@ function getYPosition($$, value: AxisTickValue, axis: YAxisId = "y"): number {
639
581
  return $$.scale[axis || "y"](normalizeYValue($$, value, axis));
640
582
  }
641
583
 
642
- /**
643
- * Get a text position along a grid line.
644
- * @param {string} position Grid label position
645
- * @param {number} start Start coordinate
646
- * @param {number} end End coordinate
647
- * @returns {number} Label coordinate
648
- * @private
649
- */
650
- function getLineTextPosition(position: string | undefined, start: number, end: number): number {
651
- if (position === "start") {
652
- return start + 4;
653
- }
654
-
655
- if (position === "middle") {
656
- return (start + end) / 2;
657
- }
658
-
659
- return end - 4;
660
- }
661
-
662
- /**
663
- * Get a text position for labels drawn with SVG-compatible rotate(-90).
664
- * @param {string} position Grid label position
665
- * @param {number} start Start coordinate
666
- * @param {number} end End coordinate
667
- * @returns {number} Label coordinate
668
- * @private
669
- */
670
- function getRotatedLineTextPosition(position: string | undefined, start: number,
671
- end: number): number {
672
- if (position === "start") {
673
- return end - 4;
674
- }
675
-
676
- if (position === "middle") {
677
- return (start + end) / 2;
678
- }
679
-
680
- return start + 4;
681
- }
682
-
683
584
  /**
684
585
  * Get global region rectangle.
685
586
  * @param {object} $$ ChartInternal context
@@ -722,7 +623,7 @@ function getRegionRect($$, region: RegionOptions): CanvasRect | null {
722
623
  * @private
723
624
  */
724
625
  export default class CanvasAxisRenderer {
725
- private painter: CanvasPainter;
626
+ painter: CanvasPainter;
726
627
 
727
628
  /**
728
629
  * Constructor.
@@ -732,7 +633,7 @@ export default class CanvasAxisRenderer {
732
633
  */
733
634
  constructor(
734
635
  private engine: CanvasEngine,
735
- private theme: CanvasTheme
636
+ public theme: CanvasTheme
736
637
  ) {
737
638
  this.painter = new CanvasPainter(engine.ctx);
738
639
  }
@@ -763,7 +664,8 @@ export default class CanvasAxisRenderer {
763
664
  */
764
665
  draw($$): void {
765
666
  this.drawRegions($$);
766
- this.drawGrid($$);
667
+ // the grid lines are drawn by the canvas part of grid(): without the module there are none
668
+ $$.getCanvasFeature?.("grid")?.draw?.call($$, this);
767
669
  this.drawAxis($$);
768
670
  }
769
671
 
@@ -782,215 +684,6 @@ export default class CanvasAxisRenderer {
782
684
  this.drawAxisLabels($$);
783
685
  }
784
686
 
785
- /**
786
- * Draw the canvas subchart x axis.
787
- * @param {object} $$ ChartInternal instance
788
- * @private
789
- */
790
- drawSubXAxis($$): void {
791
- const {ctx, painter, theme: {style: {axis}}} = this;
792
- const {
793
- config,
794
- format,
795
- scale,
796
- state: {current, margin2, width2, height2}
797
- } = $$;
798
-
799
- if (
800
- !config.subchart_show ||
801
- !config.subchart_axis_x_show ||
802
- !scale.subX ||
803
- width2 <= 0 ||
804
- height2 <= 0
805
- ) {
806
- return;
807
- }
808
-
809
- const isRotated = config.axis_rotated;
810
- const x = painter.crisp(margin2.left, axis.lineWidth);
811
- const y = painter.crisp(margin2.top + height2, axis.lineWidth);
812
- const x1 = margin2.left;
813
- const x2 = margin2.left + width2;
814
- const y1 = margin2.top;
815
- const y2 = margin2.top + height2;
816
- const rangeStart = isRotated ? y1 : x1;
817
- const rangeEnd = isRotated ? y2 : x2;
818
- const ticks = getSubXTickValues($$);
819
- const lineTicks = getSubXTickLineValues($$, ticks, axis.tickWidth);
820
- const outerTick = config.subchart_axis_x_tick_outer ?? config.axis_x_tick_outer;
821
- const tickDirection = isRotated ?
822
- (config.axis_x_tick_inner ? 1 : -1) :
823
- (config.axis_x_tick_inner ? -1 : 1);
824
- const outerTickDirection = getXOuterTickDirection(isRotated);
825
- const tickTextDirection = getXTickTextDirection(isRotated);
826
- const tickTextPosition = config.axis_x_tick_text_position;
827
- const tickRotate = !isRotated ? ($$.getAxisTickRotate?.("x") || 0) : 0;
828
- const tickFormat = format.subXAxisTick || $$.axis?.getXAxisTickFormat?.(true);
829
-
830
- painter.clipRect(
831
- isRotated ? getRotatedXAxisClipRect(margin2, current.width, height2) : {
832
- ...getHorizontalXAxisClipRect(
833
- margin2,
834
- width2,
835
- current.height - margin2.top
836
- ),
837
- y: margin2.top
838
- },
839
- () => {
840
- ctx.globalAlpha = 1;
841
- ctx.strokeStyle = axis.lineColor;
842
- ctx.lineWidth = axis.lineWidth;
843
- ctx.setLineDash([]);
844
-
845
- painter.strokePath(() => {
846
- if (isRotated) {
847
- painter.traceLine(x, y1, x, y2);
848
- } else {
849
- painter.traceLine(x1, y, x2, y);
850
- }
851
-
852
- if (outerTick) {
853
- if (isRotated) {
854
- painter.traceLine(x, y1, x + (AXIS_TICK_SIZE * outerTickDirection), y1);
855
- painter.traceLine(x, y2, x + (AXIS_TICK_SIZE * outerTickDirection), y2);
856
- } else {
857
- painter.traceLine(x1, y, x1, y + (AXIS_TICK_SIZE * outerTickDirection));
858
- painter.traceLine(x2, y, x2, y + (AXIS_TICK_SIZE * outerTickDirection));
859
- }
860
- }
861
- });
862
-
863
- const tickFont = getAxisTickFont(axis, "x");
864
-
865
- ctx.font = tickFont;
866
- ctx.fillStyle = axis.labelColor;
867
- ctx.textAlign = isRotated ? (tickTextDirection > 0 ? "left" : "right") : "center";
868
- ctx.textBaseline = isRotated ?
869
- "middle" :
870
- (tickTextDirection > 0 ? "top" : "bottom");
871
- ctx.strokeStyle = axis.tickColor;
872
- ctx.lineWidth = axis.tickWidth;
873
-
874
- // invariant across ticks: measure/resolve once per draw pass
875
- const lineHeight = getXTickTextLineHeight(painter, getFontSize(tickFont));
876
- const tickTextWidth = getXTickTextWidth($$, ticks, isRotated, scale.subX);
877
-
878
- if (config.subchart_axis_x_tick_show) {
879
- for (const tick of lineTicks) {
880
- const tickPos = scale.subX(normalizeXValue($$, tick));
881
- const tx = margin2.left + tickPos;
882
- const ty = margin2.top + tickPos;
883
- const pos = isRotated ? ty : tx;
884
-
885
- if (!isInAxisRange(pos, rangeStart, rangeEnd)) {
886
- continue;
887
- }
888
-
889
- painter.strokePath(() => {
890
- if (isRotated) {
891
- painter.traceLine(x, ty, x + (AXIS_TICK_SIZE * tickDirection), ty);
892
- } else {
893
- painter.traceLine(tx, y, tx, y + (AXIS_TICK_SIZE * tickDirection));
894
- }
895
- });
896
- }
897
- }
898
-
899
- for (const tick of ticks) {
900
- const tickPos = scale.subX(normalizeXValue($$, tick));
901
- const tx = margin2.left + tickPos;
902
- const ty = margin2.top + tickPos;
903
- const pos = isRotated ? ty : tx;
904
-
905
- if (!isInAxisRange(pos, rangeStart, rangeEnd)) {
906
- continue;
907
- }
908
-
909
- if (!config.subchart_axis_x_tick_text_show) {
910
- continue;
911
- }
912
-
913
- const lines = getXTickTextLines(
914
- $$,
915
- painter,
916
- tickFormat,
917
- tick,
918
- ticks,
919
- isRotated,
920
- scale.subX,
921
- tickTextWidth
922
- );
923
- let textX;
924
- let textY;
925
-
926
- if (isRotated) {
927
- textX = x + ((AXIS_TICK_SIZE + AXIS_TICK_PADDING) * tickTextDirection) +
928
- (tickTextPosition.x || 0);
929
- textY = ty + (tickTextPosition.y || 0);
930
- ctx.textAlign = tickTextDirection > 0 ? "left" : "right";
931
- ctx.textBaseline = "middle";
932
- } else {
933
- textX = tx + (tickTextPosition.x || 0);
934
- textY = y + ((AXIS_TICK_SIZE + AXIS_TICK_PADDING) * tickTextDirection) +
935
- (tickTextPosition.y || 0);
936
- ctx.textAlign = tickRotate ? (tickRotate > 0 ? "left" : "right") : "center";
937
- ctx.textBaseline = tickTextDirection > 0 ? "top" : "bottom";
938
- }
939
-
940
- painter.withState(textCtx => {
941
- textCtx.translate(textX, textY);
942
- tickRotate && textCtx.rotate(tickRotate * Math.PI / 180);
943
-
944
- lines.forEach((line, i) => {
945
- textCtx.fillText(line, 0, i * lineHeight);
946
- });
947
- });
948
- }
949
- }
950
- );
951
- }
952
-
953
- /**
954
- * Draw the canvas subchart y/y2 axes.
955
- * @param {object} $$ ChartInternal instance
956
- * @private
957
- */
958
- drawSubYAxes($$): void {
959
- const {
960
- config,
961
- scale,
962
- state: {margin2, width2, height2}
963
- } = $$;
964
-
965
- if (!config.subchart_show || width2 <= 0 || height2 <= 0) {
966
- return;
967
- }
968
-
969
- (["y", "y2"] as YAxisId[]).forEach(id => {
970
- const subScale = id === "y2" ? scale.subY2 : scale.subY;
971
-
972
- if (!config[`subchart_axis_${id}_show`] || !subScale) {
973
- return;
974
- }
975
-
976
- this.drawYAxis($$, id, {
977
- scale: subScale,
978
- ticks: getYTickValues($$, id, undefined, true, subScale, `subchart_axis_${id}`),
979
- format: getSubYTickFormat($$, id),
980
- index: 0,
981
- outerTick: config[`subchart_axis_${id}_tick_outer`] ??
982
- config[`axis_${id}_tick_outer`],
983
- margin: margin2,
984
- width: width2,
985
- height: height2,
986
- prefix: `subchart_axis_${id}`,
987
- tickShow: config[`subchart_axis_${id}_tick_show`],
988
- tickTextShow: config[`subchart_axis_${id}_tick_text_show`],
989
- tickTextPosition: config[`axis_${id}_tick_text_position`]
990
- });
991
- });
992
- }
993
-
994
687
  /**
995
688
  * Draw chart title.
996
689
  * @param {object} $$ ChartInternal instance
@@ -1086,95 +779,6 @@ export default class CanvasAxisRenderer {
1086
779
  });
1087
780
  }
1088
781
 
1089
- /**
1090
- * Draw visible grid lines.
1091
- * @param {object} $$ ChartInternal instance
1092
- * @private
1093
- */
1094
- drawGrid($$): void {
1095
- const {ctx, painter, theme: {style: {grid}}} = this;
1096
- const {config, scale, state: {height, margin, width}} = $$;
1097
-
1098
- if (!grid.lineColor) {
1099
- return;
1100
- }
1101
-
1102
- const isRotated = config.axis_rotated;
1103
- const x1 = margin.left;
1104
- const x2 = margin.left + width;
1105
- const y1 = margin.top;
1106
- const y2 = margin.top + height;
1107
-
1108
- painter.withState(() => {
1109
- ctx.strokeStyle = grid.lineColor;
1110
- ctx.lineWidth = grid.lineWidth;
1111
- grid.dashArray.length && ctx.setLineDash(grid.dashArray);
1112
-
1113
- if (config.grid_x_show && scale.x) {
1114
- painter.strokePath(() => {
1115
- for (const tick of getXTickValues($$)) {
1116
- const pos = getXPosition($$, tick);
1117
-
1118
- if (!isDrawable(pos)) {
1119
- continue;
1120
- }
1121
-
1122
- if (isRotated) {
1123
- painter.traceCrispLine(
1124
- x1,
1125
- margin.top + pos,
1126
- x2,
1127
- margin.top + pos,
1128
- grid.lineWidth
1129
- );
1130
- } else {
1131
- painter.traceCrispLine(
1132
- margin.left + pos,
1133
- y1,
1134
- margin.left + pos,
1135
- y2,
1136
- grid.lineWidth
1137
- );
1138
- }
1139
- }
1140
- });
1141
- }
1142
-
1143
- if (config.grid_y_show && scale.y) {
1144
- painter.strokePath(() => {
1145
- for (const tick of getYGridTickValues($$)) {
1146
- const value = normalizeYValue($$, tick);
1147
- const pos = scale.y(value);
1148
-
1149
- if (!isDrawable(pos)) {
1150
- continue;
1151
- }
1152
-
1153
- if (isRotated) {
1154
- painter.traceCrispLine(
1155
- margin.left + pos,
1156
- y1,
1157
- margin.left + pos,
1158
- y2,
1159
- grid.lineWidth
1160
- );
1161
- } else {
1162
- painter.traceCrispLine(
1163
- x1,
1164
- margin.top + pos,
1165
- x2,
1166
- margin.top + pos,
1167
- grid.lineWidth
1168
- );
1169
- }
1170
- }
1171
- });
1172
- }
1173
-
1174
- !config.grid_lines_front && this.drawGridLines($$);
1175
- });
1176
- }
1177
-
1178
782
  /**
1179
783
  * Draw configured global regions.
1180
784
  * @param {object} $$ ChartInternal instance
@@ -1236,164 +840,6 @@ export default class CanvasAxisRenderer {
1236
840
  });
1237
841
  }
1238
842
 
1239
- /**
1240
- * Draw configured x/y grid lines and labels.
1241
- * @param {object} $$ ChartInternal instance
1242
- * @private
1243
- */
1244
- drawGridLines($$): void {
1245
- const {ctx, painter, theme: {style: {axis, grid}}} = this;
1246
- const {config, scale, state: {height, margin, width}} = $$;
1247
- const isRotated = config.axis_rotated;
1248
- const x1 = margin.left;
1249
- const x2 = margin.left + width;
1250
- const y1 = margin.top;
1251
- const y2 = margin.top + height;
1252
-
1253
- if (!grid.lineColor) {
1254
- return;
1255
- }
1256
-
1257
- painter.withState(() => {
1258
- ctx.strokeStyle = grid.lineColor;
1259
- ctx.lineWidth = grid.lineWidth;
1260
- ctx.font = grid.labelFont || axis.labelFont;
1261
- ctx.fillStyle = grid.labelColor;
1262
- ctx.textBaseline = "middle";
1263
- ctx.setLineDash([]);
1264
-
1265
- const drawLabel = (
1266
- text: string | undefined,
1267
- x: number,
1268
- y: number,
1269
- rotated = false,
1270
- style?: CanvasStyle
1271
- ): void => {
1272
- if (!text) {
1273
- return;
1274
- }
1275
-
1276
- painter.text(text, x, y, {
1277
- ...style,
1278
- angle: rotated ? -90 : 0
1279
- });
1280
- };
1281
-
1282
- const drawLine = (
1283
- line: GridLine,
1284
- axisId: GridAxis,
1285
- draw: () => void
1286
- ): void => {
1287
- const style = getGridLineCanvasStyle(
1288
- this.theme.getGridLineStyle(axisId, line, "line")
1289
- );
1290
-
1291
- painter.strokePath(draw, style);
1292
- };
1293
- const getTextStyle = (axisId: GridAxis, line: GridLine): CanvasStyle | undefined =>
1294
- getGridTextCanvasStyle(this.theme.getGridLineStyle(axisId, line, "text"));
1295
-
1296
- const drawXLine = (line: GridLine): void => {
1297
- if (line.value === undefined || !scale.x) {
1298
- return;
1299
- }
1300
-
1301
- const pos = getXPosition($$, line.value);
1302
-
1303
- if (!isDrawable(pos)) {
1304
- return;
1305
- }
1306
-
1307
- if (isRotated) {
1308
- const y = margin.top + pos;
1309
-
1310
- drawLine(line, "x", () => {
1311
- painter.traceLine(x1, y, x2, y);
1312
- });
1313
- ctx.textAlign = line.position === "start" ?
1314
- "left" :
1315
- (line.position === "middle" ? "center" : "right");
1316
- drawLabel(
1317
- line.text,
1318
- getLineTextPosition(line.position, x1, x2),
1319
- y - 5,
1320
- false,
1321
- getTextStyle("x", line)
1322
- );
1323
- } else {
1324
- const x = margin.left + pos;
1325
-
1326
- drawLine(line, "x", () => {
1327
- painter.traceLine(x, y1, x, y2);
1328
- });
1329
- ctx.textAlign = line.position === "start" ?
1330
- "left" :
1331
- (line.position === "middle" ? "center" : "right");
1332
- drawLabel(
1333
- line.text,
1334
- x - 5,
1335
- getRotatedLineTextPosition(line.position, y1, y2),
1336
- true,
1337
- getTextStyle("x", line)
1338
- );
1339
- }
1340
- };
1341
-
1342
- const drawYLine = (line: GridLine): void => {
1343
- const targetScale = line.axis === "y2" ? scale.y2 : scale.y;
1344
- const axisId = line.axis === "y2" ? "y2" : "y";
1345
-
1346
- if (line.value === undefined || !targetScale) {
1347
- return;
1348
- }
1349
-
1350
- const value = normalizeYValue($$, line.value, axisId);
1351
- const pos = targetScale(value);
1352
-
1353
- if (!isDrawable(pos)) {
1354
- return;
1355
- }
1356
-
1357
- if (isRotated) {
1358
- const x = margin.left + pos;
1359
-
1360
- drawLine(line, "y", () => {
1361
- painter.traceLine(x, y1, x, y2);
1362
- });
1363
- ctx.textAlign = line.position === "start" ?
1364
- "left" :
1365
- (line.position === "middle" ? "center" : "right");
1366
- drawLabel(
1367
- line.text,
1368
- x - 5,
1369
- getRotatedLineTextPosition(line.position, y1, y2),
1370
- true,
1371
- getTextStyle("y", line)
1372
- );
1373
- } else {
1374
- const y = margin.top + pos;
1375
-
1376
- drawLine(line, "y", () => {
1377
- painter.traceLine(x1, y, x2, y);
1378
- });
1379
- ctx.textAlign = line.position === "start" ?
1380
- "left" :
1381
- (line.position === "middle" ? "center" : "right");
1382
- drawLabel(
1383
- line.text,
1384
- getLineTextPosition(line.position, x1, x2),
1385
- y - 5,
1386
- false,
1387
- getTextStyle("y", line)
1388
- );
1389
- }
1390
- };
1391
-
1392
- (config.grid_x_lines || []).forEach(drawXLine);
1393
- (config.grid_y_lines || []).forEach(drawYLine);
1394
- });
1395
- }
1396
-
1397
843
  /**
1398
844
  * Draw axes configured with axis.x/y/y2.axes.
1399
845
  * @param {object} $$ ChartInternal instance
@@ -1812,9 +1258,10 @@ export default class CanvasAxisRenderer {
1812
1258
  if (isRotated) {
1813
1259
  textX = x + ((AXIS_TICK_SIZE + AXIS_TICK_PADDING) * tickTextDirection) +
1814
1260
  (tickTextPosition.x || 0);
1815
- textY = ty + (tickTextPosition.y || 0);
1261
+ // SVG puts the baseline of the first line 3px below the tick, moved up by half of the other lines
1262
+ textY = ty + (tickTextPosition.y || 0) + 3 - ((lines.length - 1) * lineHeight / 2);
1816
1263
  ctx.textAlign = getXTickTextAlign($$, options);
1817
- ctx.textBaseline = "middle";
1264
+ ctx.textBaseline = "alphabetic";
1818
1265
  } else if (tickRotate) {
1819
1266
  const fontSize = getFontSize(tickFont);
1820
1267
  const firstDy = tickTextPosition.y ?
@@ -1861,7 +1308,7 @@ export default class CanvasAxisRenderer {
1861
1308
  * @param {object} axisOptions Additional axis options
1862
1309
  * @private
1863
1310
  */
1864
- private drawYAxis($$, id: YAxisId = "y", axisOptions?: AdditionalAxisOptions): void {
1311
+ drawYAxis($$, id: YAxisId = "y", axisOptions?: AdditionalAxisOptions): void {
1865
1312
  const {ctx, painter, theme: {style: {axis}}} = this;
1866
1313
  const {config, scale, state} = $$;
1867
1314
  const {margin, width, height} = state;
@@ -1976,7 +1423,18 @@ export default class CanvasAxisRenderer {
1976
1423
 
1977
1424
  if (tickTextShow) {
1978
1425
  for (const {tick, tx, ty} of drawableTicks) {
1979
- if (isRotated) {
1426
+ if (isRotated && tickTextDirection > 0) {
1427
+ // SVG puts the baseline of the bottom tick text at tickLength + dy (.71em)
1428
+ ctx.textBaseline = "alphabetic";
1429
+ painter.text(
1430
+ formatTick(format, tick),
1431
+ tx + (tickTextPosition.x || 0),
1432
+ y + (AXIS_TICK_LENGTH * tickTextDirection) +
1433
+ (tickTextPosition.y ?
1434
+ resolveTextOffset(tickTextPosition.y, getFontSize(tickFont)) :
1435
+ 0.71 * getFontSize(tickFont))
1436
+ );
1437
+ } else if (isRotated) {
1980
1438
  painter.text(
1981
1439
  formatTick(format, tick),
1982
1440
  tx + (tickTextPosition.x || 0),