billboard.js 3.11.3 → 3.12.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 +1 -5
- package/dist/billboard.css +13 -1
- package/dist/billboard.js +19672 -24210
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +26 -3
- package/dist/billboard.pkgd.js +24515 -30430
- package/dist/billboard.pkgd.min.js +33 -3
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +77 -175
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -3
- package/dist/plugin/billboardjs-plugin-sparkline.js +429 -1134
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +666 -1524
- package/dist/plugin/billboardjs-plugin-stanford.min.js +15 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +503 -1175
- package/dist/plugin/billboardjs-plugin-tableview.min.js +30 -3
- package/dist/plugin/billboardjs-plugin-textoverlap.js +351 -1055
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +4 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +1387 -1854
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +5 -3
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2760 -3959
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +7 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3504 -5057
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -3
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +2906 -4072
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +33 -3
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +3076 -4506
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +7 -3
- package/dist/theme/dark.css +12 -1
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +12 -1
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +12 -1
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +12 -1
- package/dist/theme/insight.min.css +2 -2
- package/dist/theme/modern.css +12 -1
- package/dist/theme/modern.min.css +3 -4
- package/dist-esm/billboard.js +9297 -8527
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +20 -27
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +155 -149
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +302 -289
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +236 -236
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +41 -43
- package/package.json +29 -49
- package/src/Chart/api/axis.ts +6 -13
- package/src/Chart/api/chart.ts +12 -11
- package/src/Chart/api/data.ts +8 -7
- package/src/Chart/api/export.ts +28 -21
- package/src/Chart/api/flow.ts +4 -2
- package/src/Chart/api/grid.ts +1 -5
- package/src/Chart/api/load.ts +2 -2
- package/src/Chart/api/regions.ts +29 -5
- package/src/Chart/api/selection.ts +2 -2
- package/src/Chart/api/show.ts +2 -3
- package/src/Chart/api/subchart.ts +2 -2
- package/src/Chart/api/tooltip.ts +8 -9
- package/src/Chart/api/x.ts +2 -2
- package/src/Chart/api/zoom.ts +2 -2
- package/src/ChartInternal/Axis/Axis.ts +119 -44
- package/src/ChartInternal/Axis/AxisRenderer.ts +53 -38
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +2 -2
- package/src/ChartInternal/ChartInternal.ts +87 -55
- package/src/ChartInternal/data/IData.ts +31 -31
- package/src/ChartInternal/data/convert.helper.ts +66 -68
- package/src/ChartInternal/data/convert.ts +11 -11
- package/src/ChartInternal/data/data.ts +51 -27
- package/src/ChartInternal/data/load.ts +7 -6
- package/src/ChartInternal/interactions/drag.ts +2 -1
- package/src/ChartInternal/interactions/eventrect.ts +84 -32
- package/src/ChartInternal/interactions/flow.ts +14 -4
- package/src/ChartInternal/interactions/interaction.ts +51 -22
- package/src/ChartInternal/interactions/subchart.ts +27 -25
- package/src/ChartInternal/interactions/zoom.ts +29 -18
- package/src/ChartInternal/internals/category.ts +1 -1
- package/src/ChartInternal/internals/class.ts +6 -6
- package/src/ChartInternal/internals/clip.ts +8 -4
- package/src/ChartInternal/internals/color.ts +70 -42
- package/src/ChartInternal/internals/domain.ts +59 -28
- package/src/ChartInternal/internals/format.ts +5 -5
- package/src/ChartInternal/internals/grid.ts +131 -47
- package/src/ChartInternal/internals/legend.ts +93 -61
- package/src/ChartInternal/internals/redraw.ts +6 -2
- package/src/ChartInternal/internals/region.ts +5 -3
- package/src/ChartInternal/internals/scale.ts +28 -15
- package/src/ChartInternal/internals/selection.ts +14 -13
- package/src/ChartInternal/internals/size.axis.ts +18 -10
- package/src/ChartInternal/internals/size.ts +98 -67
- package/src/ChartInternal/internals/style.ts +21 -19
- package/src/ChartInternal/internals/text.ts +79 -43
- package/src/ChartInternal/internals/title.ts +2 -2
- package/src/ChartInternal/internals/tooltip.ts +78 -32
- package/src/ChartInternal/internals/transform.ts +4 -4
- package/src/ChartInternal/internals/type.ts +17 -12
- package/src/ChartInternal/shape/arc.ts +78 -44
- package/src/ChartInternal/shape/area.ts +19 -22
- package/src/ChartInternal/shape/bar.ts +41 -31
- package/src/ChartInternal/shape/bubble.ts +5 -5
- package/src/ChartInternal/shape/candlestick.ts +15 -13
- package/src/ChartInternal/shape/funnel.ts +317 -0
- package/src/ChartInternal/shape/gauge.ts +16 -9
- package/src/ChartInternal/shape/line.ts +62 -46
- package/src/ChartInternal/shape/point.common.ts +1 -4
- package/src/ChartInternal/shape/point.ts +54 -34
- package/src/ChartInternal/shape/polar.ts +4 -2
- package/src/ChartInternal/shape/radar.ts +40 -22
- package/src/ChartInternal/shape/shape.ts +84 -58
- package/src/ChartInternal/shape/treemap.ts +31 -20
- package/src/Plugin/bubblecompare/index.ts +1 -3
- package/src/Plugin/sparkline/index.ts +3 -4
- package/src/Plugin/stanford/ColorScale.ts +3 -2
- package/src/Plugin/stanford/Elements.ts +15 -6
- package/src/Plugin/stanford/Options.ts +5 -5
- package/src/Plugin/stanford/index.ts +13 -9
- package/src/Plugin/tableview/Options.ts +1 -1
- package/src/Plugin/tableview/const.ts +1 -4
- package/src/Plugin/tableview/index.ts +11 -9
- package/src/Plugin/textoverlap/index.ts +4 -6
- package/src/config/Options/Options.ts +3 -3
- package/src/config/Options/axis/axis.ts +36 -0
- package/src/config/Options/axis/x.ts +34 -14
- package/src/config/Options/axis/y.ts +13 -13
- package/src/config/Options/axis/y2.ts +23 -10
- package/src/config/Options/common/color.ts +4 -4
- package/src/config/Options/common/grid.ts +4 -4
- package/src/config/Options/common/legend.ts +12 -13
- package/src/config/Options/common/main.ts +23 -23
- package/src/config/Options/common/point.ts +17 -18
- package/src/config/Options/common/title.ts +2 -2
- package/src/config/Options/common/tooltip.ts +13 -11
- package/src/config/Options/data/axis.ts +2 -2
- package/src/config/Options/data/data.ts +48 -45
- package/src/config/Options/interaction/interaction.ts +1 -1
- package/src/config/Options/interaction/subchart.ts +2 -2
- package/src/config/Options/interaction/zoom.ts +9 -9
- package/src/config/Options/shape/arc.ts +10 -13
- package/src/config/Options/shape/area.ts +5 -7
- package/src/config/Options/shape/bar.ts +8 -10
- package/src/config/Options/shape/bubble.ts +1 -1
- package/src/config/Options/shape/candlestick.ts +2 -2
- package/src/config/Options/shape/donut.ts +4 -4
- package/src/config/Options/shape/funnel.ts +38 -0
- package/src/config/Options/shape/gauge.ts +6 -6
- package/src/config/Options/shape/line.ts +3 -3
- package/src/config/Options/shape/pie.ts +5 -5
- package/src/config/Options/shape/polar.ts +3 -3
- package/src/config/Options/shape/radar.ts +2 -2
- package/src/config/Options/shape/scatter.ts +1 -1
- package/src/config/Options/shape/treemap.ts +1 -1
- package/src/config/Store/Element.ts +8 -5
- package/src/config/Store/State.ts +20 -13
- package/src/config/classes.ts +14 -4
- package/src/config/config.ts +1 -1
- package/src/config/const.ts +2 -0
- package/src/config/resolver/axis.ts +4 -4
- package/src/config/resolver/interaction.ts +3 -7
- package/src/config/resolver/shape.ts +17 -12
- package/src/core.ts +2 -3
- package/src/index.esm.ts +3 -6
- package/src/index.ts +2 -2
- package/src/module/Cache.ts +2 -3
- package/src/module/browser.ts +15 -10
- package/src/module/error.ts +9 -8
- package/src/module/generator.ts +3 -5
- package/src/module/util.ts +62 -39
- package/src/module/worker.ts +14 -11
- package/src/scss/billboard.scss +18 -0
- package/src/scss/theme/dark.scss +17 -0
- package/src/scss/theme/datalab.scss +17 -0
- package/src/scss/theme/graph.scss +17 -0
- package/src/scss/theme/insight.scss +17 -0
- package/src/scss/theme/modern.scss +17 -0
- package/types/axis.d.ts +17 -0
- package/types/bb.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/options.d.ts +9 -0
- package/types/options.shape.d.ts +26 -1
- package/types/types.d.ts +1 -0
|
@@ -5,14 +5,13 @@
|
|
|
5
5
|
import {select as d3Select} from "d3-selection";
|
|
6
6
|
import {$BAR, $CANDLESTICK, $COMMON} from "../../config/classes";
|
|
7
7
|
import {KEY} from "../../module/Cache";
|
|
8
|
-
import type {IData, IDataPoint, IDataRow} from "./IData";
|
|
9
8
|
import {
|
|
10
9
|
findIndex,
|
|
11
|
-
getUnique,
|
|
12
10
|
getScrollPosition,
|
|
11
|
+
getUnique,
|
|
13
12
|
hasValue,
|
|
14
13
|
isArray,
|
|
15
|
-
|
|
14
|
+
isBoolean,
|
|
16
15
|
isDefined,
|
|
17
16
|
isFunction,
|
|
18
17
|
isNumber,
|
|
@@ -26,6 +25,7 @@ import {
|
|
|
26
25
|
parseDate,
|
|
27
26
|
sortValue
|
|
28
27
|
} from "../../module/util";
|
|
28
|
+
import type {IData, IDataPoint, IDataRow} from "./IData";
|
|
29
29
|
|
|
30
30
|
export default {
|
|
31
31
|
isX(key) {
|
|
@@ -56,9 +56,7 @@ export default {
|
|
|
56
56
|
isGrouped(id?: string): boolean {
|
|
57
57
|
const groups = this.config.data_groups;
|
|
58
58
|
|
|
59
|
-
return id ?
|
|
60
|
-
groups.some(v => v.indexOf(id) >= 0 && v.length > 1) :
|
|
61
|
-
groups.length > 0;
|
|
59
|
+
return id ? groups.some(v => v.indexOf(id) >= 0 && v.length > 1) : groups.length > 0;
|
|
62
60
|
},
|
|
63
61
|
|
|
64
62
|
getXKey(id) {
|
|
@@ -66,7 +64,8 @@ export default {
|
|
|
66
64
|
const {config} = $$;
|
|
67
65
|
|
|
68
66
|
return config.data_x ?
|
|
69
|
-
config.data_x :
|
|
67
|
+
config.data_x :
|
|
68
|
+
(notEmpty(config.data_xs) ? config.data_xs[id] : null);
|
|
70
69
|
},
|
|
71
70
|
|
|
72
71
|
getXValuesOfXKey(key, targets) {
|
|
@@ -90,7 +89,7 @@ export default {
|
|
|
90
89
|
* @returns {number} index number
|
|
91
90
|
* @private
|
|
92
91
|
*/
|
|
93
|
-
getIndexByX(x: Date|number|string, basedX: (Date|number|string)[]): number {
|
|
92
|
+
getIndexByX(x: Date | number | string, basedX: (Date | number | string)[]): number {
|
|
94
93
|
const $$ = this;
|
|
95
94
|
|
|
96
95
|
return basedX ?
|
|
@@ -102,8 +101,10 @@ export default {
|
|
|
102
101
|
const $$ = this;
|
|
103
102
|
|
|
104
103
|
return id in $$.data.xs &&
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
$$.data.xs[id] &&
|
|
105
|
+
isValue($$.data.xs[id][i]) ?
|
|
106
|
+
$$.data.xs[id][i] :
|
|
107
|
+
i;
|
|
107
108
|
},
|
|
108
109
|
|
|
109
110
|
getOtherTargetXs(): string | null {
|
|
@@ -128,10 +129,17 @@ export default {
|
|
|
128
129
|
});
|
|
129
130
|
},
|
|
130
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Determine if x axis is multiple
|
|
134
|
+
* @returns {boolean} true: multiple, false: single
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
131
137
|
isMultipleX(): boolean {
|
|
132
|
-
return
|
|
138
|
+
return !this.config.axis_x_forceAsSingle && (
|
|
139
|
+
notEmpty(this.config.data_xs) ||
|
|
133
140
|
this.hasType("bubble") ||
|
|
134
|
-
this.hasType("scatter")
|
|
141
|
+
this.hasType("scatter")
|
|
142
|
+
);
|
|
135
143
|
},
|
|
136
144
|
|
|
137
145
|
addName(data) {
|
|
@@ -413,7 +421,10 @@ export default {
|
|
|
413
421
|
.map(v => v.x);
|
|
414
422
|
|
|
415
423
|
target = sortValue(getUnique(target))
|
|
416
|
-
.map((x, index, array) => ({
|
|
424
|
+
.map((x, index, array) => ({
|
|
425
|
+
x,
|
|
426
|
+
index: isInverted ? array.length - index - 1 : index
|
|
427
|
+
}));
|
|
417
428
|
} else if (length) {
|
|
418
429
|
target = target[0].values.concat();
|
|
419
430
|
}
|
|
@@ -527,8 +538,10 @@ export default {
|
|
|
527
538
|
const {hasAxis} = $$.state;
|
|
528
539
|
const ys = {};
|
|
529
540
|
const isMultipleX = $$.isMultipleX();
|
|
530
|
-
const xs = isMultipleX ?
|
|
531
|
-
|
|
541
|
+
const xs = isMultipleX ?
|
|
542
|
+
$$.mapTargetsToUniqueXs(targets)
|
|
543
|
+
.map(v => (isString(v) ? v : +v)) :
|
|
544
|
+
null;
|
|
532
545
|
|
|
533
546
|
targets.forEach(t => {
|
|
534
547
|
const data: any[] = [];
|
|
@@ -540,7 +553,9 @@ export default {
|
|
|
540
553
|
|
|
541
554
|
// exclude 'volume' value to correct mis domain calculation
|
|
542
555
|
if (value !== null && $$.isCandlestickType(v)) {
|
|
543
|
-
value = isArray(value) ?
|
|
556
|
+
value = isArray(value) ?
|
|
557
|
+
value.slice(0, 4) :
|
|
558
|
+
[value.open, value.high, value.low, value.close];
|
|
544
559
|
}
|
|
545
560
|
|
|
546
561
|
if (isArray(value)) {
|
|
@@ -627,8 +642,8 @@ export default {
|
|
|
627
642
|
if (orderAsc || orderDesc) {
|
|
628
643
|
const reducer = (p, c) => p + Math.abs(c.value);
|
|
629
644
|
const sum = v => (isNumber(v) ? v : (
|
|
630
|
-
"values" in v ? v.values.reduce(reducer, 0) : v.value
|
|
631
|
-
);
|
|
645
|
+
"values" in v ? v.values.reduce(reducer, 0) : v.value
|
|
646
|
+
));
|
|
632
647
|
|
|
633
648
|
fn = (t1: IData | IDataRow, t2: IData | IDataRow) => {
|
|
634
649
|
const t1Sum = sum(t1);
|
|
@@ -664,7 +679,7 @@ export default {
|
|
|
664
679
|
hasDataLabel() {
|
|
665
680
|
const dataLabels = this.config.data_labels;
|
|
666
681
|
|
|
667
|
-
return (
|
|
682
|
+
return (isBoolean(dataLabels) && dataLabels) ||
|
|
668
683
|
(isObjectType(dataLabels) && notEmpty(dataLabels));
|
|
669
684
|
},
|
|
670
685
|
|
|
@@ -694,7 +709,9 @@ export default {
|
|
|
694
709
|
const scrollPos = getScrollPosition($el.chart.node());
|
|
695
710
|
|
|
696
711
|
// get data based on the mouse coords
|
|
697
|
-
const e = inputType === "touch" && event.changedTouches ?
|
|
712
|
+
const e = inputType === "touch" && event.changedTouches ?
|
|
713
|
+
event.changedTouches[0] :
|
|
714
|
+
event;
|
|
698
715
|
|
|
699
716
|
index = findIndex(
|
|
700
717
|
coords,
|
|
@@ -782,8 +799,12 @@ export default {
|
|
|
782
799
|
.filter(v => $$.isBarType(v.id) || $$.isCandlestickType(v.id))
|
|
783
800
|
.forEach(v => {
|
|
784
801
|
const selector = $$.isBarType(v.id) ?
|
|
785
|
-
`.${$BAR.chartBar}.${$COMMON.target}${
|
|
786
|
-
|
|
802
|
+
`.${$BAR.chartBar}.${$COMMON.target}${
|
|
803
|
+
$$.getTargetSelectorSuffix(v.id)
|
|
804
|
+
} .${$BAR.bar}-${v.index}` :
|
|
805
|
+
`.${$CANDLESTICK.chartCandlestick}.${$COMMON.target}${
|
|
806
|
+
$$.getTargetSelectorSuffix(v.id)
|
|
807
|
+
} .${$CANDLESTICK.candlestick}-${v.index} path`;
|
|
787
808
|
|
|
788
809
|
if (!closest && $$.isWithinBar(main.select(selector).node())) {
|
|
789
810
|
closest = v;
|
|
@@ -968,7 +989,8 @@ export default {
|
|
|
968
989
|
// otherwise, based on the rendered angle value
|
|
969
990
|
} else {
|
|
970
991
|
const gaugeArcLength = config.gauge_fullCircle ?
|
|
971
|
-
$$.getArcLength() :
|
|
992
|
+
$$.getArcLength() :
|
|
993
|
+
$$.getStartingAngle() * -2;
|
|
972
994
|
const arcLength = $$.hasType("gauge") ? gaugeArcLength : Math.PI * 2;
|
|
973
995
|
|
|
974
996
|
ratio = (d.endAngle - d.startAngle) / arcLength;
|
|
@@ -982,7 +1004,9 @@ export default {
|
|
|
982
1004
|
|
|
983
1005
|
if (hiddenSum.length) {
|
|
984
1006
|
hiddenSum = hiddenSum
|
|
985
|
-
.reduce((acc, curr) =>
|
|
1007
|
+
.reduce((acc, curr) =>
|
|
1008
|
+
acc.map((v, i) => (isNumber(v) ? v : 0) + curr[i])
|
|
1009
|
+
);
|
|
986
1010
|
|
|
987
1011
|
total = total.map((v, i) => v - hiddenSum[i]);
|
|
988
1012
|
}
|
|
@@ -990,8 +1014,7 @@ export default {
|
|
|
990
1014
|
|
|
991
1015
|
const divisor = total[d.index];
|
|
992
1016
|
|
|
993
|
-
d.ratio = isNumber(d.value) && total && divisor ?
|
|
994
|
-
d.value / divisor : 0;
|
|
1017
|
+
d.ratio = isNumber(d.value) && total && divisor ? d.value / divisor : 0;
|
|
995
1018
|
|
|
996
1019
|
ratio = d.ratio;
|
|
997
1020
|
} else if (type === "radar") {
|
|
@@ -1064,7 +1087,8 @@ export default {
|
|
|
1064
1087
|
const $$ = this;
|
|
1065
1088
|
const {value} = d;
|
|
1066
1089
|
|
|
1067
|
-
return $$.isBarType(d) && isArray(value) && value.length >= 2 &&
|
|
1090
|
+
return $$.isBarType(d) && isArray(value) && value.length >= 2 &&
|
|
1091
|
+
value.every(v => isNumber(v));
|
|
1068
1092
|
},
|
|
1069
1093
|
|
|
1070
1094
|
/**
|
|
@@ -25,9 +25,9 @@ export default {
|
|
|
25
25
|
const {axis, data, org, scale} = $$;
|
|
26
26
|
const {append} = args;
|
|
27
27
|
const zoomState = {
|
|
28
|
-
domain: <any>
|
|
29
|
-
currentDomain: <any>
|
|
30
|
-
x: <any>
|
|
28
|
+
domain: <any>null,
|
|
29
|
+
currentDomain: <any>null,
|
|
30
|
+
x: <any>null
|
|
31
31
|
};
|
|
32
32
|
let targets = rawTargets;
|
|
33
33
|
|
|
@@ -50,8 +50,7 @@ export default {
|
|
|
50
50
|
data.targets.forEach(d => {
|
|
51
51
|
for (let i = 0; i < targets.length; i++) {
|
|
52
52
|
if (d.id === targets[i].id) {
|
|
53
|
-
d.values = append ?
|
|
54
|
-
d.values.concat(targets[i].values) : targets[i].values;
|
|
53
|
+
d.values = append ? d.values.concat(targets[i].values) : targets[i].values;
|
|
55
54
|
|
|
56
55
|
targets.splice(i, 1);
|
|
57
56
|
break;
|
|
@@ -66,7 +65,9 @@ export default {
|
|
|
66
65
|
$$.updateTargets(data.targets);
|
|
67
66
|
|
|
68
67
|
if (scale.zoom) {
|
|
69
|
-
zoomState.x = axis.isCategorized() ?
|
|
68
|
+
zoomState.x = axis.isCategorized() ?
|
|
69
|
+
scale.x.orgScale() :
|
|
70
|
+
(org.xScale || scale.x).copy();
|
|
70
71
|
zoomState.domain = $$.getXDomain(data.targets); // get updated xDomain
|
|
71
72
|
|
|
72
73
|
zoomState.x.domain(zoomState.domain);
|
|
@@ -23,7 +23,8 @@ export default {
|
|
|
23
23
|
const isSelectionGrouped = config.data_selection_grouped;
|
|
24
24
|
const isSelectable = config.interaction_enabled && config.data_selection_isselectable;
|
|
25
25
|
|
|
26
|
-
if (
|
|
26
|
+
if (
|
|
27
|
+
$$.hasArcType() ||
|
|
27
28
|
!config.data_selection_enabled || // do nothing if not selectable
|
|
28
29
|
(config.zoom_enabled && !$$.zoom.altDomain) || // skip if zoomable because of conflict drag behavior
|
|
29
30
|
!config.data_selection_multiple // skip when single selection because drag is used for multiple selection
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
+
import type {d3Selection} from "../../../types";
|
|
5
6
|
import {$COMMON, $EVENT, $SHAPE} from "../../config/classes";
|
|
6
|
-
import {
|
|
7
|
+
import {getPointer, getScrollPosition, isBoolean, isFunction} from "../../module/util";
|
|
7
8
|
|
|
8
9
|
export default {
|
|
9
10
|
/**
|
|
@@ -33,12 +34,14 @@ export default {
|
|
|
33
34
|
if ($el.eventRect) {
|
|
34
35
|
$$.updateEventRect($el.eventRect, true);
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
// do not initialize eventRect when data is empty
|
|
37
38
|
} else if ($$.data.targets.length) {
|
|
38
39
|
const eventRects = $$.$el.main.select(`.${$EVENT.eventRects}`)
|
|
39
|
-
.style("cursor", config.zoom_enabled && config.zoom_type !== "drag" ?
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
.style("cursor", config.zoom_enabled && config.zoom_type !== "drag" ?
|
|
41
|
+
(
|
|
42
|
+
config.axis_rotated ? "ns-resize" : "ew-resize"
|
|
43
|
+
) :
|
|
44
|
+
null)
|
|
42
45
|
.classed($EVENT.eventRectsMultiple, isMultipleX)
|
|
43
46
|
.classed($EVENT.eventRectsSingle, !isMultipleX);
|
|
44
47
|
|
|
@@ -51,16 +54,17 @@ export default {
|
|
|
51
54
|
$$.updateEventRect(eventRectUpdate);
|
|
52
55
|
|
|
53
56
|
// bind event to <rect> element
|
|
54
|
-
|
|
55
|
-
$$.generateEventRectsForMultipleXs(eventRectUpdate) :
|
|
56
|
-
$$.generateEventRectsForSingleX(eventRectUpdate);
|
|
57
|
+
$$.updateEventType(eventRectUpdate);
|
|
57
58
|
|
|
58
59
|
// bind draggable selection
|
|
59
60
|
eventRectUpdate.call($$.getDraggableSelection());
|
|
60
61
|
|
|
61
62
|
$el.eventRect = eventRectUpdate;
|
|
62
63
|
|
|
63
|
-
if (
|
|
64
|
+
if (
|
|
65
|
+
$$.state.inputType === "touch" && !$el.svg.on("touchstart.eventRect") &&
|
|
66
|
+
!$$.hasArcType()
|
|
67
|
+
) {
|
|
64
68
|
$$.bindTouchOnEventRect();
|
|
65
69
|
}
|
|
66
70
|
|
|
@@ -99,9 +103,7 @@ export default {
|
|
|
99
103
|
|
|
100
104
|
$$.callOverOutForTouch(index);
|
|
101
105
|
|
|
102
|
-
index === -1 ?
|
|
103
|
-
$$.unselectRect() :
|
|
104
|
-
$$.selectRectForSingle(context, index);
|
|
106
|
+
index === -1 ? $$.unselectRect() : $$.selectRectForSingle(context, index);
|
|
105
107
|
}
|
|
106
108
|
};
|
|
107
109
|
|
|
@@ -113,7 +115,7 @@ export default {
|
|
|
113
115
|
// call event.preventDefault()
|
|
114
116
|
// according 'interaction.inputType.touch.preventDefault' option
|
|
115
117
|
const preventDefault = config.interaction_inputType_touch.preventDefault;
|
|
116
|
-
const isPrevented = (
|
|
118
|
+
const isPrevented = (isBoolean(preventDefault) && preventDefault) || false;
|
|
117
119
|
const preventThreshold = (!isNaN(preventDefault) && preventDefault) || null;
|
|
118
120
|
let startPx;
|
|
119
121
|
|
|
@@ -130,9 +132,12 @@ export default {
|
|
|
130
132
|
startPx = currentXY;
|
|
131
133
|
}
|
|
132
134
|
} else if (eventType === "touchmove") {
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
if (
|
|
136
|
+
isPrevented || startPx === true || (
|
|
137
|
+
preventThreshold !== null &&
|
|
138
|
+
Math.abs(startPx - currentXY) >= preventThreshold
|
|
139
|
+
)
|
|
140
|
+
) {
|
|
136
141
|
// once prevented, keep prevented during whole 'touchmove' context
|
|
137
142
|
startPx = true;
|
|
138
143
|
event.preventDefault();
|
|
@@ -151,7 +156,10 @@ export default {
|
|
|
151
156
|
|
|
152
157
|
if (!eventRect.empty() && eventRect.classed($EVENT.eventRect)) {
|
|
153
158
|
// if touch points are > 1, means doing zooming interaction. In this case do not execute tooltip codes.
|
|
154
|
-
if (
|
|
159
|
+
if (
|
|
160
|
+
state.dragging || state.flowing || $$.hasArcType() ||
|
|
161
|
+
event.touches.length > 1
|
|
162
|
+
) {
|
|
155
163
|
return;
|
|
156
164
|
}
|
|
157
165
|
|
|
@@ -222,6 +230,26 @@ export default {
|
|
|
222
230
|
updateClientRect();
|
|
223
231
|
},
|
|
224
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Update event type (single or multiple x)
|
|
235
|
+
* @param {d3Selection | boolean} target Target element or boolean to rebind event
|
|
236
|
+
*/
|
|
237
|
+
updateEventType(target: d3Selection | boolean): void {
|
|
238
|
+
const $$ = this;
|
|
239
|
+
const isRebindCall = isBoolean(target);
|
|
240
|
+
const eventRect = isRebindCall ? $$.$el.eventRect : target;
|
|
241
|
+
const unbindEvent = isRebindCall ? target !== eventRect?.datum().multipleX : false;
|
|
242
|
+
|
|
243
|
+
if (eventRect) {
|
|
244
|
+
// release previous event listeners
|
|
245
|
+
unbindEvent && eventRect?.on("mouseover mousemove mouseout click", null);
|
|
246
|
+
|
|
247
|
+
$$.isMultipleX() ?
|
|
248
|
+
$$.generateEventRectsForMultipleXs(eventRect) :
|
|
249
|
+
$$.generateEventRectsForSingleX(eventRect);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
|
|
225
253
|
/**
|
|
226
254
|
* Updates the location and size of the eventRect.
|
|
227
255
|
* @private
|
|
@@ -231,12 +259,15 @@ export default {
|
|
|
231
259
|
const {config, scale, state} = $$;
|
|
232
260
|
const xScale = scale.zoom || scale.x;
|
|
233
261
|
const isRotated = config.axis_rotated;
|
|
262
|
+
const isMultipleX = $$.isMultipleX();
|
|
234
263
|
let x;
|
|
235
264
|
let y;
|
|
236
265
|
let w;
|
|
237
266
|
let h;
|
|
238
267
|
|
|
239
|
-
|
|
268
|
+
$$.updateEventType(isMultipleX);
|
|
269
|
+
|
|
270
|
+
if (isMultipleX) {
|
|
240
271
|
// TODO: rotated not supported yet
|
|
241
272
|
x = 0;
|
|
242
273
|
y = 0;
|
|
@@ -344,7 +375,11 @@ export default {
|
|
|
344
375
|
}
|
|
345
376
|
|
|
346
377
|
// remove possible previous focused state
|
|
347
|
-
!circle &&
|
|
378
|
+
!circle &&
|
|
379
|
+
main.selectAll(`.${$COMMON.EXPANDED}:not(.${$SHAPE.shape}-${index})`).classed(
|
|
380
|
+
$COMMON.EXPANDED,
|
|
381
|
+
false
|
|
382
|
+
);
|
|
348
383
|
|
|
349
384
|
const shapeAtIndex = main.selectAll(`.${$SHAPE.shape}-${index}`)
|
|
350
385
|
.classed($COMMON.EXPANDED, true)
|
|
@@ -364,7 +399,8 @@ export default {
|
|
|
364
399
|
.call(selected => {
|
|
365
400
|
const d = selected.data();
|
|
366
401
|
|
|
367
|
-
if (
|
|
402
|
+
if (
|
|
403
|
+
isSelectionEnabled &&
|
|
368
404
|
(isSelectionGrouped || isSelectable?.bind($$.api)(d))
|
|
369
405
|
) {
|
|
370
406
|
context.style.cursor = "pointer";
|
|
@@ -410,8 +446,10 @@ export default {
|
|
|
410
446
|
}
|
|
411
447
|
|
|
412
448
|
const sameXData = (
|
|
413
|
-
|
|
414
|
-
|
|
449
|
+
$$.isBubbleType(closest) || $$.isScatterType(closest) || !config.tooltip_grouped
|
|
450
|
+
) ?
|
|
451
|
+
[closest] :
|
|
452
|
+
$$.filterByX(targetsToShow, closest.x);
|
|
415
453
|
|
|
416
454
|
// show tooltip when cursor is close to some point
|
|
417
455
|
const selectedData = sameXData.map(d => $$.addName(d));
|
|
@@ -470,18 +508,19 @@ export default {
|
|
|
470
508
|
const {eventReceiver} = state;
|
|
471
509
|
|
|
472
510
|
const rect = eventRectEnter
|
|
473
|
-
.style("cursor",
|
|
511
|
+
.style("cursor",
|
|
512
|
+
config.data_selection_enabled && config.data_selection_grouped ? "pointer" : null)
|
|
474
513
|
.on("click", function(event) {
|
|
475
514
|
state.event = event;
|
|
476
515
|
|
|
477
516
|
const {currentIdx, data} = eventReceiver;
|
|
478
517
|
const d = data[
|
|
479
|
-
currentIdx === -1 ?
|
|
480
|
-
$$.getDataIndexFromEvent(event) : currentIdx
|
|
518
|
+
currentIdx === -1 ? $$.getDataIndexFromEvent(event) : currentIdx
|
|
481
519
|
];
|
|
482
520
|
|
|
483
521
|
$$.clickHandlerForSingleX.bind(this)(d, $$);
|
|
484
|
-
})
|
|
522
|
+
})
|
|
523
|
+
.datum({multipleX: false});
|
|
485
524
|
|
|
486
525
|
if (state.inputType === "mouse") {
|
|
487
526
|
const getData = event => {
|
|
@@ -494,6 +533,9 @@ export default {
|
|
|
494
533
|
.on("mouseover", event => {
|
|
495
534
|
state.event = event;
|
|
496
535
|
$$.updateEventRect();
|
|
536
|
+
|
|
537
|
+
Object.values($$.$el.axisTooltip)
|
|
538
|
+
.forEach((v: d3Selection) => v?.style("display", null));
|
|
497
539
|
})
|
|
498
540
|
.on("mousemove", function(event) {
|
|
499
541
|
const d = getData(event);
|
|
@@ -508,7 +550,10 @@ export default {
|
|
|
508
550
|
const stepType = config.line_step_type;
|
|
509
551
|
|
|
510
552
|
// tooltip position match for step-before & step-after
|
|
511
|
-
if (
|
|
553
|
+
if (
|
|
554
|
+
config.line_step_tooltipMatch && $$.hasType("step") &&
|
|
555
|
+
/^step\-(before|after)$/.test(stepType)
|
|
556
|
+
) {
|
|
512
557
|
const scale = $$.scale.zoom || $$.scale.x;
|
|
513
558
|
const xs = $$.axis.xs[index];
|
|
514
559
|
const inverted = scale.invert(getPointer(event, this)[0]);
|
|
@@ -520,7 +565,10 @@ export default {
|
|
|
520
565
|
}
|
|
521
566
|
}
|
|
522
567
|
|
|
523
|
-
|
|
568
|
+
$$.showAxisGridFocus();
|
|
569
|
+
|
|
570
|
+
const eventOnSameIdx = config.tooltip_grouped &&
|
|
571
|
+
index === eventReceiver.currentIdx;
|
|
524
572
|
|
|
525
573
|
// do nothing while dragging/flowing
|
|
526
574
|
if (state.dragging || state.flowing || $$.hasArcType() || eventOnSameIdx) {
|
|
@@ -533,8 +581,7 @@ export default {
|
|
|
533
581
|
eventReceiver.currentIdx = index;
|
|
534
582
|
}
|
|
535
583
|
|
|
536
|
-
index === -1 ?
|
|
537
|
-
$$.unselectRect() : $$.selectRectForSingle(this, index);
|
|
584
|
+
index === -1 ? $$.unselectRect() : $$.selectRectForSingle(this, index);
|
|
538
585
|
|
|
539
586
|
// As of individual data point(or <path>) element can't bind mouseover/out event
|
|
540
587
|
// to determine current interacting element, so use 'mousemove' event instead.
|
|
@@ -548,6 +595,8 @@ export default {
|
|
|
548
595
|
return;
|
|
549
596
|
}
|
|
550
597
|
|
|
598
|
+
$$.hideAxisGridFocus();
|
|
599
|
+
|
|
551
600
|
$$.unselectRect();
|
|
552
601
|
$$.setOverOut(false, eventReceiver.currentIdx);
|
|
553
602
|
|
|
@@ -594,7 +643,8 @@ export default {
|
|
|
594
643
|
.on("click", function(event) {
|
|
595
644
|
state.event = event;
|
|
596
645
|
$$.clickHandlerForMultipleXS.bind(this)($$);
|
|
597
|
-
})
|
|
646
|
+
})
|
|
647
|
+
.datum({multipleX: true});
|
|
598
648
|
|
|
599
649
|
if (state.inputType === "mouse") {
|
|
600
650
|
eventRectEnter
|
|
@@ -626,7 +676,9 @@ export default {
|
|
|
626
676
|
|
|
627
677
|
const mouse = getPointer(state.event, this);
|
|
628
678
|
const closest = $$.findClosestFromTargets(targetsToShow, mouse);
|
|
629
|
-
const sensitivity = config.point_sensitivity === "radius" ?
|
|
679
|
+
const sensitivity = config.point_sensitivity === "radius" ?
|
|
680
|
+
closest.r :
|
|
681
|
+
config.point_sensitivity;
|
|
630
682
|
|
|
631
683
|
if (!closest) {
|
|
632
684
|
return;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import {easeLinear as d3EaseLinear} from "d3-ease";
|
|
6
|
+
import CLASS from "../../config/classes";
|
|
6
7
|
import {generateWait} from "../../module/generator";
|
|
7
8
|
import {diffDomain} from "../../module/util";
|
|
8
|
-
import CLASS from "../../config/classes";
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
11
|
/**
|
|
@@ -37,7 +37,17 @@ export default {
|
|
|
37
37
|
// target elements
|
|
38
38
|
const elements = {};
|
|
39
39
|
|
|
40
|
-
[
|
|
40
|
+
[
|
|
41
|
+
"axis.x",
|
|
42
|
+
"grid.x",
|
|
43
|
+
"gridLines.x",
|
|
44
|
+
"region.list",
|
|
45
|
+
"text",
|
|
46
|
+
"bar",
|
|
47
|
+
"line",
|
|
48
|
+
"area",
|
|
49
|
+
"circle"
|
|
50
|
+
]
|
|
41
51
|
.forEach(v => {
|
|
42
52
|
const name = v.split(".");
|
|
43
53
|
let node = $el[name[0]];
|
|
@@ -69,7 +79,7 @@ export default {
|
|
|
69
79
|
duration = args.duration,
|
|
70
80
|
index: flowIndex,
|
|
71
81
|
length: flowLength,
|
|
72
|
-
orgDataCount
|
|
82
|
+
orgDataCount
|
|
73
83
|
} = flow;
|
|
74
84
|
|
|
75
85
|
const transform = $$.getFlowTransform(targets, orgDataCount, flowIndex, flowLength);
|
|
@@ -227,7 +237,7 @@ export default {
|
|
|
227
237
|
x(flowStart?.x || 0) - x(flowEnd.x);
|
|
228
238
|
}
|
|
229
239
|
|
|
230
|
-
const scaleX =
|
|
240
|
+
const scaleX = diffDomain(orgDomain) / diffDomain(domain);
|
|
231
241
|
|
|
232
242
|
return `translate(${translateX},0) scale(${scaleX},1)`;
|
|
233
243
|
}
|