@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.
- package/README.en-US.md +2 -2
- package/README.md +2 -2
- package/dist/g2.min.js +1 -1
- package/dist/g2.min.js.map +1 -1
- package/esm/animate/animation/sector-path-update.js +3 -2
- package/esm/animate/animation/sector-path-update.js.map +1 -1
- package/esm/chart/controller/annotation.js +3 -2
- package/esm/chart/controller/annotation.js.map +1 -1
- package/esm/chart/controller/slider.js +4 -4
- package/esm/chart/controller/slider.js.map +1 -1
- package/esm/chart/controller/tooltip.js +4 -8
- package/esm/chart/controller/tooltip.js.map +1 -1
- package/esm/component/labels.js +2 -1
- package/esm/component/labels.js.map +1 -1
- package/esm/core.d.ts +1 -1
- package/esm/core.js +1 -1
- package/esm/core.js.map +1 -1
- package/esm/geometry/label/interface.d.ts +4 -0
- package/esm/geometry/label/interface.js.map +1 -1
- package/esm/geometry/label/layout/hide-overlap.d.ts +1 -1
- package/esm/geometry/label/layout/hide-overlap.js +46 -39
- package/esm/geometry/label/layout/hide-overlap.js.map +1 -1
- package/esm/geometry/label/util/createWorker.d.ts +9 -1
- package/esm/geometry/label/util/createWorker.js +36 -2
- package/esm/geometry/label/util/createWorker.js.map +1 -1
- package/esm/geometry/shape/area/index.js +1 -0
- package/esm/geometry/shape/area/index.js.map +1 -1
- package/esm/geometry/shape/area/smooth.js +1 -0
- package/esm/geometry/shape/area/smooth.js.map +1 -1
- package/esm/geometry/shape/interval/index.js +3 -1
- package/esm/geometry/shape/interval/index.js.map +1 -1
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/esm/interaction/action/active-region.d.ts +1 -1
- package/esm/interaction/action/active-region.js.map +1 -1
- package/esm/interaction/action/cursor.d.ts +8 -0
- package/esm/interaction/action/cursor.js +12 -0
- package/esm/interaction/action/cursor.js.map +1 -1
- package/esm/util/coordinate.js.map +1 -1
- package/lib/animate/animation/sector-path-update.js +3 -2
- package/lib/animate/animation/sector-path-update.js.map +1 -1
- package/lib/chart/controller/annotation.js +3 -2
- package/lib/chart/controller/annotation.js.map +1 -1
- package/lib/chart/controller/slider.js +4 -4
- package/lib/chart/controller/slider.js.map +1 -1
- package/lib/chart/controller/tooltip.js +3 -7
- package/lib/chart/controller/tooltip.js.map +1 -1
- package/lib/component/labels.js +2 -1
- package/lib/component/labels.js.map +1 -1
- package/lib/core.d.ts +1 -1
- package/lib/core.js +1 -1
- package/lib/core.js.map +1 -1
- package/lib/geometry/label/interface.d.ts +4 -0
- package/lib/geometry/label/interface.js.map +1 -1
- package/lib/geometry/label/layout/hide-overlap.d.ts +1 -1
- package/lib/geometry/label/layout/hide-overlap.js +45 -38
- package/lib/geometry/label/layout/hide-overlap.js.map +1 -1
- package/lib/geometry/label/util/createWorker.d.ts +9 -1
- package/lib/geometry/label/util/createWorker.js +36 -2
- package/lib/geometry/label/util/createWorker.js.map +1 -1
- package/lib/geometry/shape/area/index.js +1 -0
- package/lib/geometry/shape/area/index.js.map +1 -1
- package/lib/geometry/shape/area/smooth.js +1 -0
- package/lib/geometry/shape/area/smooth.js.map +1 -1
- package/lib/geometry/shape/interval/index.js +3 -1
- package/lib/geometry/shape/interval/index.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/interaction/action/active-region.d.ts +1 -1
- package/lib/interaction/action/active-region.js.map +1 -1
- package/lib/interaction/action/cursor.d.ts +8 -0
- package/lib/interaction/action/cursor.js +12 -0
- package/lib/interaction/action/cursor.js.map +1 -1
- package/lib/util/coordinate.js.map +1 -1
- package/package.json +1 -1
- package/src/animate/animation/sector-path-update.ts +3 -2
- package/src/chart/controller/annotation.ts +7 -3
- package/src/chart/controller/slider.ts +4 -4
- package/src/chart/controller/tooltip.ts +5 -8
- package/src/component/labels.ts +2 -1
- package/src/core.ts +1 -1
- package/src/geometry/label/interface.ts +4 -0
- package/src/geometry/label/layout/hide-overlap.ts +37 -39
- package/src/geometry/label/util/createWorker.ts +36 -2
- package/src/geometry/shape/area/index.ts +1 -0
- package/src/geometry/shape/area/smooth.ts +1 -0
- package/src/geometry/shape/interval/index.ts +3 -1
- package/src/index.ts +2 -2
- package/src/interaction/action/active-region.ts +1 -1
- package/src/interaction/action/cursor.ts +12 -0
- 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.
|
|
292
|
-
const maxIndex = Math.
|
|
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.
|
|
331
|
-
const maxIndex = Math.
|
|
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,
|
|
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) {
|
package/src/component/labels.ts
CHANGED
|
@@ -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
|
@@ -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(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
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
|
-
}
|
|
81
|
-
|
|
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 ===
|
|
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
|
|
48
|
+
return new MyWorker(URL.createObjectURL(blob));
|
|
15
49
|
}
|
|
@@ -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
|
|
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;
|
package/src/util/coordinate.ts
CHANGED
|
@@ -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
|
}
|