@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,5 +1,8 @@
|
|
|
1
1
|
import { DisplayObject, Rect, Path } from '@antv/g';
|
|
2
|
-
import { subObject } from '../utils/helper';
|
|
2
|
+
import { subObject, omitPrefixObject } from '../utils/helper';
|
|
3
|
+
import { selectionOf, pixelsOf } from '../utils/scale';
|
|
4
|
+
import { createElement } from '../utils/createElement';
|
|
5
|
+
import { select, Selection } from '../utils/selection';
|
|
3
6
|
import {
|
|
4
7
|
selectG2Elements,
|
|
5
8
|
selectPlotArea,
|
|
@@ -34,6 +37,180 @@ function bboxOf(root: DisplayObject) {
|
|
|
34
37
|
return [0, 0, width, height];
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
function applyStyle(selection: Selection, style: Record<string, any>) {
|
|
41
|
+
for (const [key, value] of Object.entries(style)) {
|
|
42
|
+
selection.style(key, value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const ResizableMask = createElement((g) => {
|
|
47
|
+
const {
|
|
48
|
+
x,
|
|
49
|
+
y,
|
|
50
|
+
width,
|
|
51
|
+
height,
|
|
52
|
+
class: className,
|
|
53
|
+
renders = {},
|
|
54
|
+
handleSize: size = 10,
|
|
55
|
+
document,
|
|
56
|
+
...style
|
|
57
|
+
} = g.attributes;
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
!document ||
|
|
61
|
+
width === undefined ||
|
|
62
|
+
height === undefined ||
|
|
63
|
+
x === undefined ||
|
|
64
|
+
y === undefined
|
|
65
|
+
)
|
|
66
|
+
return;
|
|
67
|
+
|
|
68
|
+
const half = size / 2;
|
|
69
|
+
|
|
70
|
+
const renderRect = (g, options, document) => {
|
|
71
|
+
if (!g.handle) {
|
|
72
|
+
g.handle = document.createElement('rect');
|
|
73
|
+
g.append(g.handle);
|
|
74
|
+
}
|
|
75
|
+
const { handle } = g;
|
|
76
|
+
handle.attr(options);
|
|
77
|
+
return handle;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const { render: handleNRender = renderRect, ...handleNStyle } = subObject(
|
|
81
|
+
omitPrefixObject(style, 'handleNW', 'handleNE'),
|
|
82
|
+
'handleN',
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const { render: handleERender = renderRect, ...handleEStyle } = subObject(
|
|
86
|
+
style,
|
|
87
|
+
'handleE',
|
|
88
|
+
);
|
|
89
|
+
const { render: handleSRender = renderRect, ...handleSStyle } = subObject(
|
|
90
|
+
omitPrefixObject(style, 'handleSE', 'handleSW'),
|
|
91
|
+
'handleS',
|
|
92
|
+
);
|
|
93
|
+
const { render: handleWRender = renderRect, ...handleWStyle } = subObject(
|
|
94
|
+
style,
|
|
95
|
+
'handleW',
|
|
96
|
+
);
|
|
97
|
+
const { render: handleNWRender = renderRect, ...handleNWStyle } = subObject(
|
|
98
|
+
style,
|
|
99
|
+
'handleNW',
|
|
100
|
+
);
|
|
101
|
+
const { render: handleNERender = renderRect, ...handleNEStyle } = subObject(
|
|
102
|
+
style,
|
|
103
|
+
'handleNE',
|
|
104
|
+
);
|
|
105
|
+
const { render: handleSERender = renderRect, ...handleSEStyle } = subObject(
|
|
106
|
+
style,
|
|
107
|
+
'handleSE',
|
|
108
|
+
);
|
|
109
|
+
const { render: handleSWRender = renderRect, ...handleSWStyle } = subObject(
|
|
110
|
+
style,
|
|
111
|
+
'handleSW',
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const renderHandle = (g, renderNode) => {
|
|
115
|
+
const { id } = g;
|
|
116
|
+
const { x, y, ...style } = g.attributes;
|
|
117
|
+
const handle = renderNode(g, { x: 0, y: 0, ...style }, document);
|
|
118
|
+
handle.id = id;
|
|
119
|
+
handle.style.draggable = true;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const appendHandle = (handleRender) => {
|
|
123
|
+
return () => {
|
|
124
|
+
const Node = createElement((g) => renderHandle(g, handleRender));
|
|
125
|
+
return new Node({});
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const container = select(g)
|
|
130
|
+
.attr('className', className)
|
|
131
|
+
.style('x', x)
|
|
132
|
+
.style('y', y)
|
|
133
|
+
.style('draggable', true);
|
|
134
|
+
|
|
135
|
+
container
|
|
136
|
+
.maybeAppend('selection', 'rect')
|
|
137
|
+
.style('draggable', true)
|
|
138
|
+
.style('fill', 'transparent')
|
|
139
|
+
.call(applyStyle, { width, height, ...omitPrefixObject(style, 'handle') });
|
|
140
|
+
|
|
141
|
+
container
|
|
142
|
+
.maybeAppend('handle-n', appendHandle(handleNRender))
|
|
143
|
+
.style('x', half)
|
|
144
|
+
.style('y', -half)
|
|
145
|
+
.style('width', width - size)
|
|
146
|
+
.style('height', size)
|
|
147
|
+
.style('fill', 'transparent')
|
|
148
|
+
.call(applyStyle, handleNStyle);
|
|
149
|
+
|
|
150
|
+
container
|
|
151
|
+
.maybeAppend('handle-e', appendHandle(handleERender))
|
|
152
|
+
.style('x', width - half)
|
|
153
|
+
.style('y', half)
|
|
154
|
+
.style('width', size)
|
|
155
|
+
.style('height', height - size)
|
|
156
|
+
.style('fill', 'transparent')
|
|
157
|
+
.call(applyStyle, handleEStyle);
|
|
158
|
+
|
|
159
|
+
container
|
|
160
|
+
.maybeAppend('handle-s', appendHandle(handleSRender))
|
|
161
|
+
.style('x', half)
|
|
162
|
+
.style('y', height - half)
|
|
163
|
+
.style('width', width - size)
|
|
164
|
+
.style('height', size)
|
|
165
|
+
.style('fill', 'transparent')
|
|
166
|
+
.call(applyStyle, handleSStyle);
|
|
167
|
+
|
|
168
|
+
container
|
|
169
|
+
.maybeAppend('handle-w', appendHandle(handleWRender))
|
|
170
|
+
.style('x', -half)
|
|
171
|
+
.style('y', half)
|
|
172
|
+
.style('width', size)
|
|
173
|
+
.style('height', height - size)
|
|
174
|
+
.style('fill', 'transparent')
|
|
175
|
+
.call(applyStyle, handleWStyle);
|
|
176
|
+
|
|
177
|
+
container
|
|
178
|
+
.maybeAppend('handle-nw', appendHandle(handleNWRender))
|
|
179
|
+
.style('x', -half)
|
|
180
|
+
.style('y', -half)
|
|
181
|
+
.style('width', size)
|
|
182
|
+
.style('height', size)
|
|
183
|
+
.style('fill', 'transparent')
|
|
184
|
+
.call(applyStyle, handleNWStyle);
|
|
185
|
+
|
|
186
|
+
container
|
|
187
|
+
.maybeAppend('handle-ne', appendHandle(handleNERender))
|
|
188
|
+
.style('x', width - half)
|
|
189
|
+
.style('y', -half)
|
|
190
|
+
.style('width', size)
|
|
191
|
+
.style('height', size)
|
|
192
|
+
.style('fill', 'transparent')
|
|
193
|
+
.call(applyStyle, handleNEStyle);
|
|
194
|
+
|
|
195
|
+
container
|
|
196
|
+
.maybeAppend('handle-se', appendHandle(handleSERender))
|
|
197
|
+
.style('x', width - half)
|
|
198
|
+
.style('y', height - half)
|
|
199
|
+
.style('width', size)
|
|
200
|
+
.style('height', size)
|
|
201
|
+
.style('fill', 'transparent')
|
|
202
|
+
.call(applyStyle, handleSEStyle);
|
|
203
|
+
|
|
204
|
+
container
|
|
205
|
+
.maybeAppend('handle-sw', appendHandle(handleSWRender))
|
|
206
|
+
.style('x', -half)
|
|
207
|
+
.style('y', height - half)
|
|
208
|
+
.style('width', size)
|
|
209
|
+
.style('height', size)
|
|
210
|
+
.style('fill', 'transparent')
|
|
211
|
+
.call(applyStyle, handleSWStyle);
|
|
212
|
+
});
|
|
213
|
+
|
|
37
214
|
export function brush(
|
|
38
215
|
root: DisplayObject,
|
|
39
216
|
{
|
|
@@ -46,6 +223,16 @@ export function brush(
|
|
|
46
223
|
fill = '#777',
|
|
47
224
|
fillOpacity = '0.3',
|
|
48
225
|
stroke = '#fff',
|
|
226
|
+
selectedHandles = [
|
|
227
|
+
'handle-n',
|
|
228
|
+
'handle-e',
|
|
229
|
+
'handle-s',
|
|
230
|
+
'handle-w',
|
|
231
|
+
'handle-nw',
|
|
232
|
+
'handle-ne',
|
|
233
|
+
'handle-se',
|
|
234
|
+
'handle-sw',
|
|
235
|
+
],
|
|
49
236
|
...style
|
|
50
237
|
}: Record<string, any>,
|
|
51
238
|
) {
|
|
@@ -54,7 +241,7 @@ export function brush(
|
|
|
54
241
|
let moveStart = null; // Start point of moving mask.
|
|
55
242
|
let mask = null; // Mask instance.
|
|
56
243
|
let background = null;
|
|
57
|
-
let
|
|
244
|
+
let creating = false;
|
|
58
245
|
|
|
59
246
|
const [originX, originY, width, height] = extent;
|
|
60
247
|
|
|
@@ -80,7 +267,7 @@ export function brush(
|
|
|
80
267
|
pointerEvents: 'none',
|
|
81
268
|
},
|
|
82
269
|
});
|
|
83
|
-
mask = new
|
|
270
|
+
mask = new ResizableMask({
|
|
84
271
|
// @ts-ignore
|
|
85
272
|
style: {
|
|
86
273
|
x: 0,
|
|
@@ -88,6 +275,7 @@ export function brush(
|
|
|
88
275
|
width: 0,
|
|
89
276
|
height: 0,
|
|
90
277
|
draggable: true,
|
|
278
|
+
document: root.ownerDocument,
|
|
91
279
|
},
|
|
92
280
|
className: 'mask',
|
|
93
281
|
});
|
|
@@ -96,9 +284,10 @@ export function brush(
|
|
|
96
284
|
};
|
|
97
285
|
|
|
98
286
|
const initNormalMask = () => {
|
|
99
|
-
mask = new
|
|
287
|
+
mask = new ResizableMask({
|
|
100
288
|
// @ts-ignore
|
|
101
289
|
style: {
|
|
290
|
+
document: root.ownerDocument,
|
|
102
291
|
x: 0,
|
|
103
292
|
y: 0,
|
|
104
293
|
...style,
|
|
@@ -119,7 +308,7 @@ export function brush(
|
|
|
119
308
|
start = null;
|
|
120
309
|
end = null;
|
|
121
310
|
moveStart = null;
|
|
122
|
-
|
|
311
|
+
creating = false;
|
|
123
312
|
mask = null;
|
|
124
313
|
background = null;
|
|
125
314
|
brushended();
|
|
@@ -175,29 +364,69 @@ export function brush(
|
|
|
175
364
|
updateMask(currentStart, currentEnd);
|
|
176
365
|
};
|
|
177
366
|
|
|
367
|
+
const handles = {
|
|
368
|
+
'handle-n': { vector: [0, 1, 0, 0], cursor: 'ns-resize' },
|
|
369
|
+
'handle-e': { vector: [0, 0, 1, 0], cursor: 'ew-resize' },
|
|
370
|
+
'handle-s': { vector: [0, 0, 0, 1], cursor: 'ns-resize' },
|
|
371
|
+
'handle-w': { vector: [1, 0, 0, 0], cursor: 'ew-resize' },
|
|
372
|
+
'handle-nw': { vector: [1, 1, 0, 0], cursor: 'nwse-resize' },
|
|
373
|
+
'handle-ne': { vector: [0, 1, 1, 0], cursor: 'nesw-resize' },
|
|
374
|
+
'handle-se': { vector: [0, 0, 1, 1], cursor: 'nwse-resize' },
|
|
375
|
+
'handle-sw': { vector: [1, 0, 0, 1], cursor: 'nesw-resize' },
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const isMask = (target) => {
|
|
379
|
+
return isSelection(target) || isHandle(target);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
const isHandle = (target) => {
|
|
383
|
+
const { id } = target;
|
|
384
|
+
if (selectedHandles.indexOf(id) === -1) return false;
|
|
385
|
+
return new Set(Object.keys(handles)).has(id);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const isSelection = (target) => {
|
|
389
|
+
return target === mask.getElementById('selection');
|
|
390
|
+
};
|
|
391
|
+
|
|
178
392
|
// If target is plot area, create mask.
|
|
179
393
|
// If target is mask, about to update position.
|
|
180
394
|
const dragstart = (event) => {
|
|
181
395
|
const { target } = event;
|
|
182
396
|
const [offsetX, offsetY] = brushMousePosition(root, event);
|
|
183
|
-
if (
|
|
184
|
-
|
|
397
|
+
if (!mask || !isMask(target)) {
|
|
398
|
+
initMask(offsetX, offsetY);
|
|
399
|
+
creating = true;
|
|
185
400
|
return;
|
|
186
401
|
}
|
|
187
|
-
|
|
188
|
-
|
|
402
|
+
if (isMask(target)) {
|
|
403
|
+
moveStart = [offsetX, offsetY];
|
|
404
|
+
}
|
|
189
405
|
};
|
|
190
406
|
|
|
191
|
-
// If target is plot area, resize mask.
|
|
192
|
-
// If target is mask, move mask.
|
|
193
407
|
const drag = (event) => {
|
|
408
|
+
const { target } = event;
|
|
194
409
|
const mouse = brushMousePosition(root, event);
|
|
195
410
|
if (!start) return;
|
|
196
|
-
|
|
197
|
-
updateMask(start, mouse);
|
|
411
|
+
// If target is plot area, resize mask.
|
|
412
|
+
if (!moveStart) return updateMask(start, mouse);
|
|
413
|
+
|
|
414
|
+
// If target is selection area, move mask.
|
|
415
|
+
if (isSelection(target)) return moveMask(mouse);
|
|
416
|
+
|
|
417
|
+
// If target is handle area, resize mask.
|
|
418
|
+
const [dx, dy] = [mouse[0] - moveStart[0], mouse[1] - moveStart[1]];
|
|
419
|
+
const { id } = target;
|
|
420
|
+
if (handles[id]) {
|
|
421
|
+
const [sx, sy, ex, ey] = handles[id].vector;
|
|
422
|
+
return updateMask(
|
|
423
|
+
[start[0] + dx * sx, start[1] + dy * sy],
|
|
424
|
+
[end[0] + dx * ex, end[1] + dy * ey],
|
|
425
|
+
);
|
|
426
|
+
}
|
|
198
427
|
};
|
|
199
428
|
|
|
200
|
-
// If target is plot area, finish
|
|
429
|
+
// If target is plot area, finish creating.
|
|
201
430
|
// If target is mask, finish moving mask.
|
|
202
431
|
const dragend = (event) => {
|
|
203
432
|
if (moveStart) {
|
|
@@ -210,21 +439,22 @@ export function brush(
|
|
|
210
439
|
}
|
|
211
440
|
end = brushMousePosition(root, event);
|
|
212
441
|
const [fx, fy, fx1, fy1] = updateMask(start, end);
|
|
213
|
-
|
|
442
|
+
creating = false;
|
|
214
443
|
brushcreated(fx, fy, fx1, fy1, event);
|
|
215
444
|
};
|
|
216
445
|
|
|
217
446
|
// Hide mask.
|
|
218
447
|
const click = (event) => {
|
|
219
448
|
const { target } = event;
|
|
220
|
-
if (mask && target
|
|
449
|
+
if (mask && !isMask(target)) removeMask();
|
|
221
450
|
};
|
|
222
451
|
|
|
223
452
|
// Update cursor depends on hovered element.
|
|
224
453
|
const pointermove = (event) => {
|
|
225
454
|
const { target } = event;
|
|
226
|
-
if (
|
|
227
|
-
else setCursor(root, '
|
|
455
|
+
if (!mask || !isMask(target) || creating) setCursor(root, 'crosshair');
|
|
456
|
+
else if (isSelection(target)) setCursor(root, 'move');
|
|
457
|
+
else if (isHandle(target)) setCursor(root, handles[target.id].cursor);
|
|
228
458
|
};
|
|
229
459
|
|
|
230
460
|
const pointerleave = () => {
|
|
@@ -240,11 +470,18 @@ export function brush(
|
|
|
240
470
|
|
|
241
471
|
return {
|
|
242
472
|
mask,
|
|
473
|
+
move(x, y, x1, y1) {
|
|
474
|
+
if (!mask) initMask(x, y);
|
|
475
|
+
start = [x, y];
|
|
476
|
+
end = [x1, y1];
|
|
477
|
+
updateMask([x, y], [x1, y1]);
|
|
478
|
+
},
|
|
243
479
|
remove() {
|
|
244
480
|
if (mask) removeMask();
|
|
245
481
|
},
|
|
246
482
|
destroy() {
|
|
247
|
-
|
|
483
|
+
removeMask();
|
|
484
|
+
setCursor(root, 'default');
|
|
248
485
|
root.removeEventListener('dragstart', dragstart);
|
|
249
486
|
root.removeEventListener('drag', drag);
|
|
250
487
|
root.removeEventListener('dragend', dragend);
|
|
@@ -285,11 +522,14 @@ export function brushHighlight(
|
|
|
285
522
|
root,
|
|
286
523
|
{
|
|
287
524
|
elements: elementof,
|
|
525
|
+
selectedHandles,
|
|
288
526
|
siblings: siblingsof = (root) => [],
|
|
289
527
|
datum,
|
|
290
528
|
brushRegion,
|
|
291
529
|
extent: optionalExtent,
|
|
292
530
|
reverse,
|
|
531
|
+
scale,
|
|
532
|
+
coordinate,
|
|
293
533
|
series = false,
|
|
294
534
|
key = (d) => d,
|
|
295
535
|
bboxOf = (root) => {
|
|
@@ -297,6 +537,7 @@ export function brushHighlight(
|
|
|
297
537
|
return { x, y, width, height };
|
|
298
538
|
},
|
|
299
539
|
state = {},
|
|
540
|
+
emitter,
|
|
300
541
|
...rest
|
|
301
542
|
},
|
|
302
543
|
) {
|
|
@@ -379,18 +620,54 @@ export function brushHighlight(
|
|
|
379
620
|
}
|
|
380
621
|
};
|
|
381
622
|
|
|
382
|
-
|
|
623
|
+
const brushHandler = brush(root, {
|
|
383
624
|
...brushStyle,
|
|
384
625
|
extent,
|
|
385
626
|
brushRegion,
|
|
386
627
|
reverse,
|
|
387
|
-
|
|
388
|
-
|
|
628
|
+
selectedHandles,
|
|
629
|
+
brushended: () => {
|
|
630
|
+
const handler = series ? seriesBrushend : brushended;
|
|
631
|
+
emitter.emit('brush:end', { nativeEvent: true });
|
|
632
|
+
handler();
|
|
633
|
+
},
|
|
634
|
+
brushed: (x, y, x1, y1) => {
|
|
635
|
+
const selection = selectionOf(x, y, x1, y1, scale, coordinate);
|
|
636
|
+
emitter.emit('brush:highlight', {
|
|
637
|
+
nativeEvent: true,
|
|
638
|
+
data: { selection },
|
|
639
|
+
});
|
|
640
|
+
const handler = series ? seriesBrushed : brushed;
|
|
641
|
+
handler(x, y, x1, y1);
|
|
642
|
+
},
|
|
389
643
|
});
|
|
644
|
+
|
|
645
|
+
// Move brush and highlight data.
|
|
646
|
+
const onHighlight = ({ nativeEvent, data }) => {
|
|
647
|
+
if (nativeEvent) return;
|
|
648
|
+
const { selection } = data;
|
|
649
|
+
const [x, y, x1, y1] = pixelsOf(selection, scale, coordinate);
|
|
650
|
+
brushHandler.move(x, y, x1, y1);
|
|
651
|
+
};
|
|
652
|
+
emitter.on('brush:highlight', onHighlight);
|
|
653
|
+
|
|
654
|
+
// Remove brush and reset data.
|
|
655
|
+
const onRemove = () => brushHandler.remove();
|
|
656
|
+
emitter.on('brush:remove', onRemove);
|
|
657
|
+
|
|
658
|
+
// Remove event handlers.
|
|
659
|
+
const preBrushDestroy = brushHandler.destroy.bind(brushHandler);
|
|
660
|
+
brushHandler.destroy = () => {
|
|
661
|
+
emitter.off('brush:highlight', onHighlight);
|
|
662
|
+
emitter.off('brush:remove', onRemove);
|
|
663
|
+
preBrushDestroy();
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
return brushHandler;
|
|
390
667
|
}
|
|
391
668
|
|
|
392
669
|
export function BrushHighlight({ facet, brushKey, ...rest }) {
|
|
393
|
-
return (target, viewInstances) => {
|
|
670
|
+
return (target, viewInstances, emitter) => {
|
|
394
671
|
const { container, view, options } = target;
|
|
395
672
|
const plotArea = selectPlotArea(container);
|
|
396
673
|
const defaultOptions = {
|
|
@@ -400,6 +677,7 @@ export function BrushHighlight({ facet, brushKey, ...rest }) {
|
|
|
400
677
|
reverse: false,
|
|
401
678
|
};
|
|
402
679
|
const defaultStates = ['active', ['inactive', { opacity: 0.5 }]];
|
|
680
|
+
const { scale, coordinate } = view;
|
|
403
681
|
|
|
404
682
|
if (facet) {
|
|
405
683
|
const bbox = plotArea.getBounds();
|
|
@@ -418,6 +696,10 @@ export function BrushHighlight({ facet, brushKey, ...rest }) {
|
|
|
418
696
|
selectFacetViews(target, viewInstances).map((d) => d.options),
|
|
419
697
|
defaultStates,
|
|
420
698
|
),
|
|
699
|
+
emitter,
|
|
700
|
+
scale,
|
|
701
|
+
coordinate,
|
|
702
|
+
selectedHandles: undefined,
|
|
421
703
|
...defaultOptions,
|
|
422
704
|
...rest,
|
|
423
705
|
});
|
|
@@ -439,6 +721,10 @@ export function BrushHighlight({ facet, brushKey, ...rest }) {
|
|
|
439
721
|
[options, ...selectSiblingOptions(target, viewInstances, brushKey)],
|
|
440
722
|
defaultStates,
|
|
441
723
|
),
|
|
724
|
+
emitter,
|
|
725
|
+
scale,
|
|
726
|
+
coordinate,
|
|
727
|
+
selectedHandles: undefined,
|
|
442
728
|
...defaultOptions,
|
|
443
729
|
...rest,
|
|
444
730
|
});
|
package/src/interaction/event.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChartEvent } from '../utils/event';
|
|
2
2
|
|
|
3
|
-
function dataOf(element, view) {
|
|
3
|
+
export function dataOf(element, view) {
|
|
4
4
|
const { __data__: datum } = element;
|
|
5
5
|
const { markKey, index, seriesIndex } = datum;
|
|
6
6
|
const { markState } = view;
|
|
@@ -14,25 +14,31 @@ function dataOf(element, view) {
|
|
|
14
14
|
return selectedMark.data[index];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function updateData(event, target, view) {
|
|
18
|
-
const { data = {} } = event;
|
|
19
|
-
data.data = dataOf(target, view);
|
|
20
|
-
event.data = data;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
17
|
function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
|
|
24
18
|
return (e) => {
|
|
25
19
|
if (!predicate(e)) return;
|
|
26
20
|
const { target } = e;
|
|
27
21
|
const { className: elementType, markType } = target;
|
|
22
|
+
|
|
23
|
+
// Emit plot events.
|
|
24
|
+
emitter.emit(`plot:${eventType}`, e);
|
|
25
|
+
|
|
26
|
+
// If target area is plot area, do not emit extra events.
|
|
27
|
+
if (elementType === 'plot') return;
|
|
28
|
+
|
|
29
|
+
// Emit wrapped events.
|
|
28
30
|
if (elementType === 'element') {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const e1 = {
|
|
32
|
+
...e,
|
|
33
|
+
nativeEvent: true,
|
|
34
|
+
data: { data: dataOf(target, view) },
|
|
35
|
+
};
|
|
36
|
+
emitter.emit(`element:${eventType}`, e1);
|
|
37
|
+
emitter.emit(`${markType}:${eventType}`, e1);
|
|
38
|
+
} else {
|
|
39
|
+
// @todo Handle click axis and legend.
|
|
40
|
+
emitter.emit(`${elementType}:${eventType}`, e);
|
|
33
41
|
}
|
|
34
|
-
// @todo Handle click axis and legend.
|
|
35
|
-
emitter.emit(`${elementType}:click`);
|
|
36
42
|
};
|
|
37
43
|
}
|
|
38
44
|
|