billboard.js 3.17.4 → 3.18.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/CONTRIBUTING.md +12 -12
- package/README.md +12 -12
- package/dist/billboard.css +15 -1
- package/dist/billboard.js +1146 -463
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +10 -10
- package/dist/billboard.pkgd.js +1147 -464
- package/dist/billboard.pkgd.min.js +21 -21
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +117 -26
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -4
- package/dist/plugin/billboardjs-plugin-stanford.js +119 -28
- package/dist/plugin/billboardjs-plugin-stanford.min.js +10 -10
- package/dist/plugin/billboardjs-plugin-tableview.js +117 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +116 -26
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +117 -26
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +10 -10
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +120 -29
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +14 -14
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +117 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +12 -12
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +116 -26
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +10 -10
- package/dist/theme/dark.css +15 -1
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +15 -1
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +15 -1
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +15 -1
- package/dist/theme/insight.min.css +2 -2
- package/dist/theme/modern.css +15 -1
- package/dist/theme/modern.min.css +2 -2
- package/dist-esm/billboard.js +1467 -536
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +3 -2
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +5 -4
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +94 -16
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/package.json +38 -37
- package/src/Chart/Chart.ts +1 -1
- package/src/Chart/api/chart.ts +5 -5
- package/src/Chart/api/data.ts +2 -1
- package/src/Chart/api/export.ts +1 -1
- package/src/Chart/api/flow.ts +1 -1
- package/src/Chart/api/load.ts +3 -3
- package/src/Chart/api/subchart.ts +3 -3
- package/src/Chart/api/tooltip.ts +1 -1
- package/src/Chart/api/zoom.ts +1 -1
- package/src/ChartInternal/Axis/Axis.ts +1 -1
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
- package/src/ChartInternal/ChartInternal.ts +3 -2
- package/src/ChartInternal/data/IData.ts +3 -0
- package/src/ChartInternal/data/convert.helper.ts +1 -1
- package/src/ChartInternal/data/convert.ts +9 -8
- package/src/ChartInternal/data/data.ts +135 -17
- package/src/ChartInternal/data/load.ts +8 -8
- package/src/ChartInternal/interactions/drag.ts +53 -42
- package/src/ChartInternal/interactions/eventrect.ts +15 -5
- package/src/ChartInternal/interactions/flow.ts +1 -1
- package/src/ChartInternal/interactions/interaction.ts +1 -1
- package/src/ChartInternal/interactions/zoom.ts +24 -20
- package/src/ChartInternal/internals/color.ts +27 -10
- package/src/ChartInternal/internals/domain.ts +22 -5
- package/src/ChartInternal/internals/format.ts +4 -4
- package/src/ChartInternal/internals/grid.ts +11 -11
- package/src/ChartInternal/internals/legend.ts +80 -19
- package/src/ChartInternal/internals/scale.ts +6 -6
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/style.ts +3 -3
- package/src/ChartInternal/internals/text.arc.ts +304 -0
- package/src/ChartInternal/internals/text.ts +44 -14
- package/src/ChartInternal/internals/text.util.ts +19 -0
- package/src/ChartInternal/internals/title.ts +3 -3
- package/src/ChartInternal/internals/tooltip.ts +23 -15
- package/src/ChartInternal/shape/arc.ts +174 -71
- package/src/ChartInternal/shape/area.ts +2 -2
- package/src/ChartInternal/shape/bar.ts +7 -6
- package/src/ChartInternal/shape/candlestick.ts +3 -3
- package/src/ChartInternal/shape/funnel.ts +18 -18
- package/src/ChartInternal/shape/line.ts +9 -10
- package/src/ChartInternal/shape/point.common.ts +24 -6
- package/src/ChartInternal/shape/radar.ts +4 -4
- package/src/ChartInternal/shape/shape.ts +24 -6
- package/src/ChartInternal/shape/treemap.ts +19 -5
- package/src/Plugin/stanford/Options.ts +2 -2
- package/src/Plugin/tableview/Options.ts +1 -1
- package/src/config/Options/axis/axis.ts +7 -7
- package/src/config/Options/axis/x.ts +6 -6
- package/src/config/Options/axis/y.ts +4 -4
- package/src/config/Options/axis/y2.ts +16 -3
- package/src/config/Options/common/color.ts +2 -2
- package/src/config/Options/common/legend.ts +6 -5
- package/src/config/Options/common/main.ts +23 -23
- package/src/config/Options/common/point.ts +4 -3
- package/src/config/Options/common/tooltip.ts +14 -13
- package/src/config/Options/data/axis.ts +31 -6
- package/src/config/Options/data/data.ts +44 -44
- package/src/config/Options/data/selection.ts +4 -4
- package/src/config/Options/interaction/interaction.ts +2 -1
- package/src/config/Options/interaction/subchart.ts +2 -2
- package/src/config/Options/interaction/zoom.ts +4 -4
- package/src/config/Options/shape/arc.ts +4 -4
- package/src/config/Options/shape/area.ts +1 -1
- package/src/config/Options/shape/bar.ts +4 -4
- package/src/config/Options/shape/bubble.ts +2 -2
- package/src/config/Options/shape/candlestick.ts +1 -1
- package/src/config/Options/shape/donut.ts +34 -3
- package/src/config/Options/shape/gauge.ts +36 -4
- package/src/config/Options/shape/line.ts +1 -1
- package/src/config/Options/shape/pie.ts +34 -3
- package/src/config/Options/shape/polar.ts +35 -4
- package/src/config/Options/shape/radar.ts +1 -1
- package/src/config/Options/shape/scatter.ts +1 -1
- package/src/config/Options/shape/treemap.ts +31 -5
- package/src/config/Store/State.ts +11 -1
- package/src/config/classes.ts +1 -0
- package/src/core.ts +1 -1
- package/src/module/Cache.ts +29 -4
- package/src/module/generator.ts +1 -1
- package/src/module/util.ts +308 -117
- package/src/module/worker.ts +3 -3
- package/src/scss/billboard.scss +15 -0
- package/src/scss/theme/dark.scss +15 -0
- package/src/scss/theme/datalab.scss +15 -0
- package/src/scss/theme/graph.scss +15 -0
- package/src/scss/theme/insight.scss +15 -0
- package/src/scss/theme/modern.scss +15 -0
- package/types/axis.d.ts +3 -3
- package/types/chart.d.ts +4 -4
- package/types/options.d.ts +22 -9
- package/types/options.shape.d.ts +59 -2
package/src/module/Cache.ts
CHANGED
|
@@ -16,12 +16,18 @@ export const KEY = {
|
|
|
16
16
|
dataMinMax: "$dataMinMax",
|
|
17
17
|
dataTotalSum: "$dataTotalSum",
|
|
18
18
|
dataTotalPerIndex: "$totalPerIndex",
|
|
19
|
+
domainMinMax: "$domainMinMax",
|
|
20
|
+
filteredTargets: "$filteredTargets",
|
|
21
|
+
filteredNullish: "$filteredNullish",
|
|
22
|
+
visibilityChecksum: "visibilityChecksum",
|
|
19
23
|
legendItemTextBox: "legendItemTextBox",
|
|
24
|
+
legendItemMap: "$legendItemMap",
|
|
20
25
|
radarPoints: "$radarPoints",
|
|
21
26
|
radarTextWidth: "$radarTextWidth",
|
|
22
27
|
setOverOut: "setOverOut",
|
|
23
28
|
callOverOutForTouch: "callOverOutForTouch",
|
|
24
|
-
textRect: "textRect"
|
|
29
|
+
textRect: "textRect",
|
|
30
|
+
shapeOffset: "$shapeOffset"
|
|
25
31
|
};
|
|
26
32
|
|
|
27
33
|
export default class Cache {
|
|
@@ -30,9 +36,9 @@ export default class Cache {
|
|
|
30
36
|
/**
|
|
31
37
|
* Add cache
|
|
32
38
|
* @param {string} key Cache key
|
|
33
|
-
* @param {
|
|
39
|
+
* @param {string|number|boolean|object|Array|function|null|undefined} value Value to be stored
|
|
34
40
|
* @param {boolean} isDataType Weather the cache is data typed '{id:'data', id_org: 'data', values: [{x:0, index:0,...}, ...]}'
|
|
35
|
-
* @returns {
|
|
41
|
+
* @returns {string|number|boolean|object|Array|function|null|undefined} Added data value
|
|
36
42
|
* @private
|
|
37
43
|
*/
|
|
38
44
|
add(key: string, value, isDataType = false) {
|
|
@@ -54,7 +60,7 @@ export default class Cache {
|
|
|
54
60
|
* Get cahce
|
|
55
61
|
* @param {string|Array} key Cache key
|
|
56
62
|
* @param {boolean} isDataType Weather the cache is data typed '{id:'data', id_org: 'data', values: [{x:0, index:0,...}, ...]}'
|
|
57
|
-
* @returns {
|
|
63
|
+
* @returns {string|number|boolean|object|Array|function|null} Cached value
|
|
58
64
|
* @private
|
|
59
65
|
*/
|
|
60
66
|
get(key: string | string[], isDataType = false): any | null {
|
|
@@ -76,6 +82,25 @@ export default class Cache {
|
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Check if cache key exists
|
|
87
|
+
* @param {string} key Cache key
|
|
88
|
+
* @returns {boolean} True if key exists in cache
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
has(key: string): boolean {
|
|
92
|
+
return key in this.cache && this.cache[key] !== null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get all cache keys
|
|
97
|
+
* @returns {string[]} Array of cache keys
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
getKeys(): string[] {
|
|
101
|
+
return Object.keys(this.cache);
|
|
102
|
+
}
|
|
103
|
+
|
|
79
104
|
/**
|
|
80
105
|
* Reset cached data
|
|
81
106
|
* @param {boolean} all true: reset all data, false: reset only '$' prefixed key data
|
package/src/module/generator.ts
CHANGED
package/src/module/util.ts
CHANGED
|
@@ -8,64 +8,147 @@ import {pointer as d3Pointer} from "d3-selection";
|
|
|
8
8
|
import type {d3Selection} from "../../types/types";
|
|
9
9
|
import {document, requestAnimationFrame, window} from "./browser";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
11
|
+
// ====================================
|
|
12
|
+
// Internal Helper (Not Exported)
|
|
13
|
+
// ====================================
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get boundingClientRect or BBox with caching.
|
|
17
|
+
* Internal helper for getBoundingRect() and getBBox()
|
|
18
|
+
* @param {boolean} relativeViewport Relative to viewport - true: will use .getBoundingClientRect(), false: will use .getBBox()
|
|
19
|
+
* @param {SVGElement} node Target element
|
|
20
|
+
* @param {boolean} forceEval Force evaluation
|
|
21
|
+
* @returns {object}
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
function _getRect(
|
|
25
|
+
relativeViewport: boolean,
|
|
26
|
+
node: SVGElement & Partial<{rect: DOMRect | SVGRect}>,
|
|
27
|
+
forceEval = false
|
|
28
|
+
): DOMRect | SVGRect {
|
|
29
|
+
const _ = n => n[relativeViewport ? "getBoundingClientRect" : "getBBox"]();
|
|
30
|
+
|
|
31
|
+
if (forceEval) {
|
|
32
|
+
return _(node);
|
|
33
|
+
} else {
|
|
34
|
+
// will cache the value if the element is not a SVGElement or the width is not set
|
|
35
|
+
const needEvaluate = !("rect" in node) || (
|
|
36
|
+
"rect" in node && node.hasAttribute("width") &&
|
|
37
|
+
node.rect!.width !== +(node.getAttribute("width") || 0)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return needEvaluate ? (node.rect = _(node)) : node.rect!;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Internal helper to iterate over array items and invoke a callback for each valid item
|
|
46
|
+
* @param {Array} items Array to iterate
|
|
47
|
+
* @param {function} callback Callback function (item, index) => void
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
function _forEachValidItem<T>(items: T[], callback: (item: T, index: number) => void): void {
|
|
51
|
+
for (let i = 0; i < items.length; i++) {
|
|
52
|
+
const item = items[i];
|
|
53
|
+
|
|
54
|
+
if (item) {
|
|
55
|
+
callback(item, i);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Private sanitization utilities
|
|
62
|
+
* Encapsulates all XSS prevention patterns and helper functions
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
const _sanitize = (() => {
|
|
66
|
+
const DANGEROUS_TAGS =
|
|
67
|
+
"script|iframe|object|embed|form|input|button|textarea|select|style|link|meta|base|math|isindex";
|
|
68
|
+
|
|
69
|
+
// HTML entity character code map (for decoding)
|
|
70
|
+
const ENTITY_MAP = {
|
|
71
|
+
quot: 34,
|
|
72
|
+
amp: 38,
|
|
73
|
+
apos: 39,
|
|
74
|
+
lt: 60,
|
|
75
|
+
gt: 62,
|
|
76
|
+
nbsp: 160,
|
|
77
|
+
iexcl: 161,
|
|
78
|
+
cent: 162,
|
|
79
|
+
pound: 163,
|
|
80
|
+
curren: 164,
|
|
81
|
+
yen: 165
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Angle bracket codes (< and >) - never decode these to prevent tag bypass
|
|
85
|
+
const LT_CODE = 60;
|
|
86
|
+
const GT_CODE = 62;
|
|
87
|
+
|
|
88
|
+
// Maximum sanitization iterations to prevent infinite loops
|
|
89
|
+
const MAX_ITERATIONS = 10;
|
|
90
|
+
|
|
91
|
+
// Regular expressions (compiled once for performance)
|
|
92
|
+
const rx = {
|
|
93
|
+
tags: new RegExp(
|
|
94
|
+
`<(${DANGEROUS_TAGS})\\b[\\s\\S]*?>([\\s\\S]*?<\\/(${DANGEROUS_TAGS})\\s*>)?`,
|
|
95
|
+
"gi"
|
|
96
|
+
),
|
|
97
|
+
htmlEntity: /&#x([0-9a-f]+);?|&#([0-9]+);?|&([a-z]+);/gi,
|
|
98
|
+
// eslint-disable-next-line no-control-regex
|
|
99
|
+
controlChar: /[\x00-\x1F\x7F]/g,
|
|
100
|
+
eventHandler:
|
|
101
|
+
/\s+on\w+\s*=\s*(?:"[^"]*"|'[^']*'|`[^`]*`|[^\s>]*)|on\w+\s*=\s*(?:"[^"]*"|'[^']*'|`[^`]*`|[^\s>]*)/gi,
|
|
102
|
+
dangerousUri: /(href|src|action|xlink:href)\s*=\s*(['"`]?)([^'"`>\s]*)\2/gi,
|
|
103
|
+
dangerousProtocol: /^(javascript|data|vbscript):/
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
ENTITY_MAP,
|
|
108
|
+
LT_CODE,
|
|
109
|
+
GT_CODE,
|
|
110
|
+
MAX_ITERATIONS,
|
|
111
|
+
rx,
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Decode HTML entities to prevent bypass attacks
|
|
115
|
+
* @param {string} str String with potential HTML entities
|
|
116
|
+
* @returns {string} Decoded string
|
|
117
|
+
*/
|
|
118
|
+
decodeEntities(str: string): string {
|
|
119
|
+
return str.replace(rx.htmlEntity, (match, hex, dec, named) => {
|
|
120
|
+
const code = hex ?
|
|
121
|
+
parseInt(hex, 16) :
|
|
122
|
+
dec ?
|
|
123
|
+
parseInt(dec, 10) :
|
|
124
|
+
named ?
|
|
125
|
+
ENTITY_MAP[named.toLowerCase()] || 0 :
|
|
126
|
+
0;
|
|
127
|
+
|
|
128
|
+
// Never decode angle brackets to prevent tag bypass
|
|
129
|
+
return code && code !== LT_CODE && code !== GT_CODE ?
|
|
130
|
+
String.fromCharCode(code) :
|
|
131
|
+
match;
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Remove dangerous URI protocols from attribute values
|
|
137
|
+
* @param {string} str String to sanitize
|
|
138
|
+
* @returns {string} Sanitized string
|
|
139
|
+
*/
|
|
140
|
+
removeDangerousUris(str: string): string {
|
|
141
|
+
return str.replace(rx.dangerousUri, (match, attr, quote, value) => {
|
|
142
|
+
const normalized = value.toLowerCase().replace(/\s/g, "");
|
|
143
|
+
return rx.dangerousProtocol.test(normalized) ? `${attr}=${quote}${quote}` : match;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
})();
|
|
148
|
+
|
|
149
|
+
// ====================================
|
|
150
|
+
// Exported
|
|
151
|
+
// ====================================
|
|
69
152
|
|
|
70
153
|
const isValue = (v: any): boolean => v || v === 0;
|
|
71
154
|
const isFunction = (v: unknown): v is (...args: any[]) => any => typeof v === "function";
|
|
@@ -113,8 +196,8 @@ const isObject = (obj: any): boolean => obj && !obj?.nodeType && isObjectType(ob
|
|
|
113
196
|
* If default value is given, will return if given key value not found
|
|
114
197
|
* @param {object} options Source object
|
|
115
198
|
* @param {string} key Key value
|
|
116
|
-
* @param {
|
|
117
|
-
* @returns {
|
|
199
|
+
* @param {string|number|boolean|object|Array|function|null|undefined} defaultValue Default value
|
|
200
|
+
* @returns {string|number|boolean|object|Array|function|null|undefined} Option value or default value
|
|
118
201
|
* @private
|
|
119
202
|
*/
|
|
120
203
|
function getOption(options: object, key: string, defaultValue): any {
|
|
@@ -124,7 +207,7 @@ function getOption(options: object, key: string, defaultValue): any {
|
|
|
124
207
|
/**
|
|
125
208
|
* Check if value exist in the given object
|
|
126
209
|
* @param {object} dict Target object to be checked
|
|
127
|
-
* @param {
|
|
210
|
+
* @param {string|number|boolean|object|Array|function|null|undefined} value Value to be checked
|
|
128
211
|
* @returns {boolean}
|
|
129
212
|
* @private
|
|
130
213
|
*/
|
|
@@ -138,9 +221,9 @@ function hasValue(dict: object, value: any): boolean {
|
|
|
138
221
|
|
|
139
222
|
/**
|
|
140
223
|
* Call function with arguments
|
|
141
|
-
* @param {
|
|
142
|
-
* @param {
|
|
143
|
-
* @param {
|
|
224
|
+
* @param {function} fn Function to be called
|
|
225
|
+
* @param {object|null|undefined} thisArg "this" value for fn
|
|
226
|
+
* @param {...(string|number|boolean|object|Array|function|null|undefined)} args Arguments for fn
|
|
144
227
|
* @returns {boolean} true: fn is function, false: fn is not function
|
|
145
228
|
* @private
|
|
146
229
|
*/
|
|
@@ -175,49 +258,50 @@ function endall(transition, cb: Function): void {
|
|
|
175
258
|
}
|
|
176
259
|
}
|
|
177
260
|
|
|
178
|
-
// Sanitize patterns (blacklist approach with repeated application)
|
|
179
|
-
const DANGEROUS_TAGS =
|
|
180
|
-
"script|iframe|object|embed|form|input|button|textarea|select|style|link|meta|base|math|isindex";
|
|
181
|
-
const sanitizeRx = {
|
|
182
|
-
tags: new RegExp(
|
|
183
|
-
`<(${DANGEROUS_TAGS})\\b[\\s\\S]*?>([\\s\\S]*?<\\/(${DANGEROUS_TAGS})\\s*>)?`,
|
|
184
|
-
"gi"
|
|
185
|
-
),
|
|
186
|
-
// Handles: whitespace, slash, quotes before event handlers (e.g., <img/onerror=...>, <img src="x"onerror=...>)
|
|
187
|
-
eventHandlers: /[\s/"']+on\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,
|
|
188
|
-
// Handles: javascript/data/vbscript URIs with optional whitespace/newlines between protocol and colon
|
|
189
|
-
dangerousURIs: /(href|src|action|xlink:href)\s*=\s*["']?\s*(javascript|data|vbscript)\s*:/gi
|
|
190
|
-
};
|
|
191
|
-
|
|
192
261
|
/**
|
|
193
262
|
* Sanitize HTML string to prevent XSS attacks
|
|
194
263
|
* Uses blacklist approach with repeated application to prevent nested tag bypass
|
|
264
|
+
* Handles encoded characters (HTML entities, Unicode escapes) to prevent bypass attacks
|
|
195
265
|
* @param {string} str Target string value
|
|
196
266
|
* @returns {string} Sanitized string with dangerous elements removed
|
|
197
267
|
* @private
|
|
198
268
|
*/
|
|
199
269
|
function sanitize(str: string): string {
|
|
270
|
+
// Early return for non-string, empty string, or string without HTML
|
|
200
271
|
if (!isString(str) || !str || str.indexOf("<") === -1) {
|
|
201
272
|
return str;
|
|
202
273
|
}
|
|
203
274
|
|
|
204
275
|
let result = str;
|
|
205
276
|
let prev: string;
|
|
277
|
+
let iterations = 0;
|
|
206
278
|
|
|
207
279
|
// Repeat until no more changes (prevents nested tag attacks like <scri<script>pt>)
|
|
208
280
|
do {
|
|
209
281
|
prev = result;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
282
|
+
|
|
283
|
+
// 1. Decode HTML entities to prevent bypass (e.g., jav
ascript:)
|
|
284
|
+
// 2. Remove control characters (NULL, tab, newline, etc.)
|
|
285
|
+
// 3. Remove dangerous tags (script, iframe, etc.)
|
|
286
|
+
result = _sanitize.decodeEntities(result)
|
|
287
|
+
.replace(_sanitize.rx.controlChar, "")
|
|
288
|
+
.replace(_sanitize.rx.tags, "")
|
|
289
|
+
.replace(_sanitize.rx.eventHandler, ""); // 4. Remove event handlers
|
|
290
|
+
|
|
291
|
+
// 5. Remove dangerous URIs (javascript:, data:, vbscript:)
|
|
292
|
+
result = _sanitize.removeDangerousUris(result);
|
|
293
|
+
|
|
294
|
+
// Safety check to prevent infinite loops
|
|
295
|
+
if (++iterations >= _sanitize.MAX_ITERATIONS) {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
214
298
|
} while (result !== prev);
|
|
215
299
|
|
|
216
300
|
return result;
|
|
217
301
|
}
|
|
218
302
|
|
|
219
303
|
/**
|
|
220
|
-
* Set text value. If there'
|
|
304
|
+
* Set text value. If there're multiline add nodes.
|
|
221
305
|
* @param {d3Selection} node Text node
|
|
222
306
|
* @param {string} text Text value string
|
|
223
307
|
* @param {Array} dy dy value for multilined text
|
|
@@ -309,7 +393,7 @@ function getPathBox(
|
|
|
309
393
|
* @returns {Array} [x, y] Coordinates x, y array
|
|
310
394
|
* @private
|
|
311
395
|
*/
|
|
312
|
-
function getPointer(event, element?: SVGElement): number[] {
|
|
396
|
+
function getPointer(event, element?: HTMLElement | SVGElement): number[] {
|
|
313
397
|
const touches = event &&
|
|
314
398
|
(event.touches || (event.sourceEvent && event.sourceEvent.touches))?.[0];
|
|
315
399
|
let pointer = [0, 0];
|
|
@@ -343,35 +427,6 @@ function getBrushSelection(ctx) {
|
|
|
343
427
|
return selection;
|
|
344
428
|
}
|
|
345
429
|
|
|
346
|
-
/**
|
|
347
|
-
* Get boundingClientRect.
|
|
348
|
-
* Cache the evaluated value once it was called.
|
|
349
|
-
* @param {boolean} relativeViewport Relative to viewport - true: will use .getBoundingClientRect(), false: will use .getBBox()
|
|
350
|
-
* @param {SVGElement} node Target element
|
|
351
|
-
* @param {boolean} forceEval Force evaluation
|
|
352
|
-
* @returns {object}
|
|
353
|
-
* @private
|
|
354
|
-
*/
|
|
355
|
-
function getRect(
|
|
356
|
-
relativeViewport: boolean,
|
|
357
|
-
node: SVGElement & Partial<{rect: DOMRect | SVGRect}>,
|
|
358
|
-
forceEval = false
|
|
359
|
-
): DOMRect | SVGRect {
|
|
360
|
-
const _ = n => n[relativeViewport ? "getBoundingClientRect" : "getBBox"]();
|
|
361
|
-
|
|
362
|
-
if (forceEval) {
|
|
363
|
-
return _(node);
|
|
364
|
-
} else {
|
|
365
|
-
// will cache the value if the element is not a SVGElement or the width is not set
|
|
366
|
-
const needEvaluate = !("rect" in node) || (
|
|
367
|
-
"rect" in node && node.hasAttribute("width") &&
|
|
368
|
-
node.rect!.width !== +(node.getAttribute("width") || 0)
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
return needEvaluate ? (node.rect = _(node)) : node.rect!;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
430
|
/**
|
|
376
431
|
* Get boundingClientRect.
|
|
377
432
|
* @param {SVGElement} node Target element
|
|
@@ -380,7 +435,7 @@ function getRect(
|
|
|
380
435
|
* @private
|
|
381
436
|
*/
|
|
382
437
|
function getBoundingRect(node, forceEval = false) {
|
|
383
|
-
return
|
|
438
|
+
return _getRect(true, node, forceEval);
|
|
384
439
|
}
|
|
385
440
|
|
|
386
441
|
/**
|
|
@@ -391,7 +446,7 @@ function getBoundingRect(node, forceEval = false) {
|
|
|
391
446
|
* @private
|
|
392
447
|
*/
|
|
393
448
|
function getBBox(node, forceEval = false) {
|
|
394
|
-
return
|
|
449
|
+
return _getRect(false, node, forceEval);
|
|
395
450
|
}
|
|
396
451
|
|
|
397
452
|
/**
|
|
@@ -970,8 +1025,8 @@ function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | n
|
|
|
970
1025
|
|
|
971
1026
|
/**
|
|
972
1027
|
* Run function until given condition function return true
|
|
973
|
-
* @param {
|
|
974
|
-
* @param {
|
|
1028
|
+
* @param {function} fn Function to be executed when condition is true
|
|
1029
|
+
* @param {function(): boolean} conditionFn Condition function to check if condition is true
|
|
975
1030
|
* @private
|
|
976
1031
|
*/
|
|
977
1032
|
function runUntil(fn: Function, conditionFn: Function): void {
|
|
@@ -1006,3 +1061,139 @@ function parseShorthand(
|
|
|
1006
1061
|
|
|
1007
1062
|
return {top: a, right: b, bottom: c, left: d};
|
|
1008
1063
|
}
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* Schedule a RAF update to batch multiple redraw requests
|
|
1067
|
+
* Manages a RAF state object to intelligently batch rapid updates while ensuring
|
|
1068
|
+
* immediate execution for the first call (for test compatibility)
|
|
1069
|
+
* @param {object} rafState RAF state object with pendingRaf property
|
|
1070
|
+
* @param {number|null} rafState.pendingRaf ID of pending RAF or null
|
|
1071
|
+
* @param {function} callback Function to execute in RAF
|
|
1072
|
+
* @returns {void}
|
|
1073
|
+
* @private
|
|
1074
|
+
*/
|
|
1075
|
+
function scheduleRAFUpdate(rafState: {pendingRaf: number | null}, callback: () => void): void {
|
|
1076
|
+
// If there's already a pending RAF, we're in a rapid update scenario
|
|
1077
|
+
// Cancel it and schedule a new one to batch the updates
|
|
1078
|
+
if (rafState.pendingRaf !== null) {
|
|
1079
|
+
window.cancelAnimationFrame(rafState.pendingRaf);
|
|
1080
|
+
|
|
1081
|
+
// Schedule new RAF
|
|
1082
|
+
rafState.pendingRaf = window.requestAnimationFrame(() => {
|
|
1083
|
+
rafState.pendingRaf = null;
|
|
1084
|
+
callback();
|
|
1085
|
+
});
|
|
1086
|
+
} else {
|
|
1087
|
+
// First call - execute immediately for test compatibility
|
|
1088
|
+
// But set pending RAF to detect rapid consecutive calls
|
|
1089
|
+
rafState.pendingRaf = window.requestAnimationFrame(() => {
|
|
1090
|
+
rafState.pendingRaf = null;
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
callback();
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Convert an array to a Set by applying a key extractor
|
|
1099
|
+
* @param {Array} items Array of items to convert to Set
|
|
1100
|
+
* @param {function} keyFn Function to extract key from each item (item, index) => key. Defaults to identity function
|
|
1101
|
+
* @returns {Set} Set with extracted keys
|
|
1102
|
+
* @private
|
|
1103
|
+
*/
|
|
1104
|
+
function toSet<T, K = T>(
|
|
1105
|
+
items: T[],
|
|
1106
|
+
keyFn: (item: T, index: number) => K = (item => item as unknown as K)
|
|
1107
|
+
): Set<K> {
|
|
1108
|
+
const set = new Set<K>();
|
|
1109
|
+
|
|
1110
|
+
_forEachValidItem(items, (item, i) => {
|
|
1111
|
+
set.add(keyFn(item, i));
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
return set;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* Convert an array to a Map by applying key and value extractors
|
|
1119
|
+
* @param {Array} items Array of items to convert to Map
|
|
1120
|
+
* @param {function} keyFn Function to extract key from each item (item, index) => key
|
|
1121
|
+
* @param {function} valueFn Function to extract value from each item (item, index) => value. Defaults to identity function
|
|
1122
|
+
* @returns {Map} Map with extracted keys and values
|
|
1123
|
+
* @private
|
|
1124
|
+
*/
|
|
1125
|
+
function toMap<T, K, V = T>(
|
|
1126
|
+
items: T[],
|
|
1127
|
+
keyFn: (item: T, index: number) => K,
|
|
1128
|
+
valueFn: (item: T, index: number) => V = (item => item as unknown as V)
|
|
1129
|
+
): Map<K, V> {
|
|
1130
|
+
const map = new Map<K, V>();
|
|
1131
|
+
|
|
1132
|
+
_forEachValidItem(items, (item, i) => {
|
|
1133
|
+
map.set(keyFn(item, i), valueFn(item, i));
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
return map;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
export {
|
|
1140
|
+
addCssRules,
|
|
1141
|
+
asHalfPixel,
|
|
1142
|
+
brushEmpty,
|
|
1143
|
+
callFn,
|
|
1144
|
+
camelize,
|
|
1145
|
+
capitalize,
|
|
1146
|
+
ceil10,
|
|
1147
|
+
convertInputType,
|
|
1148
|
+
deepClone,
|
|
1149
|
+
diffDomain,
|
|
1150
|
+
emulateEvent,
|
|
1151
|
+
endall,
|
|
1152
|
+
extend,
|
|
1153
|
+
findIndex,
|
|
1154
|
+
getBBox,
|
|
1155
|
+
getBoundingRect,
|
|
1156
|
+
getBrushSelection,
|
|
1157
|
+
getCssRules,
|
|
1158
|
+
getMinMax,
|
|
1159
|
+
getOption,
|
|
1160
|
+
getPathBox,
|
|
1161
|
+
getPointer,
|
|
1162
|
+
getRandom,
|
|
1163
|
+
getRange,
|
|
1164
|
+
getRectSegList,
|
|
1165
|
+
getScrollPosition,
|
|
1166
|
+
getTransformCTM,
|
|
1167
|
+
getTranslation,
|
|
1168
|
+
getUnique,
|
|
1169
|
+
hasStyle,
|
|
1170
|
+
hasValue,
|
|
1171
|
+
hasViewBox,
|
|
1172
|
+
isArray,
|
|
1173
|
+
isBoolean,
|
|
1174
|
+
isDefined,
|
|
1175
|
+
isEmpty,
|
|
1176
|
+
isEmptyObject,
|
|
1177
|
+
isFunction,
|
|
1178
|
+
isNumber,
|
|
1179
|
+
isObject,
|
|
1180
|
+
isObjectType,
|
|
1181
|
+
isString,
|
|
1182
|
+
isTabVisible,
|
|
1183
|
+
isUndefined,
|
|
1184
|
+
isValue,
|
|
1185
|
+
mergeArray,
|
|
1186
|
+
mergeObj,
|
|
1187
|
+
notEmpty,
|
|
1188
|
+
parseDate,
|
|
1189
|
+
parseShorthand,
|
|
1190
|
+
runUntil,
|
|
1191
|
+
sanitize,
|
|
1192
|
+
scheduleRAFUpdate,
|
|
1193
|
+
setTextValue,
|
|
1194
|
+
sortValue,
|
|
1195
|
+
toArray,
|
|
1196
|
+
toMap,
|
|
1197
|
+
toSet,
|
|
1198
|
+
tplProcess
|
|
1199
|
+
};
|
package/src/module/worker.ts
CHANGED
|
@@ -9,7 +9,7 @@ const blob = {};
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Get Object URL
|
|
12
|
-
* @param {
|
|
12
|
+
* @param {function} fn Function to be executed in worker
|
|
13
13
|
* @param {Array} depsFn Dependency functions to run given function(fn).
|
|
14
14
|
* @returns {string}
|
|
15
15
|
* @private
|
|
@@ -56,8 +56,8 @@ export function getWorker(src) {
|
|
|
56
56
|
/**
|
|
57
57
|
* Create and run on Web Worker
|
|
58
58
|
* @param {boolean} useWorker Use Web Worker
|
|
59
|
-
* @param {
|
|
60
|
-
* @param {
|
|
59
|
+
* @param {function} fn Function to be executed in worker
|
|
60
|
+
* @param {function} callback Callback function to receive result from worker
|
|
61
61
|
* @param {Array} depsFn Dependency functions to run given function(fn).
|
|
62
62
|
* @returns {object}
|
|
63
63
|
* @example
|
package/src/scss/billboard.scss
CHANGED
|
@@ -48,6 +48,21 @@
|
|
|
48
48
|
fill: #fff;
|
|
49
49
|
font-size: 13px;
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
/* Connector line base styles */
|
|
53
|
+
.bb-arc-label-line {
|
|
54
|
+
fill: none;
|
|
55
|
+
stroke-width: 1px;
|
|
56
|
+
pointer-events: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.bb-arc-label-line {
|
|
60
|
+
stroke: #7f7f7f;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
> text.bb-arc-label-line-text {
|
|
64
|
+
fill: #000;
|
|
65
|
+
}
|
|
51
66
|
}
|
|
52
67
|
|
|
53
68
|
/*-- Funnel --*/
|
package/src/scss/theme/dark.scss
CHANGED
|
@@ -391,6 +391,21 @@ text.bb-chart-arcs-gauge-title {
|
|
|
391
391
|
fill: #fff;
|
|
392
392
|
font-size: 13px;
|
|
393
393
|
}
|
|
394
|
+
|
|
395
|
+
/* Connector line base styles */
|
|
396
|
+
.bb-arc-label-line {
|
|
397
|
+
fill: none;
|
|
398
|
+
stroke-width: 1px;
|
|
399
|
+
pointer-events: none;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.bb-arc-label-line {
|
|
403
|
+
stroke: #a0a0a0;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
> text.bb-arc-label-line-text {
|
|
407
|
+
fill: #ccc;
|
|
408
|
+
}
|
|
394
409
|
}
|
|
395
410
|
|
|
396
411
|
/*-- Radar --*/
|
|
@@ -386,6 +386,21 @@ text.bb-chart-arcs-gauge-title {
|
|
|
386
386
|
fill: #fff;
|
|
387
387
|
font-size: 14px;
|
|
388
388
|
}
|
|
389
|
+
|
|
390
|
+
/* Connector line base styles */
|
|
391
|
+
.bb-arc-label-line {
|
|
392
|
+
fill: none;
|
|
393
|
+
stroke-width: 1px;
|
|
394
|
+
pointer-events: none;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
.bb-arc-label-line {
|
|
398
|
+
stroke: #7f7f7f;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
> text.bb-arc-label-line-text {
|
|
402
|
+
fill: #000;
|
|
403
|
+
}
|
|
389
404
|
}
|
|
390
405
|
|
|
391
406
|
/*-- Radar --*/
|