@antv/g2 4.2.4 → 4.2.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.
Files changed (91) hide show
  1. package/README.en-US.md +2 -2
  2. package/README.md +2 -2
  3. package/dist/g2.min.js +1 -1
  4. package/dist/g2.min.js.map +1 -1
  5. package/esm/animate/animation/sector-path-update.js +3 -2
  6. package/esm/animate/animation/sector-path-update.js.map +1 -1
  7. package/esm/chart/controller/annotation.js +3 -2
  8. package/esm/chart/controller/annotation.js.map +1 -1
  9. package/esm/chart/controller/slider.js +4 -4
  10. package/esm/chart/controller/slider.js.map +1 -1
  11. package/esm/chart/controller/tooltip.js +4 -8
  12. package/esm/chart/controller/tooltip.js.map +1 -1
  13. package/esm/component/labels.js +2 -1
  14. package/esm/component/labels.js.map +1 -1
  15. package/esm/core.d.ts +1 -1
  16. package/esm/core.js +1 -1
  17. package/esm/core.js.map +1 -1
  18. package/esm/geometry/label/interface.d.ts +4 -0
  19. package/esm/geometry/label/interface.js.map +1 -1
  20. package/esm/geometry/label/layout/hide-overlap.d.ts +1 -1
  21. package/esm/geometry/label/layout/hide-overlap.js +46 -39
  22. package/esm/geometry/label/layout/hide-overlap.js.map +1 -1
  23. package/esm/geometry/label/util/createWorker.d.ts +9 -1
  24. package/esm/geometry/label/util/createWorker.js +36 -2
  25. package/esm/geometry/label/util/createWorker.js.map +1 -1
  26. package/esm/geometry/shape/area/index.js +1 -0
  27. package/esm/geometry/shape/area/index.js.map +1 -1
  28. package/esm/geometry/shape/area/smooth.js +1 -0
  29. package/esm/geometry/shape/area/smooth.js.map +1 -1
  30. package/esm/geometry/shape/interval/index.js +3 -1
  31. package/esm/geometry/shape/interval/index.js.map +1 -1
  32. package/esm/index.js +2 -2
  33. package/esm/index.js.map +1 -1
  34. package/esm/interaction/action/active-region.d.ts +1 -1
  35. package/esm/interaction/action/active-region.js.map +1 -1
  36. package/esm/interaction/action/cursor.d.ts +8 -0
  37. package/esm/interaction/action/cursor.js +12 -0
  38. package/esm/interaction/action/cursor.js.map +1 -1
  39. package/esm/util/coordinate.js.map +1 -1
  40. package/lib/animate/animation/sector-path-update.js +3 -2
  41. package/lib/animate/animation/sector-path-update.js.map +1 -1
  42. package/lib/chart/controller/annotation.js +3 -2
  43. package/lib/chart/controller/annotation.js.map +1 -1
  44. package/lib/chart/controller/slider.js +4 -4
  45. package/lib/chart/controller/slider.js.map +1 -1
  46. package/lib/chart/controller/tooltip.js +3 -7
  47. package/lib/chart/controller/tooltip.js.map +1 -1
  48. package/lib/component/labels.js +2 -1
  49. package/lib/component/labels.js.map +1 -1
  50. package/lib/core.d.ts +1 -1
  51. package/lib/core.js +1 -1
  52. package/lib/core.js.map +1 -1
  53. package/lib/geometry/label/interface.d.ts +4 -0
  54. package/lib/geometry/label/interface.js.map +1 -1
  55. package/lib/geometry/label/layout/hide-overlap.d.ts +1 -1
  56. package/lib/geometry/label/layout/hide-overlap.js +45 -38
  57. package/lib/geometry/label/layout/hide-overlap.js.map +1 -1
  58. package/lib/geometry/label/util/createWorker.d.ts +9 -1
  59. package/lib/geometry/label/util/createWorker.js +36 -2
  60. package/lib/geometry/label/util/createWorker.js.map +1 -1
  61. package/lib/geometry/shape/area/index.js +1 -0
  62. package/lib/geometry/shape/area/index.js.map +1 -1
  63. package/lib/geometry/shape/area/smooth.js +1 -0
  64. package/lib/geometry/shape/area/smooth.js.map +1 -1
  65. package/lib/geometry/shape/interval/index.js +3 -1
  66. package/lib/geometry/shape/interval/index.js.map +1 -1
  67. package/lib/index.js +2 -2
  68. package/lib/index.js.map +1 -1
  69. package/lib/interaction/action/active-region.d.ts +1 -1
  70. package/lib/interaction/action/active-region.js.map +1 -1
  71. package/lib/interaction/action/cursor.d.ts +8 -0
  72. package/lib/interaction/action/cursor.js +12 -0
  73. package/lib/interaction/action/cursor.js.map +1 -1
  74. package/lib/util/coordinate.js.map +1 -1
  75. package/package.json +1 -1
  76. package/src/animate/animation/sector-path-update.ts +3 -2
  77. package/src/chart/controller/annotation.ts +7 -3
  78. package/src/chart/controller/slider.ts +4 -4
  79. package/src/chart/controller/tooltip.ts +5 -8
  80. package/src/component/labels.ts +2 -1
  81. package/src/core.ts +1 -1
  82. package/src/geometry/label/interface.ts +4 -0
  83. package/src/geometry/label/layout/hide-overlap.ts +37 -39
  84. package/src/geometry/label/util/createWorker.ts +36 -2
  85. package/src/geometry/shape/area/index.ts +1 -0
  86. package/src/geometry/shape/area/smooth.ts +1 -0
  87. package/src/geometry/shape/interval/index.ts +3 -1
  88. package/src/index.ts +2 -2
  89. package/src/interaction/action/active-region.ts +1 -1
  90. package/src/interaction/action/cursor.ts +12 -0
  91. package/src/util/coordinate.ts +1 -1
@@ -288,8 +288,8 @@ export default class Slider extends Controller<SliderOption> {
288
288
 
289
289
  const xTickCount = size(xValues);
290
290
 
291
- const minIndex = Math.floor(min * (xTickCount - 1));
292
- const maxIndex = Math.floor(max * (xTickCount - 1));
291
+ const minIndex = Math.round(min * (xTickCount - 1));
292
+ const maxIndex = Math.round(max * (xTickCount - 1));
293
293
 
294
294
  let minText = get(xValues, [minIndex]);
295
295
  let maxText = get(xValues, [maxIndex]);
@@ -327,8 +327,8 @@ export default class Slider extends Controller<SliderOption> {
327
327
  const xValues = isHorizontal ? xScaleValues : xScaleValues.reverse();
328
328
  const xTickCount = size(xValues);
329
329
 
330
- const minIndex = Math.floor(min * (xTickCount - 1));
331
- const maxIndex = Math.floor(max * (xTickCount - 1));
330
+ const minIndex = Math.round(min * (xTickCount - 1));
331
+ const maxIndex = Math.round(max * (xTickCount - 1));
332
332
 
333
333
  // 增加 x 轴的过滤器
334
334
  this.view.filter(xScale.field, (value: any, datum: Datum) => {
@@ -1,7 +1,7 @@
1
1
  import { deepMix, find, get, isEqual, isFunction, mix, isString, isBoolean, flatten, isArray } from '@antv/util';
2
2
  import { Crosshair, HtmlTooltip, IGroup } from '../../dependents';
3
3
  import { Point, TooltipItem, TooltipOption } from '../../interface';
4
- import { getAngleByPoint, getDistanceToCenter, isPointInCoordinate, getCoordinateClipCfg } from '../../util/coordinate';
4
+ import { getAngleByPoint, getDistanceToCenter, getCoordinateClipCfg } from '../../util/coordinate';
5
5
  import { polarToCartesian } from '../../util/graphics';
6
6
  import { findItemsFromView } from '../../util/tooltip';
7
7
  import { BBox } from '../../util/bbox';
@@ -456,11 +456,14 @@ export default class Tooltip extends Controller<TooltipOption> {
456
456
  tooltipMarkersGroup?.setClip(undefined);
457
457
  }
458
458
 
459
+ const theme = this.view.getTheme();
460
+ const markerDefaultCfg = get(theme, ['components', 'tooltip', 'marker'], {});
461
+
459
462
  const attrs = {
460
463
  fill: item.color,
461
464
  symbol: 'circle',
462
465
  shadowColor: item.color,
463
- ...marker,
466
+ ...(isFunction(marker) ? { ...markerDefaultCfg, ...marker(item) } : marker),
464
467
  x,
465
468
  y,
466
469
  };
@@ -492,9 +495,6 @@ export default class Tooltip extends Controller<TooltipOption> {
492
495
  // 渲染 x 轴上的 tooltip 辅助线
493
496
  private renderXCrosshairs(point: Point, tooltipCfg) {
494
497
  const coordinate = this.getViewWithGeometry(this.view).getCoordinate();
495
- if (!isPointInCoordinate(coordinate, point)) {
496
- return;
497
- }
498
498
  let start;
499
499
  let end;
500
500
  if (coordinate.isRect) {
@@ -552,9 +552,6 @@ export default class Tooltip extends Controller<TooltipOption> {
552
552
  // 渲染 y 轴上的辅助线
553
553
  private renderYCrosshairs(point: Point, tooltipCfg) {
554
554
  const coordinate = this.getViewWithGeometry(this.view).getCoordinate();
555
- if (!isPointInCoordinate(coordinate, point)) {
556
- return;
557
- }
558
555
  let cfg;
559
556
  let type;
560
557
  if (coordinate.isRect) {
@@ -140,10 +140,11 @@ export default class Labels {
140
140
  }
141
141
 
142
142
  private renderLabel(cfg: LabelItem, container: IGroup): IGroup {
143
- const { id, elementId, data, mappingData, coordinate, animate, content } = cfg;
143
+ const { id, elementId, data, mappingData, coordinate, animate, content, capture } = cfg;
144
144
  const shapeAppendCfg = {
145
145
  id,
146
146
  elementId,
147
+ capture,
147
148
  data,
148
149
  origin: {
149
150
  ...mappingData,
package/src/core.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* G2 的一个壳子,不包含 Geometry,由开发者自己定义和引入 */
2
2
 
3
- export const VERSION = '4.2.4';
3
+ export const VERSION = '4.2.7';
4
4
 
5
5
  // 核心基类导出
6
6
  export { Chart, View, Event } from './chart'; // Chart, View 类
@@ -44,6 +44,10 @@ export interface LabelItem extends LabelCfg, LabelPointCfg {
44
44
  * @title 牵引线
45
45
  */
46
46
  labelLine?: null | boolean | { style?: object; path?: string };
47
+ /**
48
+ * @title 是否支持捕获
49
+ */
50
+ capture?: boolean;
47
51
  }
48
52
 
49
53
  /**
@@ -31,7 +31,7 @@ const layout = (items: Item[]): Item[] => {
31
31
  }
32
32
  }
33
33
  return boxes;
34
- }
34
+ };
35
35
 
36
36
  const cache: Map<string, any> = new Map();
37
37
  const worker = createWorker(layoutCode);
@@ -41,45 +41,43 @@ const worker = createWorker(layoutCode);
41
41
  * 不同于 'overlap' 类型的布局,该布局不会对 label 的位置进行偏移调整。
42
42
  * @param labels 参与布局调整的 label 数组集合
43
43
  */
44
- export function hideOverlap(labelItems: LabelItem[], labels: IGroup[], shapes: IShape[] | IGroup[], region: BBox) {
45
- // todo 添加 label rank
46
- return new Promise((resolve) => {
47
- const boxes = labels.map((d, idx) => ({
48
- ...getLabelBackgroundInfo(d, labelItems[idx], get(labelItems[idx], 'background.padding')),
49
- visible: true,
50
- }));
51
- const memoKey = JSON.stringify(boxes);
52
- const cb = (items: Item[]) => {
53
- cache.set(memoKey, items);
54
- each(items, ({ visible }, idx) => {
55
- const labelShape = labels[idx];
56
- if (visible) {
57
- labelShape?.show()
58
- } else {
59
- labelShape?.hide();
60
- }
61
- });
62
- return resolve(items);
63
- }
64
- if (cache.get(memoKey)) {
65
- cb(cache.get(memoKey))
66
- } else if (worker) {
67
- // Do layout in worker.
68
- try {
69
- worker.postMessage(JSON.stringify({ type: 'hide-overlap', items: boxes }));
70
- worker.onmessage = (e) => cb(Array.isArray(e.data) ? e.data : []);
71
- worker.onmessageerror = (e) => {
72
- console.warn('[AntV G2] Web worker is not available');
73
- // Normal layout in main thread.
74
- cb(layout(boxes));
75
- };
76
- } catch (e) {
77
- console.error(e);
78
- cb(layout(boxes));
44
+ export async function hideOverlap(
45
+ labelItems: LabelItem[],
46
+ labels: IGroup[],
47
+ shapes: IShape[] | IGroup[],
48
+ region: BBox
49
+ ) {
50
+ const boxes = labels.map((d, idx) => ({
51
+ ...getLabelBackgroundInfo(d, labelItems[idx], get(labelItems[idx], 'background.padding')),
52
+ visible: true,
53
+ }));
54
+ const memoKey = JSON.stringify(boxes);
55
+ const cb = (items: Item[]) => {
56
+ cache.set(memoKey, items);
57
+ each(items, ({ visible }, idx) => {
58
+ const labelShape = labels[idx];
59
+ if (visible) {
60
+ labelShape?.show();
61
+ } else {
62
+ labelShape?.hide();
79
63
  }
80
- } else {
81
- // Normal layout in main thread.
64
+ });
65
+ return items;
66
+ };
67
+ if (cache.get(memoKey)) {
68
+ cb(cache.get(memoKey));
69
+ } else if (worker) {
70
+ // Do layout in worker.
71
+ try {
72
+ const params = JSON.stringify({ type: 'hide-overlap', items: boxes });
73
+ const res = await worker.post(params, () => cb(layout(boxes)));
74
+ cb(Array.isArray(res.data) ? res.data : []);
75
+ } catch (e) {
76
+ console.error(e);
82
77
  cb(layout(boxes));
83
78
  }
84
- });
79
+ } else {
80
+ // Normal layout in main thread.
81
+ cb(layout(boxes));
82
+ }
85
83
  }
@@ -1,5 +1,39 @@
1
+ import { isFunction } from '@antv/util';
2
+
3
+ class MyWorker {
4
+ queue: any[] = [];
5
+ worker: Worker;
6
+
7
+ constructor(url) {
8
+ this.worker = new Worker(url);
9
+ this.worker.onmessage = (e: MessageEvent) => {
10
+ this.queue.shift()?.resolve(e);
11
+ };
12
+ this.worker.onmessageerror = (e: MessageEvent) => {
13
+ console.warn('[AntV G2] Web worker is not available');
14
+ this.queue.shift()?.reject(e);
15
+ };
16
+ }
17
+
18
+ post(params, onError?: () => any): Promise<MessageEvent> {
19
+ return new Promise((resolve, reject) => {
20
+ this.queue.push({ resolve, reject });
21
+ try {
22
+ this.worker.postMessage(params);
23
+ } catch (e) {
24
+ console.warn('[AntV G2] Web worker is not available');
25
+ isFunction(onError) && onError();
26
+ }
27
+ });
28
+ }
29
+
30
+ destroy() {
31
+ this.worker.terminate();
32
+ }
33
+ }
34
+
1
35
  export function createWorker(f: any) {
2
- if (typeof window === "undefined") return;
36
+ if (typeof window === 'undefined') return;
3
37
 
4
38
  let blob;
5
39
  try {
@@ -11,5 +45,5 @@ export function createWorker(f: any) {
11
45
  blob = blob.getBlob();
12
46
  }
13
47
 
14
- return new Worker(URL.createObjectURL(blob));
48
+ return new MyWorker(URL.createObjectURL(blob));
15
49
  }
@@ -41,6 +41,7 @@ registerShape('area', 'area', {
41
41
  style: {
42
42
  r: 5,
43
43
  fill: color,
44
+ fillOpacity: 1,
44
45
  },
45
46
  };
46
47
  },
@@ -28,6 +28,7 @@ registerShape('area', 'smooth', {
28
28
  style: {
29
29
  r: 5,
30
30
  fill: color,
31
+ fillOpacity: 1,
31
32
  },
32
33
  };
33
34
  },
@@ -22,7 +22,9 @@ registerShape('interval', 'rect', {
22
22
 
23
23
  const backgroundCfg = cfg?.background;
24
24
  if (backgroundCfg) {
25
- group = container.addGroup();
25
+ group = container.addGroup({
26
+ name: 'interval-group',
27
+ });
26
28
  const backgroundStyle = getBackgroundRectStyle(cfg);
27
29
  const backgroundPath = getBackgroundRectPath(cfg, this.parsePoints(cfg.points) as Point[], this.coordinate);
28
30
  group.addShape('path', {
package/src/index.ts CHANGED
@@ -576,7 +576,7 @@ registerInteraction('legend-filter', {
576
576
  isEnable: (context) => {
577
577
  return !context.isInShape('legend-item-radio');
578
578
  },
579
- action: ['list-unchecked:toggle', 'data-filter:filter', 'list-radio:show'],
579
+ action: ['legend-item-highlight:reset', 'element-highlight:reset', 'list-unchecked:toggle', 'data-filter:filter', 'list-radio:show'],
580
580
  },
581
581
  // 正反选数据: 只有当 radio === truthy 的时候才会有 legend-item-radio 这个元素
582
582
  {
@@ -609,7 +609,7 @@ registerInteraction('legend-visible-filter', {
609
609
  { trigger: 'legend-item:mouseenter', action: 'cursor:pointer' },
610
610
  { trigger: 'legend-item:mouseleave', action: 'cursor:default' },
611
611
  ],
612
- start: [{ trigger: 'legend-item:click', action: ['list-unchecked:toggle', 'element-filter:filter'] }],
612
+ start: [{ trigger: 'legend-item:click', action: ['legend-item-highlight:reset', 'element-highlight:reset', 'list-unchecked:toggle', 'element-filter:filter'] }],
613
613
  });
614
614
 
615
615
  // 出现背景框
@@ -1,5 +1,5 @@
1
1
  import { each, head, isEqual, last, get, flatten, isArray, uniq, isNil } from '@antv/util';
2
- import { View } from 'src/chart';
2
+ import View from '../../chart/view';
3
3
  import { findItemsFromViewRecurisive } from '../../util/tooltip';
4
4
  import { IShape, Point, ShapeAttrs } from '../../dependents';
5
5
  import Element from '../../geometry/element';
@@ -112,6 +112,18 @@ class CursorAction extends Action {
112
112
  public ewResize() {
113
113
  this.setCursor('ew-resize');
114
114
  }
115
+ /**
116
+ * 光标显示可以被放大
117
+ */
118
+ public zoomIn() {
119
+ this.setCursor('zoom-in');
120
+ }
121
+ /**
122
+ * 光标显示可以缩小尺寸
123
+ */
124
+ public zoomOut() {
125
+ this.setCursor('zoom-out');
126
+ }
115
127
  }
116
128
 
117
129
  export default CursorAction;
@@ -64,7 +64,7 @@ export function isPointInCoordinate(coordinate: Coordinate, point: Point) {
64
64
  result = isBetween(point.x, start.x, end.x) && isBetween(point.y, start.y, end.y);
65
65
  } else {
66
66
  const invertPoint = coordinate.invert(point);
67
-
67
+
68
68
  result = isBetween(invertPoint.x, 0, 1) && isBetween(invertPoint.y, 0, 1);
69
69
  }
70
70
  }