@antv/g2 5.1.15 → 5.1.17

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 (74) hide show
  1. package/dist/g2.lite.min.js +1 -1
  2. package/dist/g2.min.js +1 -1
  3. package/esm/index.d.ts +2 -0
  4. package/esm/interaction/elementPointMove.d.ts +9 -0
  5. package/esm/interaction/elementPointMove.js +506 -0
  6. package/esm/interaction/elementPointMove.js.map +1 -0
  7. package/esm/interaction/event.js +1 -8
  8. package/esm/interaction/event.js.map +1 -1
  9. package/esm/interaction/index.d.ts +1 -0
  10. package/esm/interaction/index.js +1 -0
  11. package/esm/interaction/index.js.map +1 -1
  12. package/esm/interaction/tooltip.js +11 -4
  13. package/esm/interaction/tooltip.js.map +1 -1
  14. package/esm/interaction/treemapDrillDown.js +1 -4
  15. package/esm/interaction/treemapDrillDown.js.map +1 -1
  16. package/esm/interaction/utils.d.ts +8 -2
  17. package/esm/interaction/utils.js +49 -6
  18. package/esm/interaction/utils.js.map +1 -1
  19. package/esm/lib/core.d.ts +2 -1
  20. package/esm/lib/core.js +2 -1
  21. package/esm/lib/core.js.map +1 -1
  22. package/esm/lib/std.d.ts +1 -0
  23. package/esm/mark/gauge.js +4 -1
  24. package/esm/mark/gauge.js.map +1 -1
  25. package/esm/runtime/scale.js +3 -3
  26. package/esm/runtime/scale.js.map +1 -1
  27. package/esm/shape/gauge/round.d.ts +3 -0
  28. package/esm/shape/gauge/round.js +40 -0
  29. package/esm/shape/gauge/round.js.map +1 -0
  30. package/esm/shape/index.d.ts +1 -0
  31. package/esm/shape/index.js +1 -0
  32. package/esm/shape/index.js.map +1 -1
  33. package/lib/index.d.ts +2 -0
  34. package/lib/interaction/elementPointMove.d.ts +9 -0
  35. package/lib/interaction/elementPointMove.js +510 -0
  36. package/lib/interaction/elementPointMove.js.map +1 -0
  37. package/lib/interaction/event.js +4 -11
  38. package/lib/interaction/event.js.map +1 -1
  39. package/lib/interaction/index.d.ts +1 -0
  40. package/lib/interaction/index.js +3 -1
  41. package/lib/interaction/index.js.map +1 -1
  42. package/lib/interaction/tooltip.js +10 -3
  43. package/lib/interaction/tooltip.js.map +1 -1
  44. package/lib/interaction/treemapDrillDown.js +2 -5
  45. package/lib/interaction/treemapDrillDown.js.map +1 -1
  46. package/lib/interaction/utils.d.ts +8 -2
  47. package/lib/interaction/utils.js +54 -6
  48. package/lib/interaction/utils.js.map +1 -1
  49. package/lib/lib/core.d.ts +2 -1
  50. package/lib/lib/core.js +1 -0
  51. package/lib/lib/core.js.map +1 -1
  52. package/lib/lib/std.d.ts +1 -0
  53. package/lib/mark/gauge.js +4 -1
  54. package/lib/mark/gauge.js.map +1 -1
  55. package/lib/runtime/scale.js +3 -3
  56. package/lib/runtime/scale.js.map +1 -1
  57. package/lib/shape/gauge/round.d.ts +3 -0
  58. package/lib/shape/gauge/round.js +44 -0
  59. package/lib/shape/gauge/round.js.map +1 -0
  60. package/lib/shape/index.d.ts +1 -0
  61. package/lib/shape/index.js +3 -1
  62. package/lib/shape/index.js.map +1 -1
  63. package/package.json +2 -2
  64. package/src/interaction/elementPointMove.ts +659 -0
  65. package/src/interaction/event.ts +1 -7
  66. package/src/interaction/index.ts +1 -0
  67. package/src/interaction/tooltip.ts +11 -3
  68. package/src/interaction/treemapDrillDown.ts +1 -5
  69. package/src/interaction/utils.ts +69 -5
  70. package/src/lib/core.ts +2 -0
  71. package/src/mark/gauge.ts +5 -1
  72. package/src/runtime/scale.ts +3 -3
  73. package/src/shape/gauge/round.ts +57 -0
  74. package/src/shape/index.ts +1 -0
@@ -0,0 +1,659 @@
1
+ import { Text, Group, Circle, Path } from '@antv/g';
2
+ import { deepMix, isUndefined, find, get } from '@antv/util';
3
+ import type { CircleStyleProps, TextStyleProps, PathStyleProps } from '@antv/g';
4
+ import { subObject } from '../utils/helper';
5
+
6
+ import {
7
+ selectPlotArea,
8
+ getPointsR,
9
+ getPointsPath,
10
+ getElements,
11
+ getThetaPath,
12
+ } from './utils';
13
+
14
+ export type ElementPointMoveOptions = {
15
+ selection?: number[];
16
+ precision?: number;
17
+ [key: string]: any;
18
+ };
19
+
20
+ const DEFAULT_STYLE = {
21
+ pointR: 6,
22
+ pointStrokeWidth: 1,
23
+ pointStroke: '#888',
24
+ pointActiveStroke: '#f5f5f5',
25
+ pathStroke: '#888',
26
+ pathLineDash: [3, 4],
27
+ labelFontSize: 12,
28
+ labelFill: '#888',
29
+ labelStroke: '#fff',
30
+ labelLineWidth: 1,
31
+ labelY: -6,
32
+ labelX: 2,
33
+ };
34
+
35
+ // point shape name.
36
+ const MOVE_POINT_NAME = 'movePoint';
37
+
38
+ // Element mouseenter change style.
39
+ const elementMouseenter = (e) => {
40
+ const element = e.target;
41
+ const { markType } = element;
42
+ // Mark line.
43
+ if (markType === 'line') {
44
+ element.attr('_lineWidth', element.attr('lineWidth') || 1);
45
+ element.attr('lineWidth', element.attr('_lineWidth') + 3);
46
+ }
47
+ // Mark interval.
48
+ if (markType === 'interval') {
49
+ element.attr('_opacity', element.attr('opacity') || 1);
50
+ element.attr('opacity', 0.7 * element.attr('_opacity'));
51
+ }
52
+ };
53
+
54
+ // Element mouseleave change style.
55
+ const elementMouseleave = (e) => {
56
+ const element = e.target;
57
+ const { markType } = element;
58
+ // Mark line.
59
+ if (markType === 'line') {
60
+ element.attr('lineWidth', element.attr('_lineWidth'));
61
+ }
62
+ // Mark interval.
63
+ if (markType === 'interval') {
64
+ element.attr('opacity', element.attr('_opacity'));
65
+ }
66
+ };
67
+
68
+ // Get the latest overall data based on the individual data changes.
69
+ const getNewData = (newChangeData, data, encode) => {
70
+ return data.map((d) => {
71
+ const isUpdate = ['x', 'color'].reduce((v, key) => {
72
+ const field = encode[key];
73
+ if (!field) return v;
74
+
75
+ if (d[field] !== newChangeData[field]) return false;
76
+
77
+ return v;
78
+ }, true);
79
+
80
+ return isUpdate ? { ...d, ...newChangeData } : d;
81
+ });
82
+ };
83
+
84
+ // Find mark interval origin element data.
85
+ const getIntervalDataRatioTransformFn = (element) => {
86
+ const y = get(element, ['__data__', 'y']);
87
+ const y1 = get(element, ['__data__', 'y1']);
88
+ const v = y1 - y;
89
+
90
+ const {
91
+ __data__: { data, encode, transform },
92
+ childNodes,
93
+ } = element.parentNode;
94
+ const isNormalizeY = find(transform, ({ type }) => type === 'normalizeY');
95
+ const yField = get(encode, ['y', 'field']);
96
+ const value = data[childNodes.indexOf(element)][yField];
97
+
98
+ return (newValue, isTheta = false) => {
99
+ if (isNormalizeY || isTheta) {
100
+ return (newValue / (1 - newValue) / (v / (1 - v))) * value;
101
+ }
102
+
103
+ return newValue;
104
+ };
105
+ };
106
+
107
+ // Find origin path data.
108
+ const getPathDataRatioTransformFn = (element, index) => {
109
+ const v = get(element, ['__data__', 'seriesItems', index, '0', 'value']);
110
+ const i = get(element, ['__data__', 'seriesIndex', index]);
111
+
112
+ const {
113
+ __data__: { data, encode, transform },
114
+ } = element.parentNode;
115
+ const isNormalizeY = find(transform, ({ type }) => type === 'normalizeY');
116
+ const yField = get(encode, ['y', 'field']);
117
+ const value = data[i][yField];
118
+
119
+ return (newValue) => {
120
+ if (isNormalizeY) {
121
+ if (v === 1) {
122
+ return newValue;
123
+ }
124
+ return (newValue / (1 - newValue) / (v / (1 - v))) * value;
125
+ }
126
+
127
+ return newValue;
128
+ };
129
+ };
130
+
131
+ // Point shape select change style.
132
+ const selectedPointsStyle = (pointsShape, selection, defaultStyle) => {
133
+ pointsShape.forEach((shape, index) => {
134
+ shape.attr(
135
+ 'stroke',
136
+ selection[1] === index
137
+ ? defaultStyle['activeStroke']
138
+ : defaultStyle['stroke'],
139
+ );
140
+ });
141
+ };
142
+
143
+ // Create help show message shape.
144
+ const createHelpShape = (
145
+ group,
146
+ circle,
147
+ pathStyle,
148
+ labelStyle,
149
+ ): [Path, Text] => {
150
+ const pathShape = new Path({
151
+ style: pathStyle,
152
+ });
153
+
154
+ const labelShape = new Text({
155
+ style: labelStyle,
156
+ });
157
+
158
+ circle.appendChild(labelShape);
159
+ group.appendChild(pathShape);
160
+ return [pathShape, labelShape];
161
+ };
162
+
163
+ // Get color scale type.
164
+ const getColorType = (scaleColor, color) => {
165
+ const indexOf = get(scaleColor, ['options', 'range', 'indexOf']);
166
+ if (!indexOf) return;
167
+ const i = scaleColor.options.range.indexOf(color);
168
+ return scaleColor.sortedDomain[i];
169
+ };
170
+
171
+ // Get the same direction new point.
172
+ const getSamePointPosition = (center, point, target) => {
173
+ const oldR = getPointsR(center, point);
174
+ const newR = getPointsR(center, target);
175
+ const ratio = newR / oldR;
176
+ const newX = center[0] + (point[0] - center[0]) * ratio;
177
+ const newY = center[1] + (point[1] - center[1]) * ratio;
178
+ return [newX, newY];
179
+ };
180
+
181
+ /**
182
+ * ElementPointMove interaction.
183
+ */
184
+ export function ElementPointMove(
185
+ elementPointMoveOptions: ElementPointMoveOptions = {},
186
+ ) {
187
+ const { selection = [], precision = 2, ...style } = elementPointMoveOptions;
188
+
189
+ const defaultStyle = { ...DEFAULT_STYLE, ...(style || {}) };
190
+
191
+ // Shape default style.
192
+ const pathDefaultStyle = subObject(defaultStyle, 'path') as PathStyleProps;
193
+ const labelDefaultStyle = subObject(defaultStyle, 'label') as TextStyleProps;
194
+ const pointDefaultStyle = subObject(
195
+ defaultStyle,
196
+ 'point',
197
+ ) as CircleStyleProps;
198
+
199
+ return (context, _, emitter) => {
200
+ const {
201
+ update,
202
+ setState,
203
+ container,
204
+ view,
205
+ options: { marks, coordinate: coordinateOptions },
206
+ } = context;
207
+ const plotArea = selectPlotArea(container);
208
+ let elements = getElements(plotArea);
209
+ let newState;
210
+ let newSelection = selection;
211
+
212
+ const { transform = [], type: coordinateType } = coordinateOptions;
213
+ const isTranspose = !!find(transform, ({ type }) => type === 'transpose');
214
+ const isPolar = coordinateType === 'polar';
215
+ const isTheta = coordinateType === 'theta';
216
+ const isArea = !!find(elements, ({ markType }) => markType === 'area');
217
+
218
+ if (isArea) {
219
+ elements = elements.filter(({ markType }) => markType === 'area');
220
+ }
221
+
222
+ // Create points
223
+ const pointsGroup = new Group({
224
+ style: {
225
+ // Tooltip point need down.
226
+ zIndex: 2,
227
+ },
228
+ });
229
+ plotArea.appendChild(pointsGroup);
230
+
231
+ const selectedChange = () => {
232
+ emitter.emit('element-point:select', {
233
+ nativeEvent: true,
234
+ data: {
235
+ selection: newSelection,
236
+ },
237
+ });
238
+ };
239
+
240
+ const dataChange = (changeData, data) => {
241
+ emitter.emit('element-point:moved', {
242
+ nativeEvent: true,
243
+ data: {
244
+ changeData,
245
+ data,
246
+ },
247
+ });
248
+ };
249
+
250
+ // Element click change style.
251
+ const elementClick = (e) => {
252
+ const element = e.target;
253
+ newSelection = [element.parentNode.childNodes.indexOf(element)];
254
+ selectedChange();
255
+ createPoints(element);
256
+ };
257
+
258
+ const elementSelect = (d) => {
259
+ const {
260
+ data: { selection },
261
+ nativeEvent,
262
+ } = d;
263
+ if (nativeEvent) return;
264
+ newSelection = selection;
265
+ const element = get(elements, [newSelection?.[0]]);
266
+ if (element) {
267
+ createPoints(element);
268
+ }
269
+ };
270
+
271
+ // Create select element points.
272
+ const createPoints = (element) => {
273
+ const { attributes, markType, __data__: data } = element;
274
+ const { stroke: fill } = attributes;
275
+ const { points, seriesTitle, color, title, seriesX, y1 } = data;
276
+ // Transpose Currently only do mark interval;
277
+ if (isTranspose && markType !== 'interval') return;
278
+
279
+ const { scale, coordinate } = newState?.view || view;
280
+ const { color: scaleColor, y: scaleY, x: scaleX } = scale;
281
+ const center = coordinate.getCenter();
282
+
283
+ pointsGroup.removeChildren();
284
+ let downPoint;
285
+
286
+ const updateView = async (x, y, color, markTypes) => {
287
+ setState('elementPointMove', (viewOptions) => {
288
+ // Update marks.
289
+ const newMarks = (newState?.options?.marks || marks).map((mark) => {
290
+ if (!markTypes.includes(mark.type)) return mark;
291
+ const { data, encode } = mark;
292
+ const encodeKeys = Object.keys(encode);
293
+
294
+ // Get change new one element data.
295
+ const newChangeData = encodeKeys.reduce((value, key) => {
296
+ const dataKey = encode[key];
297
+ if (key === 'x') {
298
+ value[dataKey] = x;
299
+ }
300
+ if (key === 'y') {
301
+ value[dataKey] = y;
302
+ }
303
+ if (key === 'color') {
304
+ value[dataKey] = color;
305
+ }
306
+ return value;
307
+ }, {} as any);
308
+ // Get change new all data.
309
+ const newData = getNewData(newChangeData, data, encode);
310
+ dataChange(newChangeData, newData);
311
+
312
+ return deepMix({}, mark, {
313
+ data: newData,
314
+ // No need animate
315
+ animate: false,
316
+ });
317
+ });
318
+
319
+ return { ...viewOptions, marks: newMarks };
320
+ });
321
+
322
+ return await update('elementPointMove');
323
+ };
324
+
325
+ if (['line', 'area'].includes(markType)) {
326
+ points.forEach((p, index) => {
327
+ const title = scaleX.invert(seriesX[index]);
328
+
329
+ // Area points have bottom point.
330
+ if (!title) return;
331
+
332
+ const circle = new Circle({
333
+ name: MOVE_POINT_NAME,
334
+ style: {
335
+ cx: p[0],
336
+ cy: p[1],
337
+ fill,
338
+ ...pointDefaultStyle,
339
+ },
340
+ });
341
+
342
+ const ratioTransform = getPathDataRatioTransformFn(element, index);
343
+
344
+ circle.addEventListener('mousedown', (e) => {
345
+ const oldPoint = coordinate.output([seriesX[index], 0]);
346
+ const pathLength = seriesTitle?.length;
347
+
348
+ container.attr('cursor', 'move');
349
+
350
+ if (newSelection[1] !== index) {
351
+ newSelection[1] = index;
352
+ selectedChange();
353
+ }
354
+ selectedPointsStyle(
355
+ pointsGroup.childNodes,
356
+ newSelection,
357
+ pointDefaultStyle,
358
+ );
359
+
360
+ const [pathShape, labelShape] = createHelpShape(
361
+ pointsGroup,
362
+ circle,
363
+ pathDefaultStyle,
364
+ labelDefaultStyle,
365
+ );
366
+
367
+ // Point move change text
368
+ const pointMousemove = (e) => {
369
+ const newCy = p[1] + e.clientY - downPoint[1];
370
+ // Area/Radar chart.
371
+ if (isArea) {
372
+ // Radar chart.
373
+ if (isPolar) {
374
+ const newCx = p[0] + e.clientX - downPoint[0];
375
+
376
+ const [newX, newY] = getSamePointPosition(center, oldPoint, [
377
+ newCx,
378
+ newCy,
379
+ ]);
380
+
381
+ const [, initY] = coordinate.output([1, scaleY.output(0)]);
382
+ const [, y] = coordinate.invert([
383
+ newX,
384
+ initY - (points[index + pathLength][1] - newY),
385
+ ]);
386
+
387
+ const nextIndex = (index + 1) % pathLength;
388
+ const lastIndex = (index - 1 + pathLength) % pathLength;
389
+ const newPath = getPointsPath([
390
+ points[lastIndex],
391
+ [newX, newY],
392
+ seriesTitle[nextIndex] && points[nextIndex],
393
+ ]);
394
+ labelShape.attr(
395
+ 'text',
396
+ ratioTransform(scaleY.invert(y)).toFixed(precision),
397
+ );
398
+ pathShape.attr('path', newPath);
399
+ circle.attr('cx', newX);
400
+ circle.attr('cy', newY);
401
+ } else {
402
+ // Area chart.
403
+ const [, initY] = coordinate.output([1, scaleY.output(0)]);
404
+ const [, y] = coordinate.invert([
405
+ p[0],
406
+ initY - (points[index + pathLength][1] - newCy),
407
+ ]);
408
+ const newPath = getPointsPath([
409
+ points[index - 1],
410
+ [p[0], newCy],
411
+ seriesTitle[index + 1] && points[index + 1],
412
+ ]);
413
+ labelShape.attr(
414
+ 'text',
415
+ ratioTransform(scaleY.invert(y)).toFixed(precision),
416
+ );
417
+ pathShape.attr('path', newPath);
418
+ circle.attr('cy', newCy);
419
+ }
420
+ } else {
421
+ // Line chart.
422
+ const [, y] = coordinate.invert([p[0], newCy]);
423
+ const newPath = getPointsPath([
424
+ points[index - 1],
425
+ [p[0], newCy],
426
+ points[index + 1],
427
+ ]);
428
+ labelShape.attr('text', scaleY.invert(y).toFixed(precision));
429
+ pathShape.attr('path', newPath);
430
+ circle.attr('cy', newCy);
431
+ }
432
+ };
433
+
434
+ downPoint = [e.clientX, e.clientY];
435
+ window.addEventListener('mousemove', pointMousemove);
436
+
437
+ const mouseupFn = async () => {
438
+ container.attr('cursor', 'default');
439
+ window.removeEventListener('mousemove', pointMousemove);
440
+ container.removeEventListener('mouseup', mouseupFn);
441
+
442
+ if (isUndefined(labelShape.attr('text'))) return;
443
+
444
+ const y = Number(labelShape.attr('text'));
445
+ const colorType = getColorType(scaleColor, color);
446
+ newState = await updateView(title, y, colorType, [
447
+ 'line',
448
+ 'area',
449
+ ]);
450
+
451
+ labelShape.remove();
452
+ pathShape.remove();
453
+ createPoints(element);
454
+ };
455
+
456
+ container.addEventListener('mouseup', mouseupFn);
457
+ });
458
+
459
+ pointsGroup.appendChild(circle);
460
+ });
461
+
462
+ selectedPointsStyle(
463
+ pointsGroup.childNodes,
464
+ newSelection,
465
+ pointDefaultStyle,
466
+ );
467
+ } else if (markType === 'interval') {
468
+ // Column chart point.
469
+ let circlePoint = [(points[0][0] + points[1][0]) / 2, points[0][1]];
470
+ // Bar chart point.
471
+ if (isTranspose) {
472
+ circlePoint = [points[0][0], (points[0][1] + points[1][1]) / 2];
473
+ } else if (isTheta) {
474
+ // Pie chart point.
475
+ circlePoint = points[0];
476
+ }
477
+
478
+ const ratioTransform = getIntervalDataRatioTransformFn(element);
479
+
480
+ const circle = new Circle({
481
+ name: MOVE_POINT_NAME,
482
+ style: {
483
+ cx: circlePoint[0],
484
+ cy: circlePoint[1],
485
+ fill,
486
+ ...pointDefaultStyle,
487
+ stroke: pointDefaultStyle['activeStroke'],
488
+ },
489
+ });
490
+
491
+ circle.addEventListener('mousedown', (e) => {
492
+ container.attr('cursor', 'move');
493
+
494
+ const colorType = getColorType(scaleColor, color);
495
+
496
+ const [pathShape, labelShape] = createHelpShape(
497
+ pointsGroup,
498
+ circle,
499
+ pathDefaultStyle,
500
+ labelDefaultStyle,
501
+ );
502
+
503
+ // Point move change text
504
+ const pointMousemove = (e) => {
505
+ if (isTranspose) {
506
+ // Bar chart.
507
+ const newCx = circlePoint[0] + e.clientX - downPoint[0];
508
+ const [initX] = coordinate.output([
509
+ scaleY.output(0),
510
+ scaleY.output(0),
511
+ ]);
512
+
513
+ const [, x] = coordinate.invert([
514
+ initX + (newCx - points[2][0]),
515
+ circlePoint[1],
516
+ ]);
517
+ const newPath = getPointsPath(
518
+ [
519
+ [newCx, points[0][1]],
520
+ [newCx, points[1][1]],
521
+ points[2],
522
+ points[3],
523
+ ],
524
+ true,
525
+ );
526
+
527
+ labelShape.attr(
528
+ 'text',
529
+ ratioTransform(scaleY.invert(x)).toFixed(precision),
530
+ );
531
+ pathShape.attr('path', newPath);
532
+ circle.attr('cx', newCx);
533
+ } else if (isTheta) {
534
+ // Pie chart.
535
+ const newCy = circlePoint[1] + e.clientY - downPoint[1];
536
+ const newCx = circlePoint[0] + e.clientX - downPoint[0];
537
+
538
+ const [newXOut, newYOut] = getSamePointPosition(
539
+ center,
540
+ [newCx, newCy],
541
+ circlePoint,
542
+ );
543
+ const [newXIn, newYIn] = getSamePointPosition(
544
+ center,
545
+ [newCx, newCy],
546
+ points[1],
547
+ );
548
+ const lastPercent = coordinate.invert([newXOut, newYOut])[1];
549
+ const percent = y1 - lastPercent;
550
+
551
+ if (percent < 0) return;
552
+ const newPath = getThetaPath(
553
+ center,
554
+ [[newXOut, newYOut], [newXIn, newYIn], points[2], points[3]],
555
+ percent > 0.5 ? 1 : 0,
556
+ );
557
+
558
+ labelShape.attr(
559
+ 'text',
560
+ ratioTransform(percent, true).toFixed(precision),
561
+ );
562
+ pathShape.attr('path', newPath);
563
+ circle.attr('cx', newXOut);
564
+ circle.attr('cy', newYOut);
565
+ } else {
566
+ // Column chart.
567
+ const newCy = circlePoint[1] + e.clientY - downPoint[1];
568
+ const [, initY] = coordinate.output([1, scaleY.output(0)]);
569
+
570
+ const [, y] = coordinate.invert([
571
+ circlePoint[0],
572
+ initY - (points[2][1] - newCy),
573
+ ]);
574
+ const newPath = getPointsPath(
575
+ [
576
+ [points[0][0], newCy],
577
+ [points[1][0], newCy],
578
+ points[2],
579
+ points[3],
580
+ ],
581
+ true,
582
+ );
583
+
584
+ labelShape.attr(
585
+ 'text',
586
+ ratioTransform(scaleY.invert(y)).toFixed(precision),
587
+ );
588
+ pathShape.attr('path', newPath);
589
+ circle.attr('cy', newCy);
590
+ }
591
+ };
592
+
593
+ downPoint = [e.clientX, e.clientY];
594
+ window.addEventListener('mousemove', pointMousemove);
595
+
596
+ // Change mosueup change data and update 、clear shape.
597
+ const mouseupFn = async () => {
598
+ container.attr('cursor', 'default');
599
+ container.removeEventListener('mouseup', mouseupFn);
600
+ window.removeEventListener('mousemove', pointMousemove);
601
+
602
+ if (isUndefined(labelShape.attr('text'))) return;
603
+
604
+ const y = Number(labelShape.attr('text'));
605
+
606
+ newState = await updateView(title, y, colorType, [markType]);
607
+
608
+ labelShape.remove();
609
+ pathShape.remove();
610
+ createPoints(element);
611
+ };
612
+
613
+ container.addEventListener('mouseup', mouseupFn);
614
+ });
615
+
616
+ pointsGroup.appendChild(circle);
617
+ }
618
+ };
619
+
620
+ // Add EventListener.
621
+ elements.forEach((element, index) => {
622
+ if (newSelection[0] === index) {
623
+ createPoints(element);
624
+ }
625
+ element.addEventListener('click', elementClick);
626
+ element.addEventListener('mouseenter', elementMouseenter);
627
+ element.addEventListener('mouseleave', elementMouseleave);
628
+ });
629
+
630
+ const rootClick = (e) => {
631
+ const element = e?.target;
632
+ if (
633
+ !element ||
634
+ (element.name !== MOVE_POINT_NAME && !elements.includes(element))
635
+ ) {
636
+ newSelection = [];
637
+ selectedChange();
638
+ pointsGroup.removeChildren();
639
+ }
640
+ };
641
+
642
+ emitter.on('element-point:select', elementSelect);
643
+ emitter.on('element-point:unselect', rootClick);
644
+ container.addEventListener('mousedown', rootClick);
645
+
646
+ // Remove EventListener.
647
+ return () => {
648
+ pointsGroup.remove();
649
+ emitter.off('element-point:select', elementSelect);
650
+ emitter.off('element-point:unselect', rootClick);
651
+ container.removeEventListener('mousedown', rootClick);
652
+ elements.forEach((element) => {
653
+ element.removeEventListener('click', elementClick);
654
+ element.removeEventListener('mouseenter', elementMouseenter);
655
+ element.removeEventListener('mouseleave', elementMouseleave);
656
+ });
657
+ };
658
+ };
659
+ }
@@ -1,4 +1,5 @@
1
1
  import { ChartEvent } from '../utils/event';
2
+ import { maybeRoot } from './utils';
2
3
 
3
4
  export function dataOf(element, view) {
4
5
  const { __data__: datum } = element;
@@ -14,13 +15,6 @@ export function dataOf(element, view) {
14
15
  return selectedMark.data[index];
15
16
  }
16
17
 
17
- function maybeRoot(node, rootOf) {
18
- if (rootOf(node)) return node;
19
- let root = node.parent;
20
- while (root && !rootOf(root)) root = root.parent;
21
- return root;
22
- }
23
-
24
18
  // For extended component
25
19
  function maybeComponentRoot(node) {
26
20
  return maybeRoot(node, (node) => node.className === 'component');
@@ -21,3 +21,4 @@ export { ScrollbarFilter } from './scrollbarFilter';
21
21
  export { Poptip } from './poptip';
22
22
  export { Event } from './event';
23
23
  export { TreemapDrillDown } from './treemapDrillDown';
24
+ export { ElementPointMove } from './elementPointMove';