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
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
isObject,
|
|
10
10
|
isUndefined,
|
|
11
11
|
isValue,
|
|
12
|
-
notEmpty
|
|
12
|
+
notEmpty,
|
|
13
|
+
toSet
|
|
13
14
|
} from "../../module/util";
|
|
14
15
|
import {runWorker} from "../../module/worker";
|
|
15
16
|
import type {IData} from "../data/IData";
|
|
@@ -22,7 +23,7 @@ import {columns, json, rows, url} from "./convert.helper";
|
|
|
22
23
|
* @returns {string} Data key
|
|
23
24
|
* @private
|
|
24
25
|
*/
|
|
25
|
-
function
|
|
26
|
+
function _getDataKeyForJson(keysParam, config) {
|
|
26
27
|
const keys = keysParam || config?.data_keys;
|
|
27
28
|
|
|
28
29
|
if (keys?.x) {
|
|
@@ -44,7 +45,7 @@ function getDataKeyForJson(keysParam, config) {
|
|
|
44
45
|
* @param {boolean} params.customX Whether the x is custom
|
|
45
46
|
* @private
|
|
46
47
|
*/
|
|
47
|
-
function
|
|
48
|
+
function _setXS(
|
|
48
49
|
ids: string[],
|
|
49
50
|
data: {[key: string]: number | null}[],
|
|
50
51
|
params: {appendXs, xs, categorized: boolean, timeSeries: boolean, customX: boolean}
|
|
@@ -95,7 +96,7 @@ export default {
|
|
|
95
96
|
/**
|
|
96
97
|
* Convert data according its type
|
|
97
98
|
* @param {object} args data object
|
|
98
|
-
* @param {
|
|
99
|
+
* @param {function} [callback] callback for url(XHR) type loading
|
|
99
100
|
* @private
|
|
100
101
|
*/
|
|
101
102
|
convertData(args, callback: Function): void {
|
|
@@ -117,12 +118,12 @@ export default {
|
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
if (data.url && callback) {
|
|
120
|
-
url(data.url, data.mimeType, data.headers,
|
|
121
|
+
url(data.url, data.mimeType, data.headers, _getDataKeyForJson(data.keys, config),
|
|
121
122
|
callback);
|
|
122
123
|
} else if (data.json) {
|
|
123
124
|
runWorker(useWorker(data.json), json, callback, [columns, rows])(
|
|
124
125
|
data.json,
|
|
125
|
-
|
|
126
|
+
_getDataKeyForJson(data.keys, config)
|
|
126
127
|
);
|
|
127
128
|
} else if (data.rows) {
|
|
128
129
|
runWorker(useWorker(data.rows), rows, callback)(data.rows);
|
|
@@ -169,7 +170,7 @@ export default {
|
|
|
169
170
|
};
|
|
170
171
|
|
|
171
172
|
// save x for update data by load when custom x and bb.x API
|
|
172
|
-
|
|
173
|
+
_setXS.bind($$)(ids, data, params);
|
|
173
174
|
|
|
174
175
|
// convert to target
|
|
175
176
|
const targets = ids.map((id, index) => {
|
|
@@ -177,7 +178,7 @@ export default {
|
|
|
177
178
|
const xKey = $$.getXKey(id);
|
|
178
179
|
const isCategory = params.customX && params.categorized;
|
|
179
180
|
const hasCategory = isCategory && (() => {
|
|
180
|
-
const categorySet =
|
|
181
|
+
const categorySet = toSet(config.axis_x_categories);
|
|
181
182
|
return data.every(v => categorySet.has(v.x));
|
|
182
183
|
})();
|
|
183
184
|
|
|
@@ -46,7 +46,26 @@ export default {
|
|
|
46
46
|
isStackNormalized(): boolean {
|
|
47
47
|
const {config} = this;
|
|
48
48
|
|
|
49
|
-
return !!(
|
|
49
|
+
return !!(
|
|
50
|
+
(config.data_stack_normalize === true ||
|
|
51
|
+
isObjectType(config.data_stack_normalize)) &&
|
|
52
|
+
config.data_groups.length
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Check if stack normalization should be applied per group
|
|
58
|
+
* @returns {boolean}
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
isStackNormalizedPerGroup(): boolean {
|
|
62
|
+
const {config} = this;
|
|
63
|
+
|
|
64
|
+
return !!(
|
|
65
|
+
isObjectType(config.data_stack_normalize) &&
|
|
66
|
+
config.data_stack_normalize?.perGroup &&
|
|
67
|
+
config.data_groups.length
|
|
68
|
+
);
|
|
50
69
|
},
|
|
51
70
|
|
|
52
71
|
/**
|
|
@@ -61,6 +80,26 @@ export default {
|
|
|
61
80
|
return id ? groups.some(v => v.indexOf(id) >= 0 && v.length > 1) : groups.length > 0;
|
|
62
81
|
},
|
|
63
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Check if the given axis has any grouped data
|
|
85
|
+
* @param {string} axisId Axis ID (e.g., "y", "y2")
|
|
86
|
+
* @returns {boolean} true if axis has grouped data
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
hasAxisGroupedData(axisId: "y" | "y2"): boolean {
|
|
90
|
+
const $$ = this;
|
|
91
|
+
const {axis} = $$;
|
|
92
|
+
const targets = $$.data.targets;
|
|
93
|
+
|
|
94
|
+
// Get all data IDs that belong to this axis
|
|
95
|
+
const axisDataIds = targets
|
|
96
|
+
.filter(t => axis.getId(t.id) === axisId)
|
|
97
|
+
.map(t => t.id);
|
|
98
|
+
|
|
99
|
+
// Check if any of the axis data IDs are in groups
|
|
100
|
+
return axisDataIds.some(id => $$.isGrouped(id));
|
|
101
|
+
},
|
|
102
|
+
|
|
64
103
|
getXKey(id) {
|
|
65
104
|
const $$ = this;
|
|
66
105
|
const {config} = $$;
|
|
@@ -325,18 +364,37 @@ export default {
|
|
|
325
364
|
|
|
326
365
|
/**
|
|
327
366
|
* Get sum of data per index
|
|
367
|
+
* @param {string} targetId Target ID to get total for (only for normalized stack per group)
|
|
328
368
|
* @private
|
|
329
369
|
* @returns {Array}
|
|
330
370
|
*/
|
|
331
|
-
getTotalPerIndex() {
|
|
371
|
+
getTotalPerIndex(targetId?: string) {
|
|
332
372
|
const $$ = this;
|
|
333
|
-
const
|
|
373
|
+
const {config} = $$;
|
|
374
|
+
const cacheKey = targetId ? `${KEY.dataTotalPerIndex}-${targetId}` : KEY.dataTotalPerIndex;
|
|
334
375
|
let sum = $$.cache.get(cacheKey);
|
|
335
376
|
|
|
336
377
|
if (($$.config.data_groups.length || $$.isStackNormalized()) && !sum) {
|
|
337
378
|
sum = [];
|
|
338
379
|
|
|
339
|
-
|
|
380
|
+
// When normalize per group is enabled and targetId is provided,
|
|
381
|
+
// only sum data within the same group
|
|
382
|
+
let {targets} = $$.data;
|
|
383
|
+
|
|
384
|
+
if ($$.isStackNormalizedPerGroup() && targetId) {
|
|
385
|
+
// Find which group the target belongs to
|
|
386
|
+
const group = config.data_groups.find(g => g.indexOf(targetId) >= 0);
|
|
387
|
+
|
|
388
|
+
if (group) {
|
|
389
|
+
// Only sum targets in the same group
|
|
390
|
+
targets = targets.filter(t => group.indexOf(t.id) >= 0);
|
|
391
|
+
} else {
|
|
392
|
+
// If target is not in any group, return null to indicate no normalization
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
targets.forEach(row => {
|
|
340
398
|
row.values.forEach((v, i) => {
|
|
341
399
|
if (!sum[i]) {
|
|
342
400
|
sum[i] = 0;
|
|
@@ -345,6 +403,8 @@ export default {
|
|
|
345
403
|
sum[i] += ~~v.value;
|
|
346
404
|
});
|
|
347
405
|
});
|
|
406
|
+
|
|
407
|
+
$$.cache.add(cacheKey, sum);
|
|
348
408
|
}
|
|
349
409
|
|
|
350
410
|
return sum;
|
|
@@ -363,7 +423,7 @@ export default {
|
|
|
363
423
|
|
|
364
424
|
if (!isNumber(total)) {
|
|
365
425
|
total = $$.data.targets.reduce((acc, t) => {
|
|
366
|
-
return acc + t.values.reduce((sum, v) => sum +
|
|
426
|
+
return acc + t.values.reduce((sum, v) => sum + (v.value ?? 0), 0);
|
|
367
427
|
}, 0);
|
|
368
428
|
|
|
369
429
|
$$.cache.add(cacheKey, total);
|
|
@@ -469,7 +529,33 @@ export default {
|
|
|
469
529
|
filterTargetsToShow(targets?) {
|
|
470
530
|
const $$ = this;
|
|
471
531
|
|
|
472
|
-
|
|
532
|
+
// When called without arguments, use caching
|
|
533
|
+
if (!targets) {
|
|
534
|
+
const {cache, data, state} = $$;
|
|
535
|
+
const cacheKey = KEY.filteredTargets;
|
|
536
|
+
const visibilityChecksum = state.hiddenTargetIds.join(",");
|
|
537
|
+
const storedChecksum = cache.get(KEY.visibilityChecksum);
|
|
538
|
+
|
|
539
|
+
// Invalidate cache if visibility changed
|
|
540
|
+
if (visibilityChecksum !== storedChecksum) {
|
|
541
|
+
cache.remove(cacheKey);
|
|
542
|
+
cache.add(KEY.visibilityChecksum, visibilityChecksum);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Return cached result if available
|
|
546
|
+
if (cache.has(cacheKey)) {
|
|
547
|
+
return cache.get(cacheKey);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Compute and cache result (store the filtered array)
|
|
551
|
+
const filtered = data.targets.filter(t => $$.isTargetToShow(t.id));
|
|
552
|
+
cache.add(cacheKey, filtered);
|
|
553
|
+
|
|
554
|
+
return filtered;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// When called with custom targets, don't cache
|
|
558
|
+
return targets.filter(t => $$.isTargetToShow(t.id));
|
|
473
559
|
},
|
|
474
560
|
|
|
475
561
|
mapTargetsToUniqueXs(targets) {
|
|
@@ -489,7 +575,7 @@ export default {
|
|
|
489
575
|
},
|
|
490
576
|
|
|
491
577
|
/**
|
|
492
|
-
* Add to
|
|
578
|
+
* Add to thetarget Ids
|
|
493
579
|
* @param {string} type State's prop name
|
|
494
580
|
* @param {Array|string} targetIds Target ids array
|
|
495
581
|
* @private
|
|
@@ -547,6 +633,9 @@ export default {
|
|
|
547
633
|
.map(v => (isString(v) ? v : +v)) :
|
|
548
634
|
null;
|
|
549
635
|
|
|
636
|
+
// Create xIndexMap for O(1) lookup instead of O(n) indexOf in getIndexByX
|
|
637
|
+
const xIndexMap = xs ? new Map(xs.map((x, i) => [x, i])) : null;
|
|
638
|
+
|
|
550
639
|
targets.forEach(t => {
|
|
551
640
|
const data: any[] = [];
|
|
552
641
|
|
|
@@ -569,8 +658,14 @@ export default {
|
|
|
569
658
|
} else if ($$.isBubbleZType(v)) {
|
|
570
659
|
data.push(hasAxis && $$.getBubbleZData(value, "y"));
|
|
571
660
|
} else {
|
|
572
|
-
if (isMultipleX) {
|
|
573
|
-
|
|
661
|
+
if (isMultipleX && xIndexMap) {
|
|
662
|
+
// Use Map for O(1) lookup instead of getIndexByX which uses indexOf
|
|
663
|
+
const xKey = isString(v.x) ? v.x : +v.x;
|
|
664
|
+
const index = xIndexMap.get(xKey);
|
|
665
|
+
|
|
666
|
+
if (index !== undefined) {
|
|
667
|
+
data[index as number] = value;
|
|
668
|
+
}
|
|
574
669
|
} else {
|
|
575
670
|
data.push(value);
|
|
576
671
|
}
|
|
@@ -620,7 +715,7 @@ export default {
|
|
|
620
715
|
/**
|
|
621
716
|
* Get data.order compare function
|
|
622
717
|
* @param {boolean} isReversed for Arc & Treemap type sort order needs to be reversed
|
|
623
|
-
* @returns {
|
|
718
|
+
* @returns {function} compare function
|
|
624
719
|
* @private
|
|
625
720
|
*/
|
|
626
721
|
getSortCompareFn(isReversed = false): Function | null {
|
|
@@ -1014,16 +1109,39 @@ export default {
|
|
|
1014
1109
|
}
|
|
1015
1110
|
} else if (type === "index") {
|
|
1016
1111
|
const dataValues = api.data.values.bind(api);
|
|
1017
|
-
|
|
1112
|
+
const {hiddenTargetIds} = state;
|
|
1113
|
+
|
|
1114
|
+
// For normalized stack per group, get total per group
|
|
1115
|
+
let total = this.getTotalPerIndex(
|
|
1116
|
+
$$.isStackNormalizedPerGroup() ? d.id : undefined
|
|
1117
|
+
);
|
|
1018
1118
|
|
|
1019
|
-
|
|
1020
|
-
|
|
1119
|
+
// If total is null, the data is not in any group - don't normalize
|
|
1120
|
+
if (total === null) {
|
|
1121
|
+
return ratio;
|
|
1122
|
+
}
|
|
1021
1123
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1124
|
+
if (hiddenTargetIds.length) {
|
|
1125
|
+
// When normalized per group, only subtract hidden data from the same group
|
|
1126
|
+
let hiddenIds = hiddenTargetIds;
|
|
1025
1127
|
|
|
1026
|
-
|
|
1128
|
+
if ($$.isStackNormalizedPerGroup() && d.id) {
|
|
1129
|
+
const group = config.data_groups.find(g => g.indexOf(d.id) >= 0);
|
|
1130
|
+
if (group) {
|
|
1131
|
+
// Only consider hidden IDs in the same group
|
|
1132
|
+
hiddenIds = hiddenIds.filter(id => group.indexOf(id) >= 0);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
if (hiddenIds.length) {
|
|
1137
|
+
let hiddenSum = dataValues(hiddenIds, false);
|
|
1138
|
+
|
|
1139
|
+
if (hiddenSum.length) {
|
|
1140
|
+
hiddenSum = hiddenSum
|
|
1141
|
+
.reduce((acc, curr) => acc.map((v, i) => ~~v + curr[i]));
|
|
1142
|
+
|
|
1143
|
+
total = total.map((v, i) => v - hiddenSum[i]);
|
|
1144
|
+
}
|
|
1027
1145
|
}
|
|
1028
1146
|
}
|
|
1029
1147
|
|
|
@@ -7,7 +7,7 @@ import {endall} from "../../module/util";
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Call done callback with resize after transition
|
|
10
|
-
* @param {
|
|
10
|
+
* @param {function} fn Callback function
|
|
11
11
|
* @param {boolean} resizeAfter Weather to resize chart after the load
|
|
12
12
|
* @private
|
|
13
13
|
*/
|
|
@@ -156,13 +156,6 @@ export default {
|
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
const targets = $el.svg.selectAll(targetIds.map(id => $$.selectorTarget(id)));
|
|
160
|
-
|
|
161
|
-
$T(targets)
|
|
162
|
-
.style("opacity", "0")
|
|
163
|
-
.remove()
|
|
164
|
-
.call(endall, done);
|
|
165
|
-
|
|
166
159
|
targetIds.forEach(id => {
|
|
167
160
|
const suffixId = $$.getTargetSelectorSuffix(id);
|
|
168
161
|
|
|
@@ -189,5 +182,12 @@ export default {
|
|
|
189
182
|
|
|
190
183
|
// Update current state chart type and elements list after redraw
|
|
191
184
|
$$.updateTypesElements();
|
|
185
|
+
|
|
186
|
+
const targets = $el.svg.selectAll(targetIds.map(id => $$.selectorTarget(id)));
|
|
187
|
+
|
|
188
|
+
$T(targets)
|
|
189
|
+
.style("opacity", "0")
|
|
190
|
+
.remove()
|
|
191
|
+
.call(endall, done);
|
|
192
192
|
}
|
|
193
193
|
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import {select as d3Select} from "d3-selection";
|
|
6
6
|
import type {d3Selection} from "../../../types/types";
|
|
7
7
|
import {$BAR, $CIRCLE, $COMMON, $DRAG, $SELECT, $SHAPE} from "../../config/classes";
|
|
8
|
-
import {getPathBox} from "../../module/util";
|
|
8
|
+
import {getPathBox, scheduleRAFUpdate} from "../../module/util";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Module used for data.selection.draggable option
|
|
@@ -40,47 +40,58 @@ export default {
|
|
|
40
40
|
const minY = isSelectionGrouped ? state.margin.top : Math.min(sy, my);
|
|
41
41
|
const maxY = isSelectionGrouped ? state.height : Math.max(sy, my);
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
43
|
+
// Use RAF batching to smooth out rapid drag events
|
|
44
|
+
const executeDrag = () => {
|
|
45
|
+
// Check if chart still exists before executing
|
|
46
|
+
if (!$$ || !$$.$el || !$$.$el.main) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
main.select(`.${$DRAG.dragarea}`)
|
|
51
|
+
.attr("x", minX)
|
|
52
|
+
.attr("y", minY)
|
|
53
|
+
.attr("width", maxX - minX)
|
|
54
|
+
.attr("height", maxY - minY);
|
|
55
|
+
|
|
56
|
+
// TODO: binary search when multiple xs
|
|
57
|
+
main.selectAll(`.${$SHAPE.shapes}`)
|
|
58
|
+
.selectAll(`.${$SHAPE.shape}`)
|
|
59
|
+
.filter(d => isSelectable?.bind($$.api)(d))
|
|
60
|
+
.each(function(d, i) {
|
|
61
|
+
const shape: d3Selection = d3Select(this);
|
|
62
|
+
const isSelected = shape.classed($SELECT.SELECTED);
|
|
63
|
+
const isIncluded = shape.classed($DRAG.INCLUDED);
|
|
64
|
+
let isWithin: any = false;
|
|
65
|
+
let toggle;
|
|
66
|
+
|
|
67
|
+
if (shape.classed($CIRCLE.circle)) {
|
|
68
|
+
const x: number = +shape.attr("cx") * 1;
|
|
69
|
+
const y: number = +shape.attr("cy") * 1;
|
|
70
|
+
|
|
71
|
+
toggle = $$.togglePoint;
|
|
72
|
+
isWithin = minX < x && x < maxX && minY < y && y < maxY;
|
|
73
|
+
} else if (shape.classed($BAR.bar)) {
|
|
74
|
+
const {x, y, width, height} = getPathBox(this);
|
|
75
|
+
|
|
76
|
+
toggle = $$.togglePath;
|
|
77
|
+
isWithin = !(maxX < x || x + width < minX) &&
|
|
78
|
+
!(maxY < y || y + height < minY);
|
|
79
|
+
} else {
|
|
80
|
+
// line/area selection not supported yet
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
if (isWithin ^ isIncluded) {
|
|
86
|
+
shape.classed($DRAG.INCLUDED, !isIncluded);
|
|
87
|
+
// TODO: included/unincluded callback here
|
|
88
|
+
shape.classed($SELECT.SELECTED, !isSelected);
|
|
89
|
+
toggle.call($$, !isSelected, shape, d, i);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
scheduleRAFUpdate($$.state, executeDrag);
|
|
84
95
|
},
|
|
85
96
|
|
|
86
97
|
/**
|
|
@@ -125,6 +125,10 @@ export default {
|
|
|
125
125
|
const preventThreshold = (!isNaN(preventDefault) && preventDefault) || null;
|
|
126
126
|
let startPx;
|
|
127
127
|
|
|
128
|
+
// Determine passive option based on preventDefault setting
|
|
129
|
+
// If preventDefault is needed, passive must be false
|
|
130
|
+
const passiveOption = !isPrevented && preventThreshold === null;
|
|
131
|
+
|
|
128
132
|
const preventEvent = event => {
|
|
129
133
|
const eventType = event.type;
|
|
130
134
|
const touch = event.changedTouches[0];
|
|
@@ -156,7 +160,7 @@ export default {
|
|
|
156
160
|
.on("touchstart", event => {
|
|
157
161
|
state.event = event;
|
|
158
162
|
$$.updateEventRect();
|
|
159
|
-
})
|
|
163
|
+
}, {passive: passiveOption})
|
|
160
164
|
.on("touchstart.eventRect touchmove.eventRect", event => {
|
|
161
165
|
state.event = event;
|
|
162
166
|
|
|
@@ -174,7 +178,7 @@ export default {
|
|
|
174
178
|
} else {
|
|
175
179
|
unselectRect();
|
|
176
180
|
}
|
|
177
|
-
},
|
|
181
|
+
}, {passive: passiveOption})
|
|
178
182
|
.on("touchend.eventRect", event => {
|
|
179
183
|
state.event = event;
|
|
180
184
|
|
|
@@ -183,7 +187,7 @@ export default {
|
|
|
183
187
|
state.cancelClick && (state.cancelClick = false);
|
|
184
188
|
}
|
|
185
189
|
}
|
|
186
|
-
},
|
|
190
|
+
}, {passive: passiveOption});
|
|
187
191
|
|
|
188
192
|
svg.on("touchstart", event => {
|
|
189
193
|
state.event = event;
|
|
@@ -192,7 +196,7 @@ export default {
|
|
|
192
196
|
if (target && target !== eventRect.node()) {
|
|
193
197
|
unselectRect();
|
|
194
198
|
}
|
|
195
|
-
});
|
|
199
|
+
}, {passive: passiveOption});
|
|
196
200
|
},
|
|
197
201
|
|
|
198
202
|
/**
|
|
@@ -473,7 +477,13 @@ export default {
|
|
|
473
477
|
if ($$.isBarType(closest.id) || dist < $$.getPointSensitivity(closest)) {
|
|
474
478
|
$$.$el.svg.select(`.${$EVENT.eventRect}`).style("cursor", "pointer");
|
|
475
479
|
|
|
476
|
-
if (
|
|
480
|
+
if (
|
|
481
|
+
triggerEvent && (
|
|
482
|
+
!state.mouseover ||
|
|
483
|
+
state.mouseover.x !== closest.x ||
|
|
484
|
+
state.mouseover.id !== closest.id
|
|
485
|
+
)
|
|
486
|
+
) {
|
|
477
487
|
config.data_onover.call($$.api, closest);
|
|
478
488
|
state.mouseover = closest;
|
|
479
489
|
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "d3-zoom";
|
|
11
11
|
import {$COMMON, $ZOOM} from "../../config/classes";
|
|
12
12
|
import {window} from "../../module/browser";
|
|
13
|
-
import {callFn, diffDomain, getPointer, isFunction} from "../../module/util";
|
|
13
|
+
import {callFn, diffDomain, getPointer, isFunction, scheduleRAFUpdate} from "../../module/util";
|
|
14
14
|
|
|
15
15
|
export default {
|
|
16
16
|
/**
|
|
@@ -120,10 +120,6 @@ export default {
|
|
|
120
120
|
d3ZoomIdentity.translate(tX, tY).scale(transform.k));
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
if (!$$.state.xTickOffset) {
|
|
124
|
-
$$.state.xTickOffset = $$.axis.x.tickOffset();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
123
|
scale.zoom = $$.getCustomizedXScale(newScale);
|
|
128
124
|
$$.axis.x.scale(scale.zoom);
|
|
129
125
|
|
|
@@ -216,22 +212,30 @@ export default {
|
|
|
216
212
|
state.dragging || isUnZoom || !event.sourceEvent
|
|
217
213
|
);
|
|
218
214
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
215
|
+
// Use RAF batching for continuous drag zoom events only
|
|
216
|
+
// Wheel zoom and API calls need synchronous execution for correct behavior and tests
|
|
217
|
+
const useRAF = sourceEvent && isMousemove && config.zoom_type !== "wheel";
|
|
218
|
+
|
|
219
|
+
const executeRedraw = () => {
|
|
220
|
+
$$.redraw({
|
|
221
|
+
withTransition: doTransition,
|
|
222
|
+
withY: config.zoom_rescale,
|
|
223
|
+
withSubchart: false,
|
|
224
|
+
withEventRect: false,
|
|
225
|
+
withDimension: false
|
|
226
|
+
});
|
|
226
227
|
|
|
227
|
-
|
|
228
|
+
$$.state.cancelClick = isMousemove;
|
|
228
229
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
// do not call event cb when is .unzoom() is called
|
|
231
|
+
!isUnZoom && callFn(
|
|
232
|
+
config.zoom_onzoom,
|
|
233
|
+
$$.api,
|
|
234
|
+
$$.state.domain ?? $$.zoom.getDomain()
|
|
235
|
+
);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
useRAF ? scheduleRAFUpdate($$.state, executeRedraw) : executeRedraw();
|
|
235
239
|
},
|
|
236
240
|
|
|
237
241
|
/**
|
|
@@ -309,7 +313,7 @@ export default {
|
|
|
309
313
|
|
|
310
314
|
/**
|
|
311
315
|
* Set zoom transform to event rect
|
|
312
|
-
* @param {
|
|
316
|
+
* @param {function} x x Axis scale function
|
|
313
317
|
* @param {Array} domain Domain value to be set
|
|
314
318
|
* @private
|
|
315
319
|
*/
|