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,415 +5,355 @@
|
|
|
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
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
10
|
+
import { document as doc, window as win } from "../browser.js";
|
|
11
|
+
import { isString } from "./type-checks.js";
|
|
12
|
+
import { mergeObj, toArray } from "./object.js";
|
|
13
|
+
import { pointer } from "d3-selection";
|
|
14
|
+
//#region src/module/util/dom.ts
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// Hoisted to module level to avoid recompilation on every addCssRules() call
|
|
16
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
17
|
+
* billboard.js project is licensed under the MIT license
|
|
18
|
+
* @ignore
|
|
19
|
+
*/
|
|
21
20
|
const RE_CSS_BB = /\s?(bb-)/g;
|
|
22
21
|
const RE_CSS_DOTS = /\.+/g;
|
|
23
22
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
* Convert a CSS selector string to dot-notation class selector
|
|
24
|
+
* @param {string} s Selector string
|
|
25
|
+
* @returns {string}
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
29
28
|
function getCssSelector(s) {
|
|
30
|
-
|
|
29
|
+
return s.replace(RE_CSS_BB, ".$1").replace(RE_CSS_DOTS, ".");
|
|
31
30
|
}
|
|
32
|
-
// ====================================
|
|
33
|
-
// Internal Helper (Not Exported)
|
|
34
|
-
// ====================================
|
|
35
31
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
* Get boundingClientRect or BBox with caching.
|
|
33
|
+
* Internal helper for getBoundingRect() and getBBox()
|
|
34
|
+
* @param {boolean} relativeViewport Relative to viewport - true: will use .getBoundingClientRect(), false: will use .getBBox()
|
|
35
|
+
* @param {SVGElement} node Target element
|
|
36
|
+
* @param {boolean} forceEval Force evaluation
|
|
37
|
+
* @returns {object}
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
44
40
|
function _getRect(relativeViewport, node, forceEval = false) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (forceEval) {
|
|
50
|
-
return _(node);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
// will cache the value if the element is not a SVGElement or the width is not set
|
|
54
|
-
const needEvaluate = !(cacheKey in node) || (node.hasAttribute("width") &&
|
|
55
|
-
node[cacheKey].width !== +(node.getAttribute("width") || 0));
|
|
56
|
-
return needEvaluate ? (node[cacheKey] = _(node)) : node[cacheKey];
|
|
57
|
-
}
|
|
41
|
+
const _ = (n) => n[relativeViewport ? "getBoundingClientRect" : "getBBox"]();
|
|
42
|
+
const cacheKey = relativeViewport ? "rectClient" : "rectBBox";
|
|
43
|
+
if (forceEval) return _(node);
|
|
44
|
+
else return !(cacheKey in node) || node.hasAttribute("width") && node[cacheKey].width !== +(node.getAttribute("width") || 0) ? node[cacheKey] = _(node) : node[cacheKey];
|
|
58
45
|
}
|
|
59
|
-
// ====================================
|
|
60
|
-
// Exported
|
|
61
|
-
// ====================================
|
|
62
46
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
* Set text value. If there're multiline add nodes.
|
|
48
|
+
* @param {d3Selection} node Text node
|
|
49
|
+
* @param {string} text Text value string
|
|
50
|
+
* @param {Array} dy dy value for multilined text
|
|
51
|
+
* @param {boolean} toMiddle To be alingned vertically middle
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
70
54
|
function setTextValue(node, text, dy = [-1, 1], toMiddle = false) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
multiline.forEach((v, i) => {
|
|
85
|
-
node.append("tspan")
|
|
86
|
-
.attr("x", 0)
|
|
87
|
-
.attr("dy", `${i === 0 ? dy[0] * len : dy[1]}em`)
|
|
88
|
-
.text(v);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
55
|
+
if (!node || !isString(text)) return;
|
|
56
|
+
if (text.indexOf("\n") === -1) node.text(text);
|
|
57
|
+
else {
|
|
58
|
+
const diff = [node.text(), text].map((v) => v.replace(/[\s\n]/g, ""));
|
|
59
|
+
if (diff[0] !== diff[1]) {
|
|
60
|
+
const multiline = text.split("\n");
|
|
61
|
+
const len = toMiddle ? multiline.length - 1 : 1;
|
|
62
|
+
node.html("");
|
|
63
|
+
multiline.forEach((v, i) => {
|
|
64
|
+
node.append("tspan").attr("x", 0).attr("dy", `${i === 0 ? dy[0] * len : dy[1]}em`).text(v);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
92
68
|
}
|
|
93
69
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
70
|
+
* Substitution of SVGPathSeg API polyfill
|
|
71
|
+
* @param {SVGGraphicsElement} path Target svg element
|
|
72
|
+
* @returns {Array}
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
99
75
|
function getRectSegList(path) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
76
|
+
const { x, y, width, height } = getBBox(path, true);
|
|
77
|
+
return [
|
|
78
|
+
{
|
|
79
|
+
x,
|
|
80
|
+
y: y + height
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
x,
|
|
84
|
+
y
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
x: x + width,
|
|
88
|
+
y
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
x: x + width,
|
|
92
|
+
y: y + height
|
|
93
|
+
}
|
|
94
|
+
];
|
|
114
95
|
}
|
|
115
96
|
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
97
|
+
* Get svg bounding path box dimension
|
|
98
|
+
* @param {SVGGraphicsElement} path Target svg element
|
|
99
|
+
* @returns {object}
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
121
102
|
function getPathBox(path) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
height
|
|
131
|
-
};
|
|
103
|
+
const { width, height } = getBoundingRect(path);
|
|
104
|
+
const items = getRectSegList(path);
|
|
105
|
+
return {
|
|
106
|
+
x: items[0].x,
|
|
107
|
+
y: Math.min(items[0].y, items[1].y),
|
|
108
|
+
width,
|
|
109
|
+
height
|
|
110
|
+
};
|
|
132
111
|
}
|
|
133
112
|
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
113
|
+
* Get event's current position coordinates
|
|
114
|
+
* @param {object} event Event object
|
|
115
|
+
* @param {SVGElement|HTMLElement} element Target element
|
|
116
|
+
* @returns {Array} [x, y] Coordinates x, y array
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
140
119
|
function getPointer(event, element) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
catch { }
|
|
148
|
-
return pointer$1.map(v => (isNaN(v) ? 0 : v));
|
|
120
|
+
const touches = event && (event.touches || event.sourceEvent && event.sourceEvent.touches)?.[0];
|
|
121
|
+
let pointer$1 = [0, 0];
|
|
122
|
+
try {
|
|
123
|
+
pointer$1 = pointer(touches || event, element);
|
|
124
|
+
} catch {}
|
|
125
|
+
return pointer$1.map((v) => isNaN(v) ? 0 : v);
|
|
149
126
|
}
|
|
150
127
|
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
128
|
+
* Get boundingClientRect.
|
|
129
|
+
* @param {SVGElement} node Target element
|
|
130
|
+
* @param {boolean} forceEval Force evaluation
|
|
131
|
+
* @returns {object}
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
157
134
|
function getBoundingRect(node, forceEval = false) {
|
|
158
|
-
|
|
135
|
+
return _getRect(true, node, forceEval);
|
|
159
136
|
}
|
|
160
137
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
138
|
+
* Get BBox.
|
|
139
|
+
* @param {SVGElement} node Target element
|
|
140
|
+
* @param {boolean} forceEval Force evaluation
|
|
141
|
+
* @returns {object}
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
167
144
|
function getBBox(node, forceEval = false) {
|
|
168
|
-
|
|
145
|
+
return _getRect(false, node, forceEval);
|
|
169
146
|
}
|
|
170
147
|
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
148
|
+
* Add CSS rules
|
|
149
|
+
* @param {object} style Style object
|
|
150
|
+
* @param {string} selector Selector string
|
|
151
|
+
* @param {Array} prop Prps arrary
|
|
152
|
+
* @returns {number} Newely added rule index
|
|
153
|
+
* @private
|
|
154
|
+
*/
|
|
178
155
|
function addCssRules(style, selector, prop) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
156
|
+
const { rootSelector = "", sheet } = style;
|
|
157
|
+
const rule = `${rootSelector} ${getCssSelector(selector)} {${prop.join(";")}}`;
|
|
158
|
+
return sheet[sheet.insertRule ? "insertRule" : "addRule"](rule, sheet.cssRules.length);
|
|
182
159
|
}
|
|
183
160
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
161
|
+
* Get css rules for specified stylesheets
|
|
162
|
+
* @param {Array} styleSheets The stylesheets to get the rules from
|
|
163
|
+
* @returns {Array}
|
|
164
|
+
* @private
|
|
165
|
+
*/
|
|
189
166
|
function getCssRules(styleSheets) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
return rules;
|
|
167
|
+
let rules = [];
|
|
168
|
+
styleSheets.forEach((sheet) => {
|
|
169
|
+
try {
|
|
170
|
+
if (sheet.cssRules && sheet.cssRules.length) rules = rules.concat(toArray(sheet.cssRules));
|
|
171
|
+
} catch (e) {
|
|
172
|
+
win.console?.warn(`Error while reading rules from ${sheet.href}: ${String(e)}`);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
return rules;
|
|
202
176
|
}
|
|
203
177
|
/**
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
178
|
+
* Get current window and container scroll position
|
|
179
|
+
* @param {HTMLElement} node Target element
|
|
180
|
+
* @returns {object} window scroll position
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
209
183
|
function getScrollPosition(node) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
184
|
+
return {
|
|
185
|
+
x: (win.pageXOffset ?? win.scrollX ?? 0) + (node.scrollLeft ?? 0),
|
|
186
|
+
y: (win.pageYOffset ?? win.scrollY ?? 0) + (node.scrollTop ?? 0)
|
|
187
|
+
};
|
|
214
188
|
}
|
|
215
189
|
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
190
|
+
* Get translation string from screen <--> svg point
|
|
191
|
+
* @param {SVGGraphicsElement} node graphics element
|
|
192
|
+
* @param {number} x target x point
|
|
193
|
+
* @param {number} y target y point
|
|
194
|
+
* @param {boolean} inverse inverse flag
|
|
195
|
+
* @returns {object}
|
|
196
|
+
*/
|
|
223
197
|
function getTransformCTM(node, x = 0, y = 0, inverse = true) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
198
|
+
const point = new DOMPoint(x, y);
|
|
199
|
+
const screen = node.getScreenCTM();
|
|
200
|
+
const res = point.matrixTransform(inverse ? screen?.inverse() : screen);
|
|
201
|
+
if (inverse === false) {
|
|
202
|
+
const rect = getBoundingRect(node);
|
|
203
|
+
res.x -= rect.x;
|
|
204
|
+
res.y -= rect.y;
|
|
205
|
+
}
|
|
206
|
+
return res;
|
|
233
207
|
}
|
|
234
208
|
/**
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
209
|
+
* Gets the SVGMatrix of an SVGGElement
|
|
210
|
+
* @param {SVGElement} node Node element
|
|
211
|
+
* @returns {SVGMatrix} matrix
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
240
214
|
function getTranslation(node) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
215
|
+
const transform = node ? node.transform : null;
|
|
216
|
+
const baseVal = transform && transform.baseVal;
|
|
217
|
+
return baseVal && baseVal.numberOfItems ? baseVal.getItem(0).matrix : {
|
|
218
|
+
a: 0,
|
|
219
|
+
b: 0,
|
|
220
|
+
c: 0,
|
|
221
|
+
d: 0,
|
|
222
|
+
e: 0,
|
|
223
|
+
f: 0
|
|
224
|
+
};
|
|
246
225
|
}
|
|
247
226
|
/**
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
227
|
+
* Get position value from element's attribute or transform
|
|
228
|
+
* @param {SVGElement} element SVG element
|
|
229
|
+
* @param {string} type Coordinate type ("x" or "y")
|
|
230
|
+
* @returns {number} Position value
|
|
231
|
+
* @private
|
|
232
|
+
*/
|
|
254
233
|
function getElementPos(element, type) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const matrix = getTranslation(element);
|
|
260
|
-
return type === "x" ? matrix.e : matrix.f;
|
|
234
|
+
const attr = element?.getAttribute?.(type);
|
|
235
|
+
if (attr) return parseFloat(attr);
|
|
236
|
+
const matrix = getTranslation(element);
|
|
237
|
+
return type === "x" ? matrix.e : matrix.f;
|
|
261
238
|
}
|
|
262
239
|
/**
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
240
|
+
* Check if svg element has viewBox attribute
|
|
241
|
+
* @param {d3Selection} svg Target svg selection
|
|
242
|
+
* @returns {boolean}
|
|
243
|
+
*/
|
|
267
244
|
function hasViewBox(svg) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return attr ? attr.trim().split(/[\s,]+/).length === 4 : false;
|
|
245
|
+
const attr = svg.attr("viewBox");
|
|
246
|
+
return attr ? attr.trim().split(/[\s,]+/).length === 4 : false;
|
|
271
247
|
}
|
|
272
248
|
/**
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
249
|
+
* Determine if given node has the specified style
|
|
250
|
+
* @param {d3Selection|SVGElement} node Target node
|
|
251
|
+
* @param {object} condition Conditional style props object
|
|
252
|
+
* @param {boolean} all If true, all condition should be matched
|
|
253
|
+
* @returns {boolean}
|
|
254
|
+
*/
|
|
279
255
|
function hasStyle(node, condition, all = false) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return has;
|
|
256
|
+
const isD3Node = !!node.node;
|
|
257
|
+
let has = false;
|
|
258
|
+
for (const [key, value] of Object.entries(condition)) {
|
|
259
|
+
has = isD3Node ? node.style(key) === value : node.style[key] === value;
|
|
260
|
+
if (all ? !has : has) break;
|
|
261
|
+
}
|
|
262
|
+
return has;
|
|
290
263
|
}
|
|
291
264
|
/**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
265
|
+
* Return if the current doc is visible or not
|
|
266
|
+
* @returns {boolean}
|
|
267
|
+
* @private
|
|
268
|
+
*/
|
|
296
269
|
function isTabVisible() {
|
|
297
|
-
|
|
270
|
+
return doc?.hidden === false || doc?.visibilityState === "visible";
|
|
298
271
|
}
|
|
299
272
|
/**
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
273
|
+
* Get the current input type
|
|
274
|
+
* @param {boolean} mouse Config value: interaction.inputType.mouse
|
|
275
|
+
* @param {boolean} touch Config value: interaction.inputType.touch
|
|
276
|
+
* @returns {string} "mouse" | "touch" | null
|
|
277
|
+
* @private
|
|
278
|
+
*/
|
|
306
279
|
function convertInputType(mouse, touch) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
else if ("ontouchmove" in win || (DocumentTouch && doc instanceof DocumentTouch)) {
|
|
319
|
-
hasTouch = true;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#avoiding_user_agent_detection
|
|
323
|
-
if (hasPointerCoarse) {
|
|
324
|
-
hasTouch = true;
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
// Only as a last resort, fall back to user agent sniffing
|
|
328
|
-
const UA = navigator.userAgent;
|
|
329
|
-
hasTouch = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) ||
|
|
330
|
-
/\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
// For non-touch device, media feature condition is: '(pointer:coarse) = false' and '(pointer:fine) = true'
|
|
335
|
-
// https://github.com/naver/billboard.js/issues/3854#issuecomment-2404183158
|
|
336
|
-
const hasMouse = mouse && !hasPointerCoarse && matchMedia?.("(pointer:fine)").matches;
|
|
337
|
-
// fallback to 'mouse' if no input type is detected.
|
|
338
|
-
return (hasMouse && "mouse") || (hasTouch && "touch") || "mouse";
|
|
280
|
+
const { DocumentTouch, matchMedia, navigator } = win;
|
|
281
|
+
const hasPointerCoarse = matchMedia?.("(pointer:coarse)").matches;
|
|
282
|
+
let hasTouch = false;
|
|
283
|
+
if (touch) if (navigator && "maxTouchPoints" in navigator) hasTouch = navigator.maxTouchPoints > 0;
|
|
284
|
+
else if ("ontouchmove" in win || DocumentTouch && doc instanceof DocumentTouch) hasTouch = true;
|
|
285
|
+
else if (hasPointerCoarse) hasTouch = true;
|
|
286
|
+
else {
|
|
287
|
+
const UA = navigator.userAgent;
|
|
288
|
+
hasTouch = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
|
|
289
|
+
}
|
|
290
|
+
return mouse && !hasPointerCoarse && matchMedia?.("(pointer:fine)").matches && "mouse" || hasTouch && "touch" || "mouse";
|
|
339
291
|
}
|
|
340
292
|
/**
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
293
|
+
* Schedule a RAF update to batch multiple redraw requests
|
|
294
|
+
* Manages a RAF state object to intelligently batch rapid updates while ensuring
|
|
295
|
+
* immediate execution for the first call (for test compatibility)
|
|
296
|
+
* @param {object} rafState RAF state object with pendingRaf property
|
|
297
|
+
* @param {number|null} rafState.pendingRaf ID of pending RAF or null
|
|
298
|
+
* @param {function} callback Function to execute in RAF
|
|
299
|
+
* @returns {void}
|
|
300
|
+
* @private
|
|
301
|
+
*/
|
|
350
302
|
function scheduleRAFUpdate(rafState, callback) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
// But set pending RAF to detect rapid consecutive calls
|
|
364
|
-
rafState.pendingRaf = win.requestAnimationFrame(() => {
|
|
365
|
-
rafState.pendingRaf = null;
|
|
366
|
-
});
|
|
367
|
-
callback();
|
|
368
|
-
}
|
|
303
|
+
if (rafState.pendingRaf !== null) {
|
|
304
|
+
win.cancelAnimationFrame(rafState.pendingRaf);
|
|
305
|
+
rafState.pendingRaf = win.requestAnimationFrame(() => {
|
|
306
|
+
rafState.pendingRaf = null;
|
|
307
|
+
callback();
|
|
308
|
+
});
|
|
309
|
+
} else {
|
|
310
|
+
rafState.pendingRaf = win.requestAnimationFrame(() => {
|
|
311
|
+
rafState.pendingRaf = null;
|
|
312
|
+
});
|
|
313
|
+
callback();
|
|
314
|
+
}
|
|
369
315
|
}
|
|
370
|
-
// emulate event
|
|
371
316
|
const emulateEvent = {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
touches: [touchObj],
|
|
413
|
-
targetTouches: [],
|
|
414
|
-
changedTouches: [touchObj]
|
|
415
|
-
}));
|
|
416
|
-
}
|
|
317
|
+
mouse: (() => {
|
|
318
|
+
const getParams = () => ({
|
|
319
|
+
bubbles: false,
|
|
320
|
+
cancelable: false,
|
|
321
|
+
screenX: 0,
|
|
322
|
+
screenY: 0,
|
|
323
|
+
clientX: 0,
|
|
324
|
+
clientY: 0
|
|
325
|
+
});
|
|
326
|
+
try {
|
|
327
|
+
new MouseEvent("t");
|
|
328
|
+
return (el, eventType, params = getParams()) => {
|
|
329
|
+
el.dispatchEvent(new MouseEvent(eventType, params));
|
|
330
|
+
};
|
|
331
|
+
} catch {
|
|
332
|
+
return (el, eventType, params = getParams()) => {
|
|
333
|
+
const mouseEvent = doc.createEvent("MouseEvent");
|
|
334
|
+
mouseEvent.initMouseEvent(eventType, params.bubbles, params.cancelable, win, 0, params.screenX, params.screenY, params.clientX, params.clientY, false, false, false, false, 0, null);
|
|
335
|
+
el.dispatchEvent(mouseEvent);
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
})(),
|
|
339
|
+
touch: (el, eventType, params) => {
|
|
340
|
+
const touchObj = new Touch(mergeObj({
|
|
341
|
+
identifier: Date.now(),
|
|
342
|
+
target: el,
|
|
343
|
+
radiusX: 2.5,
|
|
344
|
+
radiusY: 2.5,
|
|
345
|
+
rotationAngle: 10,
|
|
346
|
+
force: .5
|
|
347
|
+
}, params));
|
|
348
|
+
el.dispatchEvent(new TouchEvent(eventType, {
|
|
349
|
+
cancelable: true,
|
|
350
|
+
bubbles: true,
|
|
351
|
+
shiftKey: true,
|
|
352
|
+
touches: [touchObj],
|
|
353
|
+
targetTouches: [],
|
|
354
|
+
changedTouches: [touchObj]
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
417
357
|
};
|
|
418
|
-
|
|
358
|
+
//#endregion
|
|
419
359
|
export { addCssRules, convertInputType, emulateEvent, getBBox, getBoundingRect, getCssRules, getElementPos, getPathBox, getPointer, getRectSegList, getScrollPosition, getTransformCTM, getTranslation, hasStyle, hasViewBox, isTabVisible, scheduleRAFUpdate, setTextValue };
|