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
|
@@ -20,7 +20,7 @@ import type {IArcData, IDataRow} from "../data/IData";
|
|
|
20
20
|
* @returns {{id: string, node: SVGPatternElement}}
|
|
21
21
|
* @private
|
|
22
22
|
*/
|
|
23
|
-
const
|
|
23
|
+
const _colorizePattern = (pattern, color, id: string) => {
|
|
24
24
|
const node = d3Select(pattern.cloneNode(true));
|
|
25
25
|
|
|
26
26
|
node
|
|
@@ -43,7 +43,7 @@ const colorizePattern = (pattern, color, id: string) => {
|
|
|
43
43
|
* @returns {Array}
|
|
44
44
|
* @private
|
|
45
45
|
*/
|
|
46
|
-
function
|
|
46
|
+
function _getColorFromCss(element: d3Selection): string[] {
|
|
47
47
|
const cacheKey = KEY.colorPattern;
|
|
48
48
|
const {body} = document;
|
|
49
49
|
let pattern = body[cacheKey];
|
|
@@ -90,10 +90,12 @@ export default {
|
|
|
90
90
|
const $$ = this;
|
|
91
91
|
const {$el, config} = $$;
|
|
92
92
|
const ids: string[] = [];
|
|
93
|
+
const hasGradient = config.area_linearGradient || config.bar_linearGradient ||
|
|
94
|
+
config.point_radialGradient;
|
|
93
95
|
|
|
94
96
|
let pattern = notEmpty(config.color_pattern) ?
|
|
95
97
|
config.color_pattern :
|
|
96
|
-
d3ScaleOrdinal(
|
|
98
|
+
d3ScaleOrdinal(_getColorFromCss($el.chart) || schemeCategory10).range();
|
|
97
99
|
|
|
98
100
|
const originalColorPattern = pattern;
|
|
99
101
|
|
|
@@ -105,7 +107,7 @@ export default {
|
|
|
105
107
|
const color = p.replace(/[#\(\)\s,]/g, "");
|
|
106
108
|
const id = `${$$.state.datetimeId}-pattern-${color}-${index}`;
|
|
107
109
|
|
|
108
|
-
return
|
|
110
|
+
return _colorizePattern(tiles[index % tiles.length], p, id);
|
|
109
111
|
});
|
|
110
112
|
|
|
111
113
|
pattern = colorizedPatterns.map(p => `url(#${p.id})`);
|
|
@@ -125,13 +127,11 @@ export default {
|
|
|
125
127
|
// if callback function is provided
|
|
126
128
|
if (isFunction(colors[id])) {
|
|
127
129
|
color = colors[id].bind($$.api)(d);
|
|
128
|
-
|
|
129
|
-
// if specified, choose that color
|
|
130
130
|
} else if (colors[id]) {
|
|
131
|
+
// if specified, choose that color
|
|
131
132
|
color = colors[id];
|
|
132
|
-
|
|
133
|
-
// if not specified, choose from pattern
|
|
134
133
|
} else {
|
|
134
|
+
// if not specified, choose from pattern
|
|
135
135
|
if (ids.indexOf(id) < 0) {
|
|
136
136
|
ids.push(id);
|
|
137
137
|
}
|
|
@@ -143,7 +143,24 @@ export default {
|
|
|
143
143
|
colors[id] = color;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
color = isFunction(callback) ? callback.call($$.api, color, d) : color;
|
|
147
|
+
|
|
148
|
+
if (hasGradient) {
|
|
149
|
+
const stop = $$.$el.defs.selectAll(
|
|
150
|
+
`[id$='-gradient${$$.getTargetSelectorSuffix(id)}'] stop`
|
|
151
|
+
);
|
|
152
|
+
let hasSameColor;
|
|
153
|
+
|
|
154
|
+
stop.each(function(d, i) {
|
|
155
|
+
hasSameColor = i === 0 ?
|
|
156
|
+
this.style.stopColor :
|
|
157
|
+
this.style.stopColor === hasSameColor;
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
hasSameColor === true && stop.attr("stop-color", color);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return color;
|
|
147
164
|
};
|
|
148
165
|
},
|
|
149
166
|
|
|
@@ -178,7 +195,7 @@ export default {
|
|
|
178
195
|
|
|
179
196
|
/**
|
|
180
197
|
* Append data backgound color filter definition
|
|
181
|
-
* @param {string|object|
|
|
198
|
+
* @param {string|object|function} color Color string, object, or function
|
|
182
199
|
* @param {object} attr filter attribute
|
|
183
200
|
* @private
|
|
184
201
|
*/
|
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
isValue,
|
|
15
15
|
notEmpty,
|
|
16
16
|
parseDate,
|
|
17
|
-
sortValue
|
|
17
|
+
sortValue,
|
|
18
|
+
toSet
|
|
18
19
|
} from "../../module/util";
|
|
19
20
|
import type {IData, TDomainRange} from "../data/IData";
|
|
20
21
|
|
|
@@ -26,19 +27,23 @@ export default {
|
|
|
26
27
|
|
|
27
28
|
const dataGroups = config.data_groups;
|
|
28
29
|
const ids = $$.mapToIds(targets);
|
|
30
|
+
const idsSet = toSet(ids); // O(1) lookup instead of O(n) indexOf
|
|
29
31
|
const ys = $$.getValuesAsIdKeyed(targets);
|
|
30
32
|
|
|
31
33
|
if (dataGroups.length > 0) {
|
|
32
34
|
const hasValue = $$[`has${isMin ? "Negative" : "Positive"}ValueInTargets`](targets);
|
|
33
35
|
|
|
36
|
+
// Pre-compute axis IDs for O(1) lookup instead of repeated axis.getId() calls
|
|
37
|
+
const axisIdMap = new Map(ids.map(id => [id, axis.getId(id)]));
|
|
38
|
+
|
|
34
39
|
dataGroups.forEach(groupIds => {
|
|
35
40
|
// Determine baseId
|
|
36
41
|
const idsInGroup = groupIds
|
|
37
|
-
.filter(v =>
|
|
42
|
+
.filter(v => idsSet.has(v));
|
|
38
43
|
|
|
39
44
|
if (idsInGroup.length) {
|
|
40
45
|
const baseId = idsInGroup[0];
|
|
41
|
-
const baseAxisId =
|
|
46
|
+
const baseAxisId = axisIdMap.get(baseId);
|
|
42
47
|
|
|
43
48
|
// Initialize base value. Set to 0 if not match with the condition
|
|
44
49
|
if (hasValue && ys[baseId]) {
|
|
@@ -50,7 +55,7 @@ export default {
|
|
|
50
55
|
.filter((v, i) => i > 0)
|
|
51
56
|
.forEach(id => {
|
|
52
57
|
if (ys[id]) {
|
|
53
|
-
const axisId =
|
|
58
|
+
const axisId = axisIdMap.get(id);
|
|
54
59
|
|
|
55
60
|
ys[id].forEach((v, i) => {
|
|
56
61
|
const val = +v;
|
|
@@ -87,8 +92,20 @@ export default {
|
|
|
87
92
|
const {axis, config, scale} = $$;
|
|
88
93
|
const pfx = `axis_${axisId}`;
|
|
89
94
|
|
|
95
|
+
// Check if stack normalization should be applied for this axis
|
|
90
96
|
if ($$.isStackNormalized()) {
|
|
91
|
-
|
|
97
|
+
// Get all data IDs that belong to this axis
|
|
98
|
+
const axisDataIds = targets
|
|
99
|
+
.filter(t => axis.getId(t.id) === axisId)
|
|
100
|
+
.map(t => t.id);
|
|
101
|
+
|
|
102
|
+
// Check if any of the axis data IDs are in groups
|
|
103
|
+
const hasGroupedData = axisDataIds.some(id => $$.isGrouped(id));
|
|
104
|
+
|
|
105
|
+
// Apply normalization only if this axis has grouped data
|
|
106
|
+
if (hasGroupedData) {
|
|
107
|
+
return [0, 100];
|
|
108
|
+
}
|
|
92
109
|
}
|
|
93
110
|
|
|
94
111
|
const isLog = scale?.[axisId] && scale[axisId].type === "log";
|
|
@@ -13,7 +13,7 @@ import {isArray, isFunction, isObject, isObjectType, isValue} from "../../module
|
|
|
13
13
|
* @returns {number | string}
|
|
14
14
|
* @private
|
|
15
15
|
*/
|
|
16
|
-
function
|
|
16
|
+
function _getFormat($$, typeValue: AxisType, v: number): number | string {
|
|
17
17
|
const {config} = $$;
|
|
18
18
|
const type = `axis_${typeValue}_tick_format`;
|
|
19
19
|
const format = config[type] ? config[type] : $$.defaultValueFormat;
|
|
@@ -23,16 +23,16 @@ function getFormat($$, typeValue: AxisType, v: number): number | string {
|
|
|
23
23
|
|
|
24
24
|
export default {
|
|
25
25
|
yFormat(v: number): number | string {
|
|
26
|
-
return
|
|
26
|
+
return _getFormat(this, "y", v);
|
|
27
27
|
},
|
|
28
28
|
|
|
29
29
|
y2Format(v: number): number | string {
|
|
30
|
-
return
|
|
30
|
+
return _getFormat(this, "y2", v);
|
|
31
31
|
},
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Get default value format function
|
|
35
|
-
* @returns {
|
|
35
|
+
* @returns {function} formatter function
|
|
36
36
|
* @private
|
|
37
37
|
*/
|
|
38
38
|
getDefaultValueFormat(): Function {
|
|
@@ -8,18 +8,18 @@ import {$AXIS, $COMMON, $FOCUS, $GRID} from "../../config/classes";
|
|
|
8
8
|
import {getPointer, isArray, isValue} from "../../module/util";
|
|
9
9
|
|
|
10
10
|
// Grid position and text anchor helpers
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const _getGridTextAnchor = d => isValue(d.position) || "end";
|
|
12
|
+
const _getGridTextDx = d => (d.position === "start" ? 4 : (d.position === "middle" ? 0 : -4));
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Get grid text x value getter function
|
|
16
16
|
* @param {boolean} isX Is x Axis
|
|
17
17
|
* @param {number} width Width value
|
|
18
18
|
* @param {number} height Height value
|
|
19
|
-
* @returns {
|
|
19
|
+
* @returns {function}
|
|
20
20
|
* @private
|
|
21
21
|
*/
|
|
22
|
-
function
|
|
22
|
+
function _getGridTextX(isX, width, height): Function {
|
|
23
23
|
return d => {
|
|
24
24
|
let x = isX ? 0 : width;
|
|
25
25
|
|
|
@@ -39,7 +39,7 @@ function getGridTextX(isX, width, height): Function {
|
|
|
39
39
|
* @param {string} type Type
|
|
40
40
|
* @private
|
|
41
41
|
*/
|
|
42
|
-
function
|
|
42
|
+
function _smoothLines(el, type: string): void {
|
|
43
43
|
if (type === "grid") {
|
|
44
44
|
el.each(function() {
|
|
45
45
|
const g = d3Select(this);
|
|
@@ -159,7 +159,7 @@ export default {
|
|
|
159
159
|
.attr("y1", isRotated ? 0 : pos)
|
|
160
160
|
.attr("y2", isRotated ? state.height : pos);
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
_smoothLines(grid.y, "grid");
|
|
163
163
|
},
|
|
164
164
|
|
|
165
165
|
updateGrid() {
|
|
@@ -218,12 +218,12 @@ export default {
|
|
|
218
218
|
$T(lines
|
|
219
219
|
.attr("class", d => `${$GRID[`${type}gridLine`]} ${d.class || ""}`.trim())
|
|
220
220
|
.select("text")
|
|
221
|
-
.attr("text-anchor",
|
|
221
|
+
.attr("text-anchor", _getGridTextAnchor)
|
|
222
222
|
.attr("transform",
|
|
223
223
|
() => (isX ?
|
|
224
224
|
(isRotated ? null : "rotate(-90)") :
|
|
225
225
|
(isRotated ? "rotate(-90)" : null)))
|
|
226
|
-
.attr("dx",
|
|
226
|
+
.attr("dx", _getGridTextDx)
|
|
227
227
|
.attr("dy", -5))
|
|
228
228
|
.text(function(d) {
|
|
229
229
|
return d.text ?? this.remove();
|
|
@@ -256,7 +256,7 @@ export default {
|
|
|
256
256
|
.attr("y2", isRotated ? xv : height);
|
|
257
257
|
|
|
258
258
|
xTexts = $T(xTexts, withTransition)
|
|
259
|
-
.attr("x",
|
|
259
|
+
.attr("x", _getGridTextX(!isRotated, width, height))
|
|
260
260
|
.attr("y", xv);
|
|
261
261
|
|
|
262
262
|
yLines = $T(yLines, withTransition)
|
|
@@ -266,7 +266,7 @@ export default {
|
|
|
266
266
|
.attr("y2", isRotated ? height : yv);
|
|
267
267
|
|
|
268
268
|
yTexts = $T(yTexts, withTransition)
|
|
269
|
-
.attr("x",
|
|
269
|
+
.attr("x", _getGridTextX(isRotated, width, height))
|
|
270
270
|
.attr("y", yv);
|
|
271
271
|
|
|
272
272
|
return [
|
|
@@ -455,7 +455,7 @@ export default {
|
|
|
455
455
|
.forEach((v, i) => el.attr(v, xy[i]));
|
|
456
456
|
});
|
|
457
457
|
|
|
458
|
-
|
|
458
|
+
_smoothLines(focusEl, "grid");
|
|
459
459
|
$$.showCircleFocus?.(data);
|
|
460
460
|
},
|
|
461
461
|
|
|
@@ -12,18 +12,19 @@ import {
|
|
|
12
12
|
isDefined,
|
|
13
13
|
isEmpty,
|
|
14
14
|
isFunction,
|
|
15
|
-
notEmpty,
|
|
16
15
|
sanitize,
|
|
16
|
+
toMap,
|
|
17
17
|
tplProcess
|
|
18
18
|
} from "../../module/util";
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Get color string for given data id
|
|
22
|
+
* Internal helper used only within this file
|
|
22
23
|
* @param {string} id Data id
|
|
23
24
|
* @returns {string} Color string
|
|
24
25
|
* @private
|
|
25
26
|
*/
|
|
26
|
-
function
|
|
27
|
+
function _getLegendColor(id: string): string {
|
|
27
28
|
const $$ = this;
|
|
28
29
|
const data = $$.getDataById(id);
|
|
29
30
|
const color = $$.levelColor ? $$.levelColor(data.values[0].value) : $$.color(data);
|
|
@@ -33,11 +34,13 @@ function getLegendColor(id: string): string {
|
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Get formatted text value
|
|
37
|
+
* Internal helper used only within this file
|
|
36
38
|
* @param {string} id Legend text id
|
|
37
39
|
* @param {boolean} formatted Whether or not to format the text
|
|
38
40
|
* @returns {string} Formatted legend text
|
|
41
|
+
* @private
|
|
39
42
|
*/
|
|
40
|
-
function
|
|
43
|
+
function _getFormattedText<T = string>(id: T, formatted = true): T {
|
|
41
44
|
const {config} = this;
|
|
42
45
|
let text = config.data_names[id] ?? id;
|
|
43
46
|
|
|
@@ -48,6 +51,36 @@ function getFormattedText<T = string>(id: T, formatted = true): T {
|
|
|
48
51
|
return text;
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Build a Map of legend items for fast O(1) lookup by ID
|
|
56
|
+
* Internal helper used only within this file
|
|
57
|
+
* @param {object} $$ ChartInternal context
|
|
58
|
+
* @param {d3.selection} legendItems D3 selection of legend items
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
function _buildLegendItemMap($$, legendItems): void {
|
|
62
|
+
if (!legendItems || legendItems.empty()) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Convert D3 selection to array of [id, node] pairs
|
|
67
|
+
const items: Array<{id: string, node: HTMLElement}> = [];
|
|
68
|
+
|
|
69
|
+
legendItems.each(function(id) {
|
|
70
|
+
items.push({id, node: this});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Create Map for O(1) lookups using toMap utility
|
|
74
|
+
const itemMap = toMap(
|
|
75
|
+
items,
|
|
76
|
+
item => item.id,
|
|
77
|
+
item => item.node
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Cache the map
|
|
81
|
+
$$.cache.add(KEY.legendItemMap, itemMap);
|
|
82
|
+
}
|
|
83
|
+
|
|
51
84
|
export default {
|
|
52
85
|
/**
|
|
53
86
|
* Initialize the legend.
|
|
@@ -261,11 +294,17 @@ export default {
|
|
|
261
294
|
* @private
|
|
262
295
|
*/
|
|
263
296
|
updateLegendItemColor(id: string, color: string): void {
|
|
264
|
-
const
|
|
297
|
+
const $$ = this;
|
|
298
|
+
const {legend} = $$.$el;
|
|
265
299
|
|
|
266
300
|
if (legend) {
|
|
267
|
-
|
|
268
|
-
|
|
301
|
+
// Use cached Map lookup for O(1) performance
|
|
302
|
+
const legendItem = $$.getLegendItemById(id);
|
|
303
|
+
|
|
304
|
+
if (legendItem) {
|
|
305
|
+
d3Select(legendItem).select("line")
|
|
306
|
+
.style("stroke", color);
|
|
307
|
+
}
|
|
269
308
|
}
|
|
270
309
|
},
|
|
271
310
|
|
|
@@ -534,6 +573,31 @@ export default {
|
|
|
534
573
|
!item.empty() && item.on("click mouseout mouseover") &&
|
|
535
574
|
item.style("cursor", $$.getStylePropValue("pointer"));
|
|
536
575
|
}
|
|
576
|
+
|
|
577
|
+
// Build legend item map for O(1) lookup
|
|
578
|
+
_buildLegendItemMap($$, item);
|
|
579
|
+
},
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Get legend item node by ID using cached Map for O(1) lookup
|
|
583
|
+
* Falls back to D3 selection if map is not available
|
|
584
|
+
* @param {string} id Data ID
|
|
585
|
+
* @returns {HTMLElement | null} Legend item node
|
|
586
|
+
* @private
|
|
587
|
+
*/
|
|
588
|
+
getLegendItemById(id: string): HTMLElement | null {
|
|
589
|
+
const $$ = this;
|
|
590
|
+
const itemMap = $$.cache.get(KEY.legendItemMap);
|
|
591
|
+
|
|
592
|
+
if (itemMap && itemMap instanceof Map) {
|
|
593
|
+
return itemMap.get(id) || null;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// Fallback to D3 selection (slower)
|
|
597
|
+
const item = $$.$el.legend?.selectAll(`.${$LEGEND.legendItem}`)
|
|
598
|
+
.filter(d => d === id);
|
|
599
|
+
|
|
600
|
+
return item?.node() || null;
|
|
537
601
|
},
|
|
538
602
|
|
|
539
603
|
/**
|
|
@@ -628,12 +692,12 @@ export default {
|
|
|
628
692
|
if (config.legend_tooltip) {
|
|
629
693
|
legend.selectAll("title")
|
|
630
694
|
.data(targetIdz)
|
|
631
|
-
.text(id =>
|
|
695
|
+
.text(id => _getFormattedText.bind($$)(id, false));
|
|
632
696
|
}
|
|
633
697
|
|
|
634
698
|
const texts = legend.selectAll("text")
|
|
635
699
|
.data(targetIdz)
|
|
636
|
-
.text(id =>
|
|
700
|
+
.text(id => _getFormattedText.bind($$)(id)) // MEMO: needed for update
|
|
637
701
|
.each(function(id, i) {
|
|
638
702
|
updatePositions(this, id, i);
|
|
639
703
|
});
|
|
@@ -671,7 +735,7 @@ export default {
|
|
|
671
735
|
* @param {Array} targetIdz Data ids
|
|
672
736
|
* @param {object} dimension Dimension object
|
|
673
737
|
* @param {object} sizes Size object
|
|
674
|
-
* @returns {
|
|
738
|
+
* @returns {function} Update position function
|
|
675
739
|
* @private
|
|
676
740
|
*/
|
|
677
741
|
getUpdateLegendPositions(targetIdz, dimension, sizes) {
|
|
@@ -763,7 +827,7 @@ export default {
|
|
|
763
827
|
* Generate legend item elements
|
|
764
828
|
* @param {Array} targetIdz Data ids
|
|
765
829
|
* @param {object} itemTileSize Item tile size {width, height}
|
|
766
|
-
* @param {
|
|
830
|
+
* @param {function} updatePositions Update position function
|
|
767
831
|
* @param {object} posFn Position functions
|
|
768
832
|
* @private
|
|
769
833
|
*/
|
|
@@ -791,7 +855,7 @@ export default {
|
|
|
791
855
|
}
|
|
792
856
|
|
|
793
857
|
l.append("text")
|
|
794
|
-
.text(id =>
|
|
858
|
+
.text(id => _getFormattedText.bind($$)(id))
|
|
795
859
|
.each(function(id, i) {
|
|
796
860
|
updatePositions(this, id, i);
|
|
797
861
|
})
|
|
@@ -807,12 +871,9 @@ export default {
|
|
|
807
871
|
|
|
808
872
|
if (usePoint) {
|
|
809
873
|
const ids: string[] = [];
|
|
874
|
+
const pattern = $$.getValidPointPattern();
|
|
810
875
|
|
|
811
876
|
l.append(d => {
|
|
812
|
-
const pattern = notEmpty(config.point_pattern) ?
|
|
813
|
-
config.point_pattern :
|
|
814
|
-
[config.point_type];
|
|
815
|
-
|
|
816
877
|
ids.indexOf(d) === -1 && ids.push(d);
|
|
817
878
|
|
|
818
879
|
let point = pattern[ids.indexOf(d) % pattern.length];
|
|
@@ -825,7 +886,7 @@ export default {
|
|
|
825
886
|
("hasValidPointType" in $$) && $$.hasValidPointType(point) ? point : "use");
|
|
826
887
|
})
|
|
827
888
|
.attr("class", $LEGEND.legendItemPoint)
|
|
828
|
-
.style("fill",
|
|
889
|
+
.style("fill", _getLegendColor.bind($$))
|
|
829
890
|
.style("pointer-events", $$.getStylePropValue("none"))
|
|
830
891
|
.attr("href", (data, idx, selection) => {
|
|
831
892
|
const node = selection[idx];
|
|
@@ -837,13 +898,13 @@ export default {
|
|
|
837
898
|
} else {
|
|
838
899
|
l.append(isRectangle ? "line" : legendType)
|
|
839
900
|
.attr("class", $LEGEND.legendItemTile)
|
|
840
|
-
.style("stroke",
|
|
901
|
+
.style("stroke", _getLegendColor.bind($$))
|
|
841
902
|
.style("pointer-events", $$.getStylePropValue("none"))
|
|
842
903
|
.call(selection => {
|
|
843
904
|
if (legendType === "circle") {
|
|
844
905
|
selection
|
|
845
906
|
.attr("r", legendItemR)
|
|
846
|
-
.style("fill",
|
|
907
|
+
.style("fill", _getLegendColor.bind($$))
|
|
847
908
|
.attr("cx", isLegendRightOrInset ? posFn.x2Tile : pos)
|
|
848
909
|
.attr("cy", isLegendRightOrInset ? pos : posFn.yTile);
|
|
849
910
|
} else if (isRectangle) {
|
|
@@ -916,7 +977,7 @@ export default {
|
|
|
916
977
|
.data(targetIdz);
|
|
917
978
|
|
|
918
979
|
$T(tiles, withTransition)
|
|
919
|
-
.style("stroke",
|
|
980
|
+
.style("stroke", _getLegendColor.bind($$))
|
|
920
981
|
.call(selection => {
|
|
921
982
|
if (legendType === "circle") {
|
|
922
983
|
selection
|
|
@@ -41,8 +41,8 @@ export default {
|
|
|
41
41
|
* @param {number} min Min range value
|
|
42
42
|
* @param {number} max Max range value
|
|
43
43
|
* @param {Array} domain Domain value
|
|
44
|
-
* @param {
|
|
45
|
-
* @returns {
|
|
44
|
+
* @param {function} offset The offset getter to be sum
|
|
45
|
+
* @returns {function} scale
|
|
46
46
|
* @private
|
|
47
47
|
*/
|
|
48
48
|
getXScale(min: number, max: number, domain: number[], offset: Function) {
|
|
@@ -62,7 +62,7 @@ export default {
|
|
|
62
62
|
* @param {number} min Min value
|
|
63
63
|
* @param {number} max Max value
|
|
64
64
|
* @param {Array} domain Domain value
|
|
65
|
-
* @returns {
|
|
65
|
+
* @returns {function} Scale function
|
|
66
66
|
* @private
|
|
67
67
|
*/
|
|
68
68
|
getYScale(id: "y" | "y2", min: number, max: number, domain: number[]): Function {
|
|
@@ -78,7 +78,7 @@ export default {
|
|
|
78
78
|
* Get y Axis scale
|
|
79
79
|
* @param {string} id Axis id
|
|
80
80
|
* @param {boolean} isSub Weather is sub Axis
|
|
81
|
-
* @returns {
|
|
81
|
+
* @returns {function} Scale function
|
|
82
82
|
* @private
|
|
83
83
|
*/
|
|
84
84
|
getYScaleById(id: string, isSub = false): Function {
|
|
@@ -91,8 +91,8 @@ export default {
|
|
|
91
91
|
/**
|
|
92
92
|
* Get customized x axis scale
|
|
93
93
|
* @param {d3.scaleLinear|d3.scaleTime} scaleValue Scale function
|
|
94
|
-
* @param {
|
|
95
|
-
* @returns {
|
|
94
|
+
* @param {function} offsetValue Offset getter to be sum
|
|
95
|
+
* @returns {function} Scale function
|
|
96
96
|
* @private
|
|
97
97
|
*/
|
|
98
98
|
getCustomizedXScale(scaleValue: Function | any, offsetValue): Function {
|
|
@@ -126,7 +126,7 @@ export default {
|
|
|
126
126
|
* Returns the toggle method of the target
|
|
127
127
|
* @param {object} that shape
|
|
128
128
|
* @param {object} d Data object
|
|
129
|
-
* @returns {
|
|
129
|
+
* @returns {function} toggle method
|
|
130
130
|
* @private
|
|
131
131
|
*/
|
|
132
132
|
getToggle(that, d): Function {
|
|
@@ -13,8 +13,8 @@ export default {
|
|
|
13
13
|
* @param {boolean} withShape Set shpes' prefix class
|
|
14
14
|
* @param {string} selector CSS selector
|
|
15
15
|
* @param {Array} props CSS props list
|
|
16
|
-
* @param {
|
|
17
|
-
* @returns {
|
|
16
|
+
* @param {function} propsFn Function to retrieve value or determine for props
|
|
17
|
+
* @returns {function}
|
|
18
18
|
* @private
|
|
19
19
|
*/
|
|
20
20
|
setCssRule(withShape: boolean, selector: string, props: string[], propsFn: Function): Function {
|
|
@@ -44,7 +44,7 @@ export default {
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Get style prop value
|
|
47
|
-
* @param {
|
|
47
|
+
* @param {function|string} v Value
|
|
48
48
|
* @returns {string|null}
|
|
49
49
|
* @private
|
|
50
50
|
*/
|