@antv/g2 5.0.5 → 5.0.7
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/dist/g2-lite.min.js +4 -4
- package/dist/g2.min.js +4 -4
- package/esm/animation/morphing.js +4 -0
- package/esm/animation/morphing.js.map +1 -1
- package/esm/api/chart.d.ts +7 -8
- package/esm/api/chart.js +34 -92
- package/esm/api/chart.js.map +1 -1
- package/esm/api/utils.d.ts +10 -0
- package/esm/api/utils.js +71 -0
- package/esm/api/utils.js.map +1 -0
- package/esm/component/axis.js +15 -17
- package/esm/component/axis.js.map +1 -1
- package/esm/component/axisX.js +3 -1
- package/esm/component/axisX.js.map +1 -1
- package/esm/component/axisY.js +1 -1
- package/esm/component/axisY.js.map +1 -1
- package/esm/component/constant.js +6 -0
- package/esm/component/constant.js.map +1 -1
- package/esm/component/legendCategory.js +8 -5
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.js +91 -33
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/utils.d.ts +9 -5
- package/esm/component/utils.js +14 -14
- package/esm/component/utils.js.map +1 -1
- package/esm/interaction/brushFilter.d.ts +5 -1
- package/esm/interaction/brushFilter.js +26 -23
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +10 -3
- package/esm/interaction/brushHighlight.js +242 -30
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXHighlight.d.ts +2 -1
- package/esm/interaction/brushXHighlight.js +1 -1
- package/esm/interaction/brushXHighlight.js.map +1 -1
- package/esm/interaction/brushYHighlight.d.ts +2 -1
- package/esm/interaction/brushYHighlight.js +1 -1
- package/esm/interaction/brushYHighlight.js.map +1 -1
- package/esm/interaction/event.d.ts +1 -0
- package/esm/interaction/event.js +14 -12
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +4 -4
- package/esm/interaction/tooltip.js +103 -31
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/mark/gauge.d.ts +7 -0
- package/esm/mark/gauge.js +4 -6
- package/esm/mark/gauge.js.map +1 -1
- package/esm/runtime/plot.js +9 -6
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.js +2 -2
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/transform.js +4 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/component.d.ts +1 -0
- package/esm/shape/area/area.js +1 -1
- package/esm/shape/area/area.js.map +1 -1
- package/esm/shape/area/curve.js +1 -1
- package/esm/shape/area/curve.js.map +1 -1
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/line/curve.js +1 -1
- package/esm/shape/line/curve.js.map +1 -1
- package/esm/shape/text/advance.d.ts +1 -1
- package/esm/shape/text/advance.js +1 -1
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/text/badge.js +1 -1
- package/esm/shape/utils.js +1 -1
- package/esm/shape/utils.js.map +1 -1
- package/esm/spec/interaction.d.ts +3 -1
- package/esm/theme/classic.js +3 -0
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/classicDark.js +1 -0
- package/esm/theme/classicDark.js.map +1 -1
- package/esm/transform/filter.js +6 -2
- package/esm/transform/filter.js.map +1 -1
- package/esm/{shape → utils}/createElement.d.ts +1 -1
- package/esm/{shape → utils}/createElement.js.map +1 -1
- package/esm/utils/helper.d.ts +3 -0
- package/esm/utils/helper.js +3 -0
- package/esm/utils/helper.js.map +1 -1
- package/esm/utils/scale.d.ts +2 -0
- package/esm/utils/scale.js +21 -0
- package/esm/utils/scale.js.map +1 -1
- package/lib/animation/morphing.js +4 -0
- package/lib/animation/morphing.js.map +1 -1
- package/lib/api/chart.d.ts +7 -8
- package/lib/api/chart.js +39 -99
- package/lib/api/chart.js.map +1 -1
- package/lib/api/utils.d.ts +10 -0
- package/lib/api/utils.js +80 -0
- package/lib/api/utils.js.map +1 -0
- package/lib/component/axis.js +15 -17
- package/lib/component/axis.js.map +1 -1
- package/lib/component/axisX.js +3 -1
- package/lib/component/axisX.js.map +1 -1
- package/lib/component/axisY.js +1 -1
- package/lib/component/axisY.js.map +1 -1
- package/lib/component/constant.js +6 -0
- package/lib/component/constant.js.map +1 -1
- package/lib/component/legendCategory.js +7 -4
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.js +90 -32
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/utils.d.ts +9 -5
- package/lib/component/utils.js +16 -15
- package/lib/component/utils.js.map +1 -1
- package/lib/interaction/brushFilter.d.ts +5 -1
- package/lib/interaction/brushFilter.js +25 -22
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +10 -3
- package/lib/interaction/brushHighlight.js +241 -29
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXHighlight.d.ts +2 -1
- package/lib/interaction/brushXHighlight.js +1 -1
- package/lib/interaction/brushXHighlight.js.map +1 -1
- package/lib/interaction/brushYHighlight.d.ts +2 -1
- package/lib/interaction/brushYHighlight.js +1 -1
- package/lib/interaction/brushYHighlight.js.map +1 -1
- package/lib/interaction/event.d.ts +1 -0
- package/lib/interaction/event.js +15 -12
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +4 -4
- package/lib/interaction/tooltip.js +102 -30
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/mark/gauge.d.ts +7 -0
- package/lib/mark/gauge.js +4 -6
- package/lib/mark/gauge.js.map +1 -1
- package/lib/runtime/plot.js +9 -6
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.js +2 -2
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/transform.js +4 -1
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/component.d.ts +1 -0
- package/lib/shape/area/area.js +1 -1
- package/lib/shape/area/area.js.map +1 -1
- package/lib/shape/area/curve.js +1 -1
- package/lib/shape/area/curve.js.map +1 -1
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/line/curve.js +1 -1
- package/lib/shape/line/curve.js.map +1 -1
- package/lib/shape/text/advance.d.ts +1 -1
- package/lib/shape/text/advance.js +1 -1
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/text/badge.js +1 -1
- package/lib/shape/utils.js +1 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/spec/interaction.d.ts +3 -1
- package/lib/theme/classic.js +3 -0
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/classicDark.js +1 -0
- package/lib/theme/classicDark.js.map +1 -1
- package/lib/transform/filter.js +6 -2
- package/lib/transform/filter.js.map +1 -1
- package/lib/{shape → utils}/createElement.d.ts +1 -1
- package/lib/{shape → utils}/createElement.js.map +1 -1
- package/lib/utils/helper.d.ts +3 -0
- package/lib/utils/helper.js +5 -1
- package/lib/utils/helper.js.map +1 -1
- package/lib/utils/scale.d.ts +2 -0
- package/lib/utils/scale.js +24 -1
- package/lib/utils/scale.js.map +1 -1
- package/package.json +7 -6
- package/src/animation/morphing.ts +5 -0
- package/src/api/chart.ts +45 -116
- package/src/api/utils.ts +79 -0
- package/src/component/axis.ts +20 -18
- package/src/component/axisX.ts +3 -1
- package/src/component/axisY.ts +2 -1
- package/src/component/constant.ts +6 -0
- package/src/component/legendCategory.ts +19 -6
- package/src/component/legendContinuous.ts +185 -74
- package/src/component/utils.ts +14 -3
- package/src/interaction/brushFilter.ts +37 -22
- package/src/interaction/brushHighlight.ts +309 -23
- package/src/interaction/brushXHighlight.ts +1 -0
- package/src/interaction/brushYHighlight.ts +1 -0
- package/src/interaction/event.ts +19 -13
- package/src/interaction/tooltip.ts +154 -25
- package/src/mark/gauge.ts +13 -7
- package/src/runtime/plot.ts +7 -5
- package/src/runtime/scale.ts +2 -2
- package/src/runtime/transform.ts +2 -1
- package/src/runtime/types/component.ts +1 -0
- package/src/shape/area/area.ts +1 -1
- package/src/shape/area/curve.ts +1 -1
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/line/curve.ts +1 -1
- package/src/shape/text/advance.ts +1 -1
- package/src/shape/text/badge.ts +1 -1
- package/src/shape/utils.ts +1 -1
- package/src/spec/interaction.ts +3 -2
- package/src/theme/classic.ts +3 -0
- package/src/theme/classicDark.ts +1 -0
- package/src/transform/filter.ts +6 -2
- package/src/{shape → utils}/createElement.ts +1 -1
- package/src/utils/helper.ts +12 -1
- package/src/utils/scale.ts +23 -0
- /package/esm/{shape → utils}/createElement.js +0 -0
- /package/lib/{shape → utils}/createElement.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"src/","sources":["component/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"src/","sources":["component/utils.ts"],"names":[],"mappings":";;;AAAA,+BAAoE;AACpE,mCAAmC;AACnC,qCAAiD;AAQjD,kDAAkE;AAMlE,SAAgB,eAAe,CAAI,UAAyB;IAC1D,OAAO,KAAM,SAAQ,iBAAgB;QAGnC,YAAY,MAA8B;YACxC,KAAK,CAAC,MAAM,CAAC,CAAC;YACd,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC/B,CAAC;QAED,iBAAiB;;YACf,MAAA,MAAA,IAAI,CAAC,UAAU,EAAC,MAAM,mDAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC;QAEM,MAAM,CAAC,GAAG,GAAG,EAAE;;YACpB,IAAI,CAAC,IAAI,CAAC,IAAA,cAAO,EAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC;YAC7C,MAAA,MAAA,IAAI,CAAC,UAAU,EAAC,MAAM,mDAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;AACJ,CAAC;AAlBD,0CAkBC;AAED,SAAgB,WAAW,CACzB,MAAa,EACb,QAAgB,EAChB,IAAkD;IAElD,IAAI,CAAC,MAA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,4BAKC;AAED,SAAgB,OAAO,CAAI,KAAQ;IACjC,MAAM,YAAY,GAAG;QACnB,OAAO;QACP,YAAY;QACZ,MAAM;QACN,QAAQ;QACR,aAAa;QACb,WAAW;QACX,OAAO;QACP,MAAM;QACN,MAAM;QACN,KAAK;QACL,OAAO;QACP,OAAO;KACR,CAAC;IACF,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7C,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC5B,UAAU,CAAC,OAAO,IAAA,iBAAU,EAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC;;YAC1C,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,OAAO,UAAe,CAAC;AACzB,CAAC;AAtBD,0BAsBC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
export declare function brushFilter(root: any, { filter, reset, brushRegion, extent: optionalExtent, reverse, series, ...rest }: {
|
|
1
|
+
export declare function brushFilter(root: any, { filter, reset, brushRegion, extent: optionalExtent, reverse, emitter, scale, coordinate, selection, series, ...rest }: {
|
|
2
2
|
[x: string]: any;
|
|
3
3
|
filter: any;
|
|
4
4
|
reset: any;
|
|
5
5
|
brushRegion: any;
|
|
6
6
|
extent: any;
|
|
7
7
|
reverse: any;
|
|
8
|
+
emitter: any;
|
|
9
|
+
scale: any;
|
|
10
|
+
coordinate: any;
|
|
11
|
+
selection: any;
|
|
8
12
|
series?: boolean;
|
|
9
13
|
}): () => void;
|
|
10
14
|
export declare function BrushFilter({ hideX, hideY, ...rest }: {
|
|
@@ -40,7 +40,7 @@ function dblclick(interval = 300) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
function brushFilter(root, _a) {
|
|
43
|
-
var { filter, reset, brushRegion, extent: optionalExtent, reverse, series = false } = _a, rest = __rest(_a, ["filter", "reset", "brushRegion", "extent", "reverse", "series"]);
|
|
43
|
+
var { filter, reset, brushRegion, extent: optionalExtent, reverse, emitter, scale, coordinate, selection, series = false } = _a, rest = __rest(_a, ["filter", "reset", "brushRegion", "extent", "reverse", "emitter", "scale", "coordinate", "selection", "series"]);
|
|
44
44
|
const brushStyle = (0, helper_1.subObject)(rest, 'mask');
|
|
45
45
|
const { width: rootWidth, height: rootHeight } = root.getBBox();
|
|
46
46
|
const extent = optionalExtent
|
|
@@ -54,16 +54,27 @@ function brushFilter(root, _a) {
|
|
|
54
54
|
root.addEventListener('click', click);
|
|
55
55
|
// Filter when brush created.
|
|
56
56
|
function brushcreated(x, y, x1, y1, event) {
|
|
57
|
-
|
|
57
|
+
event.nativeEvent = true;
|
|
58
|
+
filter(selection(x, y, x1, y1), event);
|
|
58
59
|
brush.remove();
|
|
59
60
|
}
|
|
60
61
|
// Reset when dblclick.
|
|
61
62
|
function click(e) {
|
|
62
|
-
if (isDblclick(e))
|
|
63
|
+
if (isDblclick(e)) {
|
|
64
|
+
e.nativeEvent = true;
|
|
63
65
|
reset(e);
|
|
66
|
+
}
|
|
64
67
|
}
|
|
68
|
+
const onFilter = ({ nativeEvent, data }) => {
|
|
69
|
+
if (nativeEvent)
|
|
70
|
+
return;
|
|
71
|
+
const { selection } = data;
|
|
72
|
+
filter(selection, { nativeEvent: false });
|
|
73
|
+
};
|
|
74
|
+
emitter.on('brush:filter', onFilter);
|
|
65
75
|
return () => {
|
|
66
76
|
brush.destroy();
|
|
77
|
+
emitter.off('brush:filter', onFilter);
|
|
67
78
|
root.removeEventListener('click', click);
|
|
68
79
|
};
|
|
69
80
|
}
|
|
@@ -83,24 +94,18 @@ function BrushFilter(_a) {
|
|
|
83
94
|
let filtered = false;
|
|
84
95
|
let filtering = false;
|
|
85
96
|
let newView = view;
|
|
86
|
-
|
|
97
|
+
const { scale, coordinate } = view;
|
|
98
|
+
return brushFilter(plotArea, Object.assign(Object.assign({ brushRegion: (x, y, x1, y1) => [x, y, x1, y1], selection: (x, y, x1, y1) => {
|
|
99
|
+
const { scale, coordinate } = newView;
|
|
100
|
+
return (0, scale_1.selectionOf)(x, y, x1, y1, scale, coordinate);
|
|
101
|
+
}, filter: (selection, event) => __awaiter(this, void 0, void 0, function* () {
|
|
87
102
|
// Avoid redundant filter.
|
|
88
103
|
if (filtering)
|
|
89
104
|
return;
|
|
90
105
|
filtering = true;
|
|
91
|
-
// Invert visual range to abstract domain.
|
|
92
|
-
const { scale, coordinate } = newView;
|
|
93
|
-
const { x: scaleX, y: scaleY } = scale;
|
|
94
|
-
const abstractDomain = (point, start) => {
|
|
95
|
-
const [x, y] = coordinate.invert(point);
|
|
96
|
-
return [(0, scale_1.invert)(scaleX, x, start), (0, scale_1.invert)(scaleY, y, start)];
|
|
97
|
-
};
|
|
98
|
-
const p0 = abstractDomain([x, y], true);
|
|
99
|
-
const p1 = abstractDomain([x1, y1], false);
|
|
100
106
|
// Update the domain of x and y scale to filter data.
|
|
107
|
+
const [domainX, domainY] = selection;
|
|
101
108
|
const { marks } = viewOptions;
|
|
102
|
-
const domainX = (0, scale_1.domainOf)(scaleX, [p0[0], p1[0]]);
|
|
103
|
-
const domainY = (0, scale_1.domainOf)(scaleY, [p0[1], p1[1]]);
|
|
104
109
|
const newMarks = marks.map((mark) => (0, util_1.deepMix)({
|
|
105
110
|
// Hide label to keep smooth transition.
|
|
106
111
|
axis: Object.assign(Object.assign({}, (hideX && { x: { transform: [{ type: 'hide' }] } })), (hideY && { y: { transform: [{ type: 'hide' }] } })),
|
|
@@ -111,9 +116,7 @@ function BrushFilter(_a) {
|
|
|
111
116
|
},
|
|
112
117
|
}));
|
|
113
118
|
// Emit event.
|
|
114
|
-
|
|
115
|
-
event.data.selection = [domainX, domainY];
|
|
116
|
-
emitter.emit('brush:filter', event);
|
|
119
|
+
emitter.emit('brush:filter', Object.assign(Object.assign({}, event), { data: { selection: [domainX, domainY] } }));
|
|
117
120
|
// Rerender and update view.
|
|
118
121
|
const newOptions = Object.assign(Object.assign({}, viewOptions), { marks: newMarks, clip: true });
|
|
119
122
|
const newState = yield update(newOptions);
|
|
@@ -128,13 +131,13 @@ function BrushFilter(_a) {
|
|
|
128
131
|
const { x: scaleX, y: scaleY } = scale;
|
|
129
132
|
const domainX = scaleX.getOptions().domain;
|
|
130
133
|
const domainY = scaleY.getOptions().domain;
|
|
131
|
-
|
|
132
|
-
event.data.selection = [domainX, domainY];
|
|
133
|
-
emitter.emit('brush:filter', event);
|
|
134
|
+
emitter.emit('brush:filter', Object.assign(Object.assign({}, event), { data: { selection: [domainX, domainY] } }));
|
|
134
135
|
filtered = false;
|
|
135
136
|
newView = view;
|
|
136
137
|
update(viewOptions);
|
|
137
|
-
}, extent: undefined
|
|
138
|
+
}, extent: undefined, emitter,
|
|
139
|
+
scale,
|
|
140
|
+
coordinate }, defaultOptions), rest));
|
|
138
141
|
};
|
|
139
142
|
}
|
|
140
143
|
exports.BrushFilter = BrushFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brushFilter.js","sourceRoot":"src/","sources":["interaction/brushFilter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqC;AACrC,4CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"brushFilter.js","sourceRoot":"src/","sources":["interaction/brushFilter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqC;AACrC,4CAA4C;AAC5C,0CAA6C;AAC7C,qDAAwD;AACxD,mCAAyC;AAEzC,wBAAwB;AACxB,SAAS,QAAQ,CAAC,QAAQ,GAAG,GAAG;IAC9B,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,CAAC,EAAE,EAAE;QACX,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QACxB,IAAI,YAAY,KAAK,IAAI,IAAI,SAAS,GAAG,YAAY,GAAG,QAA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UAAU,IACP,cAAc,GACd,IAAI,EACP,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA5FD,kCA4FC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
|
-
export declare function brush(root: DisplayObject, { brushed, brushended, brushcreated, extent, brushRegion, reverse, fill, fillOpacity, stroke, ...style }: Record<string, any>): {
|
|
2
|
+
export declare function brush(root: DisplayObject, { brushed, brushended, brushcreated, extent, brushRegion, reverse, fill, fillOpacity, stroke, selectedHandles, ...style }: Record<string, any>): {
|
|
3
3
|
mask: any;
|
|
4
|
+
move(x: any, y: any, x1: any, y1: any): void;
|
|
4
5
|
remove(): void;
|
|
5
6
|
destroy(): void;
|
|
6
7
|
};
|
|
@@ -8,14 +9,17 @@ export declare function brush(root: DisplayObject, { brushed, brushended, brushc
|
|
|
8
9
|
* @todo Brush over view for series view.
|
|
9
10
|
* @todo Test perf.
|
|
10
11
|
*/
|
|
11
|
-
export declare function brushHighlight(root: any, { elements: elementof, siblings: siblingsof, datum, brushRegion, extent: optionalExtent, reverse, series, key, bboxOf, state, ...rest }: {
|
|
12
|
+
export declare function brushHighlight(root: any, { elements: elementof, selectedHandles, siblings: siblingsof, datum, brushRegion, extent: optionalExtent, reverse, scale, coordinate, series, key, bboxOf, state, emitter, ...rest }: {
|
|
12
13
|
[x: string]: any;
|
|
13
14
|
elements: any;
|
|
15
|
+
selectedHandles: any;
|
|
14
16
|
siblings?: (root: any) => any[];
|
|
15
17
|
datum: any;
|
|
16
18
|
brushRegion: any;
|
|
17
19
|
extent: any;
|
|
18
20
|
reverse: any;
|
|
21
|
+
scale: any;
|
|
22
|
+
coordinate: any;
|
|
19
23
|
series?: boolean;
|
|
20
24
|
key?: (d: any) => any;
|
|
21
25
|
bboxOf?: (root: any) => {
|
|
@@ -25,8 +29,10 @@ export declare function brushHighlight(root: any, { elements: elementof, sibling
|
|
|
25
29
|
height: any;
|
|
26
30
|
};
|
|
27
31
|
state?: {};
|
|
32
|
+
emitter: any;
|
|
28
33
|
}): {
|
|
29
34
|
mask: any;
|
|
35
|
+
move(x: any, y: any, x1: any, y1: any): void;
|
|
30
36
|
remove(): void;
|
|
31
37
|
destroy(): void;
|
|
32
38
|
};
|
|
@@ -34,8 +40,9 @@ export declare function BrushHighlight({ facet, brushKey, ...rest }: {
|
|
|
34
40
|
[x: string]: any;
|
|
35
41
|
facet: any;
|
|
36
42
|
brushKey: any;
|
|
37
|
-
}): (target: any, viewInstances: any) => {
|
|
43
|
+
}): (target: any, viewInstances: any, emitter: any) => {
|
|
38
44
|
mask: any;
|
|
45
|
+
move(x: any, y: any, x1: any, y1: any): void;
|
|
39
46
|
remove(): void;
|
|
40
47
|
destroy(): void;
|
|
41
48
|
} | (() => void);
|
|
@@ -14,6 +14,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.BrushHighlight = exports.brushHighlight = exports.brush = void 0;
|
|
15
15
|
const g_1 = require("@antv/g");
|
|
16
16
|
const helper_1 = require("../utils/helper");
|
|
17
|
+
const scale_1 = require("../utils/scale");
|
|
18
|
+
const createElement_1 = require("../utils/createElement");
|
|
19
|
+
const selection_1 = require("../utils/selection");
|
|
17
20
|
const utils_1 = require("./utils");
|
|
18
21
|
function intersect(bbox1, bbox2) {
|
|
19
22
|
const [minX1, minY1, maxX1, maxY1] = bbox1;
|
|
@@ -33,14 +36,142 @@ function bboxOf(root) {
|
|
|
33
36
|
const { width, height } = root.getBBox();
|
|
34
37
|
return [0, 0, width, height];
|
|
35
38
|
}
|
|
39
|
+
function applyStyle(selection, style) {
|
|
40
|
+
for (const [key, value] of Object.entries(style)) {
|
|
41
|
+
selection.style(key, value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const ResizableMask = (0, createElement_1.createElement)((g) => {
|
|
45
|
+
const _a = g.attributes, { x, y, width, height, class: className, renders = {}, handleSize: size = 10, document } = _a, style = __rest(_a, ["x", "y", "width", "height", "class", "renders", "handleSize", "document"]);
|
|
46
|
+
if (!document ||
|
|
47
|
+
width === undefined ||
|
|
48
|
+
height === undefined ||
|
|
49
|
+
x === undefined ||
|
|
50
|
+
y === undefined)
|
|
51
|
+
return;
|
|
52
|
+
const half = size / 2;
|
|
53
|
+
const renderRect = (g, options, document) => {
|
|
54
|
+
if (!g.handle) {
|
|
55
|
+
g.handle = document.createElement('rect');
|
|
56
|
+
g.append(g.handle);
|
|
57
|
+
}
|
|
58
|
+
const { handle } = g;
|
|
59
|
+
handle.attr(options);
|
|
60
|
+
return handle;
|
|
61
|
+
};
|
|
62
|
+
const _b = (0, helper_1.subObject)((0, helper_1.omitPrefixObject)(style, 'handleNW', 'handleNE'), 'handleN'), { render: handleNRender = renderRect } = _b, handleNStyle = __rest(_b, ["render"]);
|
|
63
|
+
const _c = (0, helper_1.subObject)(style, 'handleE'), { render: handleERender = renderRect } = _c, handleEStyle = __rest(_c, ["render"]);
|
|
64
|
+
const _d = (0, helper_1.subObject)((0, helper_1.omitPrefixObject)(style, 'handleSE', 'handleSW'), 'handleS'), { render: handleSRender = renderRect } = _d, handleSStyle = __rest(_d, ["render"]);
|
|
65
|
+
const _e = (0, helper_1.subObject)(style, 'handleW'), { render: handleWRender = renderRect } = _e, handleWStyle = __rest(_e, ["render"]);
|
|
66
|
+
const _f = (0, helper_1.subObject)(style, 'handleNW'), { render: handleNWRender = renderRect } = _f, handleNWStyle = __rest(_f, ["render"]);
|
|
67
|
+
const _g = (0, helper_1.subObject)(style, 'handleNE'), { render: handleNERender = renderRect } = _g, handleNEStyle = __rest(_g, ["render"]);
|
|
68
|
+
const _h = (0, helper_1.subObject)(style, 'handleSE'), { render: handleSERender = renderRect } = _h, handleSEStyle = __rest(_h, ["render"]);
|
|
69
|
+
const _j = (0, helper_1.subObject)(style, 'handleSW'), { render: handleSWRender = renderRect } = _j, handleSWStyle = __rest(_j, ["render"]);
|
|
70
|
+
const renderHandle = (g, renderNode) => {
|
|
71
|
+
const { id } = g;
|
|
72
|
+
const _a = g.attributes, { x, y } = _a, style = __rest(_a, ["x", "y"]);
|
|
73
|
+
const handle = renderNode(g, Object.assign({ x: 0, y: 0 }, style), document);
|
|
74
|
+
handle.id = id;
|
|
75
|
+
handle.style.draggable = true;
|
|
76
|
+
};
|
|
77
|
+
const appendHandle = (handleRender) => {
|
|
78
|
+
return () => {
|
|
79
|
+
const Node = (0, createElement_1.createElement)((g) => renderHandle(g, handleRender));
|
|
80
|
+
return new Node({});
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
const container = (0, selection_1.select)(g)
|
|
84
|
+
.attr('className', className)
|
|
85
|
+
.style('x', x)
|
|
86
|
+
.style('y', y)
|
|
87
|
+
.style('draggable', true);
|
|
88
|
+
container
|
|
89
|
+
.maybeAppend('selection', 'rect')
|
|
90
|
+
.style('draggable', true)
|
|
91
|
+
.style('fill', 'transparent')
|
|
92
|
+
.call(applyStyle, Object.assign({ width, height }, (0, helper_1.omitPrefixObject)(style, 'handle')));
|
|
93
|
+
container
|
|
94
|
+
.maybeAppend('handle-n', appendHandle(handleNRender))
|
|
95
|
+
.style('x', half)
|
|
96
|
+
.style('y', -half)
|
|
97
|
+
.style('width', width - size)
|
|
98
|
+
.style('height', size)
|
|
99
|
+
.style('fill', 'transparent')
|
|
100
|
+
.call(applyStyle, handleNStyle);
|
|
101
|
+
container
|
|
102
|
+
.maybeAppend('handle-e', appendHandle(handleERender))
|
|
103
|
+
.style('x', width - half)
|
|
104
|
+
.style('y', half)
|
|
105
|
+
.style('width', size)
|
|
106
|
+
.style('height', height - size)
|
|
107
|
+
.style('fill', 'transparent')
|
|
108
|
+
.call(applyStyle, handleEStyle);
|
|
109
|
+
container
|
|
110
|
+
.maybeAppend('handle-s', appendHandle(handleSRender))
|
|
111
|
+
.style('x', half)
|
|
112
|
+
.style('y', height - half)
|
|
113
|
+
.style('width', width - size)
|
|
114
|
+
.style('height', size)
|
|
115
|
+
.style('fill', 'transparent')
|
|
116
|
+
.call(applyStyle, handleSStyle);
|
|
117
|
+
container
|
|
118
|
+
.maybeAppend('handle-w', appendHandle(handleWRender))
|
|
119
|
+
.style('x', -half)
|
|
120
|
+
.style('y', half)
|
|
121
|
+
.style('width', size)
|
|
122
|
+
.style('height', height - size)
|
|
123
|
+
.style('fill', 'transparent')
|
|
124
|
+
.call(applyStyle, handleWStyle);
|
|
125
|
+
container
|
|
126
|
+
.maybeAppend('handle-nw', appendHandle(handleNWRender))
|
|
127
|
+
.style('x', -half)
|
|
128
|
+
.style('y', -half)
|
|
129
|
+
.style('width', size)
|
|
130
|
+
.style('height', size)
|
|
131
|
+
.style('fill', 'transparent')
|
|
132
|
+
.call(applyStyle, handleNWStyle);
|
|
133
|
+
container
|
|
134
|
+
.maybeAppend('handle-ne', appendHandle(handleNERender))
|
|
135
|
+
.style('x', width - half)
|
|
136
|
+
.style('y', -half)
|
|
137
|
+
.style('width', size)
|
|
138
|
+
.style('height', size)
|
|
139
|
+
.style('fill', 'transparent')
|
|
140
|
+
.call(applyStyle, handleNEStyle);
|
|
141
|
+
container
|
|
142
|
+
.maybeAppend('handle-se', appendHandle(handleSERender))
|
|
143
|
+
.style('x', width - half)
|
|
144
|
+
.style('y', height - half)
|
|
145
|
+
.style('width', size)
|
|
146
|
+
.style('height', size)
|
|
147
|
+
.style('fill', 'transparent')
|
|
148
|
+
.call(applyStyle, handleSEStyle);
|
|
149
|
+
container
|
|
150
|
+
.maybeAppend('handle-sw', appendHandle(handleSWRender))
|
|
151
|
+
.style('x', -half)
|
|
152
|
+
.style('y', height - half)
|
|
153
|
+
.style('width', size)
|
|
154
|
+
.style('height', size)
|
|
155
|
+
.style('fill', 'transparent')
|
|
156
|
+
.call(applyStyle, handleSWStyle);
|
|
157
|
+
});
|
|
36
158
|
function brush(root, _a) {
|
|
37
|
-
var { brushed = () => { }, brushended = () => { }, brushcreated = () => { }, extent = bboxOf(root), brushRegion = (x, y, x1, y1, extent) => [x, y, x1, y1], reverse = false, fill = '#777', fillOpacity = '0.3', stroke = '#fff'
|
|
159
|
+
var { brushed = () => { }, brushended = () => { }, brushcreated = () => { }, extent = bboxOf(root), brushRegion = (x, y, x1, y1, extent) => [x, y, x1, y1], reverse = false, fill = '#777', fillOpacity = '0.3', stroke = '#fff', selectedHandles = [
|
|
160
|
+
'handle-n',
|
|
161
|
+
'handle-e',
|
|
162
|
+
'handle-s',
|
|
163
|
+
'handle-w',
|
|
164
|
+
'handle-nw',
|
|
165
|
+
'handle-ne',
|
|
166
|
+
'handle-se',
|
|
167
|
+
'handle-sw',
|
|
168
|
+
] } = _a, style = __rest(_a, ["brushed", "brushended", "brushcreated", "extent", "brushRegion", "reverse", "fill", "fillOpacity", "stroke", "selectedHandles"]);
|
|
38
169
|
let start = null; // Start point of mask.
|
|
39
170
|
let end = null; // End point of mask.
|
|
40
171
|
let moveStart = null; // Start point of moving mask.
|
|
41
172
|
let mask = null; // Mask instance.
|
|
42
173
|
let background = null;
|
|
43
|
-
let
|
|
174
|
+
let creating = false;
|
|
44
175
|
const [originX, originY, width, height] = extent;
|
|
45
176
|
(0, utils_1.setCursor)(root, 'crosshair');
|
|
46
177
|
root.style.draggable = true; // Make it response to drag event.
|
|
@@ -61,7 +192,7 @@ function brush(root, _a) {
|
|
|
61
192
|
fillOpacity,
|
|
62
193
|
stroke, pointerEvents: 'none' }),
|
|
63
194
|
});
|
|
64
|
-
mask = new
|
|
195
|
+
mask = new ResizableMask({
|
|
65
196
|
// @ts-ignore
|
|
66
197
|
style: {
|
|
67
198
|
x: 0,
|
|
@@ -69,6 +200,7 @@ function brush(root, _a) {
|
|
|
69
200
|
width: 0,
|
|
70
201
|
height: 0,
|
|
71
202
|
draggable: true,
|
|
203
|
+
document: root.ownerDocument,
|
|
72
204
|
},
|
|
73
205
|
className: 'mask',
|
|
74
206
|
});
|
|
@@ -76,9 +208,9 @@ function brush(root, _a) {
|
|
|
76
208
|
root.appendChild(mask);
|
|
77
209
|
};
|
|
78
210
|
const initNormalMask = () => {
|
|
79
|
-
mask = new
|
|
211
|
+
mask = new ResizableMask({
|
|
80
212
|
// @ts-ignore
|
|
81
|
-
style: Object.assign(Object.assign({ x: 0, y: 0 }, style), { fill,
|
|
213
|
+
style: Object.assign(Object.assign({ document: root.ownerDocument, x: 0, y: 0 }, style), { fill,
|
|
82
214
|
fillOpacity,
|
|
83
215
|
stroke, draggable: true }),
|
|
84
216
|
className: 'mask',
|
|
@@ -94,7 +226,7 @@ function brush(root, _a) {
|
|
|
94
226
|
start = null;
|
|
95
227
|
end = null;
|
|
96
228
|
moveStart = null;
|
|
97
|
-
|
|
229
|
+
creating = false;
|
|
98
230
|
mask = null;
|
|
99
231
|
background = null;
|
|
100
232
|
brushended();
|
|
@@ -143,29 +275,62 @@ function brush(root, _a) {
|
|
|
143
275
|
const currentEnd = [end[0] + dx1, end[1] + dy1];
|
|
144
276
|
updateMask(currentStart, currentEnd);
|
|
145
277
|
};
|
|
278
|
+
const handles = {
|
|
279
|
+
'handle-n': { vector: [0, 1, 0, 0], cursor: 'ns-resize' },
|
|
280
|
+
'handle-e': { vector: [0, 0, 1, 0], cursor: 'ew-resize' },
|
|
281
|
+
'handle-s': { vector: [0, 0, 0, 1], cursor: 'ns-resize' },
|
|
282
|
+
'handle-w': { vector: [1, 0, 0, 0], cursor: 'ew-resize' },
|
|
283
|
+
'handle-nw': { vector: [1, 1, 0, 0], cursor: 'nwse-resize' },
|
|
284
|
+
'handle-ne': { vector: [0, 1, 1, 0], cursor: 'nesw-resize' },
|
|
285
|
+
'handle-se': { vector: [0, 0, 1, 1], cursor: 'nwse-resize' },
|
|
286
|
+
'handle-sw': { vector: [1, 0, 0, 1], cursor: 'nesw-resize' },
|
|
287
|
+
};
|
|
288
|
+
const isMask = (target) => {
|
|
289
|
+
return isSelection(target) || isHandle(target);
|
|
290
|
+
};
|
|
291
|
+
const isHandle = (target) => {
|
|
292
|
+
const { id } = target;
|
|
293
|
+
if (selectedHandles.indexOf(id) === -1)
|
|
294
|
+
return false;
|
|
295
|
+
return new Set(Object.keys(handles)).has(id);
|
|
296
|
+
};
|
|
297
|
+
const isSelection = (target) => {
|
|
298
|
+
return target === mask.getElementById('selection');
|
|
299
|
+
};
|
|
146
300
|
// If target is plot area, create mask.
|
|
147
301
|
// If target is mask, about to update position.
|
|
148
302
|
const dragstart = (event) => {
|
|
149
303
|
const { target } = event;
|
|
150
304
|
const [offsetX, offsetY] = (0, utils_1.brushMousePosition)(root, event);
|
|
151
|
-
if (
|
|
152
|
-
|
|
305
|
+
if (!mask || !isMask(target)) {
|
|
306
|
+
initMask(offsetX, offsetY);
|
|
307
|
+
creating = true;
|
|
153
308
|
return;
|
|
154
309
|
}
|
|
155
|
-
|
|
156
|
-
|
|
310
|
+
if (isMask(target)) {
|
|
311
|
+
moveStart = [offsetX, offsetY];
|
|
312
|
+
}
|
|
157
313
|
};
|
|
158
|
-
// If target is plot area, resize mask.
|
|
159
|
-
// If target is mask, move mask.
|
|
160
314
|
const drag = (event) => {
|
|
315
|
+
const { target } = event;
|
|
161
316
|
const mouse = (0, utils_1.brushMousePosition)(root, event);
|
|
162
317
|
if (!start)
|
|
163
318
|
return;
|
|
164
|
-
|
|
319
|
+
// If target is plot area, resize mask.
|
|
320
|
+
if (!moveStart)
|
|
321
|
+
return updateMask(start, mouse);
|
|
322
|
+
// If target is selection area, move mask.
|
|
323
|
+
if (isSelection(target))
|
|
165
324
|
return moveMask(mouse);
|
|
166
|
-
|
|
325
|
+
// If target is handle area, resize mask.
|
|
326
|
+
const [dx, dy] = [mouse[0] - moveStart[0], mouse[1] - moveStart[1]];
|
|
327
|
+
const { id } = target;
|
|
328
|
+
if (handles[id]) {
|
|
329
|
+
const [sx, sy, ex, ey] = handles[id].vector;
|
|
330
|
+
return updateMask([start[0] + dx * sx, start[1] + dy * sy], [end[0] + dx * ex, end[1] + dy * ey]);
|
|
331
|
+
}
|
|
167
332
|
};
|
|
168
|
-
// If target is plot area, finish
|
|
333
|
+
// If target is plot area, finish creating.
|
|
169
334
|
// If target is mask, finish moving mask.
|
|
170
335
|
const dragend = (event) => {
|
|
171
336
|
if (moveStart) {
|
|
@@ -178,22 +343,24 @@ function brush(root, _a) {
|
|
|
178
343
|
}
|
|
179
344
|
end = (0, utils_1.brushMousePosition)(root, event);
|
|
180
345
|
const [fx, fy, fx1, fy1] = updateMask(start, end);
|
|
181
|
-
|
|
346
|
+
creating = false;
|
|
182
347
|
brushcreated(fx, fy, fx1, fy1, event);
|
|
183
348
|
};
|
|
184
349
|
// Hide mask.
|
|
185
350
|
const click = (event) => {
|
|
186
351
|
const { target } = event;
|
|
187
|
-
if (mask && target
|
|
352
|
+
if (mask && !isMask(target))
|
|
188
353
|
removeMask();
|
|
189
354
|
};
|
|
190
355
|
// Update cursor depends on hovered element.
|
|
191
356
|
const pointermove = (event) => {
|
|
192
357
|
const { target } = event;
|
|
193
|
-
if (
|
|
194
|
-
(0, utils_1.setCursor)(root, 'move');
|
|
195
|
-
else
|
|
358
|
+
if (!mask || !isMask(target) || creating)
|
|
196
359
|
(0, utils_1.setCursor)(root, 'crosshair');
|
|
360
|
+
else if (isSelection(target))
|
|
361
|
+
(0, utils_1.setCursor)(root, 'move');
|
|
362
|
+
else if (isHandle(target))
|
|
363
|
+
(0, utils_1.setCursor)(root, handles[target.id].cursor);
|
|
197
364
|
};
|
|
198
365
|
const pointerleave = () => {
|
|
199
366
|
(0, utils_1.setCursor)(root, 'default');
|
|
@@ -206,13 +373,20 @@ function brush(root, _a) {
|
|
|
206
373
|
root.addEventListener('pointerleave', pointerleave);
|
|
207
374
|
return {
|
|
208
375
|
mask,
|
|
376
|
+
move(x, y, x1, y1) {
|
|
377
|
+
if (!mask)
|
|
378
|
+
initMask(x, y);
|
|
379
|
+
start = [x, y];
|
|
380
|
+
end = [x1, y1];
|
|
381
|
+
updateMask([x, y], [x1, y1]);
|
|
382
|
+
},
|
|
209
383
|
remove() {
|
|
210
384
|
if (mask)
|
|
211
385
|
removeMask();
|
|
212
386
|
},
|
|
213
387
|
destroy() {
|
|
214
|
-
|
|
215
|
-
|
|
388
|
+
removeMask();
|
|
389
|
+
(0, utils_1.setCursor)(root, 'default');
|
|
216
390
|
root.removeEventListener('dragstart', dragstart);
|
|
217
391
|
root.removeEventListener('drag', drag);
|
|
218
392
|
root.removeEventListener('dragend', dragend);
|
|
@@ -242,10 +416,10 @@ function selectSiblingOptions(target, viewInstances, brushKey) {
|
|
|
242
416
|
* @todo Test perf.
|
|
243
417
|
*/
|
|
244
418
|
function brushHighlight(root, _a) {
|
|
245
|
-
var { elements: elementof, siblings: siblingsof = (root) => [], datum, brushRegion, extent: optionalExtent, reverse, series = false, key = (d) => d, bboxOf = (root) => {
|
|
419
|
+
var { elements: elementof, selectedHandles, siblings: siblingsof = (root) => [], datum, brushRegion, extent: optionalExtent, reverse, scale, coordinate, series = false, key = (d) => d, bboxOf = (root) => {
|
|
246
420
|
const { x, y, width, height } = root.style;
|
|
247
421
|
return { x, y, width, height };
|
|
248
|
-
}, state = {} } = _a, rest = __rest(_a, ["elements", "siblings", "datum", "brushRegion", "extent", "reverse", "series", "key", "bboxOf", "state"]);
|
|
422
|
+
}, state = {}, emitter } = _a, rest = __rest(_a, ["elements", "selectedHandles", "siblings", "datum", "brushRegion", "extent", "reverse", "scale", "coordinate", "series", "key", "bboxOf", "state", "emitter"]);
|
|
249
423
|
const elements = elementof(root);
|
|
250
424
|
const siblings = siblingsof(root);
|
|
251
425
|
const siblingElements = siblings.flatMap(elementof);
|
|
@@ -319,14 +493,47 @@ function brushHighlight(root, _a) {
|
|
|
319
493
|
setState(cloned, 'active');
|
|
320
494
|
}
|
|
321
495
|
};
|
|
322
|
-
|
|
496
|
+
const brushHandler = brush(root, Object.assign(Object.assign({}, brushStyle), { extent,
|
|
323
497
|
brushRegion,
|
|
324
|
-
reverse,
|
|
498
|
+
reverse,
|
|
499
|
+
selectedHandles, brushended: () => {
|
|
500
|
+
const handler = series ? seriesBrushend : brushended;
|
|
501
|
+
emitter.emit('brush:end', { nativeEvent: true });
|
|
502
|
+
handler();
|
|
503
|
+
}, brushed: (x, y, x1, y1) => {
|
|
504
|
+
const selection = (0, scale_1.selectionOf)(x, y, x1, y1, scale, coordinate);
|
|
505
|
+
emitter.emit('brush:highlight', {
|
|
506
|
+
nativeEvent: true,
|
|
507
|
+
data: { selection },
|
|
508
|
+
});
|
|
509
|
+
const handler = series ? seriesBrushed : brushed;
|
|
510
|
+
handler(x, y, x1, y1);
|
|
511
|
+
} }));
|
|
512
|
+
// Move brush and highlight data.
|
|
513
|
+
const onHighlight = ({ nativeEvent, data }) => {
|
|
514
|
+
if (nativeEvent)
|
|
515
|
+
return;
|
|
516
|
+
const { selection } = data;
|
|
517
|
+
const [x, y, x1, y1] = (0, scale_1.pixelsOf)(selection, scale, coordinate);
|
|
518
|
+
brushHandler.move(x, y, x1, y1);
|
|
519
|
+
};
|
|
520
|
+
emitter.on('brush:highlight', onHighlight);
|
|
521
|
+
// Remove brush and reset data.
|
|
522
|
+
const onRemove = () => brushHandler.remove();
|
|
523
|
+
emitter.on('brush:remove', onRemove);
|
|
524
|
+
// Remove event handlers.
|
|
525
|
+
const preBrushDestroy = brushHandler.destroy.bind(brushHandler);
|
|
526
|
+
brushHandler.destroy = () => {
|
|
527
|
+
emitter.off('brush:highlight', onHighlight);
|
|
528
|
+
emitter.off('brush:remove', onRemove);
|
|
529
|
+
preBrushDestroy();
|
|
530
|
+
};
|
|
531
|
+
return brushHandler;
|
|
325
532
|
}
|
|
326
533
|
exports.brushHighlight = brushHighlight;
|
|
327
534
|
function BrushHighlight(_a) {
|
|
328
535
|
var { facet, brushKey } = _a, rest = __rest(_a, ["facet", "brushKey"]);
|
|
329
|
-
return (target, viewInstances) => {
|
|
536
|
+
return (target, viewInstances, emitter) => {
|
|
330
537
|
const { container, view, options } = target;
|
|
331
538
|
const plotArea = (0, utils_1.selectPlotArea)(container);
|
|
332
539
|
const defaultOptions = {
|
|
@@ -336,18 +543,23 @@ function BrushHighlight(_a) {
|
|
|
336
543
|
reverse: false,
|
|
337
544
|
};
|
|
338
545
|
const defaultStates = ['active', ['inactive', { opacity: 0.5 }]];
|
|
546
|
+
const { scale, coordinate } = view;
|
|
339
547
|
if (facet) {
|
|
340
548
|
const bbox = plotArea.getBounds();
|
|
341
549
|
const x = bbox.min[0];
|
|
342
550
|
const y = bbox.min[1];
|
|
343
551
|
const x1 = bbox.max[0];
|
|
344
552
|
const y1 = bbox.max[1];
|
|
345
|
-
return brushHighlight(plotArea.parentNode.parentNode, Object.assign(Object.assign({ elements: () => (0, utils_1.selectFacetG2Elements)(target, viewInstances), datum: (0, utils_1.createDatumof)((0, utils_1.selectFacetViews)(target, viewInstances).map((d) => d.view)), brushRegion: (x, y, x1, y1) => [x, y, x1, y1], extent: [x, y, x1, y1], state: (0, utils_1.mergeState)((0, utils_1.selectFacetViews)(target, viewInstances).map((d) => d.options), defaultStates)
|
|
553
|
+
return brushHighlight(plotArea.parentNode.parentNode, Object.assign(Object.assign({ elements: () => (0, utils_1.selectFacetG2Elements)(target, viewInstances), datum: (0, utils_1.createDatumof)((0, utils_1.selectFacetViews)(target, viewInstances).map((d) => d.view)), brushRegion: (x, y, x1, y1) => [x, y, x1, y1], extent: [x, y, x1, y1], state: (0, utils_1.mergeState)((0, utils_1.selectFacetViews)(target, viewInstances).map((d) => d.options), defaultStates), emitter,
|
|
554
|
+
scale,
|
|
555
|
+
coordinate, selectedHandles: undefined }, defaultOptions), rest));
|
|
346
556
|
}
|
|
347
557
|
const brush = brushHighlight(plotArea, Object.assign(Object.assign({ elements: utils_1.selectG2Elements, key: (element) => element.__data__.key, siblings: () => selectSiblingContainers(target, viewInstances, brushKey), datum: (0, utils_1.createDatumof)([
|
|
348
558
|
view,
|
|
349
559
|
...selectSiblingViews(target, viewInstances, brushKey).map((d) => d.view),
|
|
350
|
-
]), brushRegion: (x, y, x1, y1) => [x, y, x1, y1], extent: undefined, state: (0, utils_1.mergeState)([options, ...selectSiblingOptions(target, viewInstances, brushKey)], defaultStates)
|
|
560
|
+
]), brushRegion: (x, y, x1, y1) => [x, y, x1, y1], extent: undefined, state: (0, utils_1.mergeState)([options, ...selectSiblingOptions(target, viewInstances, brushKey)], defaultStates), emitter,
|
|
561
|
+
scale,
|
|
562
|
+
coordinate, selectedHandles: undefined }, defaultOptions), rest));
|
|
351
563
|
// Bind brush to the view it belongs to.
|
|
352
564
|
//@ts-ignore
|
|
353
565
|
plotArea.brush = brush;
|