billboard.js 4.0.3 → 4.1.0-next.2

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 (271) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1848 -494
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -24
  6. package/dist/billboard.pkgd.js +1844 -679
  7. package/dist/billboard.pkgd.min.js +24 -29
  8. package/dist/billboard.react.js +205 -0
  9. package/dist/billboard.react.min.js +9 -0
  10. package/dist/billboard.worker.js +10 -0
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.js +5 -3
  12. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
  14. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
  16. package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
  17. package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  19. package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
  20. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
  24. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
  26. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
  28. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
  30. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
  31. package/dist/theme/dark.css +1 -1
  32. package/dist/theme/dark.min.css +1 -1
  33. package/dist/theme/datalab.css +1 -1
  34. package/dist/theme/datalab.min.css +1 -1
  35. package/dist/theme/graph.css +1 -1
  36. package/dist/theme/graph.min.css +1 -1
  37. package/dist/theme/insight.css +1 -1
  38. package/dist/theme/insight.min.css +1 -1
  39. package/dist/theme/modern.css +1 -1
  40. package/dist/theme/modern.min.css +1 -1
  41. package/dist-esm/Chart/Chart.js +134 -152
  42. package/dist-esm/Chart/api/axis.js +217 -237
  43. package/dist-esm/Chart/api/category.js +54 -54
  44. package/dist-esm/Chart/api/chart.js +172 -215
  45. package/dist-esm/Chart/api/color.js +21 -21
  46. package/dist-esm/Chart/api/data.js +172 -173
  47. package/dist-esm/Chart/api/export.js +242 -262
  48. package/dist-esm/Chart/api/flow.js +198 -254
  49. package/dist-esm/Chart/api/focus.js +136 -143
  50. package/dist-esm/Chart/api/grid.js +191 -190
  51. package/dist-esm/Chart/api/group.js +31 -34
  52. package/dist-esm/Chart/api/legend.js +54 -63
  53. package/dist-esm/Chart/api/load.js +237 -257
  54. package/dist-esm/Chart/api/regions.js +148 -168
  55. package/dist-esm/Chart/api/selection.js +181 -139
  56. package/dist-esm/Chart/api/show.js +133 -147
  57. package/dist-esm/Chart/api/stubs.js +43 -42
  58. package/dist-esm/Chart/api/subchart.js +155 -172
  59. package/dist-esm/Chart/api/tooltip.js +132 -177
  60. package/dist-esm/Chart/api/x.js +67 -71
  61. package/dist-esm/Chart/api/zoom.js +183 -220
  62. package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
  63. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
  64. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
  65. package/dist-esm/ChartInternal/ChartInternal.js +573 -749
  66. package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
  67. package/dist-esm/ChartInternal/data/convert.js +200 -229
  68. package/dist-esm/ChartInternal/data/data.js +967 -1153
  69. package/dist-esm/ChartInternal/data/load.js +145 -197
  70. package/dist-esm/ChartInternal/interactions/drag.js +86 -122
  71. package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
  72. package/dist-esm/ChartInternal/interactions/flow.js +151 -215
  73. package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
  74. package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
  75. package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
  76. package/dist-esm/ChartInternal/internals/category.js +18 -18
  77. package/dist-esm/ChartInternal/internals/class.js +89 -99
  78. package/dist-esm/ChartInternal/internals/clip.js +88 -119
  79. package/dist-esm/ChartInternal/internals/color.js +233 -288
  80. package/dist-esm/ChartInternal/internals/domain.js +452 -588
  81. package/dist-esm/ChartInternal/internals/format.js +64 -77
  82. package/dist-esm/ChartInternal/internals/grid.js +333 -457
  83. package/dist-esm/ChartInternal/internals/legend.js +675 -927
  84. package/dist-esm/ChartInternal/internals/redraw.js +200 -289
  85. package/dist-esm/ChartInternal/internals/region.js +106 -159
  86. package/dist-esm/ChartInternal/internals/scale.js +186 -215
  87. package/dist-esm/ChartInternal/internals/selection.js +132 -159
  88. package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
  89. package/dist-esm/ChartInternal/internals/size.js +286 -394
  90. package/dist-esm/ChartInternal/internals/style.js +39 -41
  91. package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
  92. package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
  93. package/dist-esm/ChartInternal/internals/text.js +368 -528
  94. package/dist-esm/ChartInternal/internals/text.util.js +179 -239
  95. package/dist-esm/ChartInternal/internals/title.js +96 -121
  96. package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
  97. package/dist-esm/ChartInternal/internals/transform.js +79 -97
  98. package/dist-esm/ChartInternal/internals/type.js +285 -236
  99. package/dist-esm/ChartInternal/shape/arc.js +825 -1112
  100. package/dist-esm/ChartInternal/shape/area.js +73 -94
  101. package/dist-esm/ChartInternal/shape/bar.js +227 -288
  102. package/dist-esm/ChartInternal/shape/bubble.js +9 -8
  103. package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
  104. package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
  105. package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
  106. package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
  107. package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
  108. package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
  109. package/dist-esm/ChartInternal/shape/core/path.js +142 -115
  110. package/dist-esm/ChartInternal/shape/core/point.js +105 -125
  111. package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
  112. package/dist-esm/ChartInternal/shape/funnel.js +310 -338
  113. package/dist-esm/ChartInternal/shape/gauge.js +71 -103
  114. package/dist-esm/ChartInternal/shape/line.js +208 -278
  115. package/dist-esm/ChartInternal/shape/point.js +310 -425
  116. package/dist-esm/ChartInternal/shape/polar.js +84 -109
  117. package/dist-esm/ChartInternal/shape/radar.js +228 -318
  118. package/dist-esm/ChartInternal/shape/shape.js +782 -843
  119. package/dist-esm/ChartInternal/shape/treemap.js +152 -190
  120. package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
  121. package/dist-esm/canvas/CanvasEngine.js +148 -166
  122. package/dist-esm/canvas/CanvasPainter.js +395 -411
  123. package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
  124. package/dist-esm/canvas/CanvasTheme.js +899 -802
  125. package/dist-esm/canvas/HitDetector.js +394 -463
  126. package/dist-esm/canvas/axisTicks.js +672 -786
  127. package/dist-esm/canvas/classes.js +19 -17
  128. package/dist-esm/canvas/color.js +40 -59
  129. package/dist-esm/canvas/geometry.js +38 -38
  130. package/dist-esm/canvas/labels.js +318 -371
  131. package/dist-esm/canvas/pointPattern.js +578 -580
  132. package/dist-esm/canvas/util.js +242 -262
  133. package/dist-esm/config/Options/Options.js +29 -32
  134. package/dist-esm/config/Options/axis/axis.js +101 -101
  135. package/dist-esm/config/Options/axis/x.js +759 -755
  136. package/dist-esm/config/Options/axis/y.js +525 -522
  137. package/dist-esm/config/Options/axis/y2.js +501 -485
  138. package/dist-esm/config/Options/common/boost.js +93 -32
  139. package/dist-esm/config/Options/common/color.js +88 -87
  140. package/dist-esm/config/Options/common/grid.js +74 -73
  141. package/dist-esm/config/Options/common/legend.js +180 -179
  142. package/dist-esm/config/Options/common/main.js +474 -473
  143. package/dist-esm/config/Options/common/point.js +160 -159
  144. package/dist-esm/config/Options/common/title.js +47 -46
  145. package/dist-esm/config/Options/common/tooltip.js +253 -252
  146. package/dist-esm/config/Options/data/axis.js +173 -172
  147. package/dist-esm/config/Options/data/data.js +958 -957
  148. package/dist-esm/config/Options/data/selection.js +131 -130
  149. package/dist-esm/config/Options/interaction/interaction.js +53 -52
  150. package/dist-esm/config/Options/interaction/subchart.js +164 -73
  151. package/dist-esm/config/Options/interaction/zoom.js +86 -85
  152. package/dist-esm/config/Options/shape/arc.js +150 -149
  153. package/dist-esm/config/Options/shape/area.js +69 -68
  154. package/dist-esm/config/Options/shape/bar.js +147 -146
  155. package/dist-esm/config/Options/shape/bubble.js +35 -34
  156. package/dist-esm/config/Options/shape/candlestick.js +61 -60
  157. package/dist-esm/config/Options/shape/donut.js +181 -180
  158. package/dist-esm/config/Options/shape/funnel.js +49 -48
  159. package/dist-esm/config/Options/shape/gauge.js +237 -236
  160. package/dist-esm/config/Options/shape/line.js +58 -57
  161. package/dist-esm/config/Options/shape/pie.js +185 -184
  162. package/dist-esm/config/Options/shape/polar.js +167 -166
  163. package/dist-esm/config/Options/shape/radar.js +76 -75
  164. package/dist-esm/config/Options/shape/scatter.js +36 -36
  165. package/dist-esm/config/Options/shape/spline.js +46 -46
  166. package/dist-esm/config/Options/shape/treemap.js +80 -79
  167. package/dist-esm/config/Store/Element.js +64 -62
  168. package/dist-esm/config/Store/State.js +189 -200
  169. package/dist-esm/config/Store/Store.js +25 -26
  170. package/dist-esm/config/classes.js +157 -155
  171. package/dist-esm/config/config.js +26 -35
  172. package/dist-esm/config/const.js +120 -128
  173. package/dist-esm/config/resolver/axis.core.js +25 -25
  174. package/dist-esm/config/resolver/axis.js +26 -27
  175. package/dist-esm/config/resolver/canvas.js +2071 -2472
  176. package/dist-esm/config/resolver/canvasShape.js +201 -177
  177. package/dist-esm/config/resolver/category.js +26 -27
  178. package/dist-esm/config/resolver/export.js +24 -26
  179. package/dist-esm/config/resolver/flow.js +29 -31
  180. package/dist-esm/config/resolver/grid.js +34 -35
  181. package/dist-esm/config/resolver/interaction/selection.js +17 -17
  182. package/dist-esm/config/resolver/interaction/subchart.js +17 -17
  183. package/dist-esm/config/resolver/interaction/zoom.js +17 -17
  184. package/dist-esm/config/resolver/regions.js +30 -31
  185. package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
  186. package/dist-esm/config/resolver/shape/area.js +17 -17
  187. package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
  188. package/dist-esm/config/resolver/shape/bar.js +13 -13
  189. package/dist-esm/config/resolver/shape/bubble.js +18 -14
  190. package/dist-esm/config/resolver/shape/candlestick.js +13 -13
  191. package/dist-esm/config/resolver/shape/donut.js +11 -11
  192. package/dist-esm/config/resolver/shape/funnel.js +11 -11
  193. package/dist-esm/config/resolver/shape/gauge.js +12 -12
  194. package/dist-esm/config/resolver/shape/line.js +10 -10
  195. package/dist-esm/config/resolver/shape/pie.js +11 -11
  196. package/dist-esm/config/resolver/shape/polar.js +12 -12
  197. package/dist-esm/config/resolver/shape/radar.js +22 -14
  198. package/dist-esm/config/resolver/shape/scatter.js +13 -13
  199. package/dist-esm/config/resolver/shape/treemap.js +11 -11
  200. package/dist-esm/core.js +208 -211
  201. package/dist-esm/index.canvas.js +14 -13
  202. package/dist-esm/index.esm.js +25 -24
  203. package/dist-esm/module/Cache.js +117 -129
  204. package/dist-esm/module/browser.js +30 -35
  205. package/dist-esm/module/dsv.js +107 -127
  206. package/dist-esm/module/error.js +45 -52
  207. package/dist-esm/module/generator.js +75 -83
  208. package/dist-esm/module/sanitize.js +302 -399
  209. package/dist-esm/module/util/brush.js +27 -38
  210. package/dist-esm/module/util/dom.js +288 -348
  211. package/dist-esm/module/util/object.js +277 -341
  212. package/dist-esm/module/util/type-checks.js +21 -25
  213. package/dist-esm/module/worker.js +312 -130
  214. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
  215. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
  216. package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
  217. package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
  218. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
  219. package/dist-esm/react/index.js +157 -0
  220. package/package.json +28 -8
  221. package/src/Chart/api/selection.ts +130 -5
  222. package/src/ChartInternal/Axis/Axis.ts +164 -65
  223. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  224. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  225. package/src/ChartInternal/ChartInternal.ts +1 -1
  226. package/src/ChartInternal/data/convert.ts +54 -4
  227. package/src/ChartInternal/data/data.ts +4 -1
  228. package/src/ChartInternal/interactions/eventrect.ts +8 -2
  229. package/src/ChartInternal/interactions/subchart.ts +437 -66
  230. package/src/ChartInternal/internals/color.ts +2 -2
  231. package/src/ChartInternal/internals/domain.ts +15 -3
  232. package/src/ChartInternal/internals/grid.ts +21 -1
  233. package/src/ChartInternal/internals/scale.ts +9 -2
  234. package/src/ChartInternal/internals/selection.ts +1 -1
  235. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  236. package/src/ChartInternal/internals/text.arc.ts +3 -1
  237. package/src/ChartInternal/internals/text.ts +18 -5
  238. package/src/ChartInternal/internals/transform.ts +8 -2
  239. package/src/ChartInternal/internals/type.ts +105 -1
  240. package/src/ChartInternal/shape/IShape.ts +6 -3
  241. package/src/ChartInternal/shape/bar.ts +62 -31
  242. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  243. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  244. package/src/ChartInternal/shape/core/path.ts +76 -9
  245. package/src/ChartInternal/shape/funnel.ts +2 -3
  246. package/src/ChartInternal/shape/point.ts +2 -2
  247. package/src/ChartInternal/shape/shape.ts +149 -17
  248. package/src/Plugin/stanford/index.ts +0 -4
  249. package/src/Plugin/tableview/index.ts +85 -3
  250. package/src/Plugin/textoverlap/index.ts +9 -15
  251. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  252. package/src/canvas/CanvasRenderer.ts +247 -160
  253. package/src/canvas/CanvasTheme.ts +212 -0
  254. package/src/canvas/axisTicks.ts +122 -40
  255. package/src/config/Options/axis/y2.ts +13 -0
  256. package/src/config/Options/common/boost.ts +64 -4
  257. package/src/config/Options/common/color.ts +2 -2
  258. package/src/config/Options/interaction/subchart.ts +98 -1
  259. package/src/config/Options/shape/gauge.ts +1 -1
  260. package/src/config/Options/shape/treemap.ts +2 -2
  261. package/src/config/Store/Element.ts +3 -1
  262. package/src/config/Store/State.ts +1 -0
  263. package/src/config/classes.ts +1 -0
  264. package/src/config/resolver/canvas.ts +92 -10
  265. package/src/module/util/type-checks.ts +3 -1
  266. package/src/module/voronoi.ts +119 -0
  267. package/src/module/worker.entry.ts +61 -0
  268. package/src/module/worker.ts +346 -63
  269. package/src/react/index.ts +193 -0
  270. package/types/options.d.ts +206 -3
  271. package/types/react/index.d.ts +27 -0
@@ -3,15 +3,9 @@
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
5
 
6
- import {
7
- axisBottom as d3AxisBottom,
8
- axisLeft as d3AxisLeft,
9
- axisRight as d3AxisRight,
10
- axisTop as d3AxisTop
11
- } from "d3-axis";
12
6
  import type {AxisType} from "../../../types/types";
13
7
  import {$AXIS, $COMMON} from "../../config/classes";
14
- import {AXIS_TICK_LINE_OVERLAP_PADDING, AXIS_TICK_SIZE} from "../../config/const";
8
+ import {AXIS_TICK_LINE_OVERLAP_PADDING} from "../../config/const";
15
9
  import {KEY} from "../../module/Cache";
16
10
  import {
17
11
  capitalize,
@@ -31,6 +25,45 @@ import {
31
25
  import {getScale} from "../internals/scale";
32
26
  import AxisRenderer from "./AxisRenderer";
33
27
 
28
+ /**
29
+ * Get the corresponding main axis id for subchart axis ids.
30
+ * @param {string} id Axis id
31
+ * @returns {string} Base axis id
32
+ * @private
33
+ */
34
+ function getBaseAxisId(id: string): string {
35
+ return id === "subX" ? "x" : (
36
+ id === "subY" ? "y" : (
37
+ id === "subY2" ? "y2" : id
38
+ )
39
+ );
40
+ }
41
+
42
+ /**
43
+ * Check whether the axis id belongs to subchart.
44
+ * @param {string} id Axis id
45
+ * @returns {boolean} Whether id is a subchart axis
46
+ * @private
47
+ */
48
+ function isSubAxis(id: string): boolean {
49
+ return /^sub/.test(id);
50
+ }
51
+
52
+ /**
53
+ * Get tick option value for main/subchart axis.
54
+ * @param {object} config Chart config
55
+ * @param {string} id Axis id
56
+ * @param {string} key Tick option key
57
+ * @returns {boolean|number|string|Array|object|function|null|undefined} Tick option value
58
+ * @private
59
+ */
60
+ function getAxisTickOption(config, id: string, key: string) {
61
+ const type = getBaseAxisId(id);
62
+ const subValue = config[`subchart_axis_${type}_tick_${key}`];
63
+
64
+ return isSubAxis(id) && subValue !== undefined ? subValue : config[`axis_${type}_tick_${key}`];
65
+ }
66
+
34
67
  /**
35
68
  * Sample representative tick nodes to avoid N forced reflows in getMaxTickSize
36
69
  * @param {SVGTextElement[]} nodes All tick text nodes
@@ -416,6 +449,8 @@ class Axis {
416
449
 
417
450
  public x;
418
451
  public subX;
452
+ public subY;
453
+ public subY2;
419
454
  public y;
420
455
  public y2;
421
456
 
@@ -430,7 +465,9 @@ class Axis {
430
465
  x: "bottom",
431
466
  y: "left",
432
467
  y2: "right",
433
- subX: "bottom"
468
+ subX: "bottom",
469
+ subY: "left",
470
+ subY2: "right"
434
471
  };
435
472
 
436
473
  constructor(owner) {
@@ -553,7 +590,9 @@ class Axis {
553
590
  x: isRotated ? "left" : "bottom",
554
591
  y: isRotated ? (yInner ? "top" : "bottom") : (yInner ? "right" : "left"),
555
592
  y2: isRotated ? (y2Inner ? "bottom" : "top") : (y2Inner ? "left" : "right"),
556
- subX: isRotated ? "left" : "bottom"
593
+ subX: isRotated ? "left" : "bottom",
594
+ subY: isRotated ? (yInner ? "top" : "bottom") : (yInner ? "right" : "left"),
595
+ subY2: isRotated ? (y2Inner ? "bottom" : "top") : (y2Inner ? "left" : "right")
557
596
  };
558
597
  }
559
598
 
@@ -566,17 +605,17 @@ class Axis {
566
605
  generateAxes(id: string) {
567
606
  const $$ = this.owner;
568
607
  const {config} = $$;
569
- const axes: any[] = [];
608
+ const axes: AxisRenderer[] = [];
570
609
  const axesConfig = config[`axis_${id}_axes`];
571
610
  const isRotated = config.axis_rotated;
572
- let d3Axis;
611
+ let orient;
573
612
 
574
613
  if (id === "x") {
575
- d3Axis = isRotated ? d3AxisLeft : d3AxisBottom;
614
+ orient = isRotated ? "left" : "bottom";
576
615
  } else if (id === "y") {
577
- d3Axis = isRotated ? d3AxisBottom : d3AxisLeft;
616
+ orient = isRotated ? "bottom" : "left";
578
617
  } else if (id === "y2") {
579
- d3Axis = isRotated ? d3AxisTop : d3AxisRight;
618
+ orient = isRotated ? "top" : "right";
580
619
  }
581
620
 
582
621
  if (axesConfig.length) {
@@ -586,15 +625,27 @@ class Axis {
586
625
 
587
626
  v.domain && scale.domain(v.domain);
588
627
 
589
- axes.push(
590
- d3Axis(scale)
591
- .ticks(tick.count)
592
- .tickFormat(
593
- isFunction(tick.format) ? tick.format.bind($$.api) : ((x: any) => x)
594
- )
595
- .tickValues(tick.values)
596
- .tickSizeOuter(tick.outer === false ? 0 : AXIS_TICK_SIZE)
597
- );
628
+ // reuses the same renderer as the main axes, which is what removed the
629
+ // d3-axis dependency: `tick.outer` maps onto `outerTick`, and the rest
630
+ // of the surface (ticks/tickValues/tickFormat) is identical
631
+ const axis = new AxisRenderer({
632
+ outerTick: tick.outer !== false,
633
+ noTransition: false,
634
+ config,
635
+ id,
636
+ isSubAxes: true,
637
+ owner: $$
638
+ })
639
+ .scale(scale)
640
+ .orient(orient)
641
+ .tickFormat(
642
+ isFunction(tick.format) ? tick.format.bind($$.api) : ((x: any) => x)
643
+ );
644
+
645
+ isValue(tick.count) && axis.ticks(tick.count);
646
+ tick.values && axis.tickValues(tick.values);
647
+
648
+ axes.push(axis);
598
649
  });
599
650
  }
600
651
 
@@ -626,15 +677,17 @@ class Axis {
626
677
  const className = `${this.getAxisClassName(id)}-${i + 1}`;
627
678
  let g = main.select(`.${className.replace(/\s/, ".")}`);
628
679
 
680
+ // AxisRenderer renders through create(), unlike d3-axis' callable form
629
681
  if (g.empty()) {
630
682
  g = main.append("g")
631
683
  .attr("class", className)
632
- .style("visibility", config[`axis_${id}_show`] ? null : "hidden")
633
- .call(v);
684
+ .style("visibility", config[`axis_${id}_show`] ? null : "hidden");
685
+
686
+ v.create(g);
634
687
  } else {
635
688
  axesConfig[i].domain && scale.domain(axesConfig[i].domain);
636
689
 
637
- $T(g).call(v.scale(scale));
690
+ v.scale(scale).create($T(g));
638
691
  }
639
692
 
640
693
  g.attr("transform", $$.getTranslate(id, i + 1));
@@ -653,9 +706,10 @@ class Axis {
653
706
  */
654
707
  setAxis(id, scale, outerTick, noTransition): void {
655
708
  const $$ = this.owner;
709
+ const type = getBaseAxisId(id);
656
710
 
657
- if (id !== "subX") {
658
- this.tick[id] = this.getTickValues(id);
711
+ if (!isSubAxis(id)) {
712
+ this.tick[type] = this.getTickValues(type);
659
713
  }
660
714
 
661
715
  // @ts-ignore
@@ -676,7 +730,7 @@ class Axis {
676
730
  const $$ = this.owner;
677
731
  const {config} = $$;
678
732
  const isX = /^(x|subX)$/.test(id);
679
- const type = isX ? "x" : id;
733
+ const type = getBaseAxisId(id);
680
734
  const isCategory = isX && this.isCategorized();
681
735
  const orient = this.orient[id];
682
736
  const tickTextRotate = noTickTextRotate ? 0 : $$.getAxisTickRotate(type);
@@ -685,14 +739,16 @@ class Axis {
685
739
  if (isX) {
686
740
  tickFormat = (id === "subX") ? $$.format.subXAxisTick : $$.format.xAxisTick;
687
741
  } else {
688
- const fn = config[`axis_${id}_tick_format`];
742
+ const fn = isSubAxis(id) ?
743
+ config[`subchart_axis_${type}_tick_format`] || config[`axis_${type}_tick_format`] :
744
+ config[`axis_${type}_tick_format`];
689
745
 
690
746
  if (isFunction(fn)) {
691
747
  tickFormat = fn.bind($$.api);
692
748
  }
693
749
  }
694
750
 
695
- let tickValues = this.tick[type];
751
+ let tickValues = isSubAxis(id) ? this.getTickValues(type, true) : this.tick[type];
696
752
 
697
753
  const axisParams = mergeObj({
698
754
  outerTick,
@@ -733,7 +789,8 @@ class Axis {
733
789
  // Set tick
734
790
  axis.tickFormat(
735
791
  tickFormat || (
736
- !isX && ($$.isStackNormalized() && $$.hasAxisGroupedData(id) && (x => `${x}%`))
792
+ !isX && ($$.isStackNormalized() && $$.hasAxisGroupedData(type) &&
793
+ (x => `${x}%`))
737
794
  )
738
795
  );
739
796
 
@@ -745,7 +802,7 @@ class Axis {
745
802
  }
746
803
  }
747
804
 
748
- const tickCount = config[`axis_${type}_tick_count`];
805
+ const tickCount = getAxisTickOption(config, id, "count");
749
806
 
750
807
  tickCount && axis.ticks(tickCount);
751
808
 
@@ -756,29 +813,40 @@ class Axis {
756
813
  const $$ = this.owner;
757
814
  const {config} = $$;
758
815
  const fit = config.axis_x_tick_fit;
759
- let count = config.axis_x_tick_count;
760
- let values;
816
+ const generateValues = (countOption = config.axis_x_tick_count) => {
817
+ let count = countOption;
818
+ let values;
819
+
820
+ if (fit) {
821
+ values = $$.mapTargetsToUniqueXs(targets);
761
822
 
762
- if (fit) {
763
- values = $$.mapTargetsToUniqueXs(targets);
823
+ // if given count is greater than the value length, then limit the count.
824
+ if (this.isCategorized() && count > values.length) {
825
+ count = values.length;
826
+ }
764
827
 
765
- // if given count is greater than the value length, then limit the count.
766
- if (this.isCategorized() && count > values.length) {
767
- count = values.length;
828
+ values = this.generateTickValues(
829
+ values,
830
+ count,
831
+ this.isTimeSeries()
832
+ );
768
833
  }
769
834
 
770
- values = this.generateTickValues(
771
- values,
772
- count,
773
- this.isTimeSeries()
774
- );
775
- }
835
+ return values;
836
+ };
837
+ const values = generateValues();
776
838
 
777
839
  if (axis) {
778
840
  axis.tickValues(values);
779
841
  } else if (this.x) {
842
+ const subTickValues = this.getTickValues("x", true);
843
+ const subTickCount = getAxisTickOption(config, "subX", "count");
844
+ const subValues = subTickValues ?? (
845
+ subTickCount !== config.axis_x_tick_count ? generateValues(subTickCount) : values
846
+ );
847
+
780
848
  this.x.tickValues(values);
781
- this.subX?.tickValues(values);
849
+ this.subX?.tickValues(subValues);
782
850
  }
783
851
 
784
852
  return values;
@@ -824,13 +892,15 @@ class Axis {
824
892
  currFormat;
825
893
  }
826
894
 
827
- getTickValues(id: string) {
895
+ getTickValues(id: string, isSub = false) {
828
896
  const $$ = this.owner;
829
- const tickValues = $$.config[`axis_${id}_tick_values`];
897
+ const tickValues = isSub ?
898
+ getAxisTickOption($$.config, `sub${capitalize(id)}`, "values") :
899
+ $$.config[`axis_${id}_tick_values`];
900
+ const values = isFunction(tickValues) ? tickValues.call($$.api) : tickValues;
830
901
  const axis = $$[`${id}Axis`];
831
902
 
832
- return (isFunction(tickValues) ? tickValues.call($$.api) : tickValues) ||
833
- (axis ? axis.tickValues() : undefined);
903
+ return isSub ? values ?? undefined : values || (axis ? axis.tickValues() : undefined);
834
904
  }
835
905
 
836
906
  getLabelOptionByAxisId(id: string) {
@@ -1442,10 +1512,17 @@ class Axis {
1442
1512
  const $$ = this.owner;
1443
1513
  const {$el: {axis}, $T} = $$;
1444
1514
 
1445
- const [axisX, axisY, axisY2, axisSubX] = ["x", "y", "y2", "subX"]
1515
+ const [axisX, axisY, axisY2, axisSubX, axisSubY, axisSubY2] = [
1516
+ "x",
1517
+ "y",
1518
+ "y2",
1519
+ "subX",
1520
+ "subY",
1521
+ "subY2"
1522
+ ]
1446
1523
  .map(v => $T(axis[v], withTransition));
1447
1524
 
1448
- return {axisX, axisY, axisY2, axisSubX};
1525
+ return {axisX, axisY, axisY2, axisSubX, axisSubY, axisSubY2};
1449
1526
  }
1450
1527
 
1451
1528
  redraw(transitions, isHidden, isInit) {
@@ -1453,7 +1530,7 @@ class Axis {
1453
1530
  const {config, state, $el} = $$;
1454
1531
  const opacity = isHidden ? "0" : null;
1455
1532
 
1456
- ["x", "y", "y2", "subX"].forEach(id => {
1533
+ ["x", "y", "y2", "subX", "subY", "subY2"].forEach(id => {
1457
1534
  const axis = this[id];
1458
1535
  const $axis = $el.axis[id];
1459
1536
 
@@ -1532,8 +1609,34 @@ class Axis {
1532
1609
 
1533
1610
  // Update sub domain
1534
1611
  if (wth.Y) {
1535
- scale.subY?.domain($$.getYDomain(targetsToShow, "y"));
1536
- scale.subY2?.domain($$.getYDomain(targetsToShow, "y2"));
1612
+ const updateSubDomain = () => {
1613
+ scale.subY?.domain($$.getYDomain(targetsToShow, "y"));
1614
+ scale.subY2?.domain($$.getYDomain(targetsToShow, "y2"));
1615
+
1616
+ (["y", "y2"] as const).forEach(key => {
1617
+ const subAxisId = key === "y2" ? "subY2" : "subY";
1618
+ const axisScale = scale[subAxisId];
1619
+ const axis = $$.axis[subAxisId];
1620
+ const tickValues = this.getTickValues(key, true);
1621
+ const tickCount = getAxisTickOption(config, subAxisId, "count");
1622
+
1623
+ if (!axisScale || !axis || tickValues || !tickCount) {
1624
+ return;
1625
+ }
1626
+
1627
+ const domain = axisScale.domain();
1628
+
1629
+ axis.tickValues(
1630
+ this.generateTickValues(
1631
+ domain,
1632
+ domain.every(v => v === 0) ? 1 : tickCount,
1633
+ this.isTimeSeriesY()
1634
+ )
1635
+ );
1636
+ });
1637
+ };
1638
+
1639
+ config.subchart_show ? $$.withSubchartTypeContext(updateSubDomain) : updateSubDomain();
1537
1640
  }
1538
1641
  }
1539
1642
 
@@ -1571,22 +1674,18 @@ class Axis {
1571
1674
  const $$ = this.owner;
1572
1675
  const {config, state: {clip, current}, $el} = $$;
1573
1676
 
1574
- ["subX", "x", "y", "y2"].forEach(type => {
1677
+ ["subX", "x", "y", "y2", "subY", "subY2"].forEach(type => {
1575
1678
  const axis = $el.axis[type];
1576
1679
 
1577
- // subchart x axis should be aligned with x axis culling
1578
- const id = type === "subX" ? "x" : type;
1579
-
1580
- const cullingOptionPrefix = `axis_${id}_tick_culling`;
1581
- const toCull = config[cullingOptionPrefix];
1680
+ const toCull = getAxisTickOption(config, type, "culling");
1582
1681
 
1583
1682
  if (axis && toCull) {
1584
1683
  const tickNodes = axis.selectAll(".tick");
1585
1684
  const tickValues = sortValue(tickNodes.data(),
1586
- !config[`${cullingOptionPrefix}_reverse`]);
1685
+ !getAxisTickOption(config, type, "culling_reverse"));
1587
1686
  const tickSize = tickValues.length;
1588
- const cullingMax = config[`${cullingOptionPrefix}_max`];
1589
- const lines = config[`${cullingOptionPrefix}_lines`];
1687
+ const cullingMax = getAxisTickOption(config, type, "culling_max");
1688
+ const lines = getAxisTickOption(config, type, "culling_lines");
1590
1689
  const cullTickLine = !lines || _hasOverlappedTickLineIntervals(
1591
1690
  this[type],
1592
1691
  tickValues,
@@ -10,6 +10,32 @@ import {AXIS_TICK_LENGTH, AXIS_TICK_PADDING, AXIS_TICK_SIZE} from "../../config/
10
10
  import {isArray, isFunction, isNumber, isString, toArray} from "../../module/util";
11
11
  import Helper from "./AxisRendererHelper";
12
12
 
13
+ /**
14
+ * Get the corresponding main axis id for subchart axis ids.
15
+ * @param {string} id Axis id
16
+ * @returns {string} Base axis id
17
+ * @private
18
+ */
19
+ function getBaseAxisId(id: string): string {
20
+ return id === "subX" ? "x" : (
21
+ id === "subY" ? "y" : (
22
+ id === "subY2" ? "y2" : id
23
+ )
24
+ );
25
+ }
26
+
27
+ /**
28
+ * Get config option prefix for an axis id.
29
+ * @param {string} id Axis id
30
+ * @returns {string} Option prefix
31
+ * @private
32
+ */
33
+ function getAxisOptionPrefix(id: string): string {
34
+ const type = getBaseAxisId(id);
35
+
36
+ return /^sub/.test(id) ? `subchart_axis_${type}` : `axis_${type}`;
37
+ }
38
+
13
39
  export default class AxisRenderer {
14
40
  private helper;
15
41
  private config;
@@ -21,9 +47,10 @@ export default class AxisRenderer {
21
47
  const {config, params} = this;
22
48
  const {config: chartConfig, id, owner} = params;
23
49
  const isX = /^(x|subX)$/.test(id);
24
- const type = id === "subX" ? "x" : id;
25
- const customTickFormat = id === "subX" ?
26
- chartConfig.subchart_axis_x_tick_format || chartConfig.axis_x_tick_format :
50
+ const type = getBaseAxisId(id);
51
+ const customTickFormat = /^sub/.test(id) ?
52
+ chartConfig[`subchart_axis_${type}_tick_format`] ||
53
+ chartConfig[`axis_${type}_tick_format`] :
27
54
  chartConfig[`axis_${type}_tick_format`];
28
55
  const categoryAutoWrap = params.tickMultiline && params.isCategory && !isLeftRight &&
29
56
  !(params.tickWidth > 0);
@@ -122,14 +149,20 @@ export default class AxisRenderer {
122
149
 
123
150
  // // get the axis' tick position configuration
124
151
  const id = params.id;
125
- const tickTextPos = id && /^(x|y|y2)$/.test(id) ?
126
- params.config[`axis_${id}_tick_text_position`] :
152
+ const type = getBaseAxisId(id);
153
+ // `axis.*.axes` entries carry their own tick options only (outer/format/count/
154
+ // values). The main axis' visibility and text position never reached them while
155
+ // they were rendered by d3-axis, which reads no billboard config, so they keep
156
+ // the defaults here.
157
+ const {isSubAxes} = params;
158
+ const tickTextPos = !isSubAxes && type && /^(x|y|y2)$/.test(type) ?
159
+ params.config[`axis_${type}_tick_text_position`] :
127
160
  {x: 0, y: 0};
128
161
 
129
162
  // tick visiblity
130
- const prefix = id === "subX" ? `subchart_axis_x` : `axis_${id}`;
163
+ const prefix = getAxisOptionPrefix(id);
131
164
  const axisShow = params.config[`${prefix}_show`];
132
- const tickShow = {
165
+ const tickShow = isSubAxes ? {tick: true, text: true} : {
133
166
  tick: axisShow ? params.config[`${prefix}_tick_show`] : false,
134
167
  text: axisShow ? params.config[`${prefix}_tick_text_show`] : false
135
168
  };
@@ -423,7 +456,7 @@ export default class AxisRenderer {
423
456
  }
424
457
  } = this.params.owner;
425
458
 
426
- const tickLineInner = this.params.config[`axis_${axisId}_tick_inner`];
459
+ const tickLineInner = this.params.config[`axis_${getBaseAxisId(axisId)}_tick_inner`];
427
460
 
428
461
  switch (orient) {
429
462
  case "bottom":
@@ -72,7 +72,7 @@ export default class AxisRendererHelper {
72
72
  /**
73
73
  * Get tick transform setter function
74
74
  * @param {string} id Axis id
75
- * @returns {(selection: d3Selection, scale) => void} transfrom setter function
75
+ * @returns {function(d3Selection, d3Scale): void} transform setter function
76
76
  * @private
77
77
  */
78
78
  getTickTransformSetter(id: string): (selection: d3Selection, scale) => void {
@@ -532,7 +532,7 @@ export default class ChartInternal {
532
532
  $el.defs = $el.svg.append("defs");
533
533
 
534
534
  if (hasAxis) {
535
- ["id", "idXAxis", "idYAxis", "idGrid"].forEach(v => {
535
+ ["id", "idXAxis", "idYAxis", "idY2Axis", "idGrid"].forEach(v => {
536
536
  $$.appendClip($el.defs, state.clip[v]);
537
537
  });
538
538
  }
@@ -16,6 +16,39 @@ import {runWorker} from "../../module/worker";
16
16
  import type {IData} from "../data/IData";
17
17
  import {columns, json, rows, url} from "./convert.helper";
18
18
 
19
+ /**
20
+ * Cell count from which `boost.useWorker: "auto"` offloads conversion.
21
+ *
22
+ * Below this, structured cloning the payload to the worker and back costs more
23
+ * than the parsing it saves.
24
+ * @private
25
+ */
26
+ const WORKER_CELL_THRESHOLD = 5000;
27
+
28
+ /**
29
+ * Estimate the number of data cells to be converted.
30
+ * @param {Array} data Raw json(array form)/rows/columns data
31
+ * @returns {number} Approximate cell count
32
+ * @private
33
+ */
34
+ function _getCellCount(data): number {
35
+ const first = data[0];
36
+
37
+ // rows/columns: array of arrays
38
+ if (isArray(first)) {
39
+ let count = 0;
40
+
41
+ for (let i = 0, len = data.length; i < len; i++) {
42
+ count += data[i]?.length ?? 0;
43
+ }
44
+
45
+ return count;
46
+ }
47
+
48
+ // json: array of objects
49
+ return data.length * Object.keys(first ?? {}).length;
50
+ }
51
+
19
52
  /**
20
53
  * Get data key for JSON
21
54
  * @param {string|object} keysParam Key params
@@ -101,7 +134,22 @@ export default {
101
134
  */
102
135
  convertData(args, callback: Function): void {
103
136
  const {config} = this;
104
- const useWorker = d => d?.length && !isEmpty(d[0]) ? config.boost_useWorker : false;
137
+ const useWorker = d => {
138
+ if (!d?.length || isEmpty(d[0])) {
139
+ return false;
140
+ }
141
+
142
+ // "auto": offloading small payloads costs more in structured cloning than
143
+ // it saves, so only hand over datasets past the threshold
144
+ return config.boost_useWorker === "auto" ?
145
+ _getCellCount(d) >= WORKER_CELL_THRESHOLD :
146
+ !!config.boost_useWorker;
147
+ };
148
+ const workerOptions = config.boost_workerUrl ?
149
+ {
150
+ workerUrl: config.boost_workerUrl
151
+ } :
152
+ undefined;
105
153
  let data = args;
106
154
 
107
155
  if (args.bindto) {
@@ -121,14 +169,16 @@ export default {
121
169
  url(data.url, data.mimeType, data.headers, _getDataKeyForJson(data.keys, config),
122
170
  callback);
123
171
  } else if (data.json) {
124
- runWorker(useWorker(data.json), json, callback, [columns, rows])(
172
+ runWorker(useWorker(data.json), "json", json, callback, workerOptions)(
125
173
  data.json,
126
174
  _getDataKeyForJson(data.keys, config)
127
175
  );
128
176
  } else if (data.rows) {
129
- runWorker(useWorker(data.rows), rows, callback)(data.rows);
177
+ runWorker(useWorker(data.rows), "rows", rows, callback, workerOptions)(data.rows);
130
178
  } else if (data.columns) {
131
- runWorker(useWorker(data.columns), columns, callback)(data.columns);
179
+ runWorker(useWorker(data.columns), "columns", columns, callback, workerOptions)(
180
+ data.columns
181
+ );
132
182
  } else if (args.bindto) {
133
183
  throw Error("url or json or rows or columns is required.");
134
184
  }
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import {select as d3Select} from "d3-selection";
6
6
  import {$BAR, $CANDLESTICK, $COMMON} from "../../config/classes";
7
+ import {TYPE} from "../../config/const";
7
8
  import {KEY} from "../../module/Cache";
8
9
  import {
9
10
  findIndex,
@@ -1458,7 +1459,9 @@ export default {
1458
1459
  const $$ = this;
1459
1460
  const {value} = d;
1460
1461
 
1461
- return $$.isBarType(d) && isArray(value) && value.length >= 2 &&
1462
+ return $$.isBarType(d) &&
1463
+ !$$.isSubchartSourceTypeOf?.(d, TYPE.CANDLESTICK) &&
1464
+ isArray(value) && value.length >= 2 &&
1462
1465
  value.every(isNumber);
1463
1466
  },
1464
1467
 
@@ -390,6 +390,7 @@ export default {
390
390
  if (isTooltipGrouped) {
391
391
  $$.showTooltip(selectedData, context);
392
392
  $$.showGridFocus?.(selectedData);
393
+ $$.showSubchartGridFocus?.(selectedData);
393
394
 
394
395
  if (!isSelectionEnabled || isSelectionGrouped) {
395
396
  return;
@@ -424,6 +425,7 @@ export default {
424
425
  if (!isTooltipGrouped) {
425
426
  $$.showTooltip(d, context);
426
427
  $$.showGridFocus?.(d);
428
+ $$.showSubchartGridFocus?.(d);
427
429
  $$.unexpandCircles?.();
428
430
 
429
431
  selected.each(d => $$.setExpand(index, d.id));
@@ -458,6 +460,7 @@ export default {
458
460
 
459
461
  $$.showTooltip([closest], context);
460
462
  $$.showGridFocus?.([closest]);
463
+ $$.showSubchartGridFocus?.([closest]);
461
464
  $$.unexpandCircles?.();
462
465
 
463
466
  $$.setExpand(index, closest.id, true);
@@ -470,6 +473,7 @@ export default {
470
473
  }
471
474
  } else if (config.interaction_onout) {
472
475
  $$.hideGridFocus?.();
476
+ $$.hideSubchartGridFocus?.();
473
477
  $$.hideTooltip();
474
478
 
475
479
  !isSelectionGrouped && $$.setExpand(index);
@@ -522,6 +526,7 @@ export default {
522
526
 
523
527
  // Show xgrid focus line (optional module — grid resolver)
524
528
  $$.showGridFocus?.(selectedData);
529
+ $$.showSubchartGridFocus?.(selectedData);
525
530
 
526
531
  const dist = $$.dist(closest, mouse);
527
532
 
@@ -560,6 +565,7 @@ export default {
560
565
 
561
566
  $$.$el.eventRect?.style("cursor", null);
562
567
  $$.hideGridFocus?.();
568
+ $$.hideSubchartGridFocus?.();
563
569
 
564
570
  if (tooltip) {
565
571
  $$.hideTooltip();
@@ -640,7 +646,7 @@ export default {
640
646
  }
641
647
  }
642
648
 
643
- $$.showAxisGridFocus();
649
+ $$.showAxisGridFocus?.();
644
650
 
645
651
  const eventOnSameIdx = config.tooltip_grouped &&
646
652
  index === eventReceiver.currentIdx;
@@ -686,7 +692,7 @@ export default {
686
692
  return;
687
693
  }
688
694
 
689
- $$.hideAxisGridFocus();
695
+ $$.hideAxisGridFocus?.();
690
696
 
691
697
  $$.unselectRect();
692
698
  $$.setOverOut(false, eventReceiver.currentIdx);