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.
- package/README.md +82 -7
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +1848 -494
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +19 -24
- package/dist/billboard.pkgd.js +1844 -679
- package/dist/billboard.pkgd.min.js +24 -29
- package/dist/billboard.react.js +205 -0
- package/dist/billboard.react.min.js +9 -0
- package/dist/billboard.worker.js +10 -0
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +5 -3
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
- package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
- package/dist/theme/dark.css +1 -1
- package/dist/theme/dark.min.css +1 -1
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist/theme/modern.css +1 -1
- package/dist/theme/modern.min.css +1 -1
- package/dist-esm/Chart/Chart.js +134 -152
- package/dist-esm/Chart/api/axis.js +217 -237
- package/dist-esm/Chart/api/category.js +54 -54
- package/dist-esm/Chart/api/chart.js +172 -215
- package/dist-esm/Chart/api/color.js +21 -21
- package/dist-esm/Chart/api/data.js +172 -173
- package/dist-esm/Chart/api/export.js +242 -262
- package/dist-esm/Chart/api/flow.js +198 -254
- package/dist-esm/Chart/api/focus.js +136 -143
- package/dist-esm/Chart/api/grid.js +191 -190
- package/dist-esm/Chart/api/group.js +31 -34
- package/dist-esm/Chart/api/legend.js +54 -63
- package/dist-esm/Chart/api/load.js +237 -257
- package/dist-esm/Chart/api/regions.js +148 -168
- package/dist-esm/Chart/api/selection.js +181 -139
- package/dist-esm/Chart/api/show.js +133 -147
- package/dist-esm/Chart/api/stubs.js +43 -42
- package/dist-esm/Chart/api/subchart.js +155 -172
- package/dist-esm/Chart/api/tooltip.js +132 -177
- package/dist-esm/Chart/api/x.js +67 -71
- package/dist-esm/Chart/api/zoom.js +183 -220
- package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
- package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
- package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
- package/dist-esm/ChartInternal/ChartInternal.js +573 -749
- package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
- package/dist-esm/ChartInternal/data/convert.js +200 -229
- package/dist-esm/ChartInternal/data/data.js +967 -1153
- package/dist-esm/ChartInternal/data/load.js +145 -197
- package/dist-esm/ChartInternal/interactions/drag.js +86 -122
- package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
- package/dist-esm/ChartInternal/interactions/flow.js +151 -215
- package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
- package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
- package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
- package/dist-esm/ChartInternal/internals/category.js +18 -18
- package/dist-esm/ChartInternal/internals/class.js +89 -99
- package/dist-esm/ChartInternal/internals/clip.js +88 -119
- package/dist-esm/ChartInternal/internals/color.js +233 -288
- package/dist-esm/ChartInternal/internals/domain.js +452 -588
- package/dist-esm/ChartInternal/internals/format.js +64 -77
- package/dist-esm/ChartInternal/internals/grid.js +333 -457
- package/dist-esm/ChartInternal/internals/legend.js +675 -927
- package/dist-esm/ChartInternal/internals/redraw.js +200 -289
- package/dist-esm/ChartInternal/internals/region.js +106 -159
- package/dist-esm/ChartInternal/internals/scale.js +186 -215
- package/dist-esm/ChartInternal/internals/selection.js +132 -159
- package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
- package/dist-esm/ChartInternal/internals/size.js +286 -394
- package/dist-esm/ChartInternal/internals/style.js +39 -41
- package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
- package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
- package/dist-esm/ChartInternal/internals/text.js +368 -528
- package/dist-esm/ChartInternal/internals/text.util.js +179 -239
- package/dist-esm/ChartInternal/internals/title.js +96 -121
- package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
- package/dist-esm/ChartInternal/internals/transform.js +79 -97
- package/dist-esm/ChartInternal/internals/type.js +285 -236
- package/dist-esm/ChartInternal/shape/arc.js +825 -1112
- package/dist-esm/ChartInternal/shape/area.js +73 -94
- package/dist-esm/ChartInternal/shape/bar.js +227 -288
- package/dist-esm/ChartInternal/shape/bubble.js +9 -8
- package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
- package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
- package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
- package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
- package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
- package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
- package/dist-esm/ChartInternal/shape/core/path.js +142 -115
- package/dist-esm/ChartInternal/shape/core/point.js +105 -125
- package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
- package/dist-esm/ChartInternal/shape/funnel.js +310 -338
- package/dist-esm/ChartInternal/shape/gauge.js +71 -103
- package/dist-esm/ChartInternal/shape/line.js +208 -278
- package/dist-esm/ChartInternal/shape/point.js +310 -425
- package/dist-esm/ChartInternal/shape/polar.js +84 -109
- package/dist-esm/ChartInternal/shape/radar.js +228 -318
- package/dist-esm/ChartInternal/shape/shape.js +782 -843
- package/dist-esm/ChartInternal/shape/treemap.js +152 -190
- package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
- package/dist-esm/canvas/CanvasEngine.js +148 -166
- package/dist-esm/canvas/CanvasPainter.js +395 -411
- package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
- package/dist-esm/canvas/CanvasTheme.js +899 -802
- package/dist-esm/canvas/HitDetector.js +394 -463
- package/dist-esm/canvas/axisTicks.js +672 -786
- package/dist-esm/canvas/classes.js +19 -17
- package/dist-esm/canvas/color.js +40 -59
- package/dist-esm/canvas/geometry.js +38 -38
- package/dist-esm/canvas/labels.js +318 -371
- package/dist-esm/canvas/pointPattern.js +578 -580
- package/dist-esm/canvas/util.js +242 -262
- package/dist-esm/config/Options/Options.js +29 -32
- package/dist-esm/config/Options/axis/axis.js +101 -101
- package/dist-esm/config/Options/axis/x.js +759 -755
- package/dist-esm/config/Options/axis/y.js +525 -522
- package/dist-esm/config/Options/axis/y2.js +501 -485
- package/dist-esm/config/Options/common/boost.js +93 -32
- package/dist-esm/config/Options/common/color.js +88 -87
- package/dist-esm/config/Options/common/grid.js +74 -73
- package/dist-esm/config/Options/common/legend.js +180 -179
- package/dist-esm/config/Options/common/main.js +474 -473
- package/dist-esm/config/Options/common/point.js +160 -159
- package/dist-esm/config/Options/common/title.js +47 -46
- package/dist-esm/config/Options/common/tooltip.js +253 -252
- package/dist-esm/config/Options/data/axis.js +173 -172
- package/dist-esm/config/Options/data/data.js +958 -957
- package/dist-esm/config/Options/data/selection.js +131 -130
- package/dist-esm/config/Options/interaction/interaction.js +53 -52
- package/dist-esm/config/Options/interaction/subchart.js +164 -73
- package/dist-esm/config/Options/interaction/zoom.js +86 -85
- package/dist-esm/config/Options/shape/arc.js +150 -149
- package/dist-esm/config/Options/shape/area.js +69 -68
- package/dist-esm/config/Options/shape/bar.js +147 -146
- package/dist-esm/config/Options/shape/bubble.js +35 -34
- package/dist-esm/config/Options/shape/candlestick.js +61 -60
- package/dist-esm/config/Options/shape/donut.js +181 -180
- package/dist-esm/config/Options/shape/funnel.js +49 -48
- package/dist-esm/config/Options/shape/gauge.js +237 -236
- package/dist-esm/config/Options/shape/line.js +58 -57
- package/dist-esm/config/Options/shape/pie.js +185 -184
- package/dist-esm/config/Options/shape/polar.js +167 -166
- package/dist-esm/config/Options/shape/radar.js +76 -75
- package/dist-esm/config/Options/shape/scatter.js +36 -36
- package/dist-esm/config/Options/shape/spline.js +46 -46
- package/dist-esm/config/Options/shape/treemap.js +80 -79
- package/dist-esm/config/Store/Element.js +64 -62
- package/dist-esm/config/Store/State.js +189 -200
- package/dist-esm/config/Store/Store.js +25 -26
- package/dist-esm/config/classes.js +157 -155
- package/dist-esm/config/config.js +26 -35
- package/dist-esm/config/const.js +120 -128
- package/dist-esm/config/resolver/axis.core.js +25 -25
- package/dist-esm/config/resolver/axis.js +26 -27
- package/dist-esm/config/resolver/canvas.js +2071 -2472
- package/dist-esm/config/resolver/canvasShape.js +201 -177
- package/dist-esm/config/resolver/category.js +26 -27
- package/dist-esm/config/resolver/export.js +24 -26
- package/dist-esm/config/resolver/flow.js +29 -31
- package/dist-esm/config/resolver/grid.js +34 -35
- package/dist-esm/config/resolver/interaction/selection.js +17 -17
- package/dist-esm/config/resolver/interaction/subchart.js +17 -17
- package/dist-esm/config/resolver/interaction/zoom.js +17 -17
- package/dist-esm/config/resolver/regions.js +30 -31
- package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
- package/dist-esm/config/resolver/shape/area.js +17 -17
- package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
- package/dist-esm/config/resolver/shape/bar.js +13 -13
- package/dist-esm/config/resolver/shape/bubble.js +18 -14
- package/dist-esm/config/resolver/shape/candlestick.js +13 -13
- package/dist-esm/config/resolver/shape/donut.js +11 -11
- package/dist-esm/config/resolver/shape/funnel.js +11 -11
- package/dist-esm/config/resolver/shape/gauge.js +12 -12
- package/dist-esm/config/resolver/shape/line.js +10 -10
- package/dist-esm/config/resolver/shape/pie.js +11 -11
- package/dist-esm/config/resolver/shape/polar.js +12 -12
- package/dist-esm/config/resolver/shape/radar.js +22 -14
- package/dist-esm/config/resolver/shape/scatter.js +13 -13
- package/dist-esm/config/resolver/shape/treemap.js +11 -11
- package/dist-esm/core.js +208 -211
- package/dist-esm/index.canvas.js +14 -13
- package/dist-esm/index.esm.js +25 -24
- package/dist-esm/module/Cache.js +117 -129
- package/dist-esm/module/browser.js +30 -35
- package/dist-esm/module/dsv.js +107 -127
- package/dist-esm/module/error.js +45 -52
- package/dist-esm/module/generator.js +75 -83
- package/dist-esm/module/sanitize.js +302 -399
- package/dist-esm/module/util/brush.js +27 -38
- package/dist-esm/module/util/dom.js +288 -348
- package/dist-esm/module/util/object.js +277 -341
- package/dist-esm/module/util/type-checks.js +21 -25
- package/dist-esm/module/worker.js +312 -130
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
- package/dist-esm/react/index.js +157 -0
- package/package.json +28 -8
- package/src/Chart/api/selection.ts +130 -5
- package/src/ChartInternal/Axis/Axis.ts +164 -65
- package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/data/convert.ts +54 -4
- package/src/ChartInternal/data/data.ts +4 -1
- package/src/ChartInternal/interactions/eventrect.ts +8 -2
- package/src/ChartInternal/interactions/subchart.ts +437 -66
- package/src/ChartInternal/internals/color.ts +2 -2
- package/src/ChartInternal/internals/domain.ts +15 -3
- package/src/ChartInternal/internals/grid.ts +21 -1
- package/src/ChartInternal/internals/scale.ts +9 -2
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/subchart.util.ts +55 -0
- package/src/ChartInternal/internals/text.arc.ts +3 -1
- package/src/ChartInternal/internals/text.ts +18 -5
- package/src/ChartInternal/internals/transform.ts +8 -2
- package/src/ChartInternal/internals/type.ts +105 -1
- package/src/ChartInternal/shape/IShape.ts +6 -3
- package/src/ChartInternal/shape/bar.ts +62 -31
- package/src/ChartInternal/shape/core/barRadius.ts +129 -0
- package/src/ChartInternal/shape/core/candlestick.ts +1 -1
- package/src/ChartInternal/shape/core/path.ts +76 -9
- package/src/ChartInternal/shape/funnel.ts +2 -3
- package/src/ChartInternal/shape/point.ts +2 -2
- package/src/ChartInternal/shape/shape.ts +149 -17
- package/src/Plugin/stanford/index.ts +0 -4
- package/src/Plugin/tableview/index.ts +85 -3
- package/src/Plugin/textoverlap/index.ts +9 -15
- package/src/canvas/CanvasAxisRenderer.ts +184 -36
- package/src/canvas/CanvasRenderer.ts +247 -160
- package/src/canvas/CanvasTheme.ts +212 -0
- package/src/canvas/axisTicks.ts +122 -40
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/boost.ts +64 -4
- package/src/config/Options/common/color.ts +2 -2
- package/src/config/Options/interaction/subchart.ts +98 -1
- package/src/config/Options/shape/gauge.ts +1 -1
- package/src/config/Options/shape/treemap.ts +2 -2
- package/src/config/Store/Element.ts +3 -1
- package/src/config/Store/State.ts +1 -0
- package/src/config/classes.ts +1 -0
- package/src/config/resolver/canvas.ts +92 -10
- package/src/module/util/type-checks.ts +3 -1
- package/src/module/voronoi.ts +119 -0
- package/src/module/worker.entry.ts +61 -0
- package/src/module/worker.ts +346 -63
- package/src/react/index.ts +193 -0
- package/types/options.d.ts +206 -3
- 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.
|
|
8
|
+
* @version 4.1.0-next.2
|
|
9
9
|
* @requires billboard.js
|
|
10
10
|
* @summary billboard.js plugin
|
|
11
11
|
*/
|
|
12
|
-
import { interpolateHslLong } from
|
|
13
|
-
import { scaleSequential,
|
|
14
|
-
import { axisRight } from
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
167
|
+
return _getRect(false, node, forceEval);
|
|
164
168
|
}
|
|
165
|
-
|
|
166
|
-
({
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
|
|
355
|
-
|
|
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
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
346
|
+
* Get region area
|
|
347
|
+
* @param {Array} points Points
|
|
348
|
+
* @returns {number}
|
|
349
|
+
* @private
|
|
350
|
+
*/
|
|
368
351
|
function getRegionArea(points) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
365
|
+
* Get centroid
|
|
366
|
+
* @param {Array} points Points
|
|
367
|
+
* @returns {object}
|
|
368
|
+
* @private
|
|
369
|
+
*/
|
|
387
370
|
function getCentroid(points) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
-
|
|
408
|
-
|
|
409
|
-
|
|
391
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
392
|
+
* billboard.js project is licensed under the MIT license
|
|
393
|
+
*/
|
|
410
394
|
/**
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
-
|
|
419
|
-
}
|
|
401
|
+
if (specifier === "d") return (n) => Math.round(n).toString();
|
|
402
|
+
return (n) => String(n);
|
|
420
403
|
}
|
|
421
404
|
/**
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
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` | <optional> | Sets the opacity of the region as value between 0 and 1 |
|
|
762
|
-
* | text | Function | | <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 | | <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` | <optional> | Sets the opacity of the region as value between 0 and 1 |
|
|
646
|
+
* | text | Function | | <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 | | <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
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
688
|
+
return {
|
|
689
|
+
h: +h,
|
|
690
|
+
s: +s,
|
|
691
|
+
l: +l,
|
|
692
|
+
opacity: +opacity
|
|
693
|
+
};
|
|
810
694
|
}
|
|
811
695
|
/**
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
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
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
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 };
|