@antv/g2 5.0.6 → 5.0.8
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 +4 -7
- package/esm/api/chart.js +22 -90
- package/esm/api/chart.js.map +1 -1
- package/esm/api/mark/index.d.ts +3 -1
- package/esm/api/mark/index.js +2 -1
- package/esm/api/mark/index.js.map +1 -1
- package/esm/api/mark/mark.d.ts +7 -1
- package/esm/api/mark/mark.js +9 -0
- package/esm/api/mark/mark.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 +17 -19
- 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/composition/mark.js +2 -1
- package/esm/composition/mark.js.map +1 -1
- package/esm/data/index.d.ts +2 -0
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/data/kde.d.ts +10 -0
- package/esm/data/kde.js +30 -0
- package/esm/data/kde.js.map +1 -0
- package/esm/interaction/brushFilter.js +2 -6
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +3 -2
- package/esm/interaction/brushHighlight.js +202 -28
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXHighlight.js +1 -1
- package/esm/interaction/brushXHighlight.js.map +1 -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/density.d.ts +4 -0
- package/esm/mark/density.js +61 -0
- package/esm/mark/density.js.map +1 -0
- 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/mark/index.d.ts +2 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/runtime/component.d.ts +4 -2
- package/esm/runtime/component.js +164 -12
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/layout.d.ts +3 -3
- package/esm/runtime/layout.js +40 -21
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/plot.js +10 -7
- 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/box/violin.d.ts +3 -0
- package/esm/shape/box/violin.js +85 -0
- package/esm/shape/box/violin.js.map +1 -0
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/density/density.d.ts +8 -0
- package/esm/shape/density/density.js +50 -0
- package/esm/shape/density/density.js.map +1 -0
- package/esm/shape/index.d.ts +4 -0
- package/esm/shape/index.js +2 -0
- package/esm/shape/index.js.map +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/composition.d.ts +22 -19
- package/esm/spec/dataTransform.d.ts +34 -2
- package/esm/spec/interaction.d.ts +3 -1
- package/esm/spec/mark.d.ts +9 -8
- package/esm/spec/transform.d.ts +1 -1
- package/esm/spec/utils.d.ts +1 -0
- package/esm/stdlib/index.js +5 -5
- package/esm/stdlib/index.js.map +1 -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.js +5 -1
- package/esm/utils/scale.js.map +1 -1
- package/esm/utils/size.js +7 -4
- package/esm/utils/size.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 +4 -7
- package/lib/api/chart.js +27 -97
- package/lib/api/chart.js.map +1 -1
- package/lib/api/mark/index.d.ts +3 -1
- package/lib/api/mark/index.js +1 -0
- package/lib/api/mark/index.js.map +1 -1
- package/lib/api/mark/mark.d.ts +7 -1
- package/lib/api/mark/mark.js +10 -1
- package/lib/api/mark/mark.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 +17 -19
- 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/composition/mark.js +2 -1
- package/lib/composition/mark.js.map +1 -1
- package/lib/data/index.d.ts +2 -0
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/data/kde.d.ts +10 -0
- package/lib/data/kde.js +38 -0
- package/lib/data/kde.js.map +1 -0
- package/lib/interaction/brushFilter.js +2 -6
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +3 -2
- package/lib/interaction/brushHighlight.js +201 -27
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXHighlight.js +1 -1
- package/lib/interaction/brushXHighlight.js.map +1 -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/density.d.ts +4 -0
- package/lib/mark/density.js +65 -0
- package/lib/mark/density.js.map +1 -0
- 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/mark/index.d.ts +2 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/runtime/component.d.ts +4 -2
- package/lib/runtime/component.js +163 -10
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/layout.d.ts +3 -3
- package/lib/runtime/layout.js +40 -21
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/plot.js +10 -7
- 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/box/violin.d.ts +3 -0
- package/lib/shape/box/violin.js +89 -0
- package/lib/shape/box/violin.js.map +1 -0
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/density/density.d.ts +8 -0
- package/lib/shape/density/density.js +54 -0
- package/lib/shape/density/density.js.map +1 -0
- package/lib/shape/index.d.ts +4 -0
- package/lib/shape/index.js +6 -1
- package/lib/shape/index.js.map +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/composition.d.ts +22 -19
- package/lib/spec/dataTransform.d.ts +34 -2
- package/lib/spec/interaction.d.ts +3 -1
- package/lib/spec/mark.d.ts +9 -8
- package/lib/spec/transform.d.ts +1 -1
- package/lib/spec/utils.d.ts +1 -0
- package/lib/stdlib/index.js +2 -2
- package/lib/stdlib/index.js.map +1 -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.js +5 -1
- package/lib/utils/scale.js.map +1 -1
- package/lib/utils/size.js +7 -4
- package/lib/utils/size.js.map +1 -1
- package/package.json +5 -3
- package/src/animation/morphing.ts +5 -0
- package/src/api/chart.ts +30 -113
- package/src/api/mark/index.ts +3 -0
- package/src/api/mark/mark.ts +12 -0
- package/src/api/utils.ts +79 -0
- package/src/component/axis.ts +22 -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/composition/mark.ts +2 -0
- package/src/data/index.ts +2 -0
- package/src/data/kde.ts +53 -0
- package/src/interaction/brushFilter.ts +8 -6
- package/src/interaction/brushHighlight.ts +258 -20
- 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/density.ts +81 -0
- package/src/mark/gauge.ts +13 -7
- package/src/mark/index.ts +2 -0
- package/src/runtime/component.ts +210 -12
- package/src/runtime/layout.ts +74 -19
- package/src/runtime/plot.ts +8 -6
- 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/box/violin.ts +119 -0
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/density/density.ts +52 -0
- package/src/shape/index.ts +4 -0
- 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/composition.ts +22 -19
- package/src/spec/dataTransform.ts +35 -0
- package/src/spec/interaction.ts +3 -2
- package/src/spec/mark.ts +10 -6
- package/src/spec/transform.ts +1 -0
- package/src/spec/utils.ts +2 -0
- package/src/stdlib/index.ts +8 -0
- 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 +5 -1
- package/src/utils/size.ts +10 -4
- /package/esm/{shape → utils}/createElement.js +0 -0
- /package/lib/{shape → utils}/createElement.js +0 -0
|
@@ -1,6 +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
3
|
import { selectionOf, pixelsOf } from '../utils/scale';
|
|
4
|
+
import { createElement } from '../utils/createElement';
|
|
5
|
+
import { select, Selection } from '../utils/selection';
|
|
4
6
|
import {
|
|
5
7
|
selectG2Elements,
|
|
6
8
|
selectPlotArea,
|
|
@@ -35,6 +37,180 @@ function bboxOf(root: DisplayObject) {
|
|
|
35
37
|
return [0, 0, width, height];
|
|
36
38
|
}
|
|
37
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
|
+
|
|
38
214
|
export function brush(
|
|
39
215
|
root: DisplayObject,
|
|
40
216
|
{
|
|
@@ -47,6 +223,16 @@ export function brush(
|
|
|
47
223
|
fill = '#777',
|
|
48
224
|
fillOpacity = '0.3',
|
|
49
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
|
+
],
|
|
50
236
|
...style
|
|
51
237
|
}: Record<string, any>,
|
|
52
238
|
) {
|
|
@@ -55,7 +241,7 @@ export function brush(
|
|
|
55
241
|
let moveStart = null; // Start point of moving mask.
|
|
56
242
|
let mask = null; // Mask instance.
|
|
57
243
|
let background = null;
|
|
58
|
-
let
|
|
244
|
+
let creating = false;
|
|
59
245
|
|
|
60
246
|
const [originX, originY, width, height] = extent;
|
|
61
247
|
|
|
@@ -81,7 +267,7 @@ export function brush(
|
|
|
81
267
|
pointerEvents: 'none',
|
|
82
268
|
},
|
|
83
269
|
});
|
|
84
|
-
mask = new
|
|
270
|
+
mask = new ResizableMask({
|
|
85
271
|
// @ts-ignore
|
|
86
272
|
style: {
|
|
87
273
|
x: 0,
|
|
@@ -89,6 +275,7 @@ export function brush(
|
|
|
89
275
|
width: 0,
|
|
90
276
|
height: 0,
|
|
91
277
|
draggable: true,
|
|
278
|
+
document: root.ownerDocument,
|
|
92
279
|
},
|
|
93
280
|
className: 'mask',
|
|
94
281
|
});
|
|
@@ -97,9 +284,10 @@ export function brush(
|
|
|
97
284
|
};
|
|
98
285
|
|
|
99
286
|
const initNormalMask = () => {
|
|
100
|
-
mask = new
|
|
287
|
+
mask = new ResizableMask({
|
|
101
288
|
// @ts-ignore
|
|
102
289
|
style: {
|
|
290
|
+
document: root.ownerDocument,
|
|
103
291
|
x: 0,
|
|
104
292
|
y: 0,
|
|
105
293
|
...style,
|
|
@@ -114,16 +302,16 @@ export function brush(
|
|
|
114
302
|
};
|
|
115
303
|
|
|
116
304
|
// Remove mask and reset states.
|
|
117
|
-
const removeMask = () => {
|
|
305
|
+
const removeMask = (emit = true) => {
|
|
118
306
|
if (mask) mask.remove();
|
|
119
307
|
if (background) background.remove();
|
|
120
308
|
start = null;
|
|
121
309
|
end = null;
|
|
122
310
|
moveStart = null;
|
|
123
|
-
|
|
311
|
+
creating = false;
|
|
124
312
|
mask = null;
|
|
125
313
|
background = null;
|
|
126
|
-
brushended();
|
|
314
|
+
if (emit) brushended();
|
|
127
315
|
};
|
|
128
316
|
|
|
129
317
|
// Update mask and invoke brushended callback.
|
|
@@ -176,29 +364,69 @@ export function brush(
|
|
|
176
364
|
updateMask(currentStart, currentEnd);
|
|
177
365
|
};
|
|
178
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
|
+
|
|
179
392
|
// If target is plot area, create mask.
|
|
180
393
|
// If target is mask, about to update position.
|
|
181
394
|
const dragstart = (event) => {
|
|
182
395
|
const { target } = event;
|
|
183
396
|
const [offsetX, offsetY] = brushMousePosition(root, event);
|
|
184
|
-
if (
|
|
185
|
-
|
|
397
|
+
if (!mask || !isMask(target)) {
|
|
398
|
+
initMask(offsetX, offsetY);
|
|
399
|
+
creating = true;
|
|
186
400
|
return;
|
|
187
401
|
}
|
|
188
|
-
|
|
189
|
-
|
|
402
|
+
if (isMask(target)) {
|
|
403
|
+
moveStart = [offsetX, offsetY];
|
|
404
|
+
}
|
|
190
405
|
};
|
|
191
406
|
|
|
192
|
-
// If target is plot area, resize mask.
|
|
193
|
-
// If target is mask, move mask.
|
|
194
407
|
const drag = (event) => {
|
|
408
|
+
const { target } = event;
|
|
195
409
|
const mouse = brushMousePosition(root, event);
|
|
196
410
|
if (!start) return;
|
|
197
|
-
|
|
198
|
-
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
|
+
}
|
|
199
427
|
};
|
|
200
428
|
|
|
201
|
-
// If target is plot area, finish
|
|
429
|
+
// If target is plot area, finish creating.
|
|
202
430
|
// If target is mask, finish moving mask.
|
|
203
431
|
const dragend = (event) => {
|
|
204
432
|
if (moveStart) {
|
|
@@ -211,21 +439,22 @@ export function brush(
|
|
|
211
439
|
}
|
|
212
440
|
end = brushMousePosition(root, event);
|
|
213
441
|
const [fx, fy, fx1, fy1] = updateMask(start, end);
|
|
214
|
-
|
|
442
|
+
creating = false;
|
|
215
443
|
brushcreated(fx, fy, fx1, fy1, event);
|
|
216
444
|
};
|
|
217
445
|
|
|
218
446
|
// Hide mask.
|
|
219
447
|
const click = (event) => {
|
|
220
448
|
const { target } = event;
|
|
221
|
-
if (mask && target
|
|
449
|
+
if (mask && !isMask(target)) removeMask();
|
|
222
450
|
};
|
|
223
451
|
|
|
224
452
|
// Update cursor depends on hovered element.
|
|
225
453
|
const pointermove = (event) => {
|
|
226
454
|
const { target } = event;
|
|
227
|
-
if (
|
|
228
|
-
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);
|
|
229
458
|
};
|
|
230
459
|
|
|
231
460
|
const pointerleave = () => {
|
|
@@ -251,6 +480,9 @@ export function brush(
|
|
|
251
480
|
if (mask) removeMask();
|
|
252
481
|
},
|
|
253
482
|
destroy() {
|
|
483
|
+
// Do not emit brush:end event.
|
|
484
|
+
if (mask) removeMask(false);
|
|
485
|
+
setCursor(root, 'default');
|
|
254
486
|
root.removeEventListener('dragstart', dragstart);
|
|
255
487
|
root.removeEventListener('drag', drag);
|
|
256
488
|
root.removeEventListener('dragend', dragend);
|
|
@@ -291,6 +523,7 @@ export function brushHighlight(
|
|
|
291
523
|
root,
|
|
292
524
|
{
|
|
293
525
|
elements: elementof,
|
|
526
|
+
selectedHandles,
|
|
294
527
|
siblings: siblingsof = (root) => [],
|
|
295
528
|
datum,
|
|
296
529
|
brushRegion,
|
|
@@ -393,6 +626,7 @@ export function brushHighlight(
|
|
|
393
626
|
extent,
|
|
394
627
|
brushRegion,
|
|
395
628
|
reverse,
|
|
629
|
+
selectedHandles,
|
|
396
630
|
brushended: () => {
|
|
397
631
|
const handler = series ? seriesBrushend : brushended;
|
|
398
632
|
emitter.emit('brush:end', { nativeEvent: true });
|
|
@@ -423,9 +657,11 @@ export function brushHighlight(
|
|
|
423
657
|
emitter.on('brush:remove', onRemove);
|
|
424
658
|
|
|
425
659
|
// Remove event handlers.
|
|
660
|
+
const preBrushDestroy = brushHandler.destroy.bind(brushHandler);
|
|
426
661
|
brushHandler.destroy = () => {
|
|
427
662
|
emitter.off('brush:highlight', onHighlight);
|
|
428
663
|
emitter.off('brush:remove', onRemove);
|
|
664
|
+
preBrushDestroy();
|
|
429
665
|
};
|
|
430
666
|
|
|
431
667
|
return brushHandler;
|
|
@@ -464,6 +700,7 @@ export function BrushHighlight({ facet, brushKey, ...rest }) {
|
|
|
464
700
|
emitter,
|
|
465
701
|
scale,
|
|
466
702
|
coordinate,
|
|
703
|
+
selectedHandles: undefined,
|
|
467
704
|
...defaultOptions,
|
|
468
705
|
...rest,
|
|
469
706
|
});
|
|
@@ -488,6 +725,7 @@ export function BrushHighlight({ facet, brushKey, ...rest }) {
|
|
|
488
725
|
emitter,
|
|
489
726
|
scale,
|
|
490
727
|
coordinate,
|
|
728
|
+
selectedHandles: undefined,
|
|
491
729
|
...defaultOptions,
|
|
492
730
|
...rest,
|
|
493
731
|
});
|
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
|
|