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,782 @@
1
+ /**
2
+ * Copyright (c) 2017 ~ present NAVER Corp.
3
+ * billboard.js project is licensed under the MIT license
4
+ */
5
+ /**
6
+ * The node layout is ported from d3-sankey (https://github.com/d3/d3-sankey)
7
+ * Copyright 2015, Mike Bostock. Released under the BSD-3-Clause license.
8
+ */
9
+ import {isFunction} from "../../../module/util";
10
+
11
+ // class names of the sankey elements
12
+ export const $SANKEY = {
13
+ chartSankey: "bb-chart-sankey",
14
+ sankeyLinks: "bb-sankey-links",
15
+ sankeyLink: "bb-sankey-link",
16
+ sankeyNodes: "bb-sankey-nodes",
17
+ sankeyNode: "bb-sankey-node",
18
+ sankeyLabel: "bb-sankey-label"
19
+ };
20
+
21
+ export interface ISankeyNode {
22
+ id: string;
23
+ name: string;
24
+ index: number;
25
+ value: number;
26
+ color: string;
27
+ sourceLinks: ISankeyLink[];
28
+ targetLinks: ISankeyLink[];
29
+ depth: number;
30
+ height: number;
31
+ layer: number;
32
+ x0: number;
33
+ x1: number;
34
+ y0: number;
35
+ y1: number;
36
+ }
37
+
38
+ export interface ISankeyLink {
39
+ source: ISankeyNode;
40
+ target: ISankeyNode;
41
+ value: number;
42
+ index: number;
43
+ // the thickness of the link, and its center across the flow at the source and the target:
44
+ // y when the flow goes to the right, x when it goes down (sankey.rotated)
45
+ width: number;
46
+ y0: number;
47
+ y1: number;
48
+ }
49
+
50
+ export interface ISankeyLayout {
51
+ nodes: ISankeyNode[];
52
+ links: ISankeyLink[];
53
+ area: {left: number, top: number, width: number, height: number};
54
+ }
55
+
56
+ export interface ISankeyLabel {
57
+ text: string;
58
+ x: number;
59
+ y: number;
60
+ align: "left" | "right" | "center";
61
+ baseline: "middle" | "top" | "bottom";
62
+ }
63
+
64
+ type TAlign = (node: ISankeyNode, n: number) => number;
65
+
66
+ const ALIGN: {[key: string]: TAlign} = {
67
+ left: node => node.depth,
68
+ right: (node, n) => n - 1 - node.height,
69
+ justify: (node, n) => (node.sourceLinks.length ? node.depth : n - 1),
70
+ center: node => (
71
+ node.targetLinks.length ?
72
+ node.depth :
73
+ (node.sourceLinks.length ?
74
+ Math.min(...node.sourceLinks.map(l => l.target.depth)) - 1 :
75
+ 0)
76
+ )
77
+ };
78
+
79
+ // the property of the object itself: "constructor" or "toString" as a data id is not a key
80
+ const own = (obj, key: string) =>
81
+ obj && Object.prototype.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
82
+
83
+ const sum = (list: ISankeyLink[]) => list.reduce((acc, l) => acc + l.value, 0);
84
+ const byBreadth = (a: ISankeyNode, b: ISankeyNode) => a.y0 - b.y0;
85
+ const bySourceBreadth = (a: ISankeyLink, b: ISankeyLink) =>
86
+ byBreadth(a.source, b.source) || a.index - b.index;
87
+ const byTargetBreadth = (a: ISankeyLink, b: ISankeyLink) =>
88
+ byBreadth(a.target, b.target) || a.index - b.index;
89
+
90
+ // a link is drawn for a positive finite value only
91
+ const _isLinkValue = (value: number): boolean => value > 0 && Number.isFinite(value);
92
+
93
+ /**
94
+ * Get the nodes and the links from the data.
95
+ * A data series is a source node, and its values are the links to the nodes named by their x.
96
+ * @returns {object} Nodes and links
97
+ * @private
98
+ */
99
+ function _getGraph(): {nodes: ISankeyNode[], links: ISankeyLink[]} {
100
+ const $$ = this;
101
+ const {config} = $$;
102
+ const targets = $$.data.targets.filter($$.isSankeyType.bind($$));
103
+ const nodeMap = new Map<string, ISankeyNode>();
104
+ const nodes: ISankeyNode[] = [];
105
+ const links: ISankeyLink[] = [];
106
+
107
+ // the series get their colors in the data order first, shown or not:
108
+ // the colors of the nodes do not depend on what is hidden, nor on the renderer
109
+ targets.forEach(t => $$.color(t.id));
110
+
111
+ // then the nodes that are only targets, in the order their links are in the data
112
+ targets.forEach(t =>
113
+ t.values.forEach(v => _isLinkValue(Number(v.value)) && $$.color(String(v.x)))
114
+ );
115
+
116
+ const getNode = (id: string): ISankeyNode => {
117
+ let node = nodeMap.get(id);
118
+
119
+ if (!node) {
120
+ node = {
121
+ id,
122
+ name: String(own(config.data_names, id) ?? id),
123
+ index: nodes.length,
124
+ value: 0,
125
+ color: $$.color(id),
126
+ sourceLinks: [],
127
+ targetLinks: [],
128
+ depth: 0,
129
+ height: 0,
130
+ layer: 0,
131
+ x0: 0,
132
+ x1: 0,
133
+ y0: 0,
134
+ y1: 0
135
+ };
136
+
137
+ nodeMap.set(id, node);
138
+ nodes.push(node);
139
+ }
140
+
141
+ return node;
142
+ };
143
+
144
+ // a hidden series is a hidden node: the links to it are not there as well
145
+ targets.filter(t => $$.isTargetToShow(t.id)).forEach(t => {
146
+ t.values.forEach(v => {
147
+ const value = Number(v.value);
148
+
149
+ // a link that can not be drawn is not there
150
+ if (!_isLinkValue(value) || !$$.isTargetToShow(String(v.x))) {
151
+ return;
152
+ }
153
+
154
+ const source = getNode(t.id);
155
+ const target = getNode(String(v.x));
156
+ const link = {source, target, value, index: links.length, width: 0, y0: 0, y1: 0};
157
+
158
+ source.sourceLinks.push(link);
159
+ target.targetLinks.push(link);
160
+ links.push(link);
161
+ });
162
+ });
163
+
164
+ nodes.forEach(node => {
165
+ node.value = Math.max(sum(node.sourceLinks), sum(node.targetLinks));
166
+ });
167
+
168
+ return {nodes, links};
169
+ }
170
+
171
+ /**
172
+ * Set the depth (from the sources) or the height (from the sinks) of the nodes.
173
+ * @param {Array} nodes Nodes
174
+ * @param {string} key "depth" or "height"
175
+ * @returns {boolean} false when the links make a cycle
176
+ * @private
177
+ */
178
+ function _setDepth(nodes: ISankeyNode[], key: "depth" | "height"): boolean {
179
+ const linksKey = key === "depth" ? "sourceLinks" : "targetLinks";
180
+ const nodeKey = key === "depth" ? "target" : "source";
181
+ let current = new Set(nodes);
182
+ let x = 0;
183
+
184
+ while (current.size) {
185
+ const next = new Set<ISankeyNode>();
186
+
187
+ current.forEach(node => {
188
+ node[key] = x;
189
+ node[linksKey].forEach(link => next.add(link[nodeKey]));
190
+ });
191
+
192
+ // a node is deeper than the number of the nodes only in a cycle
193
+ if (++x > nodes.length) {
194
+ return false;
195
+ }
196
+
197
+ current = next;
198
+ }
199
+
200
+ return true;
201
+ }
202
+
203
+ /**
204
+ * Get the order of the nodes in a column, by sankey.node.sort.
205
+ * @returns {function|null} Comparator, null when the layout orders them ("auto")
206
+ * @private
207
+ */
208
+ function _getNodeSort(): ((a: ISankeyNode, b: ISankeyNode) => number) | null {
209
+ const $$ = this;
210
+ const sort = $$.config.sankey_node_sort;
211
+ const byIndex = (a: ISankeyNode, b: ISankeyNode) => a.index - b.index;
212
+
213
+ if (isFunction(sort)) {
214
+ return (a, b) =>
215
+ sort.call($$.api, $$.getSankeyNodeData(a), $$.getSankeyNodeData(b)) ||
216
+ byIndex(a, b);
217
+ }
218
+
219
+ return own({
220
+ data: byIndex,
221
+ asc: (a: ISankeyNode, b: ISankeyNode) => a.value - b.value || byIndex(a, b),
222
+ desc: (a: ISankeyNode, b: ISankeyNode) => b.value - a.value || byIndex(a, b)
223
+ }, sort) ?? null;
224
+ }
225
+
226
+ /**
227
+ * Lay out the nodes and the links in the given area.
228
+ * @param {Array} nodes Nodes
229
+ * @param {Array} links Links
230
+ * @param {object} area Area to lay out in
231
+ * @private
232
+ */
233
+ function _layout(nodes: ISankeyNode[], links: ISankeyLink[], area): void {
234
+ const $$ = this;
235
+ const {config} = $$;
236
+ const x0 = area.left;
237
+ const y0 = area.top;
238
+ const x1 = x0 + area.width;
239
+ const y1 = y0 + area.height;
240
+ const dx = config.sankey_node_width;
241
+ const align = ALIGN[config.sankey_node_align] ?? ALIGN.justify;
242
+ const sort = _getNodeSort.call($$);
243
+
244
+ // layers: the columns of the nodes
245
+ const n = Math.max(...nodes.map(d => d.depth)) + 1;
246
+ const kx = n > 1 ? (x1 - x0 - dx) / (n - 1) : 0;
247
+ const columns: ISankeyNode[][] = Array.from({length: n}, () => []);
248
+
249
+ nodes.forEach(node => {
250
+ const i = Math.max(0, Math.min(n - 1, Math.floor(align(node, n))));
251
+
252
+ node.layer = i;
253
+ node.x0 = x0 + i * kx;
254
+ node.x1 = node.x0 + dx;
255
+ columns[i].push(node);
256
+ });
257
+
258
+ // as d3-sankey nodeSort: a set order is kept, the layout does not sort the columns again
259
+ sort && columns.forEach(column => column.sort(sort));
260
+
261
+ const maxLength = Math.max(...columns.map(c => c.length));
262
+ const py = Math.min(config.sankey_node_padding,
263
+ maxLength > 1 ? (y1 - y0) / (maxLength - 1) : Infinity);
264
+
265
+ const reorderLinks = (node: ISankeyNode) => {
266
+ node.sourceLinks.sort(byTargetBreadth);
267
+ node.targetLinks.sort(bySourceBreadth);
268
+ };
269
+
270
+ // the links of the nodes linked to the node are sorted again, after it moved
271
+ const reorderNodeLinks = (node: ISankeyNode) => {
272
+ node.targetLinks.forEach(l => l.source.sourceLinks.sort(byTargetBreadth));
273
+ node.sourceLinks.forEach(l => l.target.targetLinks.sort(bySourceBreadth));
274
+ };
275
+
276
+ // initial breadths: the nodes of each column are stacked, and the column is centered
277
+ const ky = Math.min(...columns.map(c =>
278
+ (y1 - y0 - (c.length - 1) * py) /
279
+ c.reduce((acc, d) => acc + d.value, 0)
280
+ ));
281
+
282
+ columns.forEach(column => {
283
+ let y = y0;
284
+
285
+ column.forEach(node => {
286
+ node.y0 = y;
287
+ node.y1 = y + node.value * ky;
288
+ y = node.y1 + py;
289
+ node.sourceLinks.forEach(link => {
290
+ link.width = link.value * ky;
291
+ });
292
+ });
293
+
294
+ const offset = (y1 - y + py) / (column.length + 1);
295
+
296
+ column.forEach((node, i) => {
297
+ node.y0 += offset * (i + 1);
298
+ node.y1 += offset * (i + 1);
299
+ });
300
+
301
+ column.forEach(reorderLinks);
302
+ });
303
+
304
+ const move = (node: ISankeyNode, dy: number) => {
305
+ node.y0 += dy;
306
+ node.y1 += dy;
307
+ };
308
+
309
+ const toBottom = (column: ISankeyNode[], y: number, i: number, alpha: number) => {
310
+ for (; i < column.length; i++) {
311
+ const node = column[i];
312
+ const dy = (y - node.y0) * alpha;
313
+
314
+ dy > 1e-6 && move(node, dy);
315
+ y = node.y1 + py;
316
+ }
317
+ };
318
+
319
+ const toTop = (column: ISankeyNode[], y: number, i: number, alpha: number) => {
320
+ for (; i >= 0; i--) {
321
+ const node = column[i];
322
+ const dy = (node.y1 - y) * alpha;
323
+
324
+ dy > 1e-6 && move(node, -dy);
325
+ y = node.y0 - py;
326
+ }
327
+ };
328
+
329
+ const resolveCollisions = (column: ISankeyNode[], alpha: number) => {
330
+ const i = column.length >> 1;
331
+ const subject = column[i];
332
+
333
+ toTop(column, subject.y0 - py, i - 1, alpha);
334
+ toBottom(column, subject.y1 + py, i + 1, alpha);
335
+ toTop(column, y1, column.length - 1, alpha);
336
+ toBottom(column, y0, 0, alpha);
337
+ };
338
+
339
+ // the y of the link at the target, when it would be at the place of the source
340
+ const targetTop = (source: ISankeyNode, target: ISankeyNode) => {
341
+ let y = source.y0 - (source.sourceLinks.length - 1) * py / 2;
342
+
343
+ for (const {target: node, width} of source.sourceLinks) {
344
+ if (node === target) {
345
+ break;
346
+ }
347
+
348
+ y += width + py;
349
+ }
350
+
351
+ for (const {source: node, width} of target.targetLinks) {
352
+ if (node === source) {
353
+ break;
354
+ }
355
+
356
+ y -= width;
357
+ }
358
+
359
+ return y;
360
+ };
361
+
362
+ const sourceTop = (source: ISankeyNode, target: ISankeyNode) => {
363
+ let y = target.y0 - (target.targetLinks.length - 1) * py / 2;
364
+
365
+ for (const {source: node, width} of target.targetLinks) {
366
+ if (node === source) {
367
+ break;
368
+ }
369
+
370
+ y += width + py;
371
+ }
372
+
373
+ for (const {target: node, width} of source.sourceLinks) {
374
+ if (node === target) {
375
+ break;
376
+ }
377
+
378
+ y -= width;
379
+ }
380
+
381
+ return y;
382
+ };
383
+
384
+ // move each node toward the weighted center of the nodes linked to it
385
+ const relax = (column: ISankeyNode[], toRight: boolean, alpha: number, beta: number) => {
386
+ column.forEach(node => {
387
+ let y = 0;
388
+ let w = 0;
389
+
390
+ (toRight ? node.targetLinks : node.sourceLinks).forEach(link => {
391
+ const v = link.value * (link.target.layer - link.source.layer);
392
+
393
+ y += (toRight ? targetTop(link.source, node) : sourceTop(node, link.target)) * v;
394
+ w += v;
395
+ });
396
+
397
+ if (w > 0) {
398
+ move(node, (y / w - node.y0) * alpha);
399
+ reorderNodeLinks(node);
400
+ }
401
+ });
402
+
403
+ sort || column.sort(byBreadth);
404
+ resolveCollisions(column, beta);
405
+ };
406
+
407
+ const iterations = config.sankey_iterations;
408
+
409
+ for (let i = 0; i < iterations; i++) {
410
+ const alpha = 0.99 ** i;
411
+ const beta = Math.max(1 - alpha, (i + 1) / iterations);
412
+
413
+ for (let c = columns.length - 2; c >= 0; c--) {
414
+ relax(columns[c], false, alpha, beta);
415
+ }
416
+
417
+ for (let c = 1; c < columns.length; c++) {
418
+ relax(columns[c], true, alpha, beta);
419
+ }
420
+ }
421
+
422
+ // the links are stacked on their nodes, in the order of the nodes at the other end
423
+ nodes.forEach(node => {
424
+ let ys = node.y0;
425
+ let yt = node.y0;
426
+
427
+ node.sourceLinks.forEach(link => {
428
+ link.y0 = ys + link.width / 2;
429
+ ys += link.width;
430
+ });
431
+
432
+ node.targetLinks.forEach(link => {
433
+ link.y1 = yt + link.width / 2;
434
+ yt += link.width;
435
+ });
436
+ });
437
+ }
438
+
439
+ /**
440
+ * Get the area the sankey is drawn in, in chart coordinates.
441
+ * @returns {object} Area
442
+ * @private
443
+ */
444
+ function _getArea(): {left: number, top: number, width: number, height: number} {
445
+ const $$ = this;
446
+ const {config, state: {current: {width, height}, isCanvasMode, isLegendRight}} = $$;
447
+ const padding = $$.getCurrentPadding();
448
+ // canvas mode draws the legend as HTML outside of its drawing surface: only the gap is needed
449
+ const legendHeight = config.legend_show && config.legend_position === "bottom" ?
450
+ (isCanvasMode ? 0 : $$.getLegendHeight()) + 10 :
451
+ 0;
452
+ const legendRight = config.legend_show && isLegendRight ?
453
+ $$.getLegendWidth() + (config.padding?.mode === "fit" ? 0 : 20) :
454
+ 0;
455
+ const surfaceHeight = isCanvasMode ? $$.getCanvasSurfaceHeight() : height;
456
+
457
+ return {
458
+ left: padding.left,
459
+ top: padding.top,
460
+ width: Math.max(0, width - padding.left - padding.right - legendRight),
461
+ height: Math.max(0, surfaceHeight - padding.top - padding.bottom - legendHeight)
462
+ };
463
+ }
464
+
465
+ /**
466
+ * Swap the x and the y of an area.
467
+ * @param {object} area Area
468
+ * @returns {object} Transposed area
469
+ * @private
470
+ */
471
+ function _transpose(area) {
472
+ return {left: area.top, top: area.left, width: area.height, height: area.width};
473
+ }
474
+
475
+ /**
476
+ * Swap the x and the y of a node.
477
+ * @param {object} node Node
478
+ * @private
479
+ */
480
+ function _transposeNode(node: ISankeyNode): void {
481
+ const {x0, x1, y0, y1} = node;
482
+
483
+ Object.assign(node, {x0: y0, x1: y1, y0: x0, y1: x1});
484
+ }
485
+
486
+ /**
487
+ * Get the point on the link at the given position along the flow.
488
+ * The link is the cubic bezier curve of linkHorizontal (linkVertical when rotated).
489
+ * @param {Array} points Start, control 1, control 2 and end point, along the flow and across it
490
+ * @param {number} width Thickness of the link
491
+ * @param {number} f Position along the flow
492
+ * @returns {object} Position across the flow of the center line, and the half of the thickness there
493
+ * @private
494
+ */
495
+ function _getLinkPointAt(points: [number, number][], width: number,
496
+ f: number): {c: number, half: number} {
497
+ const [[fs, c0], [fm], , [ft, c1]] = points;
498
+ const bf = (t: number) => (
499
+ (1 - t) ** 3 * fs + 3 * (1 - t) * t * fm + t ** 3 * ft
500
+ );
501
+
502
+ // the flow position of the curve is monotone: find its t by bisection
503
+ let lo = 0;
504
+ let hi = 1;
505
+
506
+ for (let i = 0; i < 20; i++) {
507
+ const mid = (lo + hi) / 2;
508
+
509
+ (bf(mid) < f) === (fs < ft) ? (lo = mid) : (hi = mid);
510
+ }
511
+
512
+ const t = (lo + hi) / 2;
513
+ const df = 3 * (1 - t) ** 2 * (fm - fs) + 3 * t ** 2 * (ft - fm);
514
+ const dc = 6 * t * (1 - t) * (c1 - c0);
515
+ const slope = df ? dc / df : 0;
516
+
517
+ return {
518
+ c: c0 + (c1 - c0) * (3 * t ** 2 - 2 * t ** 3),
519
+ half: width / 2 * Math.sqrt(1 + slope * slope)
520
+ };
521
+ }
522
+
523
+ /**
524
+ * How the sankey differs from the other types for the shared code.
525
+ * It asks these through `getCustomTypeHooks()` (they are registered with the type name).
526
+ * @private
527
+ */
528
+ export const customTypeHooks = {
529
+ // the data of the nodes and the links have their names (data.names applied, "A → B")
530
+ namedData: true,
531
+
532
+ // svg: the links and the target only nodes are not of the target classes focus() finds
533
+ afterFocus($$): void {
534
+ $$.updateSankeyFocus?.();
535
+ },
536
+
537
+ // the names of the nodes are drawn by the type: there are no data labels of the values
538
+ labelData(): [] {
539
+ return [];
540
+ },
541
+
542
+ // the tooltip of a node, addressed by its id (tooltip.show({data: {id}})) or by its index
543
+ tooltipTarget($$, args) {
544
+ const {nodes} = $$.getSankeyLayout();
545
+ const node = args.data?.id ? nodes.find(d => d.id === args.data.id) : nodes[args.index];
546
+ const data = node ? [$$.getSankeyNodeData(node)] : [];
547
+
548
+ const point = node &&
549
+ ($$.config.sankey_rotated ?
550
+ [(node.x0 + node.x1) / 2, node.y1] :
551
+ [node.x1, (node.y0 + node.y1) / 2]);
552
+
553
+ return {data, point};
554
+ }
555
+ };
556
+
557
+ export default {
558
+ /**
559
+ * Whether the data belongs to the sankey type.
560
+ * @param {object} d Data object
561
+ * @returns {boolean}
562
+ * @private
563
+ */
564
+ isSankeyType(d): boolean {
565
+ return this.isTypeOf(d, "sankey");
566
+ },
567
+
568
+ /**
569
+ * Get the layout of the nodes and the links, in chart coordinates.
570
+ * Shared by the SVG and the canvas renderer.
571
+ * @returns {object} Sankey layout
572
+ * @private
573
+ */
574
+ getSankeyLayout(): ISankeyLayout {
575
+ const $$ = this;
576
+ const area = _getArea.call($$);
577
+ const {nodes, links} = _getGraph.call($$);
578
+
579
+ if (nodes.length) {
580
+ if (_setDepth(nodes, "depth") && _setDepth(nodes, "height")) {
581
+ const rotated = $$.config.sankey_rotated;
582
+
583
+ // rotated: laid out along the flow as it goes to the right, then turned to go down
584
+ _layout.call($$, nodes, links, rotated ? _transpose(area) : area);
585
+ rotated && nodes.forEach(_transposeNode);
586
+ } else {
587
+ // not thrown: the other parts of the chart keep working
588
+ console.error(
589
+ "[billboard.js] The links of the sankey chart make a cycle: it can't be drawn."
590
+ );
591
+
592
+ return {nodes: [], links: [], area};
593
+ }
594
+ }
595
+
596
+ return {nodes, links, area};
597
+ },
598
+
599
+ /**
600
+ * Get the points of a link: the same curve as d3-shape linkHorizontal (linkVertical when rotated).
601
+ * @param {object} link Link
602
+ * @param {boolean} [flow=false] Whether to get them as [along the flow, across it], for any rotation
603
+ * @returns {Array} Start, control 1, control 2 and end point
604
+ * @private
605
+ */
606
+ getSankeyLinkPoints(link: ISankeyLink, flow = false): [number, number][] {
607
+ const rotated = this.config.sankey_rotated;
608
+ const fs = rotated ? link.source.y1 : link.source.x1;
609
+ const ft = rotated ? link.target.y0 : link.target.x0;
610
+ const fm = (fs + ft) / 2;
611
+ const points: [number, number][] = [[fs, link.y0], [fm, link.y0], [fm, link.y1], [
612
+ ft,
613
+ link.y1
614
+ ]];
615
+
616
+ return rotated && !flow ? points.map(([f, c]) => [c, f]) : points;
617
+ },
618
+
619
+ /**
620
+ * Get the SVG path of a link.
621
+ * @param {object} link Link
622
+ * @returns {string} Path
623
+ * @private
624
+ */
625
+ getSankeyLinkPath(link: ISankeyLink): string {
626
+ const [p0, p1, p2, p3] = this.getSankeyLinkPoints(link);
627
+
628
+ return `M${p0}C${p1},${p2},${p3}`;
629
+ },
630
+
631
+ /**
632
+ * Whether the point is on the link.
633
+ * @param {object} link Link
634
+ * @param {number} x X coordinate
635
+ * @param {number} y Y coordinate
636
+ * @returns {boolean}
637
+ * @private
638
+ */
639
+ isSankeyLinkHit(link: ISankeyLink, x: number, y: number): boolean {
640
+ const points = this.getSankeyLinkPoints(link, true);
641
+ const [f, c] = this.config.sankey_rotated ? [y, x] : [x, y];
642
+
643
+ if (f < points[0][0] || f > points[3][0]) {
644
+ return false;
645
+ }
646
+
647
+ // the thinnest link is drawn 1px thick
648
+ const point = _getLinkPointAt(points, Math.max(1, link.width), f);
649
+
650
+ return Math.abs(c - point.c) <= point.half;
651
+ },
652
+
653
+ /**
654
+ * Get the label of a node: its name, or the text of sankey.label.format.
655
+ * @param {object} node Node
656
+ * @returns {object|null} Text, position and alignment, null when it is not shown
657
+ * @private
658
+ */
659
+ getSankeyLabel(node: ISankeyNode): ISankeyLabel | null {
660
+ const $$ = this;
661
+ const {config} = $$;
662
+
663
+ if (!config.sankey_label_show) {
664
+ return null;
665
+ }
666
+
667
+ const format = config.sankey_label_format;
668
+ const text = String(
669
+ (isFunction(format) ?
670
+ format.call($$.api, node.name, node.value, node.id) :
671
+ node.name) ?? ""
672
+ );
673
+ // on the inner side of the node: the nodes of the far half have it before them
674
+ const area = _getArea.call($$);
675
+
676
+ if (config.sankey_rotated) {
677
+ const isEnd = node.y0 > area.top + area.height / 2;
678
+
679
+ return {
680
+ text,
681
+ x: (node.x0 + node.x1) / 2,
682
+ y: isEnd ? node.y0 - 6 : node.y1 + 6,
683
+ align: "center",
684
+ baseline: isEnd ? "bottom" : "top"
685
+ };
686
+ }
687
+
688
+ const isEnd = node.x0 > area.left + area.width / 2;
689
+
690
+ return {
691
+ text,
692
+ x: isEnd ? node.x0 - 6 : node.x1 + 6,
693
+ y: (node.y0 + node.y1) / 2,
694
+ align: isEnd ? "right" : "left",
695
+ baseline: "middle"
696
+ };
697
+ },
698
+
699
+ /**
700
+ * Get the colors a link is painted with, by the sankey.link.color option.
701
+ * @param {object} link Link
702
+ * @returns {Array} The color at the source end and the color at the target end
703
+ * @private
704
+ */
705
+ getSankeyLinkColors(link: ISankeyLink): [string, string] {
706
+ const {source: {color: source}, target: {color: target}} = link;
707
+
708
+ return {
709
+ source: [source, source],
710
+ target: [target, target],
711
+ gradient: [source, target]
712
+ }[this.config.sankey_link_color] || [source, source];
713
+ },
714
+
715
+ /**
716
+ * Check whether a node or a link is defocused by focus(), defocus() or a legend hover.
717
+ * A link follows its source series. A target only node has no series, so it is defocused
718
+ * when all the links coming to it are.
719
+ * @param {object} d Node or link
720
+ * @returns {boolean} Whether it is defocused
721
+ * @private
722
+ */
723
+ isSankeyDefocused(d: ISankeyNode | ISankeyLink): boolean {
724
+ const $$ = this;
725
+ const ids: Set<string> | undefined = $$.state.defocusedTargetIds;
726
+
727
+ if (!ids?.size) {
728
+ return false;
729
+ }
730
+
731
+ if ("source" in d) {
732
+ return ids.has(d.source.id);
733
+ }
734
+
735
+ return ids.has(d.id) || (
736
+ d.targetLinks.length > 0 &&
737
+ !$$.data.targets.some(t => t.id === d.id) &&
738
+ d.targetLinks.every(link => ids.has(link.source.id))
739
+ );
740
+ },
741
+
742
+ /**
743
+ * Get the data of a node, for the tooltip and the events.
744
+ * @param {object} node Node
745
+ * @returns {object} Data
746
+ * @private
747
+ */
748
+ getSankeyNodeData(node: ISankeyNode) {
749
+ return {id: node.id, index: node.index, value: node.value, name: node.name};
750
+ },
751
+
752
+ /**
753
+ * Get the data of a link, for the tooltip and the events.
754
+ * It is of the series of the source: the name tells the source and the target.
755
+ * @param {object} link Link
756
+ * @returns {object} Data
757
+ * @private
758
+ */
759
+ getSankeyLinkData(link: ISankeyLink) {
760
+ const {source, target, value, index} = link;
761
+
762
+ return {
763
+ id: source.id,
764
+ x: target.id,
765
+ index,
766
+ value,
767
+ name: `${source.name} → ${target.name}`,
768
+ source: source.id,
769
+ target: target.id
770
+ };
771
+ },
772
+
773
+ /**
774
+ * The data labels of the values are not drawn for the sankey (see customTypeHooks.labelData).
775
+ * The shared data label code asks the points of every type, so it is there.
776
+ * @returns {function} Point getter
777
+ * @private
778
+ */
779
+ generateGetSankeyPoints(): () => undefined {
780
+ return () => undefined;
781
+ }
782
+ };