@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.
Files changed (297) hide show
  1. package/dist/g2-lite.min.js +4 -4
  2. package/dist/g2.min.js +4 -4
  3. package/esm/animation/morphing.js +4 -0
  4. package/esm/animation/morphing.js.map +1 -1
  5. package/esm/api/chart.d.ts +4 -7
  6. package/esm/api/chart.js +22 -90
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/api/mark/index.d.ts +3 -1
  9. package/esm/api/mark/index.js +2 -1
  10. package/esm/api/mark/index.js.map +1 -1
  11. package/esm/api/mark/mark.d.ts +7 -1
  12. package/esm/api/mark/mark.js +9 -0
  13. package/esm/api/mark/mark.js.map +1 -1
  14. package/esm/api/utils.d.ts +10 -0
  15. package/esm/api/utils.js +71 -0
  16. package/esm/api/utils.js.map +1 -0
  17. package/esm/component/axis.js +17 -19
  18. package/esm/component/axis.js.map +1 -1
  19. package/esm/component/axisX.js +3 -1
  20. package/esm/component/axisX.js.map +1 -1
  21. package/esm/component/axisY.js +1 -1
  22. package/esm/component/axisY.js.map +1 -1
  23. package/esm/component/constant.js +6 -0
  24. package/esm/component/constant.js.map +1 -1
  25. package/esm/component/legendCategory.js +8 -5
  26. package/esm/component/legendCategory.js.map +1 -1
  27. package/esm/component/legendContinuous.js +91 -33
  28. package/esm/component/legendContinuous.js.map +1 -1
  29. package/esm/component/utils.d.ts +9 -5
  30. package/esm/component/utils.js +14 -14
  31. package/esm/component/utils.js.map +1 -1
  32. package/esm/composition/mark.js +2 -1
  33. package/esm/composition/mark.js.map +1 -1
  34. package/esm/data/index.d.ts +2 -0
  35. package/esm/data/index.js +1 -0
  36. package/esm/data/index.js.map +1 -1
  37. package/esm/data/kde.d.ts +10 -0
  38. package/esm/data/kde.js +30 -0
  39. package/esm/data/kde.js.map +1 -0
  40. package/esm/interaction/brushFilter.js +2 -6
  41. package/esm/interaction/brushFilter.js.map +1 -1
  42. package/esm/interaction/brushHighlight.d.ts +3 -2
  43. package/esm/interaction/brushHighlight.js +202 -28
  44. package/esm/interaction/brushHighlight.js.map +1 -1
  45. package/esm/interaction/brushXHighlight.js +1 -1
  46. package/esm/interaction/brushXHighlight.js.map +1 -1
  47. package/esm/interaction/brushYHighlight.js +1 -1
  48. package/esm/interaction/brushYHighlight.js.map +1 -1
  49. package/esm/interaction/event.d.ts +1 -0
  50. package/esm/interaction/event.js +14 -12
  51. package/esm/interaction/event.js.map +1 -1
  52. package/esm/interaction/tooltip.d.ts +4 -4
  53. package/esm/interaction/tooltip.js +103 -31
  54. package/esm/interaction/tooltip.js.map +1 -1
  55. package/esm/mark/density.d.ts +4 -0
  56. package/esm/mark/density.js +61 -0
  57. package/esm/mark/density.js.map +1 -0
  58. package/esm/mark/gauge.d.ts +7 -0
  59. package/esm/mark/gauge.js +4 -6
  60. package/esm/mark/gauge.js.map +1 -1
  61. package/esm/mark/index.d.ts +2 -0
  62. package/esm/mark/index.js +1 -0
  63. package/esm/mark/index.js.map +1 -1
  64. package/esm/runtime/component.d.ts +4 -2
  65. package/esm/runtime/component.js +164 -12
  66. package/esm/runtime/component.js.map +1 -1
  67. package/esm/runtime/layout.d.ts +3 -3
  68. package/esm/runtime/layout.js +40 -21
  69. package/esm/runtime/layout.js.map +1 -1
  70. package/esm/runtime/plot.js +10 -7
  71. package/esm/runtime/plot.js.map +1 -1
  72. package/esm/runtime/scale.js +2 -2
  73. package/esm/runtime/scale.js.map +1 -1
  74. package/esm/runtime/transform.js +4 -1
  75. package/esm/runtime/transform.js.map +1 -1
  76. package/esm/runtime/types/component.d.ts +1 -0
  77. package/esm/shape/area/area.js +1 -1
  78. package/esm/shape/area/area.js.map +1 -1
  79. package/esm/shape/area/curve.js +1 -1
  80. package/esm/shape/area/curve.js.map +1 -1
  81. package/esm/shape/box/violin.d.ts +3 -0
  82. package/esm/shape/box/violin.js +85 -0
  83. package/esm/shape/box/violin.js.map +1 -0
  84. package/esm/shape/connector/connector.js +1 -1
  85. package/esm/shape/density/density.d.ts +8 -0
  86. package/esm/shape/density/density.js +50 -0
  87. package/esm/shape/density/density.js.map +1 -0
  88. package/esm/shape/index.d.ts +4 -0
  89. package/esm/shape/index.js +2 -0
  90. package/esm/shape/index.js.map +1 -1
  91. package/esm/shape/line/curve.js +1 -1
  92. package/esm/shape/line/curve.js.map +1 -1
  93. package/esm/shape/text/advance.d.ts +1 -1
  94. package/esm/shape/text/advance.js +1 -1
  95. package/esm/shape/text/advance.js.map +1 -1
  96. package/esm/shape/text/badge.js +1 -1
  97. package/esm/shape/utils.js +1 -1
  98. package/esm/shape/utils.js.map +1 -1
  99. package/esm/spec/composition.d.ts +22 -19
  100. package/esm/spec/dataTransform.d.ts +34 -2
  101. package/esm/spec/interaction.d.ts +3 -1
  102. package/esm/spec/mark.d.ts +9 -8
  103. package/esm/spec/transform.d.ts +1 -1
  104. package/esm/spec/utils.d.ts +1 -0
  105. package/esm/stdlib/index.js +5 -5
  106. package/esm/stdlib/index.js.map +1 -1
  107. package/esm/theme/classic.js +3 -0
  108. package/esm/theme/classic.js.map +1 -1
  109. package/esm/theme/classicDark.js +1 -0
  110. package/esm/theme/classicDark.js.map +1 -1
  111. package/esm/transform/filter.js +6 -2
  112. package/esm/transform/filter.js.map +1 -1
  113. package/esm/{shape → utils}/createElement.d.ts +1 -1
  114. package/esm/{shape → utils}/createElement.js.map +1 -1
  115. package/esm/utils/helper.d.ts +3 -0
  116. package/esm/utils/helper.js +3 -0
  117. package/esm/utils/helper.js.map +1 -1
  118. package/esm/utils/scale.js +5 -1
  119. package/esm/utils/scale.js.map +1 -1
  120. package/esm/utils/size.js +7 -4
  121. package/esm/utils/size.js.map +1 -1
  122. package/lib/animation/morphing.js +4 -0
  123. package/lib/animation/morphing.js.map +1 -1
  124. package/lib/api/chart.d.ts +4 -7
  125. package/lib/api/chart.js +27 -97
  126. package/lib/api/chart.js.map +1 -1
  127. package/lib/api/mark/index.d.ts +3 -1
  128. package/lib/api/mark/index.js +1 -0
  129. package/lib/api/mark/index.js.map +1 -1
  130. package/lib/api/mark/mark.d.ts +7 -1
  131. package/lib/api/mark/mark.js +10 -1
  132. package/lib/api/mark/mark.js.map +1 -1
  133. package/lib/api/utils.d.ts +10 -0
  134. package/lib/api/utils.js +80 -0
  135. package/lib/api/utils.js.map +1 -0
  136. package/lib/component/axis.js +17 -19
  137. package/lib/component/axis.js.map +1 -1
  138. package/lib/component/axisX.js +3 -1
  139. package/lib/component/axisX.js.map +1 -1
  140. package/lib/component/axisY.js +1 -1
  141. package/lib/component/axisY.js.map +1 -1
  142. package/lib/component/constant.js +6 -0
  143. package/lib/component/constant.js.map +1 -1
  144. package/lib/component/legendCategory.js +7 -4
  145. package/lib/component/legendCategory.js.map +1 -1
  146. package/lib/component/legendContinuous.js +90 -32
  147. package/lib/component/legendContinuous.js.map +1 -1
  148. package/lib/component/utils.d.ts +9 -5
  149. package/lib/component/utils.js +16 -15
  150. package/lib/component/utils.js.map +1 -1
  151. package/lib/composition/mark.js +2 -1
  152. package/lib/composition/mark.js.map +1 -1
  153. package/lib/data/index.d.ts +2 -0
  154. package/lib/data/index.js +3 -1
  155. package/lib/data/index.js.map +1 -1
  156. package/lib/data/kde.d.ts +10 -0
  157. package/lib/data/kde.js +38 -0
  158. package/lib/data/kde.js.map +1 -0
  159. package/lib/interaction/brushFilter.js +2 -6
  160. package/lib/interaction/brushFilter.js.map +1 -1
  161. package/lib/interaction/brushHighlight.d.ts +3 -2
  162. package/lib/interaction/brushHighlight.js +201 -27
  163. package/lib/interaction/brushHighlight.js.map +1 -1
  164. package/lib/interaction/brushXHighlight.js +1 -1
  165. package/lib/interaction/brushXHighlight.js.map +1 -1
  166. package/lib/interaction/brushYHighlight.js +1 -1
  167. package/lib/interaction/brushYHighlight.js.map +1 -1
  168. package/lib/interaction/event.d.ts +1 -0
  169. package/lib/interaction/event.js +15 -12
  170. package/lib/interaction/event.js.map +1 -1
  171. package/lib/interaction/tooltip.d.ts +4 -4
  172. package/lib/interaction/tooltip.js +102 -30
  173. package/lib/interaction/tooltip.js.map +1 -1
  174. package/lib/mark/density.d.ts +4 -0
  175. package/lib/mark/density.js +65 -0
  176. package/lib/mark/density.js.map +1 -0
  177. package/lib/mark/gauge.d.ts +7 -0
  178. package/lib/mark/gauge.js +4 -6
  179. package/lib/mark/gauge.js.map +1 -1
  180. package/lib/mark/index.d.ts +2 -0
  181. package/lib/mark/index.js +3 -1
  182. package/lib/mark/index.js.map +1 -1
  183. package/lib/runtime/component.d.ts +4 -2
  184. package/lib/runtime/component.js +163 -10
  185. package/lib/runtime/component.js.map +1 -1
  186. package/lib/runtime/layout.d.ts +3 -3
  187. package/lib/runtime/layout.js +40 -21
  188. package/lib/runtime/layout.js.map +1 -1
  189. package/lib/runtime/plot.js +10 -7
  190. package/lib/runtime/plot.js.map +1 -1
  191. package/lib/runtime/scale.js +2 -2
  192. package/lib/runtime/scale.js.map +1 -1
  193. package/lib/runtime/transform.js +4 -1
  194. package/lib/runtime/transform.js.map +1 -1
  195. package/lib/runtime/types/component.d.ts +1 -0
  196. package/lib/shape/area/area.js +1 -1
  197. package/lib/shape/area/area.js.map +1 -1
  198. package/lib/shape/area/curve.js +1 -1
  199. package/lib/shape/area/curve.js.map +1 -1
  200. package/lib/shape/box/violin.d.ts +3 -0
  201. package/lib/shape/box/violin.js +89 -0
  202. package/lib/shape/box/violin.js.map +1 -0
  203. package/lib/shape/connector/connector.js +1 -1
  204. package/lib/shape/density/density.d.ts +8 -0
  205. package/lib/shape/density/density.js +54 -0
  206. package/lib/shape/density/density.js.map +1 -0
  207. package/lib/shape/index.d.ts +4 -0
  208. package/lib/shape/index.js +6 -1
  209. package/lib/shape/index.js.map +1 -1
  210. package/lib/shape/line/curve.js +1 -1
  211. package/lib/shape/line/curve.js.map +1 -1
  212. package/lib/shape/text/advance.d.ts +1 -1
  213. package/lib/shape/text/advance.js +1 -1
  214. package/lib/shape/text/advance.js.map +1 -1
  215. package/lib/shape/text/badge.js +1 -1
  216. package/lib/shape/utils.js +1 -1
  217. package/lib/shape/utils.js.map +1 -1
  218. package/lib/spec/composition.d.ts +22 -19
  219. package/lib/spec/dataTransform.d.ts +34 -2
  220. package/lib/spec/interaction.d.ts +3 -1
  221. package/lib/spec/mark.d.ts +9 -8
  222. package/lib/spec/transform.d.ts +1 -1
  223. package/lib/spec/utils.d.ts +1 -0
  224. package/lib/stdlib/index.js +2 -2
  225. package/lib/stdlib/index.js.map +1 -1
  226. package/lib/theme/classic.js +3 -0
  227. package/lib/theme/classic.js.map +1 -1
  228. package/lib/theme/classicDark.js +1 -0
  229. package/lib/theme/classicDark.js.map +1 -1
  230. package/lib/transform/filter.js +6 -2
  231. package/lib/transform/filter.js.map +1 -1
  232. package/lib/{shape → utils}/createElement.d.ts +1 -1
  233. package/lib/{shape → utils}/createElement.js.map +1 -1
  234. package/lib/utils/helper.d.ts +3 -0
  235. package/lib/utils/helper.js +5 -1
  236. package/lib/utils/helper.js.map +1 -1
  237. package/lib/utils/scale.js +5 -1
  238. package/lib/utils/scale.js.map +1 -1
  239. package/lib/utils/size.js +7 -4
  240. package/lib/utils/size.js.map +1 -1
  241. package/package.json +5 -3
  242. package/src/animation/morphing.ts +5 -0
  243. package/src/api/chart.ts +30 -113
  244. package/src/api/mark/index.ts +3 -0
  245. package/src/api/mark/mark.ts +12 -0
  246. package/src/api/utils.ts +79 -0
  247. package/src/component/axis.ts +22 -18
  248. package/src/component/axisX.ts +3 -1
  249. package/src/component/axisY.ts +2 -1
  250. package/src/component/constant.ts +6 -0
  251. package/src/component/legendCategory.ts +19 -6
  252. package/src/component/legendContinuous.ts +185 -74
  253. package/src/component/utils.ts +14 -3
  254. package/src/composition/mark.ts +2 -0
  255. package/src/data/index.ts +2 -0
  256. package/src/data/kde.ts +53 -0
  257. package/src/interaction/brushFilter.ts +8 -6
  258. package/src/interaction/brushHighlight.ts +258 -20
  259. package/src/interaction/brushXHighlight.ts +1 -0
  260. package/src/interaction/brushYHighlight.ts +1 -0
  261. package/src/interaction/event.ts +19 -13
  262. package/src/interaction/tooltip.ts +154 -25
  263. package/src/mark/density.ts +81 -0
  264. package/src/mark/gauge.ts +13 -7
  265. package/src/mark/index.ts +2 -0
  266. package/src/runtime/component.ts +210 -12
  267. package/src/runtime/layout.ts +74 -19
  268. package/src/runtime/plot.ts +8 -6
  269. package/src/runtime/scale.ts +2 -2
  270. package/src/runtime/transform.ts +2 -1
  271. package/src/runtime/types/component.ts +1 -0
  272. package/src/shape/area/area.ts +1 -1
  273. package/src/shape/area/curve.ts +1 -1
  274. package/src/shape/box/violin.ts +119 -0
  275. package/src/shape/connector/connector.ts +1 -1
  276. package/src/shape/density/density.ts +52 -0
  277. package/src/shape/index.ts +4 -0
  278. package/src/shape/line/curve.ts +1 -1
  279. package/src/shape/text/advance.ts +1 -1
  280. package/src/shape/text/badge.ts +1 -1
  281. package/src/shape/utils.ts +1 -1
  282. package/src/spec/composition.ts +22 -19
  283. package/src/spec/dataTransform.ts +35 -0
  284. package/src/spec/interaction.ts +3 -2
  285. package/src/spec/mark.ts +10 -6
  286. package/src/spec/transform.ts +1 -0
  287. package/src/spec/utils.ts +2 -0
  288. package/src/stdlib/index.ts +8 -0
  289. package/src/theme/classic.ts +3 -0
  290. package/src/theme/classicDark.ts +1 -0
  291. package/src/transform/filter.ts +6 -2
  292. package/src/{shape → utils}/createElement.ts +1 -1
  293. package/src/utils/helper.ts +12 -1
  294. package/src/utils/scale.ts +5 -1
  295. package/src/utils/size.ts +10 -4
  296. /package/esm/{shape → utils}/createElement.js +0 -0
  297. /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 resizing = false;
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 Rect({
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 Rect({
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
- resizing = false;
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 (target === mask) {
185
- moveStart = [offsetX, offsetY];
397
+ if (!mask || !isMask(target)) {
398
+ initMask(offsetX, offsetY);
399
+ creating = true;
186
400
  return;
187
401
  }
188
- initMask(offsetX, offsetY);
189
- resizing = true;
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
- if (moveStart) return moveMask(mouse);
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 resizing.
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
- resizing = false;
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 !== mask) removeMask();
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 (target === mask && !resizing) setCursor(root, 'move');
228
- else setCursor(root, 'crosshair');
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
  });
@@ -9,5 +9,6 @@ export function BrushXHighlight(options) {
9
9
  return BrushHighlight({
10
10
  ...options,
11
11
  brushRegion: brushXRegion,
12
+ selectedHandles: ['handle-e', 'handle-w'],
12
13
  });
13
14
  }
@@ -9,5 +9,6 @@ export function BrushYHighlight(options) {
9
9
  return BrushHighlight({
10
10
  ...options,
11
11
  brushRegion: brushYRegion,
12
+ selectedHandles: ['handle-n', 'handle-s'],
12
13
  });
13
14
  }
@@ -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
- updateData(e, target, view);
30
- emitter.emit(`element:${eventType}`, e);
31
- emitter.emit(`${markType}:${eventType}`, e);
32
- return;
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