billboard.js 4.1.5 → 4.2.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. package/dist/billboard.css +87 -1
  2. package/dist/billboard.js +11000 -6970
  3. package/dist/billboard.min.css +2 -2
  4. package/dist/billboard.min.js +19 -19
  5. package/dist/billboard.pkgd.js +22584 -14102
  6. package/dist/billboard.pkgd.min.js +37 -37
  7. package/dist/billboard.react.js +5 -5
  8. package/dist/billboard.react.min.js +2 -2
  9. package/dist/billboard.worker.js +1 -1
  10. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-sparkline.js +21 -4
  13. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  14. package/dist/plugin/billboardjs-plugin-stanford.js +22 -13
  15. package/dist/plugin/billboardjs-plugin-stanford.min.js +4 -4
  16. package/dist/plugin/billboardjs-plugin-tableview.js +20 -3
  17. package/dist/plugin/billboardjs-plugin-tableview.min.js +4 -4
  18. package/dist/plugin/billboardjs-plugin-textoverlap.js +2 -2
  19. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  20. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +1689 -1252
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +8 -8
  22. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2288 -1012
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +10 -10
  24. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6350 -2390
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -18
  26. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +1310 -1006
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +10 -10
  28. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +1293 -1006
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
  30. package/dist/theme/dark.css +90 -1
  31. package/dist/theme/dark.min.css +2 -2
  32. package/dist/theme/datalab.css +87 -1
  33. package/dist/theme/datalab.min.css +2 -2
  34. package/dist/theme/graph.css +87 -1
  35. package/dist/theme/graph.min.css +2 -2
  36. package/dist/theme/insight.css +87 -1
  37. package/dist/theme/insight.min.css +2 -2
  38. package/dist/theme/modern.css +87 -1
  39. package/dist/theme/modern.min.css +2 -2
  40. package/dist-esm/Chart/Chart.js +5 -5
  41. package/dist-esm/Chart/api/axis.js +2 -3
  42. package/dist-esm/Chart/api/category.js +2 -3
  43. package/dist-esm/Chart/api/chart.js +2 -3
  44. package/dist-esm/Chart/api/color.js +2 -3
  45. package/dist-esm/Chart/api/data.js +3 -4
  46. package/dist-esm/Chart/api/export.js +3 -4
  47. package/dist-esm/Chart/api/flow.js +3 -4
  48. package/dist-esm/Chart/api/focus.js +5 -3
  49. package/dist-esm/Chart/api/grid.js +2 -3
  50. package/dist-esm/Chart/api/group.js +2 -3
  51. package/dist-esm/Chart/api/legend.js +1 -2
  52. package/dist-esm/Chart/api/load.js +3 -4
  53. package/dist-esm/Chart/api/regions.js +3 -4
  54. package/dist-esm/Chart/api/selection.js +3 -4
  55. package/dist-esm/Chart/api/show.js +2 -3
  56. package/dist-esm/Chart/api/stubs.js +3 -4
  57. package/dist-esm/Chart/api/subchart.js +4 -5
  58. package/dist-esm/Chart/api/tooltip.js +28 -9
  59. package/dist-esm/Chart/api/x.js +2 -3
  60. package/dist-esm/Chart/api/zoom.js +6 -7
  61. package/dist-esm/ChartInternal/Axis/Axis.js +5 -6
  62. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +9 -7
  63. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +39 -11
  64. package/dist-esm/ChartInternal/ChartInternal.js +39 -24
  65. package/dist-esm/ChartInternal/data/convert.helper.js +2 -3
  66. package/dist-esm/ChartInternal/data/convert.js +3 -4
  67. package/dist-esm/ChartInternal/data/data.js +18 -11
  68. package/dist-esm/ChartInternal/data/load.js +4 -5
  69. package/dist-esm/ChartInternal/interactions/drag.js +3 -4
  70. package/dist-esm/ChartInternal/interactions/eventrect.js +4 -5
  71. package/dist-esm/ChartInternal/interactions/flow.js +3 -4
  72. package/dist-esm/ChartInternal/interactions/interaction.js +14 -13
  73. package/dist-esm/ChartInternal/interactions/subchart.js +5 -6
  74. package/dist-esm/ChartInternal/interactions/zoom.js +4 -5
  75. package/dist-esm/ChartInternal/internals/category.js +2 -3
  76. package/dist-esm/ChartInternal/internals/class.js +5 -5
  77. package/dist-esm/ChartInternal/internals/clip.js +2 -3
  78. package/dist-esm/ChartInternal/internals/color.js +4 -5
  79. package/dist-esm/ChartInternal/internals/domain.js +7 -7
  80. package/dist-esm/ChartInternal/internals/format.js +3 -4
  81. package/dist-esm/ChartInternal/internals/grid.js +4 -5
  82. package/dist-esm/ChartInternal/internals/legend.js +7 -7
  83. package/dist-esm/ChartInternal/internals/redraw.js +8 -8
  84. package/dist-esm/ChartInternal/internals/region.js +4 -5
  85. package/dist-esm/ChartInternal/internals/scale.js +2 -3
  86. package/dist-esm/ChartInternal/internals/selection.js +3 -4
  87. package/dist-esm/ChartInternal/internals/size.axis.js +2 -3
  88. package/dist-esm/ChartInternal/internals/size.js +8 -9
  89. package/dist-esm/ChartInternal/internals/style.js +4 -5
  90. package/dist-esm/ChartInternal/internals/subchart.util.js +2 -3
  91. package/dist-esm/ChartInternal/internals/text.arc.js +3 -4
  92. package/dist-esm/ChartInternal/internals/text.js +22 -23
  93. package/dist-esm/ChartInternal/internals/text.util.js +4 -5
  94. package/dist-esm/ChartInternal/internals/title.js +4 -5
  95. package/dist-esm/ChartInternal/internals/tooltip.js +20 -20
  96. package/dist-esm/ChartInternal/internals/transform.js +5 -6
  97. package/dist-esm/ChartInternal/internals/type.js +78 -11
  98. package/dist-esm/ChartInternal/shape/arc.js +5 -6
  99. package/dist-esm/ChartInternal/shape/area.js +4 -5
  100. package/dist-esm/ChartInternal/shape/bar.js +5 -6
  101. package/dist-esm/ChartInternal/shape/boxplot.js +111 -0
  102. package/dist-esm/ChartInternal/shape/bubble.js +2 -3
  103. package/dist-esm/ChartInternal/shape/bullet.js +213 -0
  104. package/dist-esm/ChartInternal/shape/candlestick.js +5 -6
  105. package/dist-esm/ChartInternal/shape/core/barRadius.js +2 -3
  106. package/dist-esm/ChartInternal/shape/core/boxplot.js +192 -0
  107. package/dist-esm/ChartInternal/shape/core/bubble.js +4 -5
  108. package/dist-esm/ChartInternal/shape/core/bullet.js +528 -0
  109. package/dist-esm/ChartInternal/shape/core/candlestick.js +2 -3
  110. package/dist-esm/ChartInternal/shape/core/dataRegion.js +2 -3
  111. package/dist-esm/ChartInternal/shape/core/geometry.js +2 -3
  112. package/dist-esm/ChartInternal/shape/core/heatmap.js +453 -0
  113. package/dist-esm/ChartInternal/shape/core/path.js +2 -3
  114. package/dist-esm/ChartInternal/shape/core/point.js +2 -3
  115. package/dist-esm/ChartInternal/shape/core/sankey.js +576 -0
  116. package/dist-esm/ChartInternal/shape/core/treemap.js +2 -3
  117. package/dist-esm/ChartInternal/shape/funnel.js +45 -6
  118. package/dist-esm/ChartInternal/shape/gauge.js +3 -4
  119. package/dist-esm/ChartInternal/shape/heatmap.js +144 -0
  120. package/dist-esm/ChartInternal/shape/line.js +7 -8
  121. package/dist-esm/ChartInternal/shape/point.js +5 -6
  122. package/dist-esm/ChartInternal/shape/polar.js +3 -4
  123. package/dist-esm/ChartInternal/shape/radar.js +19 -7
  124. package/dist-esm/ChartInternal/shape/sankey.js +154 -0
  125. package/dist-esm/ChartInternal/shape/shape.js +7 -7
  126. package/dist-esm/ChartInternal/shape/treemap.js +8 -5
  127. package/dist-esm/canvas/CanvasAxisRenderer.js +12 -315
  128. package/dist-esm/canvas/CanvasEngine.js +2 -3
  129. package/dist-esm/canvas/CanvasPainter.js +2 -3
  130. package/dist-esm/canvas/CanvasRenderer.js +38 -408
  131. package/dist-esm/canvas/CanvasTheme.js +28 -8
  132. package/dist-esm/canvas/HitDetector.js +20 -24
  133. package/dist-esm/canvas/axisTicks.js +5 -6
  134. package/dist-esm/canvas/boxplot.js +201 -0
  135. package/dist-esm/canvas/bullet.js +212 -0
  136. package/dist-esm/canvas/classes.js +2 -3
  137. package/dist-esm/canvas/color.js +2 -3
  138. package/dist-esm/canvas/flow.js +190 -0
  139. package/dist-esm/canvas/geometry.js +2 -3
  140. package/dist-esm/canvas/grid.js +206 -0
  141. package/dist-esm/canvas/heatmap.js +141 -0
  142. package/dist-esm/canvas/labels.js +3 -4
  143. package/dist-esm/canvas/pointPattern.js +2 -3
  144. package/dist-esm/canvas/sankey.js +137 -0
  145. package/dist-esm/canvas/selection.js +473 -0
  146. package/dist-esm/canvas/subchart.js +814 -0
  147. package/dist-esm/canvas/treemap.js +100 -0
  148. package/dist-esm/canvas/util.js +2 -3
  149. package/dist-esm/config/Options/Options.js +3 -4
  150. package/dist-esm/config/Options/axis/axis.js +2 -3
  151. package/dist-esm/config/Options/axis/x.js +2 -3
  152. package/dist-esm/config/Options/axis/y.js +2 -3
  153. package/dist-esm/config/Options/axis/y2.js +14 -3
  154. package/dist-esm/config/Options/common/boost.js +2 -3
  155. package/dist-esm/config/Options/common/color.js +2 -3
  156. package/dist-esm/config/Options/common/grid.js +2 -3
  157. package/dist-esm/config/Options/common/legend.js +2 -3
  158. package/dist-esm/config/Options/common/main.js +2 -3
  159. package/dist-esm/config/Options/common/point.js +2 -3
  160. package/dist-esm/config/Options/common/title.js +2 -3
  161. package/dist-esm/config/Options/common/tooltip.js +2 -3
  162. package/dist-esm/config/Options/data/axis.js +2 -3
  163. package/dist-esm/config/Options/data/data.js +49 -4
  164. package/dist-esm/config/Options/data/selection.js +2 -3
  165. package/dist-esm/config/Options/interaction/interaction.js +2 -3
  166. package/dist-esm/config/Options/interaction/subchart.js +2 -3
  167. package/dist-esm/config/Options/interaction/zoom.js +2 -3
  168. package/dist-esm/config/Options/shape/arc.js +2 -3
  169. package/dist-esm/config/Options/shape/area.js +2 -3
  170. package/dist-esm/config/Options/shape/bar.js +2 -3
  171. package/dist-esm/config/Options/shape/boxplot.js +106 -0
  172. package/dist-esm/config/Options/shape/bubble.js +2 -3
  173. package/dist-esm/config/Options/shape/bullet.js +177 -0
  174. package/dist-esm/config/Options/shape/candlestick.js +2 -3
  175. package/dist-esm/config/Options/shape/donut.js +2 -3
  176. package/dist-esm/config/Options/shape/funnel.js +2 -3
  177. package/dist-esm/config/Options/shape/gauge.js +2 -3
  178. package/dist-esm/config/Options/shape/heatmap.js +137 -0
  179. package/dist-esm/config/Options/shape/line.js +2 -3
  180. package/dist-esm/config/Options/shape/pie.js +2 -3
  181. package/dist-esm/config/Options/shape/polar.js +2 -3
  182. package/dist-esm/config/Options/shape/radar.js +2 -3
  183. package/dist-esm/config/Options/shape/sankey.js +116 -0
  184. package/dist-esm/config/Options/shape/scatter.js +2 -3
  185. package/dist-esm/config/Options/shape/spline.js +2 -3
  186. package/dist-esm/config/Options/shape/treemap.js +2 -3
  187. package/dist-esm/config/Store/Element.js +2 -3
  188. package/dist-esm/config/Store/State.js +3 -4
  189. package/dist-esm/config/Store/Store.js +2 -3
  190. package/dist-esm/config/classes.js +2 -4
  191. package/dist-esm/config/config.js +2 -3
  192. package/dist-esm/config/const.js +31 -23
  193. package/dist-esm/config/resolver/axis.core.js +4 -5
  194. package/dist-esm/config/resolver/axis.js +2 -3
  195. package/dist-esm/config/resolver/canvas.js +112 -911
  196. package/dist-esm/config/resolver/canvasBoxplot.js +49 -0
  197. package/dist-esm/config/resolver/canvasBullet.js +29 -0
  198. package/dist-esm/config/resolver/canvasFlow.js +28 -0
  199. package/dist-esm/config/resolver/canvasGrid.js +27 -0
  200. package/dist-esm/config/resolver/canvasHeatmap.js +31 -0
  201. package/dist-esm/config/resolver/canvasSankey.js +31 -0
  202. package/dist-esm/config/resolver/canvasSelection.js +30 -0
  203. package/dist-esm/config/resolver/canvasShape.js +13 -12
  204. package/dist-esm/config/resolver/canvasSubchart.js +30 -0
  205. package/dist-esm/config/resolver/canvasType.js +48 -0
  206. package/dist-esm/config/resolver/category.js +3 -4
  207. package/dist-esm/config/resolver/customType.js +58 -0
  208. package/dist-esm/config/resolver/export.js +3 -4
  209. package/dist-esm/config/resolver/flow.js +5 -6
  210. package/dist-esm/config/resolver/grid.js +6 -7
  211. package/dist-esm/config/resolver/interaction/selection.js +6 -7
  212. package/dist-esm/config/resolver/interaction/subchart.js +6 -7
  213. package/dist-esm/config/resolver/interaction/zoom.js +6 -7
  214. package/dist-esm/config/resolver/regions.js +5 -6
  215. package/dist-esm/config/resolver/shape/arc.helpers.js +5 -6
  216. package/dist-esm/config/resolver/shape/area.js +3 -4
  217. package/dist-esm/config/resolver/shape/axis.helpers.js +2 -3
  218. package/dist-esm/config/resolver/shape/bar.js +5 -6
  219. package/dist-esm/config/resolver/shape/boxplot.js +30 -0
  220. package/dist-esm/config/resolver/shape/bubble.js +5 -6
  221. package/dist-esm/config/resolver/shape/bullet.js +23 -0
  222. package/dist-esm/config/resolver/shape/candlestick.js +5 -6
  223. package/dist-esm/config/resolver/shape/donut.js +2 -3
  224. package/dist-esm/config/resolver/shape/funnel.js +7 -6
  225. package/dist-esm/config/resolver/shape/gauge.js +4 -5
  226. package/dist-esm/config/resolver/shape/heatmap.js +23 -0
  227. package/dist-esm/config/resolver/shape/line.js +2 -3
  228. package/dist-esm/config/resolver/shape/pie.js +3 -4
  229. package/dist-esm/config/resolver/shape/polar.js +4 -5
  230. package/dist-esm/config/resolver/shape/radar.js +5 -6
  231. package/dist-esm/config/resolver/shape/sankey.js +23 -0
  232. package/dist-esm/config/resolver/shape/scatter.js +4 -5
  233. package/dist-esm/config/resolver/shape/treemap.js +4 -5
  234. package/dist-esm/core.js +5 -6
  235. package/dist-esm/index.canvas.js +13 -9
  236. package/dist-esm/index.esm.js +6 -2
  237. package/dist-esm/module/Cache.js +2 -3
  238. package/dist-esm/module/browser.js +2 -3
  239. package/dist-esm/module/dsv.js +2 -3
  240. package/dist-esm/module/error.js +23 -16
  241. package/dist-esm/module/generator.js +3 -4
  242. package/dist-esm/module/sanitize.js +2 -3
  243. package/dist-esm/module/util/brush.js +2 -3
  244. package/dist-esm/module/util/dom.js +3 -4
  245. package/dist-esm/module/util/object.js +13 -6
  246. package/dist-esm/module/util/type-checks.js +2 -3
  247. package/dist-esm/module/worker.js +2 -3
  248. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +6 -10
  249. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +10 -18
  250. package/dist-esm/plugin/billboardjs-plugin-stanford.js +17 -45
  251. package/dist-esm/plugin/billboardjs-plugin-tableview.js +10 -18
  252. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +9 -16
  253. package/dist-esm/react/index.js +2 -3
  254. package/package.json +44 -44
  255. package/src/Chart/Chart.ts +1 -0
  256. package/src/Chart/api/focus.ts +3 -0
  257. package/src/Chart/api/subchart.ts +1 -1
  258. package/src/Chart/api/tooltip.ts +54 -15
  259. package/src/ChartInternal/Axis/AxisRenderer.ts +9 -2
  260. package/src/ChartInternal/Axis/AxisRendererHelper.ts +42 -8
  261. package/src/ChartInternal/ChartInternal.ts +46 -19
  262. package/src/ChartInternal/data/IData.ts +13 -0
  263. package/src/ChartInternal/data/data.ts +26 -5
  264. package/src/ChartInternal/data/load.ts +2 -2
  265. package/src/ChartInternal/interactions/interaction.ts +15 -11
  266. package/src/ChartInternal/internals/class.ts +3 -2
  267. package/src/ChartInternal/internals/domain.ts +4 -2
  268. package/src/ChartInternal/internals/format.ts +3 -1
  269. package/src/ChartInternal/internals/legend.ts +2 -1
  270. package/src/ChartInternal/internals/redraw.ts +3 -3
  271. package/src/ChartInternal/internals/size.ts +5 -3
  272. package/src/ChartInternal/internals/text.ts +24 -28
  273. package/src/ChartInternal/internals/tooltip.ts +35 -14
  274. package/src/ChartInternal/internals/transform.ts +2 -2
  275. package/src/ChartInternal/internals/type.ts +101 -9
  276. package/src/ChartInternal/shape/boxplot.ts +172 -0
  277. package/src/ChartInternal/shape/bullet.ts +323 -0
  278. package/src/ChartInternal/shape/core/boxplot.ts +241 -0
  279. package/src/ChartInternal/shape/core/bullet.ts +734 -0
  280. package/src/ChartInternal/shape/core/heatmap.ts +665 -0
  281. package/src/ChartInternal/shape/core/sankey.ts +782 -0
  282. package/src/ChartInternal/shape/funnel.ts +73 -2
  283. package/src/ChartInternal/shape/heatmap.ts +236 -0
  284. package/src/ChartInternal/shape/radar.ts +30 -1
  285. package/src/ChartInternal/shape/sankey.ts +242 -0
  286. package/src/ChartInternal/shape/shape.ts +1 -1
  287. package/src/ChartInternal/shape/treemap.ts +10 -0
  288. package/src/Plugin/stanford/index.ts +1 -28
  289. package/src/canvas/CanvasAxisRenderer.ts +35 -574
  290. package/src/canvas/CanvasRenderer.ts +68 -640
  291. package/src/canvas/CanvasTheme.ts +92 -6
  292. package/src/canvas/HitDetector.ts +30 -28
  293. package/src/canvas/boxplot.ts +230 -0
  294. package/src/canvas/bullet.ts +269 -0
  295. package/src/canvas/flow.ts +237 -0
  296. package/src/canvas/grid.ts +359 -0
  297. package/src/canvas/heatmap.ts +147 -0
  298. package/src/canvas/labels.ts +3 -1
  299. package/src/canvas/sankey.ts +151 -0
  300. package/src/canvas/selection.ts +626 -0
  301. package/src/canvas/subchart.ts +1292 -0
  302. package/src/canvas/treemap.ts +142 -0
  303. package/src/config/Options/axis/y2.ts +13 -0
  304. package/src/config/Options/data/data.ts +47 -1
  305. package/src/config/Options/shape/boxplot.ts +95 -0
  306. package/src/config/Options/shape/bullet.ts +170 -0
  307. package/src/config/Options/shape/heatmap.ts +125 -0
  308. package/src/config/Options/shape/sankey.ts +108 -0
  309. package/src/config/Store/State.ts +1 -1
  310. package/src/config/classes.ts +0 -1
  311. package/src/config/const.ts +30 -21
  312. package/src/config/resolver/canvas.ts +126 -1290
  313. package/src/config/resolver/canvasBoxplot.ts +42 -0
  314. package/src/config/resolver/canvasBullet.ts +20 -0
  315. package/src/config/resolver/canvasFlow.ts +18 -0
  316. package/src/config/resolver/canvasGrid.ts +17 -0
  317. package/src/config/resolver/canvasHeatmap.ts +23 -0
  318. package/src/config/resolver/canvasSankey.ts +23 -0
  319. package/src/config/resolver/canvasSelection.ts +20 -0
  320. package/src/config/resolver/canvasShape.ts +6 -1
  321. package/src/config/resolver/canvasSubchart.ts +20 -0
  322. package/src/config/resolver/canvasType.ts +51 -0
  323. package/src/config/resolver/customType.ts +69 -0
  324. package/src/config/resolver/shape/boxplot.ts +31 -0
  325. package/src/config/resolver/shape/bullet.ts +18 -0
  326. package/src/config/resolver/shape/funnel.ts +8 -2
  327. package/src/config/resolver/shape/heatmap.ts +18 -0
  328. package/src/config/resolver/shape/index.ts +4 -0
  329. package/src/config/resolver/shape/sankey.ts +18 -0
  330. package/src/index.canvas.ts +9 -3
  331. package/src/index.esm.ts +4 -0
  332. package/src/index.ts +34 -0
  333. package/src/module/error.ts +32 -18
  334. package/src/module/util/object.ts +26 -1
  335. package/src/scss/billboard.scss +106 -0
  336. package/src/scss/theme/dark.scss +110 -0
  337. package/src/scss/theme/datalab.scss +106 -0
  338. package/src/scss/theme/graph.scss +106 -0
  339. package/src/scss/theme/insight.scss +106 -0
  340. package/src/scss/theme/modern.scss +106 -0
  341. package/types/bb.d.ts +4 -0
  342. package/types/canvas.d.ts +3 -0
  343. package/types/chart.d.ts +5 -0
  344. package/types/index.d.ts +4 -0
  345. package/types/options.d.ts +10 -1
  346. package/types/options.shape.d.ts +431 -0
  347. package/types/types.d.ts +4 -0
@@ -0,0 +1,734 @@
1
+ /**
2
+ * Copyright (c) 2017 ~ present NAVER Corp.
3
+ * billboard.js project is licensed under the MIT license
4
+ */
5
+ import {scaleLinear as d3ScaleLinear} from "d3-scale";
6
+ import {getElementPos, isArray, isFunction, isNumber, isObject} from "../../../module/util";
7
+ import type {IBulletData} from "../../data/IData";
8
+ import {getTextPos} from "../../internals/text.util";
9
+
10
+ // class names of the bullet elements
11
+ export const $BULLET = {
12
+ bullet: "bb-bullet",
13
+ chartBullet: "bb-chart-bullet",
14
+ chartBullets: "bb-chart-bullets",
15
+ bulletRange: "bb-bullet-range",
16
+ bulletMeasure: "bb-bullet-measure",
17
+ bulletTarget: "bb-bullet-target",
18
+ bulletAxis: "bb-bullet-axis",
19
+ bulletTitle: "bb-bullet-title"
20
+ };
21
+
22
+ export interface IBulletAxis {
23
+ scale: any;
24
+ count: number;
25
+ ticks: number[];
26
+ format: (value: number) => string;
27
+ // what the axis is drawn with: when it is the same, redrawing it would only replace its text nodes
28
+ key: string;
29
+ }
30
+
31
+ export interface IBulletLayout {
32
+ rows: IBulletData[];
33
+ area: {left: number, top: number, width: number, height: number};
34
+ isRotated: boolean;
35
+ axisSize: number;
36
+ band: number;
37
+ bandInner: number;
38
+ axisLen: number;
39
+ // axis (scale, ticks, format) shared by the rows with the same domain
40
+ axes: Map<string, IBulletAxis>;
41
+ }
42
+
43
+ export interface IBulletGeometry {
44
+ area: {left: number, top: number};
45
+ offset: {x: number, y: number};
46
+ // fill is the color given by bullet.range.colors, null for the theme default at position t (0 ~ 1)
47
+ ranges: {x: number, y: number, width: number, height: number, fill: string | null, t: number}[];
48
+ isDot: boolean;
49
+ measure: {[key: string]: number};
50
+ color: string;
51
+ // comparative target markers: one per target value
52
+ targets: {x1: number, x2: number, y1: number, y2: number}[];
53
+ axis: (IBulletAxis & {rotated: boolean, x: number, y: number}) | null;
54
+ // anchor of the data label (beside the measure, or above it when rotated), and the measure center
55
+ label: {x: number, y: number, center: {x: number, y: number}};
56
+ // title of the row, relative to the row origin: null when the titles are not shown
57
+ title: {text: string, x: number, y: number, anchor: "end" | "middle"} | null;
58
+ }
59
+
60
+ // room kept for the first/last tick labels of the horizontal axis
61
+ const AXIS_EDGE = 16;
62
+
63
+ // a number that can be drawn: NaN or Infinity would make every position of its row NaN
64
+ const isValid = (v): v is number => Number.isFinite(v);
65
+
66
+ // the property of the object itself: "constructor" or "toString" as a data id is not a key
67
+ const own = (obj, key: string) =>
68
+ obj && Object.prototype.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
69
+
70
+ /**
71
+ * Get the min and max of the values, and 0.
72
+ * (not Math.min(...values): too many values are too many arguments)
73
+ * @param {Array} values Values
74
+ * @returns {Array} Min and max
75
+ * @private
76
+ */
77
+ function _getExtent(values: number[]): [number, number] {
78
+ let min = 0;
79
+ let max = 0;
80
+
81
+ values.forEach(v => {
82
+ min = Math.min(min, v);
83
+ max = Math.max(max, v);
84
+ });
85
+
86
+ return [min, max];
87
+ }
88
+
89
+ /**
90
+ * Get the title text of the given bullet row
91
+ * @param {string} id Data id
92
+ * @param {number} value Measure value
93
+ * @returns {string} Title text
94
+ * @private
95
+ */
96
+ function _getTitleText(id: string, value: number): string {
97
+ const {config, api} = this;
98
+ const text = config.bullet_title_text;
99
+ let resolved;
100
+
101
+ if (isFunction(text)) {
102
+ resolved = text.call(api, id, value);
103
+ } else if (isObject(text)) {
104
+ resolved = own(text, id);
105
+ }
106
+
107
+ // the same name as the legend and the tooltip, by default
108
+ return String(resolved ?? own(config.data_names, id) ?? id);
109
+ }
110
+
111
+ /**
112
+ * Get the space the titles of the rows take: the width of the widest one (horizontal),
113
+ * or the height of the line under the columns (rotated)
114
+ * @param {Array} rows Bullet rows
115
+ * @returns {number} Size in px
116
+ * @private
117
+ */
118
+ function _getTitleSize(rows: IBulletData[]): number {
119
+ const $$ = this;
120
+ const {config, cache, state: {isCanvasMode}, $el} = $$;
121
+
122
+ if (config.bullet_rotated) {
123
+ return 18;
124
+ }
125
+
126
+ const titles = rows.map(d => d.title);
127
+ const key = `bullet-title-${isCanvasMode}-${titles.join("\u0000")}`;
128
+ let width: number = cache.get(key) || 0;
129
+
130
+ if (!width && isCanvasMode && $$.canvasRenderer) {
131
+ const {ctx} = $$.canvasRenderer;
132
+
133
+ ctx.save();
134
+ ctx.font = $$.canvasTheme.style.bullet.titleFont;
135
+ width = titles.reduce((w, v) => Math.max(w, ctx.measureText(v).width), 0);
136
+ ctx.restore();
137
+ } else if (!width && !isCanvasMode && $el.bullet) {
138
+ const text = $el.bullet.append("text")
139
+ .attr("class", $BULLET.bulletTitle)
140
+ .style("visibility", "hidden");
141
+
142
+ titles.forEach(v => {
143
+ width = Math.max(width, text.text(v).node().getComputedTextLength?.() || 0);
144
+ });
145
+ text.remove();
146
+ }
147
+
148
+ if (width) {
149
+ cache.add(key, width);
150
+ } else {
151
+ // it can not be measured yet (not drawn): estimate from the characters
152
+ width = titles.reduce((n, v) => Math.max(n, v.length), 0) * 6.5;
153
+ }
154
+
155
+ // the gap to the plot
156
+ return Math.ceil(width) + 8;
157
+ }
158
+
159
+ /**
160
+ * Get the plot area of the bullets
161
+ * @param {Array} rows Bullet rows, when the caller has them already
162
+ * @returns {object} size object
163
+ * @private
164
+ */
165
+ function _getArea(
166
+ rows?: IBulletData[]
167
+ ): {width: number, height: number, left: number, top: number} {
168
+ const $$ = this;
169
+ const {config, state: {current: {width, height}, isCanvasMode, isLegendRight}} = $$;
170
+ const padding = $$.getCurrentPadding();
171
+ // canvas mode draws the legend as HTML outside of its drawing surface: only the gap is needed
172
+ const legendHeight = config.legend_show && config.legend_position === "bottom" ?
173
+ (isCanvasMode ? 0 : $$.getLegendHeight()) + 10 :
174
+ 0;
175
+ const surfaceHeight = isCanvasMode ? $$.getCanvasSurfaceHeight() : height;
176
+
177
+ // keep room for the first/last tick labels of the horizontal axis
178
+ const edge = config.bullet_axis_show && !config.bullet_rotated ? AXIS_EDGE : 0;
179
+
180
+ // the right legend sits beside the plot: same spacing as the axis types
181
+ const legendRight = config.legend_show && isLegendRight ?
182
+ $$.getLegendWidth() + (config.padding?.mode === "fit" ? 0 : 20) :
183
+ 0;
184
+
185
+ const hasLabel = !config.bullet_rotated && config.bullet_label_show && $$.hasDataLabel();
186
+ const list: IBulletData[] = hasLabel || config.bullet_title_show ?
187
+ (rows ?? $$.getBulletData()) :
188
+ [];
189
+
190
+ // the label of a row is past the end of the plot, when its bar ends at the axis end:
191
+ // the value reaches the max of the scale (or is above it), or nothing of it is above 0
192
+ // (a minus sign needs room as well)
193
+ const labelRoom = hasLabel && list.some(d => d.domainMax <= 0 || d.value >= d.domainMax) ?
194
+ 14 :
195
+ 0;
196
+
197
+ // the titles are beside the plot, or under it when rotated
198
+ const titleSize = config.bullet_title_show ? _getTitleSize.call($$, list) : 0;
199
+ const titleWidth = config.bullet_rotated ? 0 : titleSize;
200
+ const titleHeight = config.bullet_rotated ? titleSize : 0;
201
+
202
+ // canvas title padding ends at the text baseline, SVG one also covers the descent
203
+ const top = padding.top + (isCanvasMode ? $$.getCanvasTitleDescent?.() || 0 : 0);
204
+
205
+ return {
206
+ width: Math.max(
207
+ 0,
208
+ width - padding.left - padding.right - edge * 2 - labelRoom - titleWidth - legendRight
209
+ ),
210
+ height: Math.max(0, surfaceHeight - legendHeight - top - padding.bottom - titleHeight),
211
+ left: padding.left + edge + titleWidth,
212
+ top
213
+ };
214
+ }
215
+
216
+ /**
217
+ * Get the space (in px) reserved for the axis of each bullet
218
+ * @returns {number} axis size
219
+ * @private
220
+ */
221
+ function _getAxisSize(): number {
222
+ const {config} = this;
223
+
224
+ return config.bullet_axis_show ? (config.bullet_rotated ? 34 : 20) : 0;
225
+ }
226
+
227
+ /**
228
+ * Resolve the qualitative range thresholds for the given bullet row
229
+ * @param {string} id Data id
230
+ * @param {number} value Measure value
231
+ * @returns {Array} Ascending range thresholds
232
+ * @private
233
+ */
234
+ function _getRanges(id: string, value: number): number[] {
235
+ const ranges = this.config.bullet_ranges;
236
+ let resolved: number[] = [];
237
+
238
+ if (isFunction(ranges)) {
239
+ resolved = ranges.call(this.api, id, value) || [];
240
+ } else if (isArray(ranges)) {
241
+ resolved = ranges;
242
+ } else if (isObject(ranges) && isArray(ranges[id])) {
243
+ resolved = ranges[id];
244
+ }
245
+
246
+ return resolved
247
+ .filter(isValid)
248
+ .sort((a, b) => a - b);
249
+ }
250
+
251
+ /**
252
+ * Resolve the comparative target values for the given bullet row
253
+ * @param {string} id Data id
254
+ * @param {number} value Measure value
255
+ * @returns {Array} Target values: empty when there is none
256
+ * @private
257
+ */
258
+ function _getTargets(id: string, value: number): number[] {
259
+ const target = this.config.bullet_target;
260
+ let resolved;
261
+
262
+ if (isFunction(target)) {
263
+ resolved = target.call(this.api, id, value);
264
+ } else if (isArray(target) || isValid(target)) {
265
+ resolved = target;
266
+ } else if (isObject(target)) {
267
+ resolved = own(target, id);
268
+ }
269
+
270
+ return (isArray(resolved) ? resolved : [resolved]).filter(isValid);
271
+ }
272
+
273
+ /**
274
+ * Get the fill color given by bullet.range.colors for the qualitative range band
275
+ * @param {number} index Band index (0 = smallest range)
276
+ * @param {number} length Total number of bands
277
+ * @returns {string|null} Color string, or null to use the default grayscale of the theme
278
+ * @private
279
+ */
280
+ function _getRangeColor(index: number, length: number): string | null {
281
+ const colors = this.config.bullet_range_colors;
282
+
283
+ if (isFunction(colors)) {
284
+ return colors.call(this.api, index, length);
285
+ } else if (isArray(colors) && colors[index]) {
286
+ return colors[index];
287
+ }
288
+
289
+ return null;
290
+ }
291
+
292
+ /**
293
+ * Get the axis (scale, ticks, format) for the given domain, shared between rows of same domain.
294
+ * @param {IBulletLayout} layout Bullet layout
295
+ * @param {number} domainMin Domain min value
296
+ * @param {number} domainMax Domain max value
297
+ * @returns {object} Axis
298
+ * @private
299
+ */
300
+ function _getAxis(layout: IBulletLayout, domainMin: number, domainMax: number): IBulletAxis {
301
+ const {config, api} = this;
302
+ const {axes, axisLen, isRotated} = layout;
303
+ const key = `${domainMin}|${domainMax}`;
304
+ let axis = axes.get(key);
305
+
306
+ if (!axis) {
307
+ const scale = d3ScaleLinear()
308
+ .domain([domainMin, domainMax])
309
+ .range(isRotated ? [axisLen, 0] : [0, axisLen]);
310
+ const {
311
+ bullet_axis_tick_count: tickCount,
312
+ bullet_axis_tick_values: tickValues,
313
+ bullet_axis_tick_format: tickFormat
314
+ } = config;
315
+ // the count is a hint for d3 to choose the ticks: it is approximate,
316
+ // and there is no use of more ticks than the pixels of the axis
317
+ const count = isValid(tickCount) && tickCount > 0 ?
318
+ Math.min(tickCount, Math.max(2, axisLen)) :
319
+ Math.max(2, Math.floor(axisLen / (isRotated ? 40 : 60)));
320
+ const [min, max] = [domainMin, domainMax];
321
+ // the given values out of the domain would be drawn out of the axis
322
+ const ticks: number[] = isArray(tickValues) ?
323
+ tickValues.filter(v => isValid(v) && v >= min && v <= max) :
324
+ scale.ticks(count);
325
+ const format: (value: number) => string = isFunction(tickFormat) ?
326
+ (value: number) => String(tickFormat.call(api, value)) :
327
+ scale.tickFormat(count);
328
+
329
+ axis = {
330
+ scale,
331
+ count,
332
+ ticks,
333
+ format,
334
+ // the rows of the same domain share the axis: its labels are made once
335
+ key: `${scale.domain()}|${scale.range()}|${ticks}|${ticks.map(format)}`
336
+ };
337
+ axes.set(key, axis);
338
+ }
339
+
340
+ return axis;
341
+ }
342
+
343
+ /**
344
+ * Get the layout shared by all bullet rows. Computed once per draw.
345
+ * @returns {object} Bullet layout
346
+ * @private
347
+ */
348
+ function _getLayout(): IBulletLayout {
349
+ const $$ = this;
350
+ const {config} = $$;
351
+ const rows: IBulletData[] = $$.getBulletData();
352
+ const area = _getArea.call($$, rows);
353
+ const isRotated = config.bullet_rotated;
354
+ const axisSize = _getAxisSize.call($$);
355
+ const band = (isRotated ? area.width : area.height) / (rows.length || 1);
356
+
357
+ return {
358
+ rows,
359
+ area,
360
+ isRotated,
361
+ axisSize,
362
+ band,
363
+ bandInner: Math.max(0, band - config.bullet_padding - axisSize),
364
+ axisLen: isRotated ? area.height : area.width,
365
+ axes: new Map()
366
+ };
367
+ }
368
+
369
+ /**
370
+ * Get the geometry of a single bullet row, relative to the row origin.
371
+ * Shared by the SVG and the canvas renderer.
372
+ * @param {object} d Bullet row data
373
+ * @param {object} layout Bullet layout
374
+ * @returns {object} Row geometry
375
+ * @private
376
+ */
377
+ function _getRowGeometry(d: IBulletData, layout: IBulletLayout): IBulletGeometry {
378
+ const $$ = this;
379
+ const {config} = $$;
380
+ const {area, isRotated, axisSize, band, bandInner, axisLen} = layout;
381
+ const {height, left, top} = area;
382
+ const {domainMin, domainMax} = d;
383
+ const measureThickness = bandInner * config.bullet_width_ratio;
384
+ const targetLen = bandInner * config.bullet_width_target_ratio;
385
+ const scale = (v: number): number => ((v - domainMin) / (domainMax - domainMin)) * axisLen;
386
+ // a position within the axis: the bar of a value out of the given axis range ends at its edge
387
+ const pos = (v: number): number => Math.min(Math.max(scale(v), 0), axisLen);
388
+ // the measure is drawn from the zero position to the value
389
+ // (the nearest end of the axis, when its range does not include 0)
390
+ const zero = pos(0);
391
+
392
+ // qualitative range bands (largest first so smaller ones overlap on top)
393
+ const ranges = d.ranges.map((value, index) => ({value, index}))
394
+ .sort((a, b) => b.value - a.value)
395
+ .map(({value, index}) => {
396
+ const len = pos(value);
397
+
398
+ return {
399
+ ...(isRotated ?
400
+ {x: 0, y: height - len, width: bandInner, height: len} :
401
+ {x: 0, y: 0, width: len, height: bandInner}),
402
+ fill: _getRangeColor.call($$, index, d.ranges.length),
403
+ // the default grayscale: smaller range (index 0) is the darkest
404
+ t: index / Math.max(d.ranges.length - 1, 1)
405
+ };
406
+ });
407
+
408
+ // measure (bar or dot)
409
+ const isDot = config.bullet_type === "dot";
410
+ const markerSize = config.bullet_marker_size || measureThickness / 2;
411
+ const len = pos(d.value);
412
+ const isNegative = d.value < 0;
413
+ let measure;
414
+
415
+ if (isDot) {
416
+ measure = {
417
+ cx: isRotated ? bandInner / 2 : len,
418
+ cy: isRotated ? height - len : bandInner / 2,
419
+ r: markerSize
420
+ };
421
+ } else {
422
+ const size = Math.abs(len - zero);
423
+
424
+ measure = isRotated ?
425
+ {
426
+ x: (bandInner - measureThickness) / 2,
427
+ y: height - Math.max(zero, len),
428
+ width: measureThickness,
429
+ height: size
430
+ } :
431
+ {
432
+ x: Math.min(zero, len),
433
+ y: (bandInner - measureThickness) / 2,
434
+ width: size,
435
+ height: measureThickness
436
+ };
437
+ }
438
+
439
+ // comparative target markers
440
+ // (a target out of the given axis range is not drawn: at the edge it would tell a wrong value)
441
+ const targets: IBulletGeometry["targets"] = d.targets
442
+ .filter(value => value >= domainMin && value <= domainMax)
443
+ .map(value => {
444
+ const at = scale(value);
445
+
446
+ return isRotated ?
447
+ {
448
+ x1: (bandInner - targetLen) / 2,
449
+ x2: (bandInner + targetLen) / 2,
450
+ y1: height - at,
451
+ y2: height - at
452
+ } :
453
+ {
454
+ x1: at,
455
+ x2: at,
456
+ y1: (bandInner - targetLen) / 2,
457
+ y2: (bandInner + targetLen) / 2
458
+ };
459
+ });
460
+
461
+ // data label: keep it clear of the dot marker
462
+ const gap = isDot ? markerSize : 0;
463
+ // the label of a negative value is at the zero position: the end of its measure can be
464
+ // at the edge of the plot, where there is no room for it
465
+ const labelPos = isNegative ? zero : len;
466
+ const label: IBulletGeometry["label"] = {
467
+ ...(isRotated ?
468
+ {x: bandInner / 2, y: height - labelPos - gap - 6} :
469
+ {x: labelPos + gap + 5, y: bandInner / 2}),
470
+ center: isDot ?
471
+ {x: measure.cx, y: measure.cy} :
472
+ {x: measure.x + measure.width / 2, y: measure.y + measure.height / 2}
473
+ };
474
+
475
+ // beside the plot, clear of the first tick label; under the column when rotated
476
+ const title: IBulletGeometry["title"] = config.bullet_title_show ?
477
+ (isRotated ?
478
+ {text: d.title, x: bandInner / 2, y: height + 13, anchor: "middle"} :
479
+ {text: d.title, x: -(axisSize ? AXIS_EDGE : 0) - 6, y: bandInner / 2, anchor: "end"}) :
480
+ null;
481
+
482
+ return {
483
+ area: {left, top},
484
+ offset: isRotated ? {x: d.index * band + axisSize, y: 0} : {x: 0, y: d.index * band},
485
+ ranges,
486
+ isDot,
487
+ measure,
488
+ color: $$.color(d),
489
+ targets,
490
+ title,
491
+ // quantitative scale axis
492
+ axis: axisSize ?
493
+ {
494
+ ..._getAxis.call($$, layout, domainMin, domainMax),
495
+ rotated: isRotated,
496
+ x: 0,
497
+ y: isRotated ? 0 : bandInner
498
+ } :
499
+ null,
500
+ label
501
+ };
502
+ }
503
+
504
+ /**
505
+ * How the data labels of a bullet differ from the other types.
506
+ * The shared data label code asks these through `getCustomTypeHooks()`.
507
+ * They are registered with the type name (registerCustomType()).
508
+ * @private
509
+ */
510
+ export const customTypeHooks = {
511
+ // the legend is placed beside its own plot, not by the size of an arc
512
+ ownLegendLayout: true,
513
+
514
+ // the label is not drawn with the color of the series
515
+ themeTextColor: true,
516
+
517
+ // beside the measure, or above it when rotated
518
+ textAnchor($$): string {
519
+ return $$.config.bullet_rotated || $$.config.data_labels.centered ? "middle" : "start";
520
+ },
521
+
522
+ // a bullet has one label, for its measure: the last value
523
+ labelData($$, d): IBulletData[] {
524
+ const last = d.values[d.values.length - 1];
525
+
526
+ return $$.config.bullet_label_show && last &&
527
+ (isNumber(last.value) || Boolean(last.value)) ?
528
+ [last] :
529
+ [];
530
+ },
531
+
532
+ // bullet.label.format takes precedence over data.labels.format
533
+ labelFormat($$): ((value: number, id: string) => unknown) | undefined {
534
+ const format = $$.config.bullet_label_format;
535
+
536
+ return isFunction(format) ? (value, id) => format.call($$.api, value, id) : undefined;
537
+ },
538
+
539
+ // a bullet is one row per data id, not a value per index: tooltip.show() addresses it so,
540
+ // and the tooltip is placed at its measure
541
+ tooltipTarget($$, args): {data: IBulletData[], point?: number[]} {
542
+ const rows: IBulletData[] = $$.getBulletData().filter(d => $$.isTargetToShow(d.id));
543
+ const data = args.data?.id ?
544
+ rows.filter(d => d.id === args.data.id) :
545
+ [rows[args.index]].filter(Boolean);
546
+
547
+ return {data, point: data[0] && $$.getBulletMeasureCenter(data[0])};
548
+ },
549
+
550
+ // points[0]: label anchor, points[1]: center of the measure
551
+ // Preserve current position when points unavailable (during hide transition)
552
+ textX($$, points, d, textElement): number {
553
+ return points ?
554
+ points[$$.config.data_labels.centered ? 1 : 0][0] + getTextPos.call($$, d, "x") :
555
+ getElementPos(textElement, "x");
556
+ },
557
+
558
+ // beside the measure the label is centered on the row, above it (rotated) it sits on y
559
+ textY($$, points, d, textElement, rect): number {
560
+ if (!points) {
561
+ return getElementPos(textElement, "y");
562
+ }
563
+
564
+ const centered = $$.config.data_labels.centered;
565
+ const y = points[centered ? 1 : 0][1];
566
+
567
+ return (centered || !$$.config.bullet_rotated ? y + rect.height / 2 - 3 : y) +
568
+ getTextPos.call($$, d, "y");
569
+ }
570
+ };
571
+
572
+ export default {
573
+ /**
574
+ * Whether the data belongs to the bullet type.
575
+ * @param {object} d Data object
576
+ * @returns {boolean}
577
+ * @private
578
+ */
579
+ isBulletType(d): boolean {
580
+ return this.isTypeOf(d, "bullet");
581
+ },
582
+
583
+ /**
584
+ * Get the plot area of the bullets
585
+ * @returns {object} Plot size and offset
586
+ * @private
587
+ */
588
+ getBulletSize(): {width: number, height: number, left: number, top: number} {
589
+ return _getArea.call(this);
590
+ },
591
+
592
+ /**
593
+ * Get the space the canvas title text takes below its baseline.
594
+ * SVG title padding includes it, but canvas title padding stops at the baseline.
595
+ * @returns {number} Title descent
596
+ * @private
597
+ */
598
+ getCanvasTitleDescent(): number {
599
+ const {config, canvasRenderer, canvasTheme} = this;
600
+
601
+ if (!config.title_text || !canvasRenderer) {
602
+ return 0;
603
+ }
604
+
605
+ const {ctx} = canvasRenderer;
606
+
607
+ ctx.save();
608
+ ctx.font = canvasTheme.style.title.font;
609
+
610
+ const descent = ctx.measureText(String(config.title_text)).fontBoundingBoxDescent || 0;
611
+
612
+ ctx.restore();
613
+
614
+ return descent;
615
+ },
616
+
617
+ /**
618
+ * Get bullet rows data
619
+ * @returns {Array} Bullet rows
620
+ * @private
621
+ */
622
+ getBulletData(): IBulletData[] {
623
+ const $$ = this;
624
+ const targets = $$.data.targets.filter($$.isBulletType.bind($$));
625
+
626
+ return targets.map((t, index) => {
627
+ // the measure is a single value: use the latest one (one that can not be drawn is 0)
628
+ const latest = Number(t.values[t.values.length - 1]?.value);
629
+ const value = isValid(latest) ? latest : 0;
630
+ const ranges = _getRanges.call($$, t.id, value);
631
+ const targets = _getTargets.call($$, t.id, value);
632
+ // by default the domain includes everything drawn, and 0 (the origin of the measure)
633
+ const [autoMin, autoMax] = _getExtent([value].concat(targets, ranges));
634
+ const {bullet_axis_min: min, bullet_axis_max: max} = $$.config;
635
+ let domainMin = isValid(min) ? min : autoMin;
636
+ let domainMax = isValid(max) ? max : autoMax;
637
+
638
+ // min and max that do not make a range are ignored
639
+ if (domainMin >= domainMax) {
640
+ domainMin = autoMin;
641
+ domainMax = autoMax;
642
+ }
643
+
644
+ if (domainMax === domainMin) {
645
+ domainMax = domainMin + 1;
646
+ }
647
+
648
+ // when no ranges given, generate 3 bands from the domain
649
+ const span = domainMax - domainMin;
650
+ const resolvedRanges = ranges.length ?
651
+ ranges :
652
+ [0.5, 0.75, 1].map(v => domainMin + span * v);
653
+
654
+ return {
655
+ id: t.id,
656
+ index,
657
+ x: index,
658
+ name: t.id,
659
+ value,
660
+ title: $$.config.bullet_title_show ? _getTitleText.call($$, t.id, value) : "",
661
+ ranges: resolvedRanges,
662
+ targets,
663
+ domainMin,
664
+ domainMax
665
+ };
666
+ });
667
+ },
668
+
669
+ /**
670
+ * Get the layout shared by all rows. Compute it once per draw and pass it to each row.
671
+ * @returns {object} Bullet layout
672
+ * @private
673
+ */
674
+ getBulletLayout(): IBulletLayout {
675
+ return _getLayout.call(this);
676
+ },
677
+
678
+ /**
679
+ * Get the center of the measure of a bullet row, in chart coordinates.
680
+ * @param {object} d Bullet row data
681
+ * @returns {Array} x, y coordinate
682
+ * @private
683
+ */
684
+ getBulletMeasureCenter(d: IBulletData): number[] {
685
+ const {area, offset, measure} = _getRowGeometry.call(this, d, _getLayout.call(this));
686
+ const [x, y] = "cx" in measure ?
687
+ [measure.cx, measure.cy] :
688
+ [measure.x + measure.width / 2, measure.y + measure.height / 2];
689
+
690
+ return [area.left + offset.x + x, area.top + offset.y + y];
691
+ },
692
+
693
+ /**
694
+ * Get the positions of the data label of each row, for the data label pipeline.
695
+ * @returns {function(IDataRow): Array.<Array.<number>>} Point getter: [anchor, measure center]
696
+ * @private
697
+ */
698
+ generateGetBulletPoints(): (d: {id: string}) => number[][] | undefined {
699
+ const $$ = this;
700
+ let points: {[id: string]: number[][]} | undefined;
701
+
702
+ // computed when the first label is positioned: not at all without data labels
703
+ return d => {
704
+ if (!points) {
705
+ const layout = _getLayout.call($$);
706
+
707
+ points = {};
708
+ layout.rows.forEach(row => {
709
+ const {area, offset, label} = _getRowGeometry.call($$, row, layout);
710
+ const x = area.left + offset.x;
711
+ const y = area.top + offset.y;
712
+
713
+ points![row.id] = [
714
+ [x + label.x, y + label.y],
715
+ [x + label.center.x, y + label.center.y]
716
+ ];
717
+ });
718
+ }
719
+
720
+ return points[d.id];
721
+ };
722
+ },
723
+
724
+ /**
725
+ * Get the geometry of a bullet row. Shared by the SVG and the canvas renderer.
726
+ * @param {object} d Bullet row data
727
+ * @param {object} layout Bullet layout from getBulletLayout()
728
+ * @returns {object} Row geometry, relative to the row origin
729
+ * @private
730
+ */
731
+ getBulletRowGeometry(d: IBulletData, layout: IBulletLayout): IBulletGeometry {
732
+ return _getRowGeometry.call(this, d, layout);
733
+ }
734
+ };