billboard.js 4.0.3 → 4.1.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 (270) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1841 -491
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -24
  6. package/dist/billboard.pkgd.js +1837 -676
  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 +2 -2
  12. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-sparkline.js +3 -2
  14. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-stanford.js +3 -2
  16. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  17. package/dist/plugin/billboardjs-plugin-tableview.js +57 -27
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  19. package/dist/plugin/billboardjs-plugin-textoverlap.js +72 -54
  20. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +3 -2
  24. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3 -2
  26. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +57 -27
  28. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +65 -3556
  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 +6 -0
  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/voronoi.ts +119 -0
  266. package/src/module/worker.entry.ts +61 -0
  267. package/src/module/worker.ts +346 -63
  268. package/src/react/index.ts +193 -0
  269. package/types/options.d.ts +206 -3
  270. package/types/react/index.d.ts +27 -0
@@ -5,306 +5,431 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.3
8
+ * @version 4.1.0-next.1
9
9
  */
10
- import { brushY, brushX, brushSelection } from 'd3-brush';
11
- import { select } from 'd3-selection';
12
- import CLASS from '../../config/classes.js';
13
- import { SUBCHART_BRUSH_HANDLE_PATH } from '../../config/const.js';
14
- import { brushEmpty } from '../../module/util/brush.js';
15
- import { capitalize } from '../../module/util/object.js';
16
- import { isArray } from '../../module/util/type-checks.js';
17
-
10
+ import { SUBCHART_BRUSH_HANDLE_PATH } from "../../config/const.js";
11
+ import { window as win } from "../../module/browser.js";
12
+ import { isArray } from "../../module/util/type-checks.js";
13
+ import { capitalize } from "../../module/util/object.js";
14
+ import { emulateEvent, getBoundingRect, getPointer } from "../../module/util/dom.js";
15
+ import { brushEmpty } from "../../module/util/brush.js";
16
+ import classes_default from "../../config/classes.js";
17
+ import { getMainCoordFromSubchartCoord, isContinuousGridFocusEnabled } from "../internals/subchart.util.js";
18
+ import { select } from "d3-selection";
19
+ import { brushSelection, brushX, brushY } from "d3-brush";
20
+ //#region src/ChartInternal/interactions/subchart.ts
18
21
  /**
19
- * Copyright (c) 2017 ~ present NAVER Corp.
20
- * billboard.js project is licensed under the MIT license
21
- */
22
- var subchart = {
23
- /**
24
- * Initialize the brush.
25
- * @private
26
- */
27
- initBrush() {
28
- const $$ = this;
29
- const { config, scale, $el: { subchart }, state } = $$;
30
- const isRotated = config.axis_rotated;
31
- const height = config.subchart_size_height;
32
- let lastDomain;
33
- let lastSelection;
34
- let timeout;
35
- // set the brush
36
- $$.brush = (isRotated ? brushY() : brushX()).handleSize(5);
37
- // bind brush event
38
- $$.brush.on("start brush end", event => {
39
- const { selection, sourceEvent, target, type } = event;
40
- if (type === "start") {
41
- $$.state.inputType === "touch" && $$.hideTooltip();
42
- lastSelection = sourceEvent ? selection : null;
43
- // sourceEvent && (state.domain = null);
44
- }
45
- // if (type === "brush") {
46
- if (/(start|brush)/.test(type)) {
47
- // when brush selection updates happens on one edge, update only chainging edge and
48
- // is only for adjustment of given domain range to be used to return current domain range.
49
- type === "brush" && sourceEvent && state.domain &&
50
- lastSelection?.forEach((v, i) => {
51
- if (v !== selection[i]) {
52
- state.domain[i] = scale.x.orgDomain()[i];
53
- }
54
- });
55
- $$.redrawForBrush(type !== "start");
56
- }
57
- if (type === "end") {
58
- lastDomain = scale.x.orgDomain();
59
- }
60
- // handle brush's handle position & visibility
61
- if (target?.handle) {
62
- if (selection === null) {
63
- $$.brush.handle.attr("display", "none");
64
- }
65
- else {
66
- $$.brush.handle.attr("display", null)
67
- .attr("transform", (d, i) => {
68
- const pos = [selection[i], height / 2];
69
- return `translate(${isRotated ? pos.reverse() : pos})`;
70
- });
71
- }
72
- }
73
- });
74
- $$.brush.updateResize = function () {
75
- timeout && clearTimeout(timeout);
76
- timeout = setTimeout(() => {
77
- const selection = this.getSelection();
78
- lastDomain && brushSelection(selection.node()) &&
79
- this.move(selection, lastDomain.map(scale.subX.orgScale()));
80
- }, 0);
81
- };
82
- $$.brush.update = function () {
83
- const extent = this.extent()();
84
- if (extent[1].filter(v => isNaN(v)).length === 0) {
85
- subchart.main?.select(`.${CLASS.brush}`).call(this);
86
- }
87
- return this;
88
- };
89
- // set the brush extent
90
- $$.brush.scale = function (scale) {
91
- const h = config.subchart_size_height;
92
- let extent = $$.axis.getExtent();
93
- if (!extent && scale.range) {
94
- extent = [[0, 0], [scale.range()[1], h]];
95
- }
96
- else if (isArray(extent)) {
97
- extent = extent.map((v, i) => [v, i > 0 ? h : i]);
98
- }
99
- // [[x0, y0], [x1, y1]], where [x0, y0] is the top-left corner and [x1, y1] is the bottom-right corner
100
- isRotated && extent[1].reverse();
101
- this.extent(extent);
102
- // when extent updates, brush selection also be re-applied
103
- // https://github.com/d3/d3/issues/2918
104
- this.update();
105
- };
106
- $$.brush.getSelection = () => (
107
- // @ts-ignore
108
- subchart.main ? subchart.main.select(`.${CLASS.brush}`) : select([]));
109
- },
110
- /**
111
- * Initialize the subchart.
112
- * @private
113
- */
114
- initSubchart() {
115
- const $$ = this;
116
- const { config, state: { clip, hasAxis }, $el: { defs, svg, subchart, axis } } = $$;
117
- if (!hasAxis) {
118
- return;
119
- }
120
- const visibility = config.subchart_show ? null : "hidden";
121
- const clipId = `${clip.id}-subchart`;
122
- const clipPath = $$.getClipPath(clipId);
123
- clip.idSubchart = clipId;
124
- $$.appendClip(defs, clipId);
125
- $$.initBrush();
126
- subchart.main = svg.append("g")
127
- .classed(CLASS.subchart, true)
128
- .attr("transform", $$.getTranslate("context"));
129
- const { main } = subchart;
130
- main.style("visibility", visibility);
131
- // Define g for chart area
132
- main.append("g")
133
- .attr("clip-path", clipPath)
134
- .attr("class", CLASS.chart);
135
- // Define g for chart types area
136
- ["bar", "line", "bubble", "candlestick", "scatter"].forEach(v => {
137
- const type = capitalize(/^(bubble|scatter)$/.test(v) ? "circle" : v);
138
- if ($$.hasType(v) || $$.hasTypeOf(type)) {
139
- const chart = main.select(`.${CLASS.chart}`);
140
- const chartClassName = CLASS[`chart${type}s`];
141
- if (chart.select(`.${chartClassName}`).empty()) {
142
- chart
143
- .append("g")
144
- .attr("class", chartClassName);
145
- }
146
- }
147
- });
148
- // Add extent rect for Brush
149
- const brush = main.append("g")
150
- .attr("clip-path", clipPath)
151
- .attr("class", CLASS.brush)
152
- .call($$.brush);
153
- config.subchart_showHandle && $$.addBrushHandle(brush);
154
- // ATTENTION: This must be called AFTER chart added
155
- // Add Axis
156
- axis.subX = main.append("g")
157
- .attr("class", CLASS.axisX)
158
- .attr("transform", $$.getTranslate("subX"))
159
- .attr("clip-path", config.axis_rotated ? "" : clip.pathXAxis)
160
- .style("visibility", config.subchart_axis_x_show ? visibility : "hidden");
161
- },
162
- /**
163
- * Add brush handle
164
- * Enabled when: subchart.showHandle=true
165
- * @param {d3Selection} brush Brush selection
166
- * @private
167
- */
168
- addBrushHandle(brush) {
169
- const $$ = this;
170
- const { config } = $$;
171
- const isRotated = config.axis_rotated;
172
- const initRange = config.subchart_init_range;
173
- const customHandleClass = "handle--custom";
174
- const path = SUBCHART_BRUSH_HANDLE_PATH[isRotated ? "y" : "x"];
175
- $$.brush.handle = brush.selectAll(`.${customHandleClass}`)
176
- .data(isRotated ? [{ type: "n" }, { type: "s" }] : [{ type: "w" }, { type: "e" }])
177
- .enter()
178
- .append("path")
179
- .attr("class", customHandleClass)
180
- .attr("cursor", `${isRotated ? "ns" : "ew"}-resize`)
181
- .attr("d", d => path[/[se]/.test(d.type) ? "end" : "start"])
182
- .attr("display", initRange ? null : "none");
183
- },
184
- /**
185
- * Update sub chart
186
- * @param {object} targets $$.data.targets
187
- * @private
188
- */
189
- updateTargetsForSubchart(targets) {
190
- const $$ = this;
191
- const { config, state, $el: { subchart: { main } } } = $$;
192
- if (config.subchart_show) {
193
- ["bar", "line", "bubble", "candlestick", "scatter"]
194
- .filter(v => $$.hasType(v) || $$.hasTypeOf(capitalize(v)))
195
- .forEach(v => {
196
- const isPointType = /^(bubble|scatter)$/.test(v);
197
- const name = capitalize(isPointType ? "circle" : v);
198
- const chartClass = $$.getChartClass(name, true);
199
- const shapeClass = $$.getClass(isPointType ? "circles" : `${v}s`, true);
200
- const shapeChart = main.select(`.${CLASS[`chart${`${name}s`}`]}`);
201
- if (isPointType) {
202
- const circle = shapeChart
203
- .selectAll(`.${CLASS.circles}`)
204
- .data(targets.filter($$[`is${capitalize(v)}Type`].bind($$)))
205
- .attr("class", shapeClass);
206
- circle.exit().remove();
207
- circle.enter().append("g")
208
- .attr("class", shapeClass);
209
- }
210
- else {
211
- const shapeUpdate = shapeChart
212
- .selectAll(`.${CLASS[`chart${name}`]}`)
213
- .attr("class", chartClass)
214
- .data(targets.filter($$[`is${name}Type`].bind($$)));
215
- const shapeEnter = shapeUpdate.enter()
216
- .append("g")
217
- .style("opacity", "0")
218
- .attr("class", chartClass)
219
- .append("g")
220
- .attr("class", shapeClass);
221
- shapeUpdate.exit().remove();
222
- // Area
223
- v === "line" && $$.hasTypeOf("Area") &&
224
- shapeEnter.append("g").attr("class", $$.getClass("areas", true));
225
- }
226
- });
227
- // -- Brush --//
228
- main.selectAll(`.${CLASS.brush} rect`)
229
- .attr(config.axis_rotated ? "width" : "height", config.axis_rotated ? state.width2 : state.height2);
230
- }
231
- },
232
- /**
233
- * Redraw subchart.
234
- * @private
235
- * @param {boolean} withSubchart whether or not to show subchart
236
- * @param {number} duration duration
237
- * @param {object} shape Shape's info
238
- */
239
- redrawSubchart(withSubchart, duration, shape) {
240
- const $$ = this;
241
- const { config, $el: { subchart: { main } }, state } = $$;
242
- const withTransition = !!duration;
243
- main.style("visibility", config.subchart_show ? null : "hidden");
244
- // subchart
245
- if (config.subchart_show) {
246
- // reflect main chart to extent on subchart if zoomed
247
- if (state.event?.type === "zoom") {
248
- $$.brush.update();
249
- }
250
- // update subchart elements if needed
251
- if (withSubchart) {
252
- const initRange = config.subchart_init_range;
253
- // extent rect
254
- !brushEmpty($$) && $$.brush.update();
255
- Object.keys(shape.type).forEach(v => {
256
- const name = capitalize(v);
257
- const drawFn = $$[`generateDraw${name}`](shape.indices[v], true);
258
- // call shape's update & redraw method
259
- $$[`update${name}`](withTransition, true);
260
- $$[`redraw${name}`](drawFn, withTransition, true);
261
- });
262
- if ($$.hasType("bubble") || $$.hasType("scatter")) {
263
- const { cx } = shape.pos;
264
- const cy = $$.updateCircleY(true);
265
- $$.updateCircle(true);
266
- $$.redrawCircle(cx, cy, withTransition, undefined, true);
267
- }
268
- if (!state.rendered && initRange) {
269
- state.domain = initRange;
270
- $$.brush.move($$.brush.getSelection(), initRange.map($$.scale.x));
271
- }
272
- }
273
- }
274
- },
275
- /**
276
- * Redraw the brush.
277
- * @param {boolean} [callCallbck=true] Call 'onbrush' callback or not.
278
- * @private
279
- */
280
- redrawForBrush(callCallbck = true) {
281
- const $$ = this;
282
- const { config: { subchart_onbrush: onBrush, zoom_rescale: withY }, scale, state } = $$;
283
- $$.redraw({
284
- withTransition: false,
285
- withY,
286
- withSubchart: false,
287
- withUpdateXDomain: true,
288
- withDimension: false
289
- });
290
- callCallbck && state.rendered &&
291
- onBrush.bind($$.api)(state.domain ?? scale.x.orgDomain());
292
- },
293
- /**
294
- * Transform context
295
- * @param {boolean} withTransition indicates transition is enabled
296
- * @param {object} transitions The return value of the generateTransitions method of Axis.
297
- * @private
298
- */
299
- transformContext(withTransition, transitions) {
300
- const $$ = this;
301
- const { $el: { subchart }, $T } = $$;
302
- const subXAxis = transitions?.axisSubX ?
303
- transitions.axisSubX :
304
- $T(subchart.main.select(`.${CLASS.axisX}`), withTransition);
305
- subchart.main.attr("transform", $$.getTranslate("context"));
306
- subXAxis.attr("transform", $$.getTranslate("subX"));
307
- }
22
+ * Copyright (c) 2017 ~ present NAVER Corp.
23
+ * billboard.js project is licensed under the MIT license
24
+ */
25
+ const SUBCHART_TYPES = [
26
+ "bar",
27
+ "line",
28
+ "bubble",
29
+ "candlestick",
30
+ "scatter"
31
+ ];
32
+ const FOCUS_GRID_STYLE_PROPS = [
33
+ "opacity",
34
+ "stroke",
35
+ "stroke-dasharray",
36
+ "stroke-dashoffset",
37
+ "stroke-linecap",
38
+ "stroke-linejoin",
39
+ "stroke-miterlimit",
40
+ "stroke-opacity",
41
+ "stroke-width"
42
+ ];
43
+ /**
44
+ * Copy main focus grid computed styles to the subchart focus grid line.
45
+ * @param {object} $$ ChartInternal instance
46
+ * @param {object} line Subchart focus grid line selection
47
+ * @private
48
+ */
49
+ function syncSubchartGridFocusStyle($$, line) {
50
+ const source = $$.$el.grid?.main?.select(`line.${classes_default.xgridFocus}`).node();
51
+ if (!source || !win.getComputedStyle) return;
52
+ const style = win.getComputedStyle(source);
53
+ FOCUS_GRID_STYLE_PROPS.forEach((prop) => {
54
+ const value = style.getPropertyValue(prop);
55
+ value && line.style(prop, value);
56
+ });
57
+ }
58
+ /**
59
+ * Convert an SVG attr value to finite number with fallback.
60
+ * @param {string|null} value Attribute value
61
+ * @param {number} fallback Fallback value
62
+ * @returns {number} Numeric value
63
+ * @private
64
+ */
65
+ function getFiniteAttr(value, fallback) {
66
+ const parsed = Number(value);
67
+ return Number.isFinite(parsed) ? parsed : fallback;
68
+ }
69
+ /**
70
+ * Show a single clipped-free x focus grid line spanning main chart and subchart.
71
+ * @param {object} $$ ChartInternal instance
72
+ * @returns {boolean} Whether continuous focus line was rendered
73
+ * @private
74
+ */
75
+ function showContinuousSubchartGridFocus($$) {
76
+ if (!isContinuousGridFocusEnabled($$)) return false;
77
+ const { config, state, $el } = $$;
78
+ const mainLine = $el.grid?.main?.select(`line.${classes_default.xgridFocus}:not(.${classes_default.xgridFocusContinuous})`);
79
+ const line = $el.main.select(`line.${classes_default.xgridFocusContinuous}`);
80
+ if (!mainLine?.node() || !line.node()) return false;
81
+ const x2 = state.margin2.left - state.margin.left + state.width2;
82
+ const y2 = state.margin2.top - state.margin.top + state.height2;
83
+ syncSubchartGridFocusStyle($$, line);
84
+ config.axis_rotated ? line.attr("x1", getFiniteAttr(mainLine.attr("x1"), 0)).attr("x2", x2).attr("y1", getFiniteAttr(mainLine.attr("y1"), -10)).attr("y2", getFiniteAttr(mainLine.attr("y2"), -10)) : line.attr("x1", getFiniteAttr(mainLine.attr("x1"), -10)).attr("x2", getFiniteAttr(mainLine.attr("x2"), -10)).attr("y1", getFiniteAttr(mainLine.attr("y1"), 0)).attr("y2", y2);
85
+ line.style("visibility", null);
86
+ mainLine.style("visibility", "hidden");
87
+ return true;
88
+ }
89
+ /**
90
+ * Hide continuous subchart focus grid line.
91
+ * @param {object} $$ ChartInternal instance
92
+ * @private
93
+ */
94
+ function hideContinuousSubchartGridFocus($$) {
95
+ $$.$el.main?.select(`line.${classes_default.xgridFocusContinuous}`).style("visibility", "hidden");
96
+ }
97
+ /**
98
+ * Get main chart pointer coordinates that correspond to a subchart pointer event.
99
+ * @param {object} $$ ChartInternal instance
100
+ * @param {Event} event Input event
101
+ * @param {SVGElement} context Subchart event rect
102
+ * @returns {Array|null} Main chart local coordinates
103
+ * @private
104
+ */
105
+ function getMainPointFromSubchartEvent($$, event, context) {
106
+ const { config, state } = $$;
107
+ const [x, y] = getPointer(event, context);
108
+ const mainCoord = getMainCoordFromSubchartCoord($$, config.axis_rotated ? y : x);
109
+ if (mainCoord === null) return null;
110
+ return config.axis_rotated ? [state.width / 2, mainCoord] : [mainCoord, state.height / 2];
111
+ }
112
+ /**
113
+ * Dispatch a subchart pointer event through the main chart event rect.
114
+ * @param {object} $$ ChartInternal instance
115
+ * @param {string} type Event type
116
+ * @param {Event} event Input event
117
+ * @param {SVGElement} context Subchart event rect
118
+ * @private
119
+ */
120
+ function dispatchSubchartEvent($$, type, event, context) {
121
+ const mainEventRect = $$.$el.eventRect?.node?.();
122
+ if (!mainEventRect) return;
123
+ const point = getMainPointFromSubchartEvent($$, event, context) || [0, 0];
124
+ const rect = getBoundingRect(mainEventRect, true);
125
+ const clientX = rect.left + point[0];
126
+ const clientY = rect.top + point[1];
127
+ const params = {
128
+ bubbles: true,
129
+ cancelable: true,
130
+ screenX: clientX,
131
+ screenY: clientY,
132
+ clientX,
133
+ clientY
134
+ };
135
+ /^touch/.test(type) ? emulateEvent.touch(mainEventRect, type, params) : emulateEvent.mouse(mainEventRect, type, params);
136
+ }
137
+ var subchart_default = {
138
+ /**
139
+ * Whether subchart brush interaction is enabled.
140
+ * @returns {boolean}
141
+ * @private
142
+ */
143
+ isSubchartBrushEnabled() {
144
+ const { config } = this;
145
+ return config.subchart_show && config.subchart_brush_enabled !== false;
146
+ },
147
+ /**
148
+ * Bind event rect handlers for subchart hover interactions.
149
+ * @param {d3Selection} eventRect Subchart event rect selection
150
+ * @private
151
+ */
152
+ bindSubchartEventRect(eventRect) {
153
+ const $$ = this;
154
+ const { config, state } = $$;
155
+ eventRect.on("mouseover mousemove mouseout touchstart touchmove touchend", null);
156
+ if (!config.interaction_enabled) return;
157
+ if (state.inputType === "mouse") eventRect.on("mouseover mousemove", function(event) {
158
+ if ($$.isSubchartBrushEnabled()) return;
159
+ dispatchSubchartEvent($$, event.type, event, this);
160
+ }).on("mouseout", function(event) {
161
+ if ($$.isSubchartBrushEnabled()) return;
162
+ dispatchSubchartEvent($$, "mouseout", event, this);
163
+ });
164
+ else if (state.inputType === "touch") eventRect.on("touchstart touchmove touchend", function(event) {
165
+ if ($$.isSubchartBrushEnabled() || event.touches?.length > 1) return;
166
+ dispatchSubchartEvent($$, event.type, event, this);
167
+ });
168
+ },
169
+ /**
170
+ * Initialize the brush.
171
+ * @private
172
+ */
173
+ initBrush() {
174
+ const $$ = this;
175
+ const { config, scale, $el: { subchart }, state } = $$;
176
+ const isRotated = config.axis_rotated;
177
+ const height = config.subchart_size_height;
178
+ let lastDomain;
179
+ let lastSelection;
180
+ let timeout;
181
+ $$.brush = (isRotated ? brushY() : brushX()).handleSize(5);
182
+ $$.brush.on("start brush end", (event) => {
183
+ const { selection, sourceEvent, target, type } = event;
184
+ if (type === "start") {
185
+ $$.state.inputType === "touch" && $$.hideTooltip();
186
+ lastSelection = sourceEvent ? selection : null;
187
+ }
188
+ if (/(start|brush)/.test(type)) {
189
+ type === "brush" && sourceEvent && state.domain && lastSelection?.forEach((v, i) => {
190
+ if (v !== selection[i]) state.domain[i] = scale.x.orgDomain()[i];
191
+ });
192
+ $$.redrawForBrush(type !== "start");
193
+ }
194
+ if (type === "end") lastDomain = scale.x.orgDomain();
195
+ if (target?.handle) if (selection === null) $$.brush.handle.attr("display", "none");
196
+ else $$.brush.handle.attr("display", null).attr("transform", (d, i) => {
197
+ const pos = [selection[i], height / 2];
198
+ return `translate(${isRotated ? pos.reverse() : pos})`;
199
+ });
200
+ });
201
+ $$.brush.updateResize = function() {
202
+ timeout && clearTimeout(timeout);
203
+ timeout = setTimeout(() => {
204
+ const selection = this.getSelection();
205
+ lastDomain && brushSelection(selection.node()) && this.move(selection, lastDomain.map(scale.subX.orgScale()));
206
+ }, 0);
207
+ };
208
+ $$.brush.update = function() {
209
+ if (this.extent()()[1].filter((v) => isNaN(v)).length === 0) subchart.main?.select(`.${classes_default.brush}`).call(this);
210
+ return this;
211
+ };
212
+ $$.brush.scale = function(scale) {
213
+ const h = config.subchart_size_height;
214
+ let extent = $$.axis.getExtent();
215
+ if (!extent && scale.range) extent = [[0, 0], [scale.range()[1], h]];
216
+ else if (isArray(extent)) extent = extent.map((v, i) => [v, i > 0 ? h : i]);
217
+ isRotated && extent[1].reverse();
218
+ this.extent(extent);
219
+ this.update();
220
+ };
221
+ $$.brush.getSelection = () => subchart.main ? subchart.main.select(`.${classes_default.brush}`) : select([]);
222
+ },
223
+ /**
224
+ * Initialize the subchart.
225
+ * @private
226
+ */
227
+ initSubchart() {
228
+ const $$ = this;
229
+ const { config, state: { clip, hasAxis }, $el: { defs, svg, subchart, axis } } = $$;
230
+ if (!hasAxis) return;
231
+ const visibility = config.subchart_show ? null : "hidden";
232
+ const clipId = `${clip.id}-subchart`;
233
+ const clipPath = $$.getClipPath(clipId);
234
+ clip.idSubchart = clipId;
235
+ $$.appendClip(defs, clipId);
236
+ $$.initBrush();
237
+ subchart.main = svg.append("g").classed(classes_default.subchart, true).attr("transform", $$.getTranslate("context"));
238
+ const { main } = subchart;
239
+ main.style("visibility", visibility);
240
+ main.append("g").attr("clip-path", clipPath).attr("class", classes_default.chart);
241
+ $$.withSubchartTypeContext(() => {
242
+ SUBCHART_TYPES.forEach((v) => {
243
+ const type = capitalize(/^(bubble|scatter)$/.test(v) ? "circle" : v);
244
+ if ($$.hasType(v) || $$.hasTypeOf(type)) {
245
+ const chart = main.select(`.${classes_default.chart}`);
246
+ const chartClassName = classes_default[`chart${type}s`];
247
+ if (chart.select(`.${chartClassName}`).empty()) chart.append("g").attr("class", chartClassName);
248
+ }
249
+ });
250
+ });
251
+ const brush = main.append("g").attr("clip-path", clipPath).attr("class", classes_default.brush).style("pointer-events", $$.isSubchartBrushEnabled() ? null : "none").call($$.brush);
252
+ config.subchart_showHandle && $$.addBrushHandle(brush);
253
+ subchart.eventRect = main.append("g").attr("clip-path", clipPath).attr("class", `${classes_default.eventRects} ${classes_default.eventRects}-subchart`).style("fill-opacity", "0").style("pointer-events", $$.isSubchartBrushEnabled() ? "none" : "all").append("rect").attr("class", `${classes_default.eventRect} ${classes_default.eventRect}-subchart`).attr("width", $$.state.width2).attr("height", $$.state.height2);
254
+ $$.bindSubchartEventRect(subchart.eventRect);
255
+ main.append("g").attr("clip-path", clipPath).attr("class", classes_default.xgridFocus).append("line").attr("class", classes_default.xgridFocus).style("visibility", "hidden");
256
+ axis.subX = main.append("g").attr("class", classes_default.axisX).attr("transform", $$.getTranslate("subX")).attr("clip-path", config.axis_rotated ? "" : clip.pathXAxis).style("visibility", config.subchart_axis_x_show ? visibility : "hidden");
257
+ axis.subY = main.append("g").attr("class", classes_default.axisY).attr("transform", $$.getTranslate("subY")).style("visibility", config.subchart_axis_y_show ? visibility : "hidden");
258
+ axis.subY2 = main.append("g").attr("class", classes_default.axisY2).attr("transform", $$.getTranslate("subY2")).style("visibility", config.subchart_axis_y2_show ? visibility : "hidden");
259
+ },
260
+ /**
261
+ * Add brush handle
262
+ * Enabled when: subchart.showHandle=true
263
+ * @param {d3Selection} brush Brush selection
264
+ * @private
265
+ */
266
+ addBrushHandle(brush) {
267
+ const $$ = this;
268
+ const { config } = $$;
269
+ const isRotated = config.axis_rotated;
270
+ const initRange = config.subchart_init_range;
271
+ const customHandleClass = "handle--custom";
272
+ const path = SUBCHART_BRUSH_HANDLE_PATH[isRotated ? "y" : "x"];
273
+ $$.brush.handle = brush.selectAll(`.${customHandleClass}`).data(isRotated ? [{ type: "n" }, { type: "s" }] : [{ type: "w" }, { type: "e" }]).enter().append("path").attr("class", customHandleClass).attr("cursor", `${isRotated ? "ns" : "ew"}-resize`).attr("d", (d) => path[/[se]/.test(d.type) ? "end" : "start"]).attr("display", initRange ? null : "none");
274
+ },
275
+ /**
276
+ * Update sub chart
277
+ * @param {object} targets $$.data.targets
278
+ * @private
279
+ */
280
+ updateTargetsForSubchart(targets) {
281
+ const $$ = this;
282
+ const { config, state, $el: { subchart: { main } } } = $$;
283
+ if (config.subchart_show) {
284
+ $$.withSubchartTypeContext(() => {
285
+ SUBCHART_TYPES.filter((v) => $$.hasType(v) || $$.hasTypeOf(capitalize(v))).forEach((v) => {
286
+ const isPointType = /^(bubble|scatter)$/.test(v);
287
+ const name = capitalize(isPointType ? "circle" : v);
288
+ const chartClass = $$.getChartClass(name, true);
289
+ const shapeClass = $$.getClass(isPointType ? "circles" : `${v}s`, true);
290
+ const shapeChart = main.select(`.${classes_default[`chart${`${name}s`}`]}`);
291
+ if (isPointType) {
292
+ const circle = shapeChart.selectAll(`.${classes_default.circles}`).data(targets.filter($$[`is${capitalize(v)}Type`].bind($$))).attr("class", shapeClass);
293
+ circle.exit().remove();
294
+ circle.enter().append("g").attr("class", shapeClass);
295
+ } else {
296
+ const shapeUpdate = shapeChart.selectAll(`.${classes_default[`chart${name}`]}`).attr("class", chartClass).data(targets.filter($$[`is${name}Type`].bind($$)));
297
+ const shapeEnter = shapeUpdate.enter().append("g").style("opacity", "0").attr("class", chartClass).append("g").attr("class", shapeClass);
298
+ shapeUpdate.exit().remove();
299
+ v === "line" && $$.hasTypeOf("Area") && shapeEnter.append("g").attr("class", $$.getClass("areas", true));
300
+ }
301
+ });
302
+ });
303
+ main.selectAll(`.${classes_default.brush} rect`).attr(config.axis_rotated ? "width" : "height", config.axis_rotated ? state.width2 : state.height2);
304
+ $$.$el.subchart.eventRect?.attr("width", state.width2).attr("height", state.height2).style("pointer-events", $$.isSubchartBrushEnabled() ? "none" : "all");
305
+ }
306
+ },
307
+ /**
308
+ * Update subchart y domains using subchart type options.
309
+ * @param {object} targets Targets to show
310
+ * @private
311
+ */
312
+ updateSubchartYDomain(targets) {
313
+ const $$ = this;
314
+ const { scale } = $$;
315
+ const targetsToShow = targets || $$.filterTargetsToShow($$.data.targets);
316
+ scale.subY?.domain($$.getYDomain(targetsToShow, "y"));
317
+ scale.subY2?.domain($$.getYDomain(targetsToShow, "y2"));
318
+ },
319
+ /**
320
+ * Redraw subchart.
321
+ * @private
322
+ * @param {boolean} withSubchart whether or not to show subchart
323
+ * @param {number} duration duration
324
+ */
325
+ redrawSubchart(withSubchart, duration) {
326
+ const $$ = this;
327
+ const { config, $el: { subchart: { main } }, state } = $$;
328
+ const withTransition = !!duration;
329
+ main.style("visibility", config.subchart_show ? null : "hidden");
330
+ main.select(`.${classes_default.brush}`).style("pointer-events", $$.isSubchartBrushEnabled() ? null : "none");
331
+ $$.$el.subchart.eventRect?.style("pointer-events", $$.isSubchartBrushEnabled() ? "none" : "all");
332
+ $$.$el.axis.subY?.style("visibility", config.subchart_axis_y_show ? null : "hidden");
333
+ $$.$el.axis.subY2?.style("visibility", config.subchart_axis_y2_show ? null : "hidden");
334
+ if (config.subchart_show) {
335
+ if (state.event?.type === "zoom") $$.brush.update();
336
+ if (withSubchart) {
337
+ const initRange = config.subchart_init_range;
338
+ !brushEmpty($$) && $$.brush.update();
339
+ $$.withSubchartTypeContext(() => {
340
+ const targetsToShow = state._targetsToShow || $$.filterTargetsToShow($$.data.targets);
341
+ $$.updateSubchartYDomain(targetsToShow);
342
+ const subchartShape = $$.getDrawShape();
343
+ Object.keys(subchartShape.type).forEach((v) => {
344
+ const name = capitalize(v);
345
+ const drawFn = $$[`generateDraw${name}`](subchartShape.indices[v], true);
346
+ $$[`update${name}`](withTransition, true);
347
+ $$[`redraw${name}`](drawFn, withTransition, true);
348
+ });
349
+ if ($$.hasType("bubble") || $$.hasType("scatter")) {
350
+ const { cx } = subchartShape.pos;
351
+ const cy = $$.updateCircleY(true);
352
+ $$.updateCircle(true);
353
+ $$.redrawCircle(cx, cy, withTransition, void 0, true);
354
+ }
355
+ });
356
+ if (!state.rendered && initRange) {
357
+ state.domain = initRange;
358
+ $$.brush.move($$.brush.getSelection(), initRange.map($$.scale.x));
359
+ }
360
+ }
361
+ }
362
+ },
363
+ /**
364
+ * Show a focus grid line on subchart following main chart focus.
365
+ * @param {Array} data Selected data
366
+ * @private
367
+ */
368
+ showSubchartGridFocus(data) {
369
+ const $$ = this;
370
+ const { config, state, $el: { subchart: { main } } } = $$;
371
+ if (!main || !config.subchart_show || $$.isSubchartBrushEnabled() || config.grid_focus_show === false || config.subchart_grid_focus === false || !config.tooltip_show || config.axis_tooltip) return;
372
+ const focus = (Array.isArray(data) ? data : [data]).find((d) => d && $$.getBaseValue(d) != null);
373
+ if (!focus) {
374
+ $$.hideSubchartGridFocus();
375
+ return;
376
+ }
377
+ const pos = $$.scale.subX(focus.x);
378
+ if (!Number.isFinite(pos)) {
379
+ $$.hideSubchartGridFocus();
380
+ return;
381
+ }
382
+ const line = main.select(`g.${classes_default.xgridFocus} line.${classes_default.xgridFocus}`);
383
+ if (showContinuousSubchartGridFocus($$)) {
384
+ line.style("visibility", "hidden");
385
+ return;
386
+ }
387
+ syncSubchartGridFocusStyle($$, line);
388
+ config.axis_rotated ? line.attr("x1", 0).attr("x2", state.width2).attr("y1", pos).attr("y2", pos) : line.attr("x1", pos).attr("x2", pos).attr("y1", 0).attr("y2", state.height2);
389
+ line.style("visibility", null);
390
+ },
391
+ /**
392
+ * Hide subchart focus grid line.
393
+ * @private
394
+ */
395
+ hideSubchartGridFocus() {
396
+ hideContinuousSubchartGridFocus(this);
397
+ this.$el.subchart.main?.select(`g.${classes_default.xgridFocus} line.${classes_default.xgridFocus}`).style("visibility", "hidden");
398
+ },
399
+ /**
400
+ * Redraw the brush.
401
+ * @param {boolean} [callCallbck=true] Call 'onbrush' callback or not.
402
+ * @private
403
+ */
404
+ redrawForBrush(callCallbck = true) {
405
+ const $$ = this;
406
+ const { config: { subchart_onbrush: onBrush, zoom_rescale: withY }, scale, state } = $$;
407
+ $$.redraw({
408
+ withTransition: false,
409
+ withY,
410
+ withSubchart: false,
411
+ withUpdateXDomain: true,
412
+ withDimension: false
413
+ });
414
+ callCallbck && state.rendered && onBrush.bind($$.api)(state.domain ?? scale.x.orgDomain());
415
+ },
416
+ /**
417
+ * Transform context
418
+ * @param {boolean} withTransition indicates transition is enabled
419
+ * @param {object} transitions The return value of the generateTransitions method of Axis.
420
+ * @private
421
+ */
422
+ transformContext(withTransition, transitions) {
423
+ const $$ = this;
424
+ const { $el: { subchart }, $T } = $$;
425
+ const subXAxis = transitions?.axisSubX ? transitions.axisSubX : $T(subchart.main.select(`.${classes_default.axisX}`), withTransition);
426
+ const subYAxis = transitions?.axisSubY ? transitions.axisSubY : $T(subchart.main.select(`.${classes_default.axisY}`), withTransition);
427
+ const subY2Axis = transitions?.axisSubY2 ? transitions.axisSubY2 : $T(subchart.main.select(`.${classes_default.axisY2}`), withTransition);
428
+ subchart.main.attr("transform", $$.getTranslate("context"));
429
+ subXAxis.attr("transform", $$.getTranslate("subX"));
430
+ subYAxis.attr("transform", $$.getTranslate("subY"));
431
+ subY2Axis.attr("transform", $$.getTranslate("subY2"));
432
+ }
308
433
  };
309
-
310
- export { subchart as default };
434
+ //#endregion
435
+ export { subchart_default as default };