billboard.js 4.0.3 → 4.1.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/README.md +82 -7
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +1848 -494
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +19 -24
  6. package/dist/billboard.pkgd.js +1844 -679
  7. package/dist/billboard.pkgd.min.js +24 -29
  8. package/dist/billboard.react.js +205 -0
  9. package/dist/billboard.react.min.js +9 -0
  10. package/dist/billboard.worker.js +10 -0
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.js +5 -3
  12. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
  14. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
  16. package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
  17. package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  19. package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
  20. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
  24. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
  26. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
  28. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
  30. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
  31. package/dist/theme/dark.css +1 -1
  32. package/dist/theme/dark.min.css +1 -1
  33. package/dist/theme/datalab.css +1 -1
  34. package/dist/theme/datalab.min.css +1 -1
  35. package/dist/theme/graph.css +1 -1
  36. package/dist/theme/graph.min.css +1 -1
  37. package/dist/theme/insight.css +1 -1
  38. package/dist/theme/insight.min.css +1 -1
  39. package/dist/theme/modern.css +1 -1
  40. package/dist/theme/modern.min.css +1 -1
  41. package/dist-esm/Chart/Chart.js +134 -152
  42. package/dist-esm/Chart/api/axis.js +217 -237
  43. package/dist-esm/Chart/api/category.js +54 -54
  44. package/dist-esm/Chart/api/chart.js +172 -215
  45. package/dist-esm/Chart/api/color.js +21 -21
  46. package/dist-esm/Chart/api/data.js +172 -173
  47. package/dist-esm/Chart/api/export.js +242 -262
  48. package/dist-esm/Chart/api/flow.js +198 -254
  49. package/dist-esm/Chart/api/focus.js +136 -143
  50. package/dist-esm/Chart/api/grid.js +191 -190
  51. package/dist-esm/Chart/api/group.js +31 -34
  52. package/dist-esm/Chart/api/legend.js +54 -63
  53. package/dist-esm/Chart/api/load.js +237 -257
  54. package/dist-esm/Chart/api/regions.js +148 -168
  55. package/dist-esm/Chart/api/selection.js +181 -139
  56. package/dist-esm/Chart/api/show.js +133 -147
  57. package/dist-esm/Chart/api/stubs.js +43 -42
  58. package/dist-esm/Chart/api/subchart.js +155 -172
  59. package/dist-esm/Chart/api/tooltip.js +132 -177
  60. package/dist-esm/Chart/api/x.js +67 -71
  61. package/dist-esm/Chart/api/zoom.js +183 -220
  62. package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
  63. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
  64. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
  65. package/dist-esm/ChartInternal/ChartInternal.js +573 -749
  66. package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
  67. package/dist-esm/ChartInternal/data/convert.js +200 -229
  68. package/dist-esm/ChartInternal/data/data.js +967 -1153
  69. package/dist-esm/ChartInternal/data/load.js +145 -197
  70. package/dist-esm/ChartInternal/interactions/drag.js +86 -122
  71. package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
  72. package/dist-esm/ChartInternal/interactions/flow.js +151 -215
  73. package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
  74. package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
  75. package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
  76. package/dist-esm/ChartInternal/internals/category.js +18 -18
  77. package/dist-esm/ChartInternal/internals/class.js +89 -99
  78. package/dist-esm/ChartInternal/internals/clip.js +88 -119
  79. package/dist-esm/ChartInternal/internals/color.js +233 -288
  80. package/dist-esm/ChartInternal/internals/domain.js +452 -588
  81. package/dist-esm/ChartInternal/internals/format.js +64 -77
  82. package/dist-esm/ChartInternal/internals/grid.js +333 -457
  83. package/dist-esm/ChartInternal/internals/legend.js +675 -927
  84. package/dist-esm/ChartInternal/internals/redraw.js +200 -289
  85. package/dist-esm/ChartInternal/internals/region.js +106 -159
  86. package/dist-esm/ChartInternal/internals/scale.js +186 -215
  87. package/dist-esm/ChartInternal/internals/selection.js +132 -159
  88. package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
  89. package/dist-esm/ChartInternal/internals/size.js +286 -394
  90. package/dist-esm/ChartInternal/internals/style.js +39 -41
  91. package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
  92. package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
  93. package/dist-esm/ChartInternal/internals/text.js +368 -528
  94. package/dist-esm/ChartInternal/internals/text.util.js +179 -239
  95. package/dist-esm/ChartInternal/internals/title.js +96 -121
  96. package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
  97. package/dist-esm/ChartInternal/internals/transform.js +79 -97
  98. package/dist-esm/ChartInternal/internals/type.js +285 -236
  99. package/dist-esm/ChartInternal/shape/arc.js +825 -1112
  100. package/dist-esm/ChartInternal/shape/area.js +73 -94
  101. package/dist-esm/ChartInternal/shape/bar.js +227 -288
  102. package/dist-esm/ChartInternal/shape/bubble.js +9 -8
  103. package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
  104. package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
  105. package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
  106. package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
  107. package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
  108. package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
  109. package/dist-esm/ChartInternal/shape/core/path.js +142 -115
  110. package/dist-esm/ChartInternal/shape/core/point.js +105 -125
  111. package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
  112. package/dist-esm/ChartInternal/shape/funnel.js +310 -338
  113. package/dist-esm/ChartInternal/shape/gauge.js +71 -103
  114. package/dist-esm/ChartInternal/shape/line.js +208 -278
  115. package/dist-esm/ChartInternal/shape/point.js +310 -425
  116. package/dist-esm/ChartInternal/shape/polar.js +84 -109
  117. package/dist-esm/ChartInternal/shape/radar.js +228 -318
  118. package/dist-esm/ChartInternal/shape/shape.js +782 -843
  119. package/dist-esm/ChartInternal/shape/treemap.js +152 -190
  120. package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
  121. package/dist-esm/canvas/CanvasEngine.js +148 -166
  122. package/dist-esm/canvas/CanvasPainter.js +395 -411
  123. package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
  124. package/dist-esm/canvas/CanvasTheme.js +899 -802
  125. package/dist-esm/canvas/HitDetector.js +394 -463
  126. package/dist-esm/canvas/axisTicks.js +672 -786
  127. package/dist-esm/canvas/classes.js +19 -17
  128. package/dist-esm/canvas/color.js +40 -59
  129. package/dist-esm/canvas/geometry.js +38 -38
  130. package/dist-esm/canvas/labels.js +318 -371
  131. package/dist-esm/canvas/pointPattern.js +578 -580
  132. package/dist-esm/canvas/util.js +242 -262
  133. package/dist-esm/config/Options/Options.js +29 -32
  134. package/dist-esm/config/Options/axis/axis.js +101 -101
  135. package/dist-esm/config/Options/axis/x.js +759 -755
  136. package/dist-esm/config/Options/axis/y.js +525 -522
  137. package/dist-esm/config/Options/axis/y2.js +501 -485
  138. package/dist-esm/config/Options/common/boost.js +93 -32
  139. package/dist-esm/config/Options/common/color.js +88 -87
  140. package/dist-esm/config/Options/common/grid.js +74 -73
  141. package/dist-esm/config/Options/common/legend.js +180 -179
  142. package/dist-esm/config/Options/common/main.js +474 -473
  143. package/dist-esm/config/Options/common/point.js +160 -159
  144. package/dist-esm/config/Options/common/title.js +47 -46
  145. package/dist-esm/config/Options/common/tooltip.js +253 -252
  146. package/dist-esm/config/Options/data/axis.js +173 -172
  147. package/dist-esm/config/Options/data/data.js +958 -957
  148. package/dist-esm/config/Options/data/selection.js +131 -130
  149. package/dist-esm/config/Options/interaction/interaction.js +53 -52
  150. package/dist-esm/config/Options/interaction/subchart.js +164 -73
  151. package/dist-esm/config/Options/interaction/zoom.js +86 -85
  152. package/dist-esm/config/Options/shape/arc.js +150 -149
  153. package/dist-esm/config/Options/shape/area.js +69 -68
  154. package/dist-esm/config/Options/shape/bar.js +147 -146
  155. package/dist-esm/config/Options/shape/bubble.js +35 -34
  156. package/dist-esm/config/Options/shape/candlestick.js +61 -60
  157. package/dist-esm/config/Options/shape/donut.js +181 -180
  158. package/dist-esm/config/Options/shape/funnel.js +49 -48
  159. package/dist-esm/config/Options/shape/gauge.js +237 -236
  160. package/dist-esm/config/Options/shape/line.js +58 -57
  161. package/dist-esm/config/Options/shape/pie.js +185 -184
  162. package/dist-esm/config/Options/shape/polar.js +167 -166
  163. package/dist-esm/config/Options/shape/radar.js +76 -75
  164. package/dist-esm/config/Options/shape/scatter.js +36 -36
  165. package/dist-esm/config/Options/shape/spline.js +46 -46
  166. package/dist-esm/config/Options/shape/treemap.js +80 -79
  167. package/dist-esm/config/Store/Element.js +64 -62
  168. package/dist-esm/config/Store/State.js +189 -200
  169. package/dist-esm/config/Store/Store.js +25 -26
  170. package/dist-esm/config/classes.js +157 -155
  171. package/dist-esm/config/config.js +26 -35
  172. package/dist-esm/config/const.js +120 -128
  173. package/dist-esm/config/resolver/axis.core.js +25 -25
  174. package/dist-esm/config/resolver/axis.js +26 -27
  175. package/dist-esm/config/resolver/canvas.js +2071 -2472
  176. package/dist-esm/config/resolver/canvasShape.js +201 -177
  177. package/dist-esm/config/resolver/category.js +26 -27
  178. package/dist-esm/config/resolver/export.js +24 -26
  179. package/dist-esm/config/resolver/flow.js +29 -31
  180. package/dist-esm/config/resolver/grid.js +34 -35
  181. package/dist-esm/config/resolver/interaction/selection.js +17 -17
  182. package/dist-esm/config/resolver/interaction/subchart.js +17 -17
  183. package/dist-esm/config/resolver/interaction/zoom.js +17 -17
  184. package/dist-esm/config/resolver/regions.js +30 -31
  185. package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
  186. package/dist-esm/config/resolver/shape/area.js +17 -17
  187. package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
  188. package/dist-esm/config/resolver/shape/bar.js +13 -13
  189. package/dist-esm/config/resolver/shape/bubble.js +18 -14
  190. package/dist-esm/config/resolver/shape/candlestick.js +13 -13
  191. package/dist-esm/config/resolver/shape/donut.js +11 -11
  192. package/dist-esm/config/resolver/shape/funnel.js +11 -11
  193. package/dist-esm/config/resolver/shape/gauge.js +12 -12
  194. package/dist-esm/config/resolver/shape/line.js +10 -10
  195. package/dist-esm/config/resolver/shape/pie.js +11 -11
  196. package/dist-esm/config/resolver/shape/polar.js +12 -12
  197. package/dist-esm/config/resolver/shape/radar.js +22 -14
  198. package/dist-esm/config/resolver/shape/scatter.js +13 -13
  199. package/dist-esm/config/resolver/shape/treemap.js +11 -11
  200. package/dist-esm/core.js +208 -211
  201. package/dist-esm/index.canvas.js +14 -13
  202. package/dist-esm/index.esm.js +25 -24
  203. package/dist-esm/module/Cache.js +117 -129
  204. package/dist-esm/module/browser.js +30 -35
  205. package/dist-esm/module/dsv.js +107 -127
  206. package/dist-esm/module/error.js +45 -52
  207. package/dist-esm/module/generator.js +75 -83
  208. package/dist-esm/module/sanitize.js +302 -399
  209. package/dist-esm/module/util/brush.js +27 -38
  210. package/dist-esm/module/util/dom.js +288 -348
  211. package/dist-esm/module/util/object.js +277 -341
  212. package/dist-esm/module/util/type-checks.js +21 -25
  213. package/dist-esm/module/worker.js +312 -130
  214. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
  215. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
  216. package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
  217. package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
  218. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
  219. package/dist-esm/react/index.js +157 -0
  220. package/package.json +28 -8
  221. package/src/Chart/api/selection.ts +130 -5
  222. package/src/ChartInternal/Axis/Axis.ts +164 -65
  223. package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
  224. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  225. package/src/ChartInternal/ChartInternal.ts +1 -1
  226. package/src/ChartInternal/data/convert.ts +54 -4
  227. package/src/ChartInternal/data/data.ts +4 -1
  228. package/src/ChartInternal/interactions/eventrect.ts +8 -2
  229. package/src/ChartInternal/interactions/subchart.ts +437 -66
  230. package/src/ChartInternal/internals/color.ts +2 -2
  231. package/src/ChartInternal/internals/domain.ts +15 -3
  232. package/src/ChartInternal/internals/grid.ts +21 -1
  233. package/src/ChartInternal/internals/scale.ts +9 -2
  234. package/src/ChartInternal/internals/selection.ts +1 -1
  235. package/src/ChartInternal/internals/subchart.util.ts +55 -0
  236. package/src/ChartInternal/internals/text.arc.ts +3 -1
  237. package/src/ChartInternal/internals/text.ts +18 -5
  238. package/src/ChartInternal/internals/transform.ts +8 -2
  239. package/src/ChartInternal/internals/type.ts +105 -1
  240. package/src/ChartInternal/shape/IShape.ts +6 -3
  241. package/src/ChartInternal/shape/bar.ts +62 -31
  242. package/src/ChartInternal/shape/core/barRadius.ts +129 -0
  243. package/src/ChartInternal/shape/core/candlestick.ts +1 -1
  244. package/src/ChartInternal/shape/core/path.ts +76 -9
  245. package/src/ChartInternal/shape/funnel.ts +2 -3
  246. package/src/ChartInternal/shape/point.ts +2 -2
  247. package/src/ChartInternal/shape/shape.ts +149 -17
  248. package/src/Plugin/stanford/index.ts +0 -4
  249. package/src/Plugin/tableview/index.ts +85 -3
  250. package/src/Plugin/textoverlap/index.ts +9 -15
  251. package/src/canvas/CanvasAxisRenderer.ts +184 -36
  252. package/src/canvas/CanvasRenderer.ts +247 -160
  253. package/src/canvas/CanvasTheme.ts +212 -0
  254. package/src/canvas/axisTicks.ts +122 -40
  255. package/src/config/Options/axis/y2.ts +13 -0
  256. package/src/config/Options/common/boost.ts +64 -4
  257. package/src/config/Options/common/color.ts +2 -2
  258. package/src/config/Options/interaction/subchart.ts +98 -1
  259. package/src/config/Options/shape/gauge.ts +1 -1
  260. package/src/config/Options/shape/treemap.ts +2 -2
  261. package/src/config/Store/Element.ts +3 -1
  262. package/src/config/Store/State.ts +1 -0
  263. package/src/config/classes.ts +1 -0
  264. package/src/config/resolver/canvas.ts +92 -10
  265. package/src/module/util/type-checks.ts +3 -1
  266. package/src/module/voronoi.ts +119 -0
  267. package/src/module/worker.entry.ts +61 -0
  268. package/src/module/worker.ts +346 -63
  269. package/src/react/index.ts +193 -0
  270. package/types/options.d.ts +206 -3
  271. package/types/react/index.d.ts +27 -0
@@ -5,32 +5,21 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 4.0.3
8
+ * @version 4.1.0-next.2
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
12
- import { interpolateHslLong } from 'd3-interpolate';
13
- import { scaleSequential, scaleSymlog, scaleSequentialLog } from 'd3-scale';
14
- import { axisRight } from 'd3-axis';
15
-
16
- /**
17
- * Copyright (c) 2017 ~ present NAVER Corp.
18
- * billboard.js project is licensed under the MIT license
19
- */
20
- /**
21
- * CSS class names definition
22
- * @private
23
- */
12
+ import { interpolateHslLong } from "d3-interpolate";
13
+ import { scaleSequential, scaleSequentialLog, scaleSymlog } from "d3-scale";
14
+ import { axisRight } from "d3-axis";
15
+ //#region src/config/classes.ts
24
16
  const $TOOLTIP = {
25
- tooltip: "bb-tooltip",
26
- tooltipName: "bb-tooltip-name"
17
+ tooltip: "bb-tooltip",
18
+ tooltipContainer: "bb-tooltip-container",
19
+ tooltipName: "bb-tooltip-name"
27
20
  };
28
-
29
- /**
30
- * Copyright (c) 2017 ~ present NAVER Corp.
31
- * billboard.js project is licensed under the MIT license
32
- * @ignore
33
- */
21
+ //#endregion
22
+ //#region src/module/util/type-checks.ts
34
23
  const isFunction = (v) => typeof v === "function";
35
24
  const isString = (v) => typeof v === "string";
36
25
  const isNumber = (v) => typeof v === "number";
@@ -38,950 +27,828 @@ const isUndefined = (v) => typeof v === "undefined";
38
27
  const isDefined = (v) => typeof v !== "undefined";
39
28
  const isObjectType = (v) => typeof v === "object";
40
29
  const isEmptyObject = (obj) => {
41
- for (const x in obj) {
42
- return false;
43
- }
44
- return true;
30
+ for (const x in obj) if (Object.prototype.hasOwnProperty.call(obj, x)) return false;
31
+ return true;
45
32
  };
46
- const isEmpty = (o) => (isUndefined(o) || o === null ||
47
- (isString(o) && o.length === 0) ||
48
- (isObjectType(o) && !(o instanceof Date) && isEmptyObject(o)) ||
49
- (isNumber(o) && isNaN(o)));
50
-
51
- /**
52
- * Copyright (c) 2017 ~ present NAVER Corp.
53
- * billboard.js project is licensed under the MIT license
54
- */
55
- /**
56
- * Window object
57
- * @private
58
- */
59
- /* eslint-disable no-new-func, no-undef */
60
- /**
61
- * Get global object
62
- * @returns {object} window object
63
- * @private
64
- */
33
+ const isEmpty = (o) => isUndefined(o) || o === null || isString(o) && o.length === 0 || isObjectType(o) && !(o instanceof Date) && isEmptyObject(o) || isNumber(o) && isNaN(o);
34
+ /**
35
+ * Check if is array
36
+ * @param {Array} arr Data to be checked
37
+ * @returns {boolean}
38
+ * @private
39
+ */
40
+ const isArray = (arr) => Array.isArray(arr);
41
+ /**
42
+ * Check if is object
43
+ * @param {object} obj Data to be checked
44
+ * @returns {boolean}
45
+ * @private
46
+ */
47
+ const isObject = (obj) => obj && !obj?.nodeType && isObjectType(obj) && !isArray(obj);
48
+ //#endregion
49
+ //#region src/module/browser.ts
50
+ /**
51
+ * Copyright (c) 2017 ~ present NAVER Corp.
52
+ * billboard.js project is licensed under the MIT license
53
+ */
54
+ /**
55
+ * Window object
56
+ * @private
57
+ */
58
+ /**
59
+ * Get global object
60
+ * @returns {object} window object
61
+ * @private
62
+ */
65
63
  function getGlobal() {
66
- return (typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object &&
67
- globalThis) ||
68
- (typeof self === "object" && self !== null && self.Object === Object && self) ||
69
- Function("return this")();
64
+ return typeof globalThis === "object" && globalThis !== null && globalThis.Object === Object && globalThis || typeof self === "object" && self !== null && self.Object === Object && self || Function("return this")();
65
+ }
66
+ /**
67
+ * Get fallback object
68
+ * @param {object} w global object
69
+ * @returns {Array} fallback object array
70
+ * @private
71
+ */
72
+ function getFallback(w) {
73
+ const hasRAF = typeof w?.requestAnimationFrame === "function" && typeof w?.cancelAnimationFrame === "function";
74
+ const hasRIC = typeof w?.requestIdleCallback === "function" && typeof w?.cancelIdleCallback === "function";
75
+ const request = (cb) => setTimeout(cb, 1);
76
+ const cancel = (id) => clearTimeout(id);
77
+ return [
78
+ hasRAF ? w.requestAnimationFrame : request,
79
+ hasRAF ? w.cancelAnimationFrame : cancel,
80
+ hasRIC ? w.requestIdleCallback : request,
81
+ hasRIC ? w.cancelIdleCallback : cancel
82
+ ];
70
83
  }
71
84
  const win = getGlobal();
72
85
  const doc = win?.document;
73
-
74
- /**
75
- * Copyright (c) 2017 ~ present NAVER Corp.
76
- * billboard.js project is licensed under the MIT license
77
- * @ignore
78
- */
79
- /**
80
- * Get range
81
- * @param {number} start Start number
82
- * @param {number} end End number
83
- * @param {number} step Step number
84
- * @returns {Array}
85
- * @private
86
- */
86
+ const [requestAnimationFrame, cancelAnimationFrame, requestIdleCallback, cancelIdleCallback] = getFallback(win);
87
+ //#endregion
88
+ //#region src/module/util/object.ts
89
+ /**
90
+ * Merge object returning new object
91
+ * @param {object} target Target object
92
+ * @param {object} objectN Source object
93
+ * @returns {object} merged target object
94
+ * @private
95
+ */
96
+ function mergeObj(target, ...objectN) {
97
+ if (!objectN.length || objectN.length === 1 && !objectN[0]) return target;
98
+ const source = objectN.shift();
99
+ if (isObject(target) && isObject(source)) Object.keys(source).forEach((key) => {
100
+ if (!/^(__proto__|constructor|prototype)$/i.test(key)) {
101
+ const value = source[key];
102
+ if (value instanceof Date) target[key] = new Date(value.getTime());
103
+ else if (isObject(value)) {
104
+ !target[key] && (target[key] = {});
105
+ target[key] = mergeObj(target[key], value);
106
+ } else target[key] = isArray(value) ? value.concat() : value;
107
+ }
108
+ });
109
+ return mergeObj(target, ...objectN);
110
+ }
111
+ /**
112
+ * Get range
113
+ * @param {number} start Start number
114
+ * @param {number} end End number
115
+ * @param {number} step Step number
116
+ * @returns {Array}
117
+ * @private
118
+ */
87
119
  const getRange = (start, end, step = 1) => {
88
- const res = [];
89
- const n = Math.max(0, Math.ceil((end - start) / step)) | 0;
90
- for (let i = 0; i < n; i++) {
91
- res.push(start + i * step);
92
- }
93
- return res;
120
+ const res = [];
121
+ const n = Math.max(0, Math.ceil((end - start) / step)) | 0;
122
+ for (let i = 0; i < n; i++) res.push(start + i * step);
123
+ return res;
94
124
  };
95
125
  /**
96
- * Get parsed date value
97
- * (It must be called in 'ChartInternal' context)
98
- * @param {Date|string|number} date Value of date to be parsed
99
- * @returns {Date}
100
- * @private
101
- */
126
+ * Get parsed date value
127
+ * (It must be called in 'ChartInternal' context)
128
+ * @param {Date|string|number} date Value of date to be parsed
129
+ * @returns {Date}
130
+ * @private
131
+ */
102
132
  function parseDate(date) {
103
- let parsedDate;
104
- if (date instanceof Date) {
105
- parsedDate = date;
106
- }
107
- else if (isString(date)) {
108
- const { config, format } = this;
109
- // if fails to parse, try by new Date()
110
- // https://github.com/naver/billboard.js/issues/1714
111
- parsedDate = format.dataTime(config.data_xFormat)(date) ?? new Date(date);
112
- }
113
- else if (isNumber(date) && !isNaN(date)) {
114
- parsedDate = new Date(+date);
115
- }
116
- if (!parsedDate || isNaN(+parsedDate)) {
117
- console && console.error &&
118
- console.error(`Failed to parse x '${date}' to Date object`);
119
- }
120
- return parsedDate;
133
+ let parsedDate;
134
+ if (date instanceof Date) parsedDate = date;
135
+ else if (isString(date)) {
136
+ const { config, format } = this;
137
+ parsedDate = format.dataTime(config.data_xFormat)(date) ?? new Date(date);
138
+ } else if (isNumber(date) && !isNaN(date)) parsedDate = /* @__PURE__ */ new Date(+date);
139
+ if (!parsedDate || isNaN(+parsedDate)) console && console.error && console.error(`Failed to parse x '${date}' to Date object`);
140
+ return parsedDate;
121
141
  }
122
-
123
- /**
124
- * Copyright (c) 2017 ~ present NAVER Corp.
125
- * billboard.js project is licensed under the MIT license
126
- * @ignore
127
- */
128
- // ====================================
129
- // Internal Helper (Not Exported)
130
- // ====================================
131
- /**
132
- * Get boundingClientRect or BBox with caching.
133
- * Internal helper for getBoundingRect() and getBBox()
134
- * @param {boolean} relativeViewport Relative to viewport - true: will use .getBoundingClientRect(), false: will use .getBBox()
135
- * @param {SVGElement} node Target element
136
- * @param {boolean} forceEval Force evaluation
137
- * @returns {object}
138
- * @private
139
- */
142
+ //#endregion
143
+ //#region src/module/util/dom.ts
144
+ /**
145
+ * Get boundingClientRect or BBox with caching.
146
+ * Internal helper for getBoundingRect() and getBBox()
147
+ * @param {boolean} relativeViewport Relative to viewport - true: will use .getBoundingClientRect(), false: will use .getBBox()
148
+ * @param {SVGElement} node Target element
149
+ * @param {boolean} forceEval Force evaluation
150
+ * @returns {object}
151
+ * @private
152
+ */
140
153
  function _getRect(relativeViewport, node, forceEval = false) {
141
- const _ = n => n["getBBox"]();
142
- // cache per API: getBoundingClientRect(viewport coords) and getBBox(local coords)
143
- // return different values for the same node and must not share one slot
144
- const cacheKey = "rectBBox";
145
- if (forceEval) {
146
- return _(node);
147
- }
148
- else {
149
- // will cache the value if the element is not a SVGElement or the width is not set
150
- const needEvaluate = !(cacheKey in node) || (node.hasAttribute("width") &&
151
- node[cacheKey].width !== +(node.getAttribute("width") || 0));
152
- return needEvaluate ? (node[cacheKey] = _(node)) : node[cacheKey];
153
- }
154
+ const _ = (n) => n[relativeViewport ? "getBoundingClientRect" : "getBBox"]();
155
+ const cacheKey = relativeViewport ? "rectClient" : "rectBBox";
156
+ if (forceEval) return _(node);
157
+ else return !(cacheKey in node) || node.hasAttribute("width") && node[cacheKey].width !== +(node.getAttribute("width") || 0) ? node[cacheKey] = _(node) : node[cacheKey];
154
158
  }
155
159
  /**
156
- * Get BBox.
157
- * @param {SVGElement} node Target element
158
- * @param {boolean} forceEval Force evaluation
159
- * @returns {object}
160
- * @private
161
- */
160
+ * Get BBox.
161
+ * @param {SVGElement} node Target element
162
+ * @param {boolean} forceEval Force evaluation
163
+ * @returns {object}
164
+ * @private
165
+ */
162
166
  function getBBox(node, forceEval = false) {
163
- return _getRect(false, node, forceEval);
167
+ return _getRect(false, node, forceEval);
164
168
  }
165
- // emulate event
166
- ({
167
- mouse: (() => {
168
- const getParams = () => ({
169
- bubbles: false,
170
- cancelable: false,
171
- screenX: 0,
172
- screenY: 0,
173
- clientX: 0,
174
- clientY: 0
175
- });
176
- try {
177
- // eslint-disable-next-line no-new
178
- new MouseEvent("t");
179
- return (el, eventType, params = getParams()) => {
180
- el.dispatchEvent(new MouseEvent(eventType, params));
181
- };
182
- }
183
- catch {
184
- // Polyfills DOM4 MouseEvent
185
- return (el, eventType, params = getParams()) => {
186
- const mouseEvent = doc.createEvent("MouseEvent");
187
- // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent
188
- mouseEvent.initMouseEvent(eventType, params.bubbles, params.cancelable, win, 0, // the event's mouse click count
189
- params.screenX, params.screenY, params.clientX, params.clientY, false, false, false, false, 0, null);
190
- el.dispatchEvent(mouseEvent);
191
- };
192
- }
193
- })()});
194
-
195
- /**
196
- * Load configuration option
197
- * @param {object} config User's generation config value
198
- * @private
199
- */
169
+ (() => {
170
+ const getParams = () => ({
171
+ bubbles: false,
172
+ cancelable: false,
173
+ screenX: 0,
174
+ screenY: 0,
175
+ clientX: 0,
176
+ clientY: 0
177
+ });
178
+ try {
179
+ new MouseEvent("t");
180
+ return (el, eventType, params = getParams()) => {
181
+ el.dispatchEvent(new MouseEvent(eventType, params));
182
+ };
183
+ } catch {
184
+ return (el, eventType, params = getParams()) => {
185
+ const mouseEvent = doc.createEvent("MouseEvent");
186
+ mouseEvent.initMouseEvent(eventType, params.bubbles, params.cancelable, win, 0, params.screenX, params.screenY, params.clientX, params.clientY, false, false, false, false, 0, null);
187
+ el.dispatchEvent(mouseEvent);
188
+ };
189
+ }
190
+ })();
191
+ //#endregion
192
+ //#region src/config/config.ts
193
+ /**
194
+ * Load configuration option
195
+ * @param {object} config User's generation config value
196
+ * @private
197
+ */
200
198
  function loadConfig(config) {
201
- const thisConfig = this.config;
202
- let target;
203
- let keys;
204
- let read;
205
- const find = () => {
206
- const key = keys.shift();
207
- if (key && target && isObjectType(target) && key in target) {
208
- target = target[key];
209
- return find();
210
- }
211
- else if (!key) {
212
- return target;
213
- }
214
- return undefined;
215
- };
216
- Object.keys(thisConfig).forEach(key => {
217
- target = config;
218
- keys = key.split("_");
219
- read = find();
220
- if (isDefined(read)) {
221
- thisConfig[key] = read;
222
- }
223
- });
224
- // only should run in the ChartInternal context
225
- if (this.api) {
226
- this.state.orgConfig = config;
227
- }
199
+ const thisConfig = this.config;
200
+ let target;
201
+ let keys;
202
+ let read;
203
+ const find = () => {
204
+ const key = keys.shift();
205
+ if (key && target && isObjectType(target) && key in target) {
206
+ target = target[key];
207
+ return find();
208
+ } else if (!key) return target;
209
+ };
210
+ Object.keys(thisConfig).forEach((key) => {
211
+ target = config;
212
+ keys = key.split("_");
213
+ read = find();
214
+ if (isDefined(read)) thisConfig[key] = read;
215
+ });
216
+ if (this.api) this.state.orgConfig = config;
228
217
  }
229
-
230
- /**
231
- * Copyright (c) 2017 ~ present NAVER Corp.
232
- * billboard.js project is licensed under the MIT license
233
- */
234
- /**
235
- * Base class to generate billboard.js plugin
236
- * @class Plugin
237
- */
238
- /**
239
- * Version info string for plugin
240
- * @name version
241
- * @static
242
- * @memberof Plugin
243
- * @type {string}
244
- * @example
245
- * bb.plugin.stanford.version; // ex) 1.9.0
246
- */
247
- class Plugin {
248
- $$;
249
- options;
250
- config;
251
- static version = "4.0.3";
252
- /**
253
- * Constructor
254
- * @param {Any} options config option object
255
- * @private
256
- */
257
- constructor(options = {}) {
258
- this.options = options;
259
- }
260
- /**
261
- * Load plugin config from options
262
- * @private
263
- */
264
- loadConfig() {
265
- loadConfig.call(this, this.options);
266
- }
267
- /**
268
- * Lifecycle hook for 'beforeInit' phase.
269
- * @private
270
- */
271
- $beforeInit() { }
272
- /**
273
- * Lifecycle hook for 'init' phase.
274
- * @private
275
- */
276
- $init() { }
277
- /**
278
- * Lifecycle hook for 'afterInit' phase.
279
- * @private
280
- */
281
- $afterInit() { }
282
- /**
283
- * Lifecycle hook for 'redraw' phase.
284
- * @private
285
- */
286
- $redraw() { }
287
- /**
288
- * Lifecycle hook for 'willDestroy' phase.
289
- * @private
290
- */
291
- $willDestroy() {
292
- Object.keys(this).forEach(key => {
293
- this[key] = null;
294
- delete this[key];
295
- });
296
- }
297
- }
298
-
299
- /**
300
- * Copyright (c) 2017 ~ present NAVER Corp.
301
- * billboard.js project is licensed under the MIT license
302
- */
303
- /**
304
- * CSS class names definition
305
- * @private
306
- */
307
- var CLASS = {
308
- colorScale: "bb-colorscale",
309
- stanfordElements: "bb-stanford-elements",
310
- stanfordLine: "bb-stanford-line",
311
- stanfordLines: "bb-stanford-lines",
312
- stanfordRegion: "bb-stanford-region",
313
- stanfordRegions: "bb-stanford-regions"
218
+ //#endregion
219
+ //#region src/Plugin/Plugin.ts
220
+ /**
221
+ * Copyright (c) 2017 ~ present NAVER Corp.
222
+ * billboard.js project is licensed under the MIT license
223
+ */
224
+ /**
225
+ * Base class to generate billboard.js plugin
226
+ * @class Plugin
227
+ */
228
+ /**
229
+ * Version info string for plugin
230
+ * @name version
231
+ * @static
232
+ * @memberof Plugin
233
+ * @type {string}
234
+ * @example
235
+ * bb.plugin.stanford.version; // ex) 1.9.0
236
+ */
237
+ var Plugin = class {
238
+ $$;
239
+ options;
240
+ config;
241
+ static version = "4.1.0-next.2";
242
+ /**
243
+ * Constructor
244
+ * @param {Any} options config option object
245
+ * @private
246
+ */
247
+ constructor(options = {}) {
248
+ this.options = options;
249
+ }
250
+ /**
251
+ * Load plugin config from options
252
+ * @private
253
+ */
254
+ loadConfig() {
255
+ loadConfig.call(this, this.options);
256
+ }
257
+ /**
258
+ * Lifecycle hook for 'beforeInit' phase.
259
+ * @private
260
+ */
261
+ $beforeInit() {}
262
+ /**
263
+ * Lifecycle hook for 'init' phase.
264
+ * @private
265
+ */
266
+ $init() {}
267
+ /**
268
+ * Lifecycle hook for 'afterInit' phase.
269
+ * @private
270
+ */
271
+ $afterInit() {}
272
+ /**
273
+ * Lifecycle hook for 'redraw' phase.
274
+ * @private
275
+ */
276
+ $redraw() {}
277
+ /**
278
+ * Lifecycle hook for 'willDestroy' phase.
279
+ * @private
280
+ */
281
+ $willDestroy() {
282
+ Object.keys(this).forEach((key) => {
283
+ this[key] = null;
284
+ delete this[key];
285
+ });
286
+ }
314
287
  };
315
-
316
- /**
317
- * Copyright (c) 2017 ~ present NAVER Corp.
318
- * billboard.js project is licensed under the MIT license
319
- * @ignore
320
- */
321
- /**
322
- * Check if point is in region
323
- * @param {object} point Point
324
- * @param {Array} region Region
325
- * @returns {boolean}
326
- * @private
327
- */
288
+ //#endregion
289
+ //#region src/Plugin/stanford/classes.ts
290
+ /**
291
+ * Copyright (c) 2017 ~ present NAVER Corp.
292
+ * billboard.js project is licensed under the MIT license
293
+ */
294
+ /**
295
+ * CSS class names definition
296
+ * @private
297
+ */
298
+ var classes_default = {
299
+ colorScale: "bb-colorscale",
300
+ stanfordElements: "bb-stanford-elements",
301
+ stanfordLine: "bb-stanford-line",
302
+ stanfordLines: "bb-stanford-lines",
303
+ stanfordRegion: "bb-stanford-region",
304
+ stanfordRegions: "bb-stanford-regions"
305
+ };
306
+ //#endregion
307
+ //#region src/Plugin/stanford/util.ts
308
+ /**
309
+ * Copyright (c) 2017 ~ present NAVER Corp.
310
+ * billboard.js project is licensed under the MIT license
311
+ * @ignore
312
+ */
313
+ /**
314
+ * Check if point is in region
315
+ * @param {object} point Point
316
+ * @param {Array} region Region
317
+ * @returns {boolean}
318
+ * @private
319
+ */
328
320
  function pointInRegion(point, region) {
329
- // ray-casting algorithm based on
330
- // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
331
- const x = point.x;
332
- const y = point.value;
333
- let inside = false;
334
- for (let i = 0, j = region.length - 1; i < region.length; j = i++) {
335
- const xi = region[i].x;
336
- const yi = region[i].y;
337
- const xj = region[j].x;
338
- const yj = region[j].y;
339
- const intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
340
- if (intersect) {
341
- inside = !inside;
342
- }
343
- }
344
- return inside;
321
+ const x = point.x;
322
+ const y = point.value;
323
+ let inside = false;
324
+ for (let i = 0, j = region.length - 1; i < region.length; j = i++) {
325
+ const xi = region[i].x;
326
+ const yi = region[i].y;
327
+ const xj = region[j].x;
328
+ const yj = region[j].y;
329
+ if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) inside = !inside;
330
+ }
331
+ return inside;
345
332
  }
346
333
  /**
347
- * Compare epochs
348
- * @param {object} a Target
349
- * @param {object} b Source
350
- * @returns {number}
351
- * @private
352
- */
334
+ * Compare epochs
335
+ * @param {object} a Target
336
+ * @param {object} b Source
337
+ * @returns {number}
338
+ * @private
339
+ */
353
340
  function compareEpochs(a, b) {
354
- if (a.epochs < b.epochs) {
355
- return -1;
356
- }
357
- if (a.epochs > b.epochs) {
358
- return 1;
359
- }
360
- return 0;
341
+ if (a.epochs < b.epochs) return -1;
342
+ if (a.epochs > b.epochs) return 1;
343
+ return 0;
361
344
  }
362
345
  /**
363
- * Get region area
364
- * @param {Array} points Points
365
- * @returns {number}
366
- * @private
367
- */
346
+ * Get region area
347
+ * @param {Array} points Points
348
+ * @returns {number}
349
+ * @private
350
+ */
368
351
  function getRegionArea(points) {
369
- let area = 0;
370
- let point1;
371
- let point2;
372
- for (let i = 0, l = points.length, j = l - 1; i < l; j = i, i++) {
373
- point1 = points[i];
374
- point2 = points[j];
375
- area += point1.x * point2.y;
376
- area -= point1.y * point2.x;
377
- }
378
- area /= 2;
379
- return area;
352
+ let area = 0;
353
+ let point1;
354
+ let point2;
355
+ for (let i = 0, l = points.length, j = l - 1; i < l; j = i, i++) {
356
+ point1 = points[i];
357
+ point2 = points[j];
358
+ area += point1.x * point2.y;
359
+ area -= point1.y * point2.x;
360
+ }
361
+ area /= 2;
362
+ return area;
380
363
  }
381
364
  /**
382
- * Get centroid
383
- * @param {Array} points Points
384
- * @returns {object}
385
- * @private
386
- */
365
+ * Get centroid
366
+ * @param {Array} points Points
367
+ * @returns {object}
368
+ * @private
369
+ */
387
370
  function getCentroid(points) {
388
- const area = getRegionArea(points);
389
- let x = 0;
390
- let y = 0;
391
- let f;
392
- for (let i = 0, l = points.length, j = l - 1; i < l; j = i, i++) {
393
- const point1 = points[i];
394
- const point2 = points[j];
395
- f = point1.x * point2.y - point2.x * point1.y;
396
- x += (point1.x + point2.x) * f;
397
- y += (point1.y + point2.y) * f;
398
- }
399
- f = area * 6;
400
- return {
401
- x: x / f,
402
- y: y / f
403
- };
371
+ const area = getRegionArea(points);
372
+ let x = 0;
373
+ let y = 0;
374
+ let f;
375
+ for (let i = 0, l = points.length, j = l - 1; i < l; j = i, i++) {
376
+ const point1 = points[i];
377
+ const point2 = points[j];
378
+ f = point1.x * point2.y - point2.x * point1.y;
379
+ x += (point1.x + point2.x) * f;
380
+ y += (point1.y + point2.y) * f;
381
+ }
382
+ f = area * 6;
383
+ return {
384
+ x: x / f,
385
+ y: y / f
386
+ };
404
387
  }
405
-
388
+ //#endregion
389
+ //#region src/Plugin/stanford/ColorScale.ts
406
390
  /**
407
- * Copyright (c) 2017 ~ present NAVER Corp.
408
- * billboard.js project is licensed under the MIT license
409
- */
391
+ * Copyright (c) 2017 ~ present NAVER Corp.
392
+ * billboard.js project is licensed under the MIT license
393
+ */
410
394
  /**
411
- * Simple number formatter.
412
- * Supports "d" specifier (decimal notation, rounded to integer).
413
- * @param {string} specifier Format specifier
414
- * @returns {function} Formatter function
415
- */
395
+ * Simple number formatter.
396
+ * Supports "d" specifier (decimal notation, rounded to integer).
397
+ * @param {string} specifier Format specifier
398
+ * @returns {function} Formatter function
399
+ */
416
400
  function format(specifier) {
417
- {
418
- return (n) => Math.round(n).toString();
419
- }
401
+ if (specifier === "d") return (n) => Math.round(n).toString();
402
+ return (n) => String(n);
420
403
  }
421
404
  /**
422
- * Stanford diagram plugin color scale class
423
- * @class ColorScale
424
- * @param {Stanford} owner Stanford instance
425
- * @private
426
- */
427
- class ColorScale {
428
- owner;
429
- colorScale;
430
- constructor(owner) {
431
- this.owner = owner;
432
- }
433
- drawColorScale() {
434
- const { $$, config } = this.owner;
435
- const target = $$.data.targets[0];
436
- const height = $$.state.height - config.padding_bottom - config.padding_top;
437
- const barWidth = config.scale_width;
438
- const barHeight = 5;
439
- const points = getRange(config.padding_bottom, height, barHeight);
440
- const inverseScale = scaleSequential(target.colors)
441
- .domain([points[points.length - 1], points[0]]);
442
- if (this.colorScale) {
443
- this.colorScale.remove();
444
- }
445
- this.colorScale = $$.$el.svg.append("g")
446
- .attr("width", 50)
447
- .attr("height", height)
448
- .attr("class", CLASS.colorScale);
449
- this.colorScale.append("g")
450
- .attr("transform", `translate(0, ${config.padding_top})`)
451
- .selectAll("bars")
452
- .data(points)
453
- .enter()
454
- .append("rect")
455
- .attr("y", (d, i) => i * barHeight)
456
- .attr("x", 0)
457
- .attr("width", barWidth)
458
- .attr("height", barHeight)
459
- .attr("fill", d => inverseScale(d));
460
- // Legend Axis
461
- const axisScale = scaleSymlog()
462
- .domain([target.minEpochs, target.maxEpochs])
463
- .range([
464
- points[0] + config.padding_top + points[points.length - 1] + barHeight - 1,
465
- points[0] + config.padding_top
466
- ]);
467
- const legendAxis = axisRight(axisScale);
468
- const scaleFormat = config.scale_format;
469
- if (scaleFormat === "pow10") {
470
- legendAxis.tickValues([1, 10, 100, 1000, 10000, 100000, 1000000, 10000000]);
471
- }
472
- else if (isFunction(scaleFormat)) {
473
- legendAxis.tickFormat(scaleFormat);
474
- }
475
- else {
476
- legendAxis.tickFormat(format());
477
- }
478
- // Draw Axis
479
- const axis = this.colorScale.append("g")
480
- .attr("class", "legend axis")
481
- .attr("transform", `translate(${barWidth},0)`)
482
- .call(legendAxis);
483
- if (scaleFormat === "pow10") {
484
- axis.selectAll(".tick text")
485
- .text(null)
486
- .filter(d => d / Math.pow(10, Math.ceil(Math.log(d) / Math.LN10 - 1e-12)) === 1) // Power of Ten
487
- .text(10)
488
- .append("tspan")
489
- .attr("dy", "-.7em") // https://bl.ocks.org/mbostock/6738229
490
- .text(d => Math.round(Math.log(d) / Math.LN10));
491
- }
492
- this.colorScale.attr("transform", `translate(${$$.state.current.width - this.xForColorScale()}, 0)`);
493
- }
494
- xForColorScale() {
495
- return this.owner.config.padding_right +
496
- getBBox(this.colorScale.node(), true).width;
497
- }
498
- getColorScalePadding() {
499
- return this.xForColorScale() + this.owner.config.padding_left + 20;
500
- }
501
- }
502
-
503
- /**
504
- * Copyright (c) 2017 ~ present NAVER Corp.
505
- * billboard.js project is licensed under the MIT license
506
- */
507
- // @ts-nocheck
508
- /**
509
- * Stanford diagram plugin element class
510
- * @class ColorScale
511
- * @param {Stanford} owner Stanford instance
512
- * @private
513
- */
514
- class Elements {
515
- owner;
516
- constructor(owner) {
517
- this.owner = owner;
518
- // MEMO: Avoid blocking eventRect
519
- const elements = owner.$$.$el.main.select(".bb-chart")
520
- .append("g")
521
- .attr("class", CLASS.stanfordElements);
522
- elements.append("g").attr("class", CLASS.stanfordLines);
523
- elements.append("g").attr("class", CLASS.stanfordRegions);
524
- }
525
- updateStanfordLines(duration) {
526
- const { $$ } = this.owner;
527
- const { config, $el: { main } } = $$;
528
- const isRotated = config.axis_rotated;
529
- const xvCustom = this.xvCustom.bind($$);
530
- const yvCustom = this.yvCustom.bind($$);
531
- // Stanford-Lines
532
- const stanfordLine = main.select(`.${CLASS.stanfordLines}`)
533
- .style("shape-rendering", "geometricprecision")
534
- .selectAll(`.${CLASS.stanfordLine}`)
535
- .data(this.owner.config.lines);
536
- // exit
537
- stanfordLine.exit().transition()
538
- .duration(duration)
539
- .style("opacity", "0")
540
- .remove();
541
- // enter
542
- const stanfordLineEnter = stanfordLine.enter().append("g");
543
- stanfordLineEnter.append("line")
544
- .style("opacity", "0");
545
- stanfordLineEnter
546
- .merge(stanfordLine)
547
- .attr("class", d => CLASS.stanfordLine + (d.class ? ` ${d.class}` : ""))
548
- .select("line")
549
- .transition()
550
- .duration(duration)
551
- .attr("x1", d => {
552
- const v = isRotated ? yvCustom(d, "y1") : xvCustom(d, "x1");
553
- return v;
554
- })
555
- .attr("x2", d => (isRotated ? yvCustom(d, "y2") : xvCustom(d, "x2")))
556
- .attr("y1", d => {
557
- const v = isRotated ? xvCustom(d, "x1") : yvCustom(d, "y1");
558
- return v;
559
- })
560
- .attr("y2", d => (isRotated ? xvCustom(d, "x2") : yvCustom(d, "y2")))
561
- .transition()
562
- .style("opacity", null);
563
- }
564
- updateStanfordRegions(duration) {
565
- const { $$ } = this.owner;
566
- const { config, $el: { main } } = $$;
567
- const isRotated = config.axis_rotated;
568
- const xvCustom = this.xvCustom.bind($$);
569
- const yvCustom = this.yvCustom.bind($$);
570
- const countPointsInRegion = this.owner.countEpochsInRegion.bind($$);
571
- // Stanford-Regions
572
- let stanfordRegion = main.select(`.${CLASS.stanfordRegions}`)
573
- .selectAll(`.${CLASS.stanfordRegion}`)
574
- .data(this.owner.config.regions);
575
- // exit
576
- stanfordRegion.exit().transition()
577
- .duration(duration)
578
- .style("opacity", "0")
579
- .remove();
580
- // enter
581
- const stanfordRegionEnter = stanfordRegion.enter().append("g");
582
- stanfordRegionEnter.append("polygon")
583
- .style("opacity", "0");
584
- stanfordRegionEnter.append("text")
585
- .attr("transform", isRotated ? "rotate(-90)" : "")
586
- .style("opacity", "0");
587
- stanfordRegion = stanfordRegionEnter.merge(stanfordRegion);
588
- // update
589
- stanfordRegion
590
- .attr("class", d => CLASS.stanfordRegion + (d.class ? ` ${d.class}` : ""))
591
- .select("polygon")
592
- .transition()
593
- .duration(duration)
594
- .attr("points", d => d.points.map(value => [
595
- isRotated ? yvCustom(value, "y") : xvCustom(value, "x"),
596
- isRotated ? xvCustom(value, "x") : yvCustom(value, "y")
597
- ].join(",")).join(" "))
598
- .transition()
599
- .style("opacity", d => String(d.opacity ? d.opacity : 0.2));
600
- stanfordRegion.select("text")
601
- .transition()
602
- .duration(duration)
603
- .attr("x", d => (isRotated ?
604
- yvCustom(getCentroid(d.points), "y") :
605
- xvCustom(getCentroid(d.points), "x")))
606
- .attr("y", d => (isRotated ?
607
- xvCustom(getCentroid(d.points), "x") :
608
- yvCustom(getCentroid(d.points), "y")))
609
- .text(d => {
610
- if (d.text) {
611
- const { value, percentage } = countPointsInRegion(d.points);
612
- return d.text(value, percentage);
613
- }
614
- return "";
615
- })
616
- .attr("text-anchor", "middle")
617
- .attr("dominant-baseline", "middle")
618
- .transition()
619
- .style("opacity", null);
620
- }
621
- updateStanfordElements(duration = 0) {
622
- this.updateStanfordLines(duration);
623
- this.updateStanfordRegions(duration);
624
- }
625
- xvCustom(d, xyValue) {
626
- const $$ = this;
627
- const { axis, config } = $$;
628
- let value = xyValue ? d[xyValue] : $$.getBaseValue(d);
629
- if (axis.isTimeSeries()) {
630
- value = parseDate.call($$, value);
631
- }
632
- else if (axis.isCategorized() && isString(value)) {
633
- value = config.axis_x_categories.indexOf(d.value);
634
- }
635
- return $$.scale.x(value);
636
- }
637
- yvCustom(d, xyValue) {
638
- const $$ = this;
639
- const yScale = d.axis && d.axis === "y2" ? $$.scale.y2 : $$.scale.y;
640
- const value = xyValue ? d[xyValue] : $$.getBaseValue(d);
641
- return yScale(value);
642
- }
643
- }
644
-
645
- /**
646
- * Copyright (c) 2017 ~ present NAVER Corp.
647
- * billboard.js project is licensed under the MIT license
648
- */
649
- /**
650
- * Stanford diagram plugin option class
651
- * @class StanfordOptions
652
- * @param {Options} options Stanford plugin options
653
- * @augments Plugin
654
- * @returns {StanfordOptions}
655
- * @private
656
- */
657
- class Options {
658
- constructor() {
659
- return {
660
- /**
661
- * Set the color of the color scale. This function receives a value between 0 and 1, and should return a color.
662
- * @name colors
663
- * @memberof plugin-stanford
664
- * @type {function}
665
- * @default undefined
666
- * @example
667
- * colors: d3.interpolateHslLong(
668
- * d3.hsl(250, 1, 0.5), d3.hsl(0, 1, 0.5)
669
- * )
670
- */
671
- colors: undefined,
672
- /**
673
- * Specify the key of epochs values in the data.
674
- * @name epochs
675
- * @memberof plugin-stanford
676
- * @type {Array}
677
- * @default []
678
- * @example
679
- * epochs: [ 1, 1, 2, 2, ... ]
680
- */
681
- epochs: [],
682
- /**
683
- * Show additional lines anywhere on the chart.
684
- * - Each line object should consist with following options:
685
- *
686
- * | Key | Type | Description |
687
- * | --- | --- | --- |
688
- * | x1 | Number | Starting position on the x axis |
689
- * | y1 | Number | Starting position on the y axis |
690
- * | x2 | Number | Ending position on the x axis |
691
- * | y2 | Number | Ending position on the y axis |
692
- * | class | String | Optional value. Set a custom css class to this line. |
693
- * @type {Array}
694
- * @memberof plugin-stanford
695
- * @default []
696
- * @example
697
- * lines: [
698
- * { x1: 0, y1: 0, x2: 65, y2: 65, class: "line1" },
699
- * { x1: 0, x2: 65, y1: 40, y2: 40, class: "line2" }
700
- * ]
701
- */
702
- lines: [],
703
- /**
704
- * Set scale values
705
- * @name scale
706
- * @memberof plugin-stanford
707
- * @type {object}
708
- * @property {object} [scale] scale object
709
- * @property {number} [scale.min=undefined] Minimum value of the color scale. Default: lowest value in epochs
710
- * @property {number} [scale.max=undefined] Maximum value of the color scale. Default: highest value in epochs
711
- * @property {number} [scale.width=20] Width of the color scale
712
- * @property {string|function} [scale.format=undefined] Format of the axis of the color scale. Use 'pow10' to format as powers of 10 or a custom function. Example: d3.format("d")
713
- * @example
714
- * scale: {
715
- * max: 10000,
716
- * min: 1,
717
- * width: 500,
718
- *
719
- * // specify 'pow10' to format as powers of 10
720
- * format: "pow10",
721
- *
722
- * // or specify a format function
723
- * format: function(x) {
724
- * return x +"%";
725
- * }
726
- * },
727
- */
728
- scale_min: undefined,
729
- scale_max: undefined,
730
- scale_width: 20,
731
- scale_format: undefined,
732
- /**
733
- * The padding for color scale element
734
- * @name padding
735
- * @memberof plugin-stanford
736
- * @type {object}
737
- * @property {object} [padding] padding object
738
- * @property {number} [padding.top=0] Top padding value.
739
- * @property {number} [padding.right=0] Right padding value.
740
- * @property {number} [padding.bottom=0] Bottom padding value.
741
- * @property {number} [padding.left=0] Left padding value.
742
- * @example
743
- * padding: {
744
- * top: 15,
745
- * right: 0,
746
- * bottom: 0,
747
- * left: 0
748
- * },
749
- */
750
- padding_top: 0,
751
- padding_right: 0,
752
- padding_bottom: 0,
753
- padding_left: 0,
754
- /**
755
- * Show additional regions anywhere on the chart.
756
- * - Each region object should consist with following options:
757
- *
758
- * | Key | Type | Default | Attributes | Description |
759
- * | --- | --- | --- | --- | --- |
760
- * | points | Array | | | Accepts a group of objects that has x and y.<br>These points should be added in a counter-clockwise fashion to make a closed polygon. |
761
- * | opacity | Number | `0.2` | &lt;optional> | Sets the opacity of the region as value between 0 and 1 |
762
- * | text | Function | | &lt;optional> | This function receives a value and percentage of the number of epochs in this region.<br>Return a string to place text in the middle of the region. |
763
- * | class | String | | &lt;optional> | Se a custom css class to this region, use the fill property in css to set a background color. |
764
- * @name regions
765
- * @memberof plugin-stanford
766
- * @type {Array}
767
- * @default []
768
- * @example
769
- * regions: [
770
- * {
771
- * points: [ // add points counter-clockwise
772
- * { x: 0, y: 0 },
773
- * { x: 40, y: 40 },
774
- * { x: 0, y: 40 },
775
- * ],
776
- * text: function (value, percentage) {
777
- * return `Normal Operations: ${value} (${percentage}%)`;
778
- * },
779
- * opacity: 0.2, // 0 to 1
780
- * class: "test-polygon1"
781
- * },
782
- * ...
783
- * ]
784
- */
785
- regions: []
786
- };
787
- }
788
- }
789
-
790
- /**
791
- * Copyright (c) 2017 ~ present NAVER Corp.
792
- * billboard.js project is licensed under the MIT license
793
- */
794
- // @ts-nocheck
795
- /**
796
- * Creates an HSL color object.
797
- * @param {number} h Hue (0-360)
798
- * @param {number} s Saturation (0-1)
799
- * @param {number} l Lightness (0-1)
800
- * @param {number} opacity Opacity (0-1), defaults to 1
801
- * @returns {HSLColor} HSL color object
802
- */
405
+ * Stanford diagram plugin color scale class
406
+ * @class ColorScale
407
+ * @param {Stanford} owner Stanford instance
408
+ * @private
409
+ */
410
+ var ColorScale = class {
411
+ owner;
412
+ colorScale;
413
+ constructor(owner) {
414
+ this.owner = owner;
415
+ }
416
+ drawColorScale() {
417
+ const { $$, config } = this.owner;
418
+ const target = $$.data.targets[0];
419
+ const height = $$.state.height - config.padding_bottom - config.padding_top;
420
+ const barWidth = config.scale_width;
421
+ const barHeight = 5;
422
+ const points = getRange(config.padding_bottom, height, barHeight);
423
+ const inverseScale = scaleSequential(target.colors).domain([points[points.length - 1], points[0]]);
424
+ if (this.colorScale) this.colorScale.remove();
425
+ this.colorScale = $$.$el.svg.append("g").attr("width", 50).attr("height", height).attr("class", classes_default.colorScale);
426
+ this.colorScale.append("g").attr("transform", `translate(0, ${config.padding_top})`).selectAll("bars").data(points).enter().append("rect").attr("y", (d, i) => i * barHeight).attr("x", 0).attr("width", barWidth).attr("height", barHeight).attr("fill", (d) => inverseScale(d));
427
+ const legendAxis = axisRight(scaleSymlog().domain([target.minEpochs, target.maxEpochs]).range([points[0] + config.padding_top + points[points.length - 1] + barHeight - 1, points[0] + config.padding_top]));
428
+ const scaleFormat = config.scale_format;
429
+ if (scaleFormat === "pow10") legendAxis.tickValues([
430
+ 1,
431
+ 10,
432
+ 100,
433
+ 1e3,
434
+ 1e4,
435
+ 1e5,
436
+ 1e6,
437
+ 1e7
438
+ ]);
439
+ else if (isFunction(scaleFormat)) legendAxis.tickFormat(scaleFormat);
440
+ else legendAxis.tickFormat(format("d"));
441
+ const axis = this.colorScale.append("g").attr("class", "legend axis").attr("transform", `translate(${barWidth},0)`).call(legendAxis);
442
+ if (scaleFormat === "pow10") axis.selectAll(".tick text").text(null).filter((d) => d / Math.pow(10, Math.ceil(Math.log(d) / Math.LN10 - 1e-12)) === 1).text(10).append("tspan").attr("dy", "-.7em").text((d) => Math.round(Math.log(d) / Math.LN10));
443
+ this.colorScale.attr("transform", `translate(${$$.state.current.width - this.xForColorScale()}, 0)`);
444
+ }
445
+ xForColorScale() {
446
+ return this.owner.config.padding_right + getBBox(this.colorScale.node(), true).width;
447
+ }
448
+ getColorScalePadding() {
449
+ return this.xForColorScale() + this.owner.config.padding_left + 20;
450
+ }
451
+ };
452
+ //#endregion
453
+ //#region src/Plugin/stanford/Elements.ts
454
+ /**
455
+ * Copyright (c) 2017 ~ present NAVER Corp.
456
+ * billboard.js project is licensed under the MIT license
457
+ */
458
+ /**
459
+ * Stanford diagram plugin element class
460
+ * @class ColorScale
461
+ * @param {Stanford} owner Stanford instance
462
+ * @private
463
+ */
464
+ var Elements = class {
465
+ owner;
466
+ constructor(owner) {
467
+ this.owner = owner;
468
+ const elements = owner.$$.$el.main.select(".bb-chart").append("g").attr("class", classes_default.stanfordElements);
469
+ elements.append("g").attr("class", classes_default.stanfordLines);
470
+ elements.append("g").attr("class", classes_default.stanfordRegions);
471
+ }
472
+ updateStanfordLines(duration) {
473
+ const { $$ } = this.owner;
474
+ const { config, $el: { main } } = $$;
475
+ const isRotated = config.axis_rotated;
476
+ const xvCustom = this.xvCustom.bind($$);
477
+ const yvCustom = this.yvCustom.bind($$);
478
+ const stanfordLine = main.select(`.${classes_default.stanfordLines}`).style("shape-rendering", "geometricprecision").selectAll(`.${classes_default.stanfordLine}`).data(this.owner.config.lines);
479
+ stanfordLine.exit().transition().duration(duration).style("opacity", "0").remove();
480
+ const stanfordLineEnter = stanfordLine.enter().append("g");
481
+ stanfordLineEnter.append("line").style("opacity", "0");
482
+ stanfordLineEnter.merge(stanfordLine).attr("class", (d) => classes_default.stanfordLine + (d.class ? ` ${d.class}` : "")).select("line").transition().duration(duration).attr("x1", (d) => {
483
+ return isRotated ? yvCustom(d, "y1") : xvCustom(d, "x1");
484
+ }).attr("x2", (d) => isRotated ? yvCustom(d, "y2") : xvCustom(d, "x2")).attr("y1", (d) => {
485
+ return isRotated ? xvCustom(d, "x1") : yvCustom(d, "y1");
486
+ }).attr("y2", (d) => isRotated ? xvCustom(d, "x2") : yvCustom(d, "y2")).transition().style("opacity", null);
487
+ }
488
+ updateStanfordRegions(duration) {
489
+ const { $$ } = this.owner;
490
+ const { config, $el: { main } } = $$;
491
+ const isRotated = config.axis_rotated;
492
+ const xvCustom = this.xvCustom.bind($$);
493
+ const yvCustom = this.yvCustom.bind($$);
494
+ const countPointsInRegion = this.owner.countEpochsInRegion.bind($$);
495
+ let stanfordRegion = main.select(`.${classes_default.stanfordRegions}`).selectAll(`.${classes_default.stanfordRegion}`).data(this.owner.config.regions);
496
+ stanfordRegion.exit().transition().duration(duration).style("opacity", "0").remove();
497
+ const stanfordRegionEnter = stanfordRegion.enter().append("g");
498
+ stanfordRegionEnter.append("polygon").style("opacity", "0");
499
+ stanfordRegionEnter.append("text").attr("transform", isRotated ? "rotate(-90)" : "").style("opacity", "0");
500
+ stanfordRegion = stanfordRegionEnter.merge(stanfordRegion);
501
+ stanfordRegion.attr("class", (d) => classes_default.stanfordRegion + (d.class ? ` ${d.class}` : "")).select("polygon").transition().duration(duration).attr("points", (d) => d.points.map((value) => [isRotated ? yvCustom(value, "y") : xvCustom(value, "x"), isRotated ? xvCustom(value, "x") : yvCustom(value, "y")].join(",")).join(" ")).transition().style("opacity", (d) => String(d.opacity ? d.opacity : .2));
502
+ stanfordRegion.select("text").transition().duration(duration).attr("x", (d) => isRotated ? yvCustom(getCentroid(d.points), "y") : xvCustom(getCentroid(d.points), "x")).attr("y", (d) => isRotated ? xvCustom(getCentroid(d.points), "x") : yvCustom(getCentroid(d.points), "y")).text((d) => {
503
+ if (d.text) {
504
+ const { value, percentage } = countPointsInRegion(d.points);
505
+ return d.text(value, percentage);
506
+ }
507
+ return "";
508
+ }).attr("text-anchor", "middle").attr("dominant-baseline", "middle").transition().style("opacity", null);
509
+ }
510
+ updateStanfordElements(duration = 0) {
511
+ this.updateStanfordLines(duration);
512
+ this.updateStanfordRegions(duration);
513
+ }
514
+ xvCustom(d, xyValue) {
515
+ const $$ = this;
516
+ const { axis, config } = $$;
517
+ let value = xyValue ? d[xyValue] : $$.getBaseValue(d);
518
+ if (axis.isTimeSeries()) value = parseDate.call($$, value);
519
+ else if (axis.isCategorized() && isString(value)) value = config.axis_x_categories.indexOf(d.value);
520
+ return $$.scale.x(value);
521
+ }
522
+ yvCustom(d, xyValue) {
523
+ const $$ = this;
524
+ return (d.axis && d.axis === "y2" ? $$.scale.y2 : $$.scale.y)(xyValue ? d[xyValue] : $$.getBaseValue(d));
525
+ }
526
+ };
527
+ //#endregion
528
+ //#region src/Plugin/stanford/Options.ts
529
+ /**
530
+ * Copyright (c) 2017 ~ present NAVER Corp.
531
+ * billboard.js project is licensed under the MIT license
532
+ */
533
+ /**
534
+ * Stanford diagram plugin option class
535
+ * @class StanfordOptions
536
+ * @param {Options} options Stanford plugin options
537
+ * @augments Plugin
538
+ * @returns {StanfordOptions}
539
+ * @private
540
+ */
541
+ var Options = class {
542
+ constructor() {
543
+ return {
544
+ /**
545
+ * Set the color of the color scale. This function receives a value between 0 and 1, and should return a color.
546
+ * @name colors
547
+ * @memberof plugin-stanford
548
+ * @type {function}
549
+ * @default undefined
550
+ * @example
551
+ * colors: d3.interpolateHslLong(
552
+ * d3.hsl(250, 1, 0.5), d3.hsl(0, 1, 0.5)
553
+ * )
554
+ */
555
+ colors: void 0,
556
+ /**
557
+ * Specify the key of epochs values in the data.
558
+ * @name epochs
559
+ * @memberof plugin-stanford
560
+ * @type {Array}
561
+ * @default []
562
+ * @example
563
+ * epochs: [ 1, 1, 2, 2, ... ]
564
+ */
565
+ epochs: [],
566
+ /**
567
+ * Show additional lines anywhere on the chart.
568
+ * - Each line object should consist with following options:
569
+ *
570
+ * | Key | Type | Description |
571
+ * | --- | --- | --- |
572
+ * | x1 | Number | Starting position on the x axis |
573
+ * | y1 | Number | Starting position on the y axis |
574
+ * | x2 | Number | Ending position on the x axis |
575
+ * | y2 | Number | Ending position on the y axis |
576
+ * | class | String | Optional value. Set a custom css class to this line. |
577
+ * @type {Array}
578
+ * @memberof plugin-stanford
579
+ * @default []
580
+ * @example
581
+ * lines: [
582
+ * { x1: 0, y1: 0, x2: 65, y2: 65, class: "line1" },
583
+ * { x1: 0, x2: 65, y1: 40, y2: 40, class: "line2" }
584
+ * ]
585
+ */
586
+ lines: [],
587
+ /**
588
+ * Set scale values
589
+ * @name scale
590
+ * @memberof plugin-stanford
591
+ * @type {object}
592
+ * @property {object} [scale] scale object
593
+ * @property {number} [scale.min=undefined] Minimum value of the color scale. Default: lowest value in epochs
594
+ * @property {number} [scale.max=undefined] Maximum value of the color scale. Default: highest value in epochs
595
+ * @property {number} [scale.width=20] Width of the color scale
596
+ * @property {string|function} [scale.format=undefined] Format of the axis of the color scale. Use 'pow10' to format as powers of 10 or a custom function. Example: d3.format("d")
597
+ * @example
598
+ * scale: {
599
+ * max: 10000,
600
+ * min: 1,
601
+ * width: 500,
602
+ *
603
+ * // specify 'pow10' to format as powers of 10
604
+ * format: "pow10",
605
+ *
606
+ * // or specify a format function
607
+ * format: function(x) {
608
+ * return x +"%";
609
+ * }
610
+ * },
611
+ */
612
+ scale_min: void 0,
613
+ scale_max: void 0,
614
+ scale_width: 20,
615
+ scale_format: void 0,
616
+ /**
617
+ * The padding for color scale element
618
+ * @name padding
619
+ * @memberof plugin-stanford
620
+ * @type {object}
621
+ * @property {object} [padding] padding object
622
+ * @property {number} [padding.top=0] Top padding value.
623
+ * @property {number} [padding.right=0] Right padding value.
624
+ * @property {number} [padding.bottom=0] Bottom padding value.
625
+ * @property {number} [padding.left=0] Left padding value.
626
+ * @example
627
+ * padding: {
628
+ * top: 15,
629
+ * right: 0,
630
+ * bottom: 0,
631
+ * left: 0
632
+ * },
633
+ */
634
+ padding_top: 0,
635
+ padding_right: 0,
636
+ padding_bottom: 0,
637
+ padding_left: 0,
638
+ /**
639
+ * Show additional regions anywhere on the chart.
640
+ * - Each region object should consist with following options:
641
+ *
642
+ * | Key | Type | Default | Attributes | Description |
643
+ * | --- | --- | --- | --- | --- |
644
+ * | points | Array | | | Accepts a group of objects that has x and y.<br>These points should be added in a counter-clockwise fashion to make a closed polygon. |
645
+ * | opacity | Number | `0.2` | &lt;optional> | Sets the opacity of the region as value between 0 and 1 |
646
+ * | text | Function | | &lt;optional> | This function receives a value and percentage of the number of epochs in this region.<br>Return a string to place text in the middle of the region. |
647
+ * | class | String | | &lt;optional> | Se a custom css class to this region, use the fill property in css to set a background color. |
648
+ * @name regions
649
+ * @memberof plugin-stanford
650
+ * @type {Array}
651
+ * @default []
652
+ * @example
653
+ * regions: [
654
+ * {
655
+ * points: [ // add points counter-clockwise
656
+ * { x: 0, y: 0 },
657
+ * { x: 40, y: 40 },
658
+ * { x: 0, y: 40 },
659
+ * ],
660
+ * text: function (value, percentage) {
661
+ * return `Normal Operations: ${value} (${percentage}%)`;
662
+ * },
663
+ * opacity: 0.2, // 0 to 1
664
+ * class: "test-polygon1"
665
+ * },
666
+ * ...
667
+ * ]
668
+ */
669
+ regions: []
670
+ };
671
+ }
672
+ };
673
+ //#endregion
674
+ //#region src/Plugin/stanford/index.ts
675
+ /**
676
+ * Copyright (c) 2017 ~ present NAVER Corp.
677
+ * billboard.js project is licensed under the MIT license
678
+ */
679
+ /**
680
+ * Creates an HSL color object.
681
+ * @param {number} h Hue (0-360)
682
+ * @param {number} s Saturation (0-1)
683
+ * @param {number} l Lightness (0-1)
684
+ * @param {number} opacity Opacity (0-1), defaults to 1
685
+ * @returns {HSLColor} HSL color object
686
+ */
803
687
  function hsl(h, s, l, opacity = 1) {
804
- return {
805
- h: +h,
806
- s: 1,
807
- l: 0.5,
808
- opacity: +opacity
809
- };
688
+ return {
689
+ h: +h,
690
+ s: +s,
691
+ l: +l,
692
+ opacity: +opacity
693
+ };
810
694
  }
811
695
  /**
812
- * Stanford diagram plugin
813
- * - **NOTE:**
814
- * - Plugins aren't built-in. Need to be loaded or imported to be used.
815
- * - Non required modules from billboard.js core, need to be installed separately.
816
- * - Is preferable use `scatter` as data.type
817
- * - **Required modules:**
818
- * - [d3-selection](https://github.com/d3/d3-selection)
819
- * - [d3-interpolate](https://github.com/d3/d3-interpolate)
820
- * - [d3-scale](https://github.com/d3/d3-scale)
821
- * - [d3-brush](https://github.com/d3/d3-brush)
822
- * - [d3-axis](https://github.com/d3/d3-axis)
823
- * @class plugin-stanford
824
- * @requires d3-selection
825
- * @requires d3-interpolate
826
- * @requires d3-scale
827
- * @requires d3-brush
828
- * @requires d3-axis
829
- * @param {object} options Stanford plugin options
830
- * @augments Plugin
831
- * @returns {Stanford}
832
- * @example
833
- * // Plugin must be loaded before the use.
834
- * <script src="$YOUR_PATH/plugin/billboardjs-plugin-stanford.js"></script>
835
- *
836
- * var chart = bb.generate({
837
- * data: {
838
- * columns: [ ... ],
839
- * type: "scatter"
840
- * }
841
- * ...
842
- * plugins: [
843
- * new bb.plugin.stanford({
844
- * colors: d3.interpolateHslLong(
845
- * d3.hsl(250, 1, 0.5), d3.hsl(0, 1, 0.5)
846
- * ),
847
- * epochs: [ 1, 1, 2, 2, ... ],
848
- * lines: [
849
- * { x1: 0, y1: 0, x2: 65, y2: 65, class: "line1" },
850
- * { x1: 0, x2: 65, y1: 40, y2: 40, class: "line2" }
851
- * ],
852
- * scale: {
853
- * max: 10000,
854
- * min: 1,
855
- * width: 500,
856
- * format: 'pow10',
857
- * },
858
- * padding: {
859
- * top: 15,
860
- * right: 0,
861
- * bottom: 0,
862
- * left: 0
863
- * },
864
- * regions: [
865
- * {
866
- * points: [ // add points counter-clockwise
867
- * { x: 0, y: 0 },
868
- * { x: 40, y: 40 },
869
- * { x: 0, y: 40 }
870
- * ],
871
- * text: function (value, percentage) {
872
- * return `Normal Operations: ${value} (${percentage}%)`;
873
- * },
874
- * opacity: 0.2, // 0 to 1
875
- * class: "test-polygon1"
876
- * },
877
- * ...
878
- * ]
879
- * }
880
- * ]
881
- * });
882
- * @example
883
- * import {bb} from "billboard.js";
884
- * import Stanford from "billboard.js/dist/billboardjs-plugin-stanford";
885
- *
886
- * bb.generate({
887
- * plugins: [
888
- * new Stanford({ ... })
889
- * ]
890
- * })
891
- */
892
- class Stanford extends Plugin {
893
- colorScale;
894
- elements;
895
- constructor(options) {
896
- super(options);
897
- this.config = new Options();
898
- return this;
899
- }
900
- $beforeInit() {
901
- const { $$ } = this;
902
- // override on config values & methods
903
- $$.config.data_xSort = false;
904
- $$.isMultipleX = () => true;
905
- $$.showGridFocus = () => { };
906
- $$.labelishData = d => d.values;
907
- $$.opacityForCircle = () => 1;
908
- const getCurrentPadding = $$.getCurrentPadding.bind($$);
909
- $$.getCurrentPadding = () => {
910
- const padding = getCurrentPadding();
911
- padding.right += this.colorScale ? this.colorScale.getColorScalePadding() : 0;
912
- return padding;
913
- };
914
- }
915
- $init() {
916
- const { $$ } = this;
917
- this.loadConfig();
918
- $$.color = this.getStanfordPointColor.bind($$);
919
- this.colorScale = new ColorScale(this);
920
- this.elements = new Elements(this);
921
- this.convertData();
922
- this.initStanfordData();
923
- this.setStanfordTooltip();
924
- this.colorScale.drawColorScale();
925
- $$.right += this.colorScale ? this.colorScale.getColorScalePadding() : 0;
926
- this.$redraw();
927
- }
928
- $redraw(duration) {
929
- this.colorScale?.drawColorScale();
930
- this.elements?.updateStanfordElements(duration);
931
- }
932
- getOptions() {
933
- return new Options();
934
- }
935
- convertData() {
936
- const data = this.$$.data.targets;
937
- const epochs = this.options.epochs;
938
- data.forEach(d => {
939
- d.values.forEach((v, i) => {
940
- v.epochs = epochs[i];
941
- });
942
- d.minEpochs = undefined;
943
- d.maxEpochs = undefined;
944
- d.colors = undefined;
945
- d.colorscale = undefined;
946
- });
947
- }
948
- initStanfordData() {
949
- const { config } = this;
950
- const target = this.$$.data.targets[0];
951
- // TODO STANFORD see if (data.js -> orderTargets)+ can be used instead
952
- // Make larger values appear on top
953
- target.values.sort(compareEpochs);
954
- // Get min/max epochs
955
- let minEpoch = Infinity;
956
- let maxEpoch = -Infinity;
957
- for (let i = 0; i < target.values.length; i++) {
958
- const e = target.values[i].epochs;
959
- if (e < minEpoch)
960
- minEpoch = e;
961
- if (e > maxEpoch)
962
- maxEpoch = e;
963
- }
964
- target.minEpochs = !isNaN(config.scale_min) ? config.scale_min : minEpoch;
965
- target.maxEpochs = !isNaN(config.scale_max) ? config.scale_max : maxEpoch;
966
- target.colors = isFunction(config.colors) ?
967
- config.colors :
968
- interpolateHslLong(hsl(250), hsl(0));
969
- target.colorscale = scaleSequentialLog(target.colors)
970
- .domain([target.minEpochs, target.maxEpochs]);
971
- }
972
- getStanfordPointColor(d) {
973
- const target = this.data.targets[0];
974
- return target.colorscale(d.epochs);
975
- }
976
- setStanfordTooltip() {
977
- const { config } = this.$$;
978
- if (isEmpty(config.tooltip_contents)) {
979
- config.tooltip_contents = function (d, defaultTitleFormat, defaultValueFormat, color) {
980
- const { data_x } = config;
981
- let html = `<table class="${$TOOLTIP.tooltip}"><tbody>`;
982
- d.forEach(v => {
983
- const { id = "", value = 0, epochs = 0, x = "" } = v;
984
- html += `<tr>
696
+ * Stanford diagram plugin
697
+ * - **NOTE:**
698
+ * - Plugins aren't built-in. Need to be loaded or imported to be used.
699
+ * - Non required modules from billboard.js core, need to be installed separately.
700
+ * - Is preferable use `scatter` as data.type
701
+ * - **Required modules:**
702
+ * - [d3-selection](https://github.com/d3/d3-selection)
703
+ * - [d3-interpolate](https://github.com/d3/d3-interpolate)
704
+ * - [d3-brush](https://github.com/d3/d3-brush)
705
+ * @class plugin-stanford
706
+ * @requires d3-selection
707
+ * @requires d3-interpolate
708
+ * @requires d3-brush
709
+ * @param {object} options Stanford plugin options
710
+ * @augments Plugin
711
+ * @returns {Stanford}
712
+ * @example
713
+ * // Plugin must be loaded before the use.
714
+ * <script src="$YOUR_PATH/plugin/billboardjs-plugin-stanford.js"><\/script>
715
+ *
716
+ * var chart = bb.generate({
717
+ * data: {
718
+ * columns: [ ... ],
719
+ * type: "scatter"
720
+ * }
721
+ * ...
722
+ * plugins: [
723
+ * new bb.plugin.stanford({
724
+ * colors: d3.interpolateHslLong(
725
+ * d3.hsl(250, 1, 0.5), d3.hsl(0, 1, 0.5)
726
+ * ),
727
+ * epochs: [ 1, 1, 2, 2, ... ],
728
+ * lines: [
729
+ * { x1: 0, y1: 0, x2: 65, y2: 65, class: "line1" },
730
+ * { x1: 0, x2: 65, y1: 40, y2: 40, class: "line2" }
731
+ * ],
732
+ * scale: {
733
+ * max: 10000,
734
+ * min: 1,
735
+ * width: 500,
736
+ * format: 'pow10',
737
+ * },
738
+ * padding: {
739
+ * top: 15,
740
+ * right: 0,
741
+ * bottom: 0,
742
+ * left: 0
743
+ * },
744
+ * regions: [
745
+ * {
746
+ * points: [ // add points counter-clockwise
747
+ * { x: 0, y: 0 },
748
+ * { x: 40, y: 40 },
749
+ * { x: 0, y: 40 }
750
+ * ],
751
+ * text: function (value, percentage) {
752
+ * return `Normal Operations: ${value} (${percentage}%)`;
753
+ * },
754
+ * opacity: 0.2, // 0 to 1
755
+ * class: "test-polygon1"
756
+ * },
757
+ * ...
758
+ * ]
759
+ * }
760
+ * ]
761
+ * });
762
+ * @example
763
+ * import {bb} from "billboard.js";
764
+ * import Stanford from "billboard.js/dist/billboardjs-plugin-stanford";
765
+ *
766
+ * bb.generate({
767
+ * plugins: [
768
+ * new Stanford({ ... })
769
+ * ]
770
+ * })
771
+ */
772
+ var Stanford = class extends Plugin {
773
+ constructor(options) {
774
+ super(options);
775
+ this.config = new Options();
776
+ return this;
777
+ }
778
+ $beforeInit() {
779
+ const { $$ } = this;
780
+ $$.config.data_xSort = false;
781
+ $$.isMultipleX = () => true;
782
+ $$.showGridFocus = () => {};
783
+ $$.labelishData = (d) => d.values;
784
+ $$.opacityForCircle = () => 1;
785
+ const getCurrentPadding = $$.getCurrentPadding.bind($$);
786
+ $$.getCurrentPadding = () => {
787
+ const padding = getCurrentPadding();
788
+ padding.right += this.colorScale ? this.colorScale.getColorScalePadding() : 0;
789
+ return padding;
790
+ };
791
+ }
792
+ $init() {
793
+ const { $$ } = this;
794
+ this.loadConfig();
795
+ $$.color = this.getStanfordPointColor.bind($$);
796
+ this.colorScale = new ColorScale(this);
797
+ this.elements = new Elements(this);
798
+ this.convertData();
799
+ this.initStanfordData();
800
+ this.setStanfordTooltip();
801
+ this.colorScale.drawColorScale();
802
+ $$.right += this.colorScale ? this.colorScale.getColorScalePadding() : 0;
803
+ this.$redraw();
804
+ }
805
+ $redraw(duration) {
806
+ this.colorScale?.drawColorScale();
807
+ this.elements?.updateStanfordElements(duration);
808
+ }
809
+ getOptions() {
810
+ return new Options();
811
+ }
812
+ convertData() {
813
+ const data = this.$$.data.targets;
814
+ const epochs = this.options.epochs;
815
+ data.forEach((d) => {
816
+ d.values.forEach((v, i) => {
817
+ v.epochs = epochs[i];
818
+ });
819
+ d.minEpochs = void 0;
820
+ d.maxEpochs = void 0;
821
+ d.colors = void 0;
822
+ d.colorscale = void 0;
823
+ });
824
+ }
825
+ initStanfordData() {
826
+ const { config } = this;
827
+ const target = this.$$.data.targets[0];
828
+ target.values.sort(compareEpochs);
829
+ let minEpoch = Infinity;
830
+ let maxEpoch = -Infinity;
831
+ for (let i = 0; i < target.values.length; i++) {
832
+ const e = target.values[i].epochs;
833
+ if (e < minEpoch) minEpoch = e;
834
+ if (e > maxEpoch) maxEpoch = e;
835
+ }
836
+ target.minEpochs = !isNaN(config.scale_min) ? config.scale_min : minEpoch;
837
+ target.maxEpochs = !isNaN(config.scale_max) ? config.scale_max : maxEpoch;
838
+ target.colors = isFunction(config.colors) ? config.colors : interpolateHslLong(hsl(250, 1, .5), hsl(0, 1, .5));
839
+ target.colorscale = scaleSequentialLog(target.colors).domain([target.minEpochs, target.maxEpochs]);
840
+ }
841
+ getStanfordPointColor(d) {
842
+ return this.data.targets[0].colorscale(d.epochs);
843
+ }
844
+ setStanfordTooltip() {
845
+ const { config } = this.$$;
846
+ if (isEmpty(config.tooltip_contents)) config.tooltip_contents = function(d, defaultTitleFormat, defaultValueFormat, color) {
847
+ const { data_x } = config;
848
+ let html = `<table class="${$TOOLTIP.tooltip}"><tbody>`;
849
+ d.forEach((v) => {
850
+ const { id = "", value = 0, epochs = 0, x = "" } = v;
851
+ html += `<tr>
985
852
  <th>${data_x || ""}</th>
986
853
  <th class="value">${defaultTitleFormat(x)}</th>
987
854
  </tr>
@@ -993,26 +860,22 @@ class Stanford extends Plugin {
993
860
  <td class="name"><span style="background-color:${color(v)}"></span>Epochs</td>
994
861
  <td class="value">${defaultValueFormat(epochs)}</td>
995
862
  </tr>`;
996
- });
997
- return `${html}</tbody></table>`;
998
- };
999
- }
1000
- }
1001
- countEpochsInRegion(region) {
1002
- const $$ = this;
1003
- const target = $$.data.targets[0];
1004
- const total = target.values.reduce((accumulator, currentValue) => accumulator + Number(currentValue.epochs), 0);
1005
- const value = target.values.reduce((accumulator, currentValue) => {
1006
- if (pointInRegion(currentValue, region)) {
1007
- return accumulator + Number(currentValue.epochs);
1008
- }
1009
- return accumulator;
1010
- }, 0);
1011
- return {
1012
- value,
1013
- percentage: value !== 0 ? +(value / total * 100).toFixed(1) : 0
1014
- };
1015
- }
1016
- }
1017
-
863
+ });
864
+ return `${html}</tbody></table>`;
865
+ };
866
+ }
867
+ countEpochsInRegion(region) {
868
+ const target = this.data.targets[0];
869
+ const total = target.values.reduce((accumulator, currentValue) => accumulator + Number(currentValue.epochs), 0);
870
+ const value = target.values.reduce((accumulator, currentValue) => {
871
+ if (pointInRegion(currentValue, region)) return accumulator + Number(currentValue.epochs);
872
+ return accumulator;
873
+ }, 0);
874
+ return {
875
+ value,
876
+ percentage: value !== 0 ? +(value / total * 100).toFixed(1) : 0
877
+ };
878
+ }
879
+ };
880
+ //#endregion
1018
881
  export { Stanford as default };