billboard.js 4.0.2 → 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 (272) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1938 -557
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -25
  6. package/dist/billboard.pkgd.js +1934 -742
  7. package/dist/billboard.pkgd.min.js +24 -30
  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 -147
  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 +970 -1147
  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 +286 -245
  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 -272
  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 -413
  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 -828
  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/focus.ts +8 -12
  222. package/src/Chart/api/selection.ts +130 -5
  223. package/src/ChartInternal/Axis/Axis.ts +164 -65
  224. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  225. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  226. package/src/ChartInternal/ChartInternal.ts +1 -1
  227. package/src/ChartInternal/data/convert.ts +54 -4
  228. package/src/ChartInternal/data/data.ts +19 -6
  229. package/src/ChartInternal/interactions/eventrect.ts +6 -0
  230. package/src/ChartInternal/interactions/subchart.ts +437 -66
  231. package/src/ChartInternal/internals/color.ts +7 -6
  232. package/src/ChartInternal/internals/domain.ts +15 -3
  233. package/src/ChartInternal/internals/grid.ts +21 -1
  234. package/src/ChartInternal/internals/scale.ts +9 -2
  235. package/src/ChartInternal/internals/selection.ts +1 -1
  236. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  237. package/src/ChartInternal/internals/text.arc.ts +3 -1
  238. package/src/ChartInternal/internals/text.ts +19 -6
  239. package/src/ChartInternal/internals/transform.ts +8 -2
  240. package/src/ChartInternal/internals/type.ts +131 -33
  241. package/src/ChartInternal/shape/IShape.ts +6 -3
  242. package/src/ChartInternal/shape/bar.ts +87 -37
  243. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  244. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  245. package/src/ChartInternal/shape/core/path.ts +76 -9
  246. package/src/ChartInternal/shape/funnel.ts +2 -3
  247. package/src/ChartInternal/shape/line.ts +1 -1
  248. package/src/ChartInternal/shape/point.ts +27 -13
  249. package/src/ChartInternal/shape/shape.ts +172 -18
  250. package/src/Plugin/stanford/index.ts +0 -4
  251. package/src/Plugin/tableview/index.ts +85 -3
  252. package/src/Plugin/textoverlap/index.ts +9 -15
  253. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  254. package/src/canvas/CanvasRenderer.ts +247 -160
  255. package/src/canvas/CanvasTheme.ts +212 -0
  256. package/src/canvas/axisTicks.ts +122 -40
  257. package/src/config/Options/axis/y2.ts +13 -0
  258. package/src/config/Options/common/boost.ts +64 -4
  259. package/src/config/Options/common/color.ts +2 -2
  260. package/src/config/Options/interaction/subchart.ts +98 -1
  261. package/src/config/Options/shape/gauge.ts +1 -1
  262. package/src/config/Options/shape/treemap.ts +2 -2
  263. package/src/config/Store/Element.ts +3 -1
  264. package/src/config/Store/State.ts +1 -0
  265. package/src/config/classes.ts +1 -0
  266. package/src/config/resolver/canvas.ts +92 -10
  267. package/src/module/voronoi.ts +119 -0
  268. package/src/module/worker.entry.ts +61 -0
  269. package/src/module/worker.ts +346 -63
  270. package/src/react/index.ts +193 -0
  271. package/types/options.d.ts +206 -3
  272. package/types/react/index.d.ts +27 -0
@@ -5,547 +5,415 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.2
8
+ * @version 4.1.0-next.1
9
9
  */
10
- import { select } from 'd3-selection';
11
- import { $COMMON } from '../../config/classes.js';
12
- import { AXIS_TICK_LENGTH, AXIS_TICK_SIZE, AXIS_TICK_PADDING } from '../../config/const.js';
13
- import AxisRendererHelper from './AxisRendererHelper.js';
14
- import { isFunction, isArray, isNumber, isString } from '../../module/util/type-checks.js';
15
- import { toArray } from '../../module/util/object.js';
16
-
10
+ import { isArray, isFunction, isNumber, isString } from "../../module/util/type-checks.js";
11
+ import { toArray } from "../../module/util/object.js";
12
+ import { $COMMON } from "../../config/classes.js";
13
+ import AxisRendererHelper from "./AxisRendererHelper.js";
14
+ import { select } from "d3-selection";
15
+ //#region src/ChartInternal/Axis/AxisRenderer.ts
17
16
  /**
18
- * Copyright (c) 2017 ~ present NAVER Corp.
19
- * billboard.js project is licensed under the MIT license
20
- * @ignore
21
- */
22
- class AxisRenderer {
23
- helper;
24
- config;
25
- params;
26
- g;
27
- generatedTicks = [];
28
- canReuseTickTextOnResize(isLeftRight) {
29
- const { config, params } = this;
30
- const { config: chartConfig, id, owner } = params;
31
- const isX = /^(x|subX)$/.test(id);
32
- const type = id === "subX" ? "x" : id;
33
- const customTickFormat = id === "subX" ?
34
- chartConfig.subchart_axis_x_tick_format || chartConfig.axis_x_tick_format :
35
- chartConfig[`axis_${type}_tick_format`];
36
- const categoryAutoWrap = params.tickMultiline && params.isCategory && !isLeftRight &&
37
- !(params.tickWidth > 0);
38
- return !!(owner.state.resizing &&
39
- !owner.state.flowing &&
40
- !isFunction(chartConfig.axis_evalTextSize) &&
41
- !customTickFormat &&
42
- !params.tickTitle &&
43
- !(isX && chartConfig.axis_x_tick_autorotate) &&
44
- !categoryAutoWrap &&
45
- config.withoutTransition);
46
- }
47
- canReuseTickNodesOnResize(tickNodes, ticks, isLeftRight, tickShow) {
48
- if (tickShow.tick || !tickShow.text || !this.canReuseTickTextOnResize(isLeftRight) ||
49
- tickNodes.size() !== ticks.length) {
50
- return false;
51
- }
52
- const nodes = tickNodes.nodes();
53
- for (let i = 0; i < ticks.length; i++) {
54
- const current = nodes[i].__data__;
55
- const next = ticks[i];
56
- if (current instanceof Date || next instanceof Date) {
57
- if (+current !== +next) {
58
- return false;
59
- }
60
- }
61
- else if (current !== next) {
62
- return false;
63
- }
64
- }
65
- return true;
66
- }
67
- constructor(params = {}) {
68
- const config = {
69
- innerTickSize: AXIS_TICK_SIZE,
70
- outerTickSize: params.outerTick ? AXIS_TICK_SIZE : 0,
71
- orient: "bottom",
72
- range: [],
73
- tickArguments: null,
74
- tickCentered: null,
75
- tickCulling: true,
76
- tickFormat: null,
77
- tickLength: AXIS_TICK_LENGTH,
78
- tickOffset: 0,
79
- tickPadding: AXIS_TICK_PADDING,
80
- tickValues: null,
81
- transition: null,
82
- noTransition: params.noTransition
83
- };
84
- config.tickLength = Math.max(config.innerTickSize, 0) + config.tickPadding;
85
- this.config = config;
86
- this.params = params;
87
- this.helper = new AxisRendererHelper(this);
88
- }
89
- /**
90
- * Create axis element
91
- * @param {d3.selection} g Axis selection
92
- * @private
93
- */
94
- create(g) {
95
- const ctx = this;
96
- const { config, helper, params } = ctx;
97
- const { scale } = helper;
98
- const { orient } = config;
99
- const splitTickText = this.splitTickText.bind(ctx);
100
- const isLeftRight = /^(left|right)$/.test(orient);
101
- const isTopBottom = /^(top|bottom)$/.test(orient);
102
- // line/text enter and path update
103
- const tickTransform = helper.getTickTransformSetter(isTopBottom ? "x" : "y");
104
- const axisPx = tickTransform === helper.axisX ? "y" : "x";
105
- const sign = /^(top|left)$/.test(orient) ? -1 : 1;
106
- // tick text helpers
107
- const rotate = params.tickTextRotate;
108
- this.config.range = scale.rangeExtent ?
109
- scale.rangeExtent() :
110
- helper.scaleExtent((params.orgXScale || scale).range());
111
- const { innerTickSize, tickLength, range } = config;
112
- // // get the axis' tick position configuration
113
- const id = params.id;
114
- const tickTextPos = id && /^(x|y|y2)$/.test(id) ?
115
- params.config[`axis_${id}_tick_text_position`] :
116
- { x: 0, y: 0 };
117
- // tick visiblity
118
- const prefix = id === "subX" ? `subchart_axis_x` : `axis_${id}`;
119
- const axisShow = params.config[`${prefix}_show`];
120
- const tickShow = {
121
- tick: axisShow ? params.config[`${prefix}_tick_show`] : false,
122
- text: axisShow ? params.config[`${prefix}_tick_text_show`] : false
123
- };
124
- const evalTextSize = params.config.axis_evalTextSize;
125
- let $g;
126
- g.each(function () {
127
- const g = select(this);
128
- let scale0 = this.__chart__ || scale;
129
- let scale1 = helper.copyScale();
130
- $g = g;
131
- this.__chart__ = scale1;
132
- config.tickOffset = params.isCategory ? (scale1(1) - scale1(0)) / 2 : 0;
133
- // update selection - data join
134
- const path = g.selectAll(".domain").data([0]);
135
- // enter + update selection
136
- path.enter().append("path")
137
- .attr("class", "domain")
138
- // https://observablehq.com/@d3/d3-selection-2-0
139
- .merge(path)
140
- .attr("d", () => {
141
- const outerTickSized = config.outerTickSize * sign;
142
- return isTopBottom ?
143
- `M${range[0]},${outerTickSized}V0H${range[1]}V${outerTickSized}` :
144
- `M${outerTickSized},${range[0]}H0V${range[1]}H${outerTickSized}`;
145
- });
146
- if (tickShow.tick || tickShow.text) {
147
- // count of tick data in array
148
- const ticks = config.tickValues ||
149
- helper.generateTicks(scale1, isLeftRight || params.config.axis_rotated);
150
- // set generated ticks
151
- ctx.generatedTicks = ticks;
152
- // update selection
153
- let tick = g.selectAll(".tick");
154
- const canReuseTickNodes = ctx.canReuseTickNodesOnResize(tick, ticks, isLeftRight || params.config.axis_rotated, tickShow);
155
- if (canReuseTickNodes) {
156
- tickTransform(tick, scale1);
157
- }
158
- else {
159
- tick = tick.data(ticks, scale1);
160
- // enter selection
161
- const tickEnter = tick
162
- .enter()
163
- .insert("g", ".domain")
164
- .attr("class", "tick");
165
- // MEMO: No exit transition. The reason is this transition affects max tick width calculation because old tick will be included in the ticks.
166
- const tickExit = tick.exit().remove();
167
- // enter + update selection
168
- tick = tickEnter.merge(tick);
169
- tickShow.tick && tickEnter.append("line");
170
- tickShow.text && tickEnter.append("text");
171
- const hasTickChange = !tickEnter.empty() || !tickExit.empty();
172
- const reuseTickText = tickShow.text && !hasTickChange &&
173
- ctx.canReuseTickTextOnResize(isLeftRight || params.config.axis_rotated);
174
- let sizeFor1Char = { w: 0, h: 0 };
175
- let textUpdate = tick.selectAll("text.__bb-empty");
176
- if (tickShow.text && !reuseTickText) {
177
- const tickText = tick.select("text");
178
- const counts = [];
179
- textUpdate = tickText;
180
- if (isFunction(evalTextSize)) {
181
- // set evalTextSize to dummy axis element to be used in .getMaxTickSize()
182
- sizeFor1Char = evalTextSize.bind(ctx.params.owner.api)(tickText.node(), id);
183
- if (this.classList.contains($COMMON.dummy)) {
184
- this.sizeFor1Char = sizeFor1Char;
185
- }
186
- }
187
- if (!sizeFor1Char || sizeFor1Char.w === 0 || sizeFor1Char.h === 0) {
188
- sizeFor1Char = ctx.helper.getSizeFor1Char(orient, tickText, !!evalTextSize);
189
- }
190
- let tspan = tickText
191
- .selectAll("tspan")
192
- .data((d, index) => {
193
- let split;
194
- if (params.tickMultiline) {
195
- split = splitTickText(d, scale1, ticks, isLeftRight, sizeFor1Char.w);
196
- }
197
- else {
198
- const formatted = helper.textFormatted(d);
199
- split = isArray(formatted) ? formatted.concat() : [formatted];
200
- }
201
- counts[index] = split.length;
202
- return split.map(splitted => ({ index, splitted }));
203
- });
204
- tspan.exit().remove();
205
- tspan = tspan
206
- .enter()
207
- .append("tspan")
208
- .merge(tspan)
209
- .text(d => d.splitted);
210
- // set <tspan>'s position
211
- tspan
212
- .attr("x", isTopBottom ? 0 : tickLength * sign)
213
- .attr("dx", (() => {
214
- let dx = 0;
215
- if (/(top|bottom)/.test(orient) && rotate) {
216
- dx = 8 * Math.sin(Math.PI * (rotate / 180)) *
217
- (orient === "top" ? -1 : 1);
218
- }
219
- return dx + (tickTextPos.x || 0);
220
- })())
221
- .attr("dy", (d, i) => {
222
- const defValue = ".71em";
223
- let dy = 0;
224
- if (orient !== "top") {
225
- dy = sizeFor1Char.h;
226
- if (i === 0) {
227
- dy = isLeftRight ?
228
- -((counts[d.index] - 1) * (sizeFor1Char.h / 2) - 3) :
229
- (tickTextPos.y === 0 ? defValue : 0);
230
- }
231
- }
232
- return isNumber(dy) && tickTextPos.y ?
233
- dy + tickTextPos.y :
234
- dy || defValue;
235
- });
236
- }
237
- const lineUpdate = tick.select("line");
238
- tickEnter.select("line").attr(`${axisPx}2`, innerTickSize * sign);
239
- tickEnter.select("text").attr(axisPx, tickLength * sign);
240
- ctx.setTickLineTextPosition(lineUpdate, textUpdate, sizeFor1Char);
241
- // Append <title> for tooltip display
242
- if (params.tickTitle) {
243
- const title = textUpdate.select("title");
244
- const tickTitle = params.tickTitle;
245
- (title.empty() ? textUpdate.append("title") : title)
246
- .text(index => tickTitle[Number(index)]);
247
- }
248
- if (scale1.bandwidth) {
249
- const x = scale1;
250
- const dx = x.bandwidth() / 2;
251
- scale0 = d => x(d) + dx;
252
- scale1 = scale0;
253
- }
254
- else if (scale0.bandwidth) {
255
- scale0 = scale1;
256
- }
257
- else {
258
- tickTransform(tickExit, scale1);
259
- }
260
- // when .flow(), it should follow flow's transition config
261
- // otherwise make to use ChartInternals.$T()
262
- tick = params.owner.state.flowing ?
263
- helper.transitionise(tick) :
264
- params.owner.$T(tick);
265
- tickTransform(tickEnter, scale0);
266
- tickTransform(tick.style("opacity", null), scale1);
267
- }
268
- }
269
- });
270
- this.g = $g;
271
- }
272
- /**
273
- * Get generated ticks
274
- * @param {number} count Count of ticks
275
- * @returns {Array} Generated ticks
276
- * @private
277
- */
278
- getGeneratedTicks(count) {
279
- const len = this.generatedTicks?.length - 1;
280
- let res = this.generatedTicks;
281
- if (len > count) {
282
- const interval = Math.round((len / count) + 0.1);
283
- res = this.generatedTicks
284
- .map((v, i) => (i % interval === 0 ? v : null))
285
- .filter(v => v !== null)
286
- .splice(0, count);
287
- }
288
- return res;
289
- }
290
- /**
291
- * Get tick x/y coordinate
292
- * @returns {{x: number, y: number}}
293
- * @private
294
- */
295
- getTickXY() {
296
- const { config } = this;
297
- const pos = { x: 0, y: 0 };
298
- if (this.params.isCategory) {
299
- pos.x = config.tickCentered ? 0 : config.tickOffset;
300
- pos.y = config.tickCentered ? config.tickOffset : 0;
301
- }
302
- return pos;
303
- }
304
- /**
305
- * Get tick size
306
- * @param {object} d data object
307
- * @returns {number}
308
- * @private
309
- */
310
- getTickSize(d) {
311
- const { scale } = this.helper;
312
- const { config } = this;
313
- const { innerTickSize, range } = config;
314
- const tickPosition = scale(d) +
315
- (config.tickCentered ? 0 : config.tickOffset);
316
- return range[0] < tickPosition && tickPosition < range[1] ? innerTickSize : 0;
317
- }
318
- /**
319
- * Set tick's line & text position
320
- * @param {d3.selection} lineUpdate Line selection
321
- * @param {d3.selection} textUpdate Text selection
322
- * @param {object} sizeFor1Char Size for 1 char
323
- * @private
324
- */
325
- setTickLineTextPosition(lineUpdate, textUpdate, sizeFor1Char) {
326
- const tickPos = this.getTickXY();
327
- const { innerTickSize, orient, tickLength, tickOffset } = this.config;
328
- const axisId = this.params.id;
329
- const rotate = this.params.tickTextRotate;
330
- const baseHeight = 6;
331
- const charHeight = (sizeFor1Char.h / 2) - baseHeight;
332
- const textAnchorForText = r => {
333
- const value = ["start", "end"];
334
- orient === "top" && value.reverse();
335
- return !r ? "middle" : value[r > 0 ? 0 : 1];
336
- };
337
- const textTransform = r => (r ? `rotate(${r})` : null);
338
- const yForText = r => {
339
- const r2 = r / (orient === "bottom" ? 15 : 23);
340
- const y = r ? 11.5 - 2.5 * r2 * (r > 0 ? 1 : -1) : tickLength;
341
- return y;
342
- };
343
- const { config: { axis_rotated: isRotated, axis_x_tick_text_inner: inner } } = this.params.owner;
344
- const tickLineInner = this.params.config[`axis_${axisId}_tick_inner`];
345
- switch (orient) {
346
- case "bottom":
347
- lineUpdate
348
- .attr("x1", tickPos.x)
349
- .attr("x2", tickPos.x)
350
- .attr("y2", d => this.getTickSize.bind(this)(d) * (tickLineInner ? -1 : 1));
351
- textUpdate
352
- .attr("x", 0)
353
- .attr("y", yForText(rotate))
354
- .style("text-anchor", (d, i, { length }) => {
355
- if (!isRotated && i === 0 && (inner === true || inner.first)) {
356
- return "start";
357
- }
358
- else if (!isRotated && i === length - 1 && (inner === true || inner.last)) {
359
- return "end";
360
- }
361
- return textAnchorForText(rotate);
362
- })
363
- .attr("transform", textTransform(rotate));
364
- break;
365
- case "top":
366
- lineUpdate
367
- .attr("x2", 0)
368
- .attr("y2", tickLineInner ? innerTickSize : -innerTickSize);
369
- textUpdate
370
- .attr("x", 0)
371
- .attr("y", -(yForText(rotate) + charHeight + baseHeight))
372
- .style("text-anchor", textAnchorForText(rotate))
373
- .attr("transform", textTransform(rotate));
374
- break;
375
- case "left":
376
- lineUpdate
377
- .attr("x2", tickLineInner ? innerTickSize : -innerTickSize)
378
- .attr("y1", tickPos.y)
379
- .attr("y2", tickPos.y);
380
- textUpdate
381
- .attr("x", -tickLength)
382
- .attr("y", tickOffset + (isRotated ? charHeight / 4 : charHeight))
383
- .style("text-anchor", "end");
384
- break;
385
- case "right":
386
- lineUpdate
387
- .attr("x2", tickLineInner ? -innerTickSize : innerTickSize)
388
- .attr("y2", 0);
389
- textUpdate
390
- .attr("x", tickLength)
391
- .attr("y", charHeight)
392
- .style("text-anchor", "start");
393
- }
394
- }
395
- // this should be called only when category axis
396
- splitTickText(d, scale, ticks, isLeftRight, charWidth) {
397
- const { params } = this;
398
- const tickText = this.helper.textFormatted(d);
399
- const splitted = isString(tickText) && tickText.indexOf("\n") > -1 ?
400
- tickText.split("\n") :
401
- [];
402
- if (splitted.length) {
403
- return splitted;
404
- }
405
- if (isArray(tickText)) {
406
- return tickText;
407
- }
408
- let tickWidth = params.tickWidth;
409
- if (!tickWidth || tickWidth <= 0) {
410
- tickWidth = isLeftRight ? 95 : (params.isCategory ?
411
- (params.isInverted ?
412
- scale(ticks[0]) - scale(ticks[1]) :
413
- scale(ticks[1]) - scale(ticks[0])) - 12 :
414
- 110);
415
- }
416
- // split given text by tick width size
417
- // eslint-disable-next-line
418
- function split(splitted, text) {
419
- let subtext;
420
- let spaceIndex;
421
- let textWidth;
422
- for (let i = 1; i < text.length; i++) {
423
- if (text.charAt(i) === " ") {
424
- spaceIndex = i;
425
- }
426
- subtext = text.substr(0, i + 1);
427
- textWidth = charWidth * subtext.length;
428
- // if text width gets over tick width, split by space index or current index
429
- if (tickWidth < textWidth) {
430
- return split(splitted.concat(text.substr(0, spaceIndex || i)), text.slice(spaceIndex ? spaceIndex + 1 : i));
431
- }
432
- }
433
- return splitted.concat(text);
434
- }
435
- return split(splitted, String(tickText));
436
- }
437
- scale(x) {
438
- if (!arguments.length) {
439
- return this.helper.scale;
440
- }
441
- this.helper.scale = x;
442
- return this;
443
- }
444
- orient(x) {
445
- if (!arguments.length) {
446
- return this.config.orient;
447
- }
448
- this.config.orient = x in {
449
- top: 1,
450
- right: 1,
451
- bottom: 1,
452
- left: 1
453
- } ?
454
- String(x) :
455
- "bottom";
456
- return this;
457
- }
458
- tickFormat(format) {
459
- const { config } = this;
460
- if (!arguments.length) {
461
- return config.tickFormat;
462
- }
463
- config.tickFormat = format;
464
- return this;
465
- }
466
- tickCentered(isCentered) {
467
- const { config } = this;
468
- if (!arguments.length) {
469
- return config.tickCentered;
470
- }
471
- config.tickCentered = isCentered;
472
- return this;
473
- }
474
- /**
475
- * Return tick's offset value.
476
- * The value will be set for 'category' axis type.
477
- * @returns {number}
478
- * @private
479
- */
480
- tickOffset() {
481
- return this.config.tickOffset;
482
- }
483
- /**
484
- * Get tick interval count
485
- * @private
486
- * @param {number} size Total data size
487
- * @returns {number}
488
- */
489
- tickInterval(size) {
490
- const { outerTickSize, tickOffset, tickValues } = this.config;
491
- let interval;
492
- if (this.params.isCategory) {
493
- const scale = this.params.owner.scale.zoom ?? this.helper.scale;
494
- interval = tickOffset * 2 || Math.abs(scale(1) - scale(0));
495
- }
496
- else {
497
- const scale = this.params.owner.scale.zoom ?? this.helper.scale;
498
- const length = this.g ?
499
- this.g.select("path.domain")
500
- .node()
501
- .getTotalLength() - outerTickSize * 2 :
502
- Math.abs(scale.range()[1] - scale.range()[0]);
503
- interval = length / (size || this.g?.selectAll("line").size() || 1);
504
- // get the interval by its values
505
- if (tickValues) {
506
- for (let i = 0; i < tickValues.length - 1; i++) {
507
- const intervalByValue = scale(tickValues[i + 1]) - scale(tickValues[i]);
508
- if (intervalByValue && intervalByValue < interval) {
509
- interval = intervalByValue;
510
- }
511
- }
512
- }
513
- }
514
- return interval === Infinity ? 0 : interval;
515
- }
516
- ticks(...args) {
517
- const { config } = this;
518
- if (!args.length) {
519
- return config.tickArguments;
520
- }
521
- config.tickArguments = toArray(args);
522
- return this;
523
- }
524
- tickCulling(culling) {
525
- const { config } = this;
526
- if (!arguments.length) {
527
- return config.tickCulling;
528
- }
529
- config.tickCulling = culling;
530
- return this;
531
- }
532
- tickValues(x) {
533
- const { config } = this;
534
- if (isFunction(x)) {
535
- config.tickValues = () => x(this.helper.scale.domain());
536
- }
537
- else {
538
- if (!arguments.length) {
539
- return config.tickValues;
540
- }
541
- config.tickValues = x;
542
- }
543
- return this;
544
- }
545
- setTransition(t) {
546
- this.config.transition = t;
547
- return this;
548
- }
17
+ * Copyright (c) 2017 ~ present NAVER Corp.
18
+ * billboard.js project is licensed under the MIT license
19
+ * @ignore
20
+ */
21
+ /**
22
+ * Get the corresponding main axis id for subchart axis ids.
23
+ * @param {string} id Axis id
24
+ * @returns {string} Base axis id
25
+ * @private
26
+ */
27
+ function getBaseAxisId(id) {
28
+ return id === "subX" ? "x" : id === "subY" ? "y" : id === "subY2" ? "y2" : id;
29
+ }
30
+ /**
31
+ * Get config option prefix for an axis id.
32
+ * @param {string} id Axis id
33
+ * @returns {string} Option prefix
34
+ * @private
35
+ */
36
+ function getAxisOptionPrefix(id) {
37
+ const type = getBaseAxisId(id);
38
+ return /^sub/.test(id) ? `subchart_axis_${type}` : `axis_${type}`;
549
39
  }
550
-
40
+ var AxisRenderer = class {
41
+ helper;
42
+ config;
43
+ params;
44
+ g;
45
+ generatedTicks = [];
46
+ canReuseTickTextOnResize(isLeftRight) {
47
+ const { config, params } = this;
48
+ const { config: chartConfig, id, owner } = params;
49
+ const isX = /^(x|subX)$/.test(id);
50
+ const type = getBaseAxisId(id);
51
+ const customTickFormat = /^sub/.test(id) ? chartConfig[`subchart_axis_${type}_tick_format`] || chartConfig[`axis_${type}_tick_format`] : chartConfig[`axis_${type}_tick_format`];
52
+ const categoryAutoWrap = params.tickMultiline && params.isCategory && !isLeftRight && !(params.tickWidth > 0);
53
+ return !!(owner.state.resizing && !owner.state.flowing && !isFunction(chartConfig.axis_evalTextSize) && !customTickFormat && !params.tickTitle && !(isX && chartConfig.axis_x_tick_autorotate) && !categoryAutoWrap && config.withoutTransition);
54
+ }
55
+ canReuseTickNodesOnResize(tickNodes, ticks, isLeftRight, tickShow) {
56
+ if (tickShow.tick || !tickShow.text || !this.canReuseTickTextOnResize(isLeftRight) || tickNodes.size() !== ticks.length) return false;
57
+ const nodes = tickNodes.nodes();
58
+ for (let i = 0; i < ticks.length; i++) {
59
+ const current = nodes[i].__data__;
60
+ const next = ticks[i];
61
+ if (current instanceof Date || next instanceof Date) {
62
+ if (+current !== +next) return false;
63
+ } else if (current !== next) return false;
64
+ }
65
+ return true;
66
+ }
67
+ constructor(params = {}) {
68
+ const config = {
69
+ innerTickSize: 6,
70
+ outerTickSize: params.outerTick ? 6 : 0,
71
+ orient: "bottom",
72
+ range: [],
73
+ tickArguments: null,
74
+ tickCentered: null,
75
+ tickCulling: true,
76
+ tickFormat: null,
77
+ tickLength: 9,
78
+ tickOffset: 0,
79
+ tickPadding: 3,
80
+ tickValues: null,
81
+ transition: null,
82
+ noTransition: params.noTransition
83
+ };
84
+ config.tickLength = Math.max(config.innerTickSize, 0) + config.tickPadding;
85
+ this.config = config;
86
+ this.params = params;
87
+ this.helper = new AxisRendererHelper(this);
88
+ }
89
+ /**
90
+ * Create axis element
91
+ * @param {d3.selection} g Axis selection
92
+ * @private
93
+ */
94
+ create(g) {
95
+ const ctx = this;
96
+ const { config, helper, params } = ctx;
97
+ const { scale } = helper;
98
+ const { orient } = config;
99
+ const splitTickText = this.splitTickText.bind(ctx);
100
+ const isLeftRight = /^(left|right)$/.test(orient);
101
+ const isTopBottom = /^(top|bottom)$/.test(orient);
102
+ const tickTransform = helper.getTickTransformSetter(isTopBottom ? "x" : "y");
103
+ const axisPx = tickTransform === helper.axisX ? "y" : "x";
104
+ const sign = /^(top|left)$/.test(orient) ? -1 : 1;
105
+ const rotate = params.tickTextRotate;
106
+ this.config.range = scale.rangeExtent ? scale.rangeExtent() : helper.scaleExtent((params.orgXScale || scale).range());
107
+ const { innerTickSize, tickLength, range } = config;
108
+ const id = params.id;
109
+ const type = getBaseAxisId(id);
110
+ const { isSubAxes } = params;
111
+ const tickTextPos = !isSubAxes && type && /^(x|y|y2)$/.test(type) ? params.config[`axis_${type}_tick_text_position`] : {
112
+ x: 0,
113
+ y: 0
114
+ };
115
+ const prefix = getAxisOptionPrefix(id);
116
+ const axisShow = params.config[`${prefix}_show`];
117
+ const tickShow = isSubAxes ? {
118
+ tick: true,
119
+ text: true
120
+ } : {
121
+ tick: axisShow ? params.config[`${prefix}_tick_show`] : false,
122
+ text: axisShow ? params.config[`${prefix}_tick_text_show`] : false
123
+ };
124
+ const evalTextSize = params.config.axis_evalTextSize;
125
+ let $g;
126
+ g.each(function() {
127
+ const g = select(this);
128
+ let scale0 = this.__chart__ || scale;
129
+ let scale1 = helper.copyScale();
130
+ $g = g;
131
+ this.__chart__ = scale1;
132
+ config.tickOffset = params.isCategory ? (scale1(1) - scale1(0)) / 2 : 0;
133
+ const path = g.selectAll(".domain").data([0]);
134
+ path.enter().append("path").attr("class", "domain").merge(path).attr("d", () => {
135
+ const outerTickSized = config.outerTickSize * sign;
136
+ return isTopBottom ? `M${range[0]},${outerTickSized}V0H${range[1]}V${outerTickSized}` : `M${outerTickSized},${range[0]}H0V${range[1]}H${outerTickSized}`;
137
+ });
138
+ if (tickShow.tick || tickShow.text) {
139
+ const ticks = config.tickValues || helper.generateTicks(scale1, isLeftRight || params.config.axis_rotated);
140
+ ctx.generatedTicks = ticks;
141
+ let tick = g.selectAll(".tick");
142
+ if (ctx.canReuseTickNodesOnResize(tick, ticks, isLeftRight || params.config.axis_rotated, tickShow)) tickTransform(tick, scale1);
143
+ else {
144
+ tick = tick.data(ticks, scale1);
145
+ const tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick");
146
+ const tickExit = tick.exit().remove();
147
+ tick = tickEnter.merge(tick);
148
+ tickShow.tick && tickEnter.append("line");
149
+ tickShow.text && tickEnter.append("text");
150
+ const hasTickChange = !tickEnter.empty() || !tickExit.empty();
151
+ const reuseTickText = tickShow.text && !hasTickChange && ctx.canReuseTickTextOnResize(isLeftRight || params.config.axis_rotated);
152
+ let sizeFor1Char = {
153
+ w: 0,
154
+ h: 0
155
+ };
156
+ let textUpdate = tick.selectAll("text.__bb-empty");
157
+ if (tickShow.text && !reuseTickText) {
158
+ const tickText = tick.select("text");
159
+ const counts = [];
160
+ textUpdate = tickText;
161
+ if (isFunction(evalTextSize)) {
162
+ sizeFor1Char = evalTextSize.bind(ctx.params.owner.api)(tickText.node(), id);
163
+ if (this.classList.contains($COMMON.dummy)) this.sizeFor1Char = sizeFor1Char;
164
+ }
165
+ if (!sizeFor1Char || sizeFor1Char.w === 0 || sizeFor1Char.h === 0) sizeFor1Char = ctx.helper.getSizeFor1Char(orient, tickText, !!evalTextSize);
166
+ let tspan = tickText.selectAll("tspan").data((d, index) => {
167
+ let split;
168
+ if (params.tickMultiline) split = splitTickText(d, scale1, ticks, isLeftRight, sizeFor1Char.w);
169
+ else {
170
+ const formatted = helper.textFormatted(d);
171
+ split = isArray(formatted) ? formatted.concat() : [formatted];
172
+ }
173
+ counts[index] = split.length;
174
+ return split.map((splitted) => ({
175
+ index,
176
+ splitted
177
+ }));
178
+ });
179
+ tspan.exit().remove();
180
+ tspan = tspan.enter().append("tspan").merge(tspan).text((d) => d.splitted);
181
+ tspan.attr("x", isTopBottom ? 0 : tickLength * sign).attr("dx", (() => {
182
+ let dx = 0;
183
+ if (/(top|bottom)/.test(orient) && rotate) dx = 8 * Math.sin(Math.PI * (rotate / 180)) * (orient === "top" ? -1 : 1);
184
+ return dx + (tickTextPos.x || 0);
185
+ })()).attr("dy", (d, i) => {
186
+ const defValue = ".71em";
187
+ let dy = 0;
188
+ if (orient !== "top") {
189
+ dy = sizeFor1Char.h;
190
+ if (i === 0) dy = isLeftRight ? -((counts[d.index] - 1) * (sizeFor1Char.h / 2) - 3) : tickTextPos.y === 0 ? defValue : 0;
191
+ }
192
+ return isNumber(dy) && tickTextPos.y ? dy + tickTextPos.y : dy || defValue;
193
+ });
194
+ }
195
+ const lineUpdate = tick.select("line");
196
+ tickEnter.select("line").attr(`${axisPx}2`, innerTickSize * sign);
197
+ tickEnter.select("text").attr(axisPx, tickLength * sign);
198
+ ctx.setTickLineTextPosition(lineUpdate, textUpdate, sizeFor1Char);
199
+ if (params.tickTitle) {
200
+ const title = textUpdate.select("title");
201
+ const tickTitle = params.tickTitle;
202
+ (title.empty() ? textUpdate.append("title") : title).text((index) => tickTitle[Number(index)]);
203
+ }
204
+ if (scale1.bandwidth) {
205
+ const x = scale1;
206
+ const dx = x.bandwidth() / 2;
207
+ scale0 = (d) => x(d) + dx;
208
+ scale1 = scale0;
209
+ } else if (scale0.bandwidth) scale0 = scale1;
210
+ else tickTransform(tickExit, scale1);
211
+ tick = params.owner.state.flowing ? helper.transitionise(tick) : params.owner.$T(tick);
212
+ tickTransform(tickEnter, scale0);
213
+ tickTransform(tick.style("opacity", null), scale1);
214
+ }
215
+ }
216
+ });
217
+ this.g = $g;
218
+ }
219
+ /**
220
+ * Get generated ticks
221
+ * @param {number} count Count of ticks
222
+ * @returns {Array} Generated ticks
223
+ * @private
224
+ */
225
+ getGeneratedTicks(count) {
226
+ const len = this.generatedTicks?.length - 1;
227
+ let res = this.generatedTicks;
228
+ if (len > count) {
229
+ const interval = Math.round(len / count + .1);
230
+ res = this.generatedTicks.map((v, i) => i % interval === 0 ? v : null).filter((v) => v !== null).splice(0, count);
231
+ }
232
+ return res;
233
+ }
234
+ /**
235
+ * Get tick x/y coordinate
236
+ * @returns {{x: number, y: number}}
237
+ * @private
238
+ */
239
+ getTickXY() {
240
+ const { config } = this;
241
+ const pos = {
242
+ x: 0,
243
+ y: 0
244
+ };
245
+ if (this.params.isCategory) {
246
+ pos.x = config.tickCentered ? 0 : config.tickOffset;
247
+ pos.y = config.tickCentered ? config.tickOffset : 0;
248
+ }
249
+ return pos;
250
+ }
251
+ /**
252
+ * Get tick size
253
+ * @param {object} d data object
254
+ * @returns {number}
255
+ * @private
256
+ */
257
+ getTickSize(d) {
258
+ const { scale } = this.helper;
259
+ const { config } = this;
260
+ const { innerTickSize, range } = config;
261
+ const tickPosition = scale(d) + (config.tickCentered ? 0 : config.tickOffset);
262
+ return range[0] < tickPosition && tickPosition < range[1] ? innerTickSize : 0;
263
+ }
264
+ /**
265
+ * Set tick's line & text position
266
+ * @param {d3.selection} lineUpdate Line selection
267
+ * @param {d3.selection} textUpdate Text selection
268
+ * @param {object} sizeFor1Char Size for 1 char
269
+ * @private
270
+ */
271
+ setTickLineTextPosition(lineUpdate, textUpdate, sizeFor1Char) {
272
+ const tickPos = this.getTickXY();
273
+ const { innerTickSize, orient, tickLength, tickOffset } = this.config;
274
+ const axisId = this.params.id;
275
+ const rotate = this.params.tickTextRotate;
276
+ const baseHeight = 6;
277
+ const charHeight = sizeFor1Char.h / 2 - baseHeight;
278
+ const textAnchorForText = (r) => {
279
+ const value = ["start", "end"];
280
+ orient === "top" && value.reverse();
281
+ return !r ? "middle" : value[r > 0 ? 0 : 1];
282
+ };
283
+ const textTransform = (r) => r ? `rotate(${r})` : null;
284
+ const yForText = (r) => {
285
+ const r2 = r / (orient === "bottom" ? 15 : 23);
286
+ return r ? 11.5 - 2.5 * r2 * (r > 0 ? 1 : -1) : tickLength;
287
+ };
288
+ const { config: { axis_rotated: isRotated, axis_x_tick_text_inner: inner } } = this.params.owner;
289
+ const tickLineInner = this.params.config[`axis_${getBaseAxisId(axisId)}_tick_inner`];
290
+ switch (orient) {
291
+ case "bottom":
292
+ lineUpdate.attr("x1", tickPos.x).attr("x2", tickPos.x).attr("y2", (d) => this.getTickSize.bind(this)(d) * (tickLineInner ? -1 : 1));
293
+ textUpdate.attr("x", 0).attr("y", yForText(rotate)).style("text-anchor", (d, i, { length }) => {
294
+ if (!isRotated && i === 0 && (inner === true || inner.first)) return "start";
295
+ else if (!isRotated && i === length - 1 && (inner === true || inner.last)) return "end";
296
+ return textAnchorForText(rotate);
297
+ }).attr("transform", textTransform(rotate));
298
+ break;
299
+ case "top":
300
+ lineUpdate.attr("x2", 0).attr("y2", tickLineInner ? innerTickSize : -innerTickSize);
301
+ textUpdate.attr("x", 0).attr("y", -(yForText(rotate) + charHeight + baseHeight)).style("text-anchor", textAnchorForText(rotate)).attr("transform", textTransform(rotate));
302
+ break;
303
+ case "left":
304
+ lineUpdate.attr("x2", tickLineInner ? innerTickSize : -innerTickSize).attr("y1", tickPos.y).attr("y2", tickPos.y);
305
+ textUpdate.attr("x", -tickLength).attr("y", tickOffset + (isRotated ? charHeight / 4 : charHeight)).style("text-anchor", "end");
306
+ break;
307
+ case "right":
308
+ lineUpdate.attr("x2", tickLineInner ? -innerTickSize : innerTickSize).attr("y2", 0);
309
+ textUpdate.attr("x", tickLength).attr("y", charHeight).style("text-anchor", "start");
310
+ }
311
+ }
312
+ splitTickText(d, scale, ticks, isLeftRight, charWidth) {
313
+ const { params } = this;
314
+ const tickText = this.helper.textFormatted(d);
315
+ const splitted = isString(tickText) && tickText.indexOf("\n") > -1 ? tickText.split("\n") : [];
316
+ if (splitted.length) return splitted;
317
+ if (isArray(tickText)) return tickText;
318
+ let tickWidth = params.tickWidth;
319
+ if (!tickWidth || tickWidth <= 0) tickWidth = isLeftRight ? 95 : params.isCategory ? (params.isInverted ? scale(ticks[0]) - scale(ticks[1]) : scale(ticks[1]) - scale(ticks[0])) - 12 : 110;
320
+ function split(splitted, text) {
321
+ let subtext;
322
+ let spaceIndex;
323
+ let textWidth;
324
+ for (let i = 1; i < text.length; i++) {
325
+ if (text.charAt(i) === " ") spaceIndex = i;
326
+ subtext = text.substr(0, i + 1);
327
+ textWidth = charWidth * subtext.length;
328
+ if (tickWidth < textWidth) return split(splitted.concat(text.substr(0, spaceIndex || i)), text.slice(spaceIndex ? spaceIndex + 1 : i));
329
+ }
330
+ return splitted.concat(text);
331
+ }
332
+ return split(splitted, String(tickText));
333
+ }
334
+ scale(x) {
335
+ if (!arguments.length) return this.helper.scale;
336
+ this.helper.scale = x;
337
+ return this;
338
+ }
339
+ orient(x) {
340
+ if (!arguments.length) return this.config.orient;
341
+ this.config.orient = x in {
342
+ top: 1,
343
+ right: 1,
344
+ bottom: 1,
345
+ left: 1
346
+ } ? String(x) : "bottom";
347
+ return this;
348
+ }
349
+ tickFormat(format) {
350
+ const { config } = this;
351
+ if (!arguments.length) return config.tickFormat;
352
+ config.tickFormat = format;
353
+ return this;
354
+ }
355
+ tickCentered(isCentered) {
356
+ const { config } = this;
357
+ if (!arguments.length) return config.tickCentered;
358
+ config.tickCentered = isCentered;
359
+ return this;
360
+ }
361
+ /**
362
+ * Return tick's offset value.
363
+ * The value will be set for 'category' axis type.
364
+ * @returns {number}
365
+ * @private
366
+ */
367
+ tickOffset() {
368
+ return this.config.tickOffset;
369
+ }
370
+ /**
371
+ * Get tick interval count
372
+ * @private
373
+ * @param {number} size Total data size
374
+ * @returns {number}
375
+ */
376
+ tickInterval(size) {
377
+ const { outerTickSize, tickOffset, tickValues } = this.config;
378
+ let interval;
379
+ if (this.params.isCategory) {
380
+ const scale = this.params.owner.scale.zoom ?? this.helper.scale;
381
+ interval = tickOffset * 2 || Math.abs(scale(1) - scale(0));
382
+ } else {
383
+ const scale = this.params.owner.scale.zoom ?? this.helper.scale;
384
+ interval = (this.g ? this.g.select("path.domain").node().getTotalLength() - outerTickSize * 2 : Math.abs(scale.range()[1] - scale.range()[0])) / (size || this.g?.selectAll("line").size() || 1);
385
+ if (tickValues) for (let i = 0; i < tickValues.length - 1; i++) {
386
+ const intervalByValue = scale(tickValues[i + 1]) - scale(tickValues[i]);
387
+ if (intervalByValue && intervalByValue < interval) interval = intervalByValue;
388
+ }
389
+ }
390
+ return interval === Infinity ? 0 : interval;
391
+ }
392
+ ticks(...args) {
393
+ const { config } = this;
394
+ if (!args.length) return config.tickArguments;
395
+ config.tickArguments = toArray(args);
396
+ return this;
397
+ }
398
+ tickCulling(culling) {
399
+ const { config } = this;
400
+ if (!arguments.length) return config.tickCulling;
401
+ config.tickCulling = culling;
402
+ return this;
403
+ }
404
+ tickValues(x) {
405
+ const { config } = this;
406
+ if (isFunction(x)) config.tickValues = () => x(this.helper.scale.domain());
407
+ else {
408
+ if (!arguments.length) return config.tickValues;
409
+ config.tickValues = x;
410
+ }
411
+ return this;
412
+ }
413
+ setTransition(t) {
414
+ this.config.transition = t;
415
+ return this;
416
+ }
417
+ };
418
+ //#endregion
551
419
  export { AxisRenderer as default };