@antv/g2 4.1.36 → 4.1.40
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/CHANGELOG.md +43 -0
- package/dist/g2.min.js +4 -4
- package/dist/g2.min.js.map +1 -1
- package/esm/chart/controller/annotation.js +35 -21
- package/esm/chart/controller/annotation.js.map +1 -1
- package/esm/chart/controller/scrollbar.js +3 -1
- package/esm/chart/controller/scrollbar.js.map +1 -1
- package/esm/chart/controller/slider.js +7 -1
- package/esm/chart/controller/slider.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/index.js +8 -0
- package/esm/index.js.map +1 -1
- package/esm/interaction/action/component/list-focus.js +31 -6
- package/esm/interaction/action/component/list-focus.js.map +1 -1
- package/esm/interaction/action/component/list-radio.d.ts +18 -0
- package/esm/interaction/action/component/list-radio.js +92 -2
- package/esm/interaction/action/component/list-radio.js.map +1 -1
- package/esm/interface.js.map +1 -1
- package/lib/chart/controller/annotation.js +35 -21
- package/lib/chart/controller/annotation.js.map +1 -1
- package/lib/chart/controller/scrollbar.js +3 -1
- package/lib/chart/controller/scrollbar.js.map +1 -1
- package/lib/chart/controller/slider.js +7 -1
- package/lib/chart/controller/slider.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/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/interaction/action/component/list-focus.js +31 -6
- package/lib/interaction/action/component/list-focus.js.map +1 -1
- package/lib/interaction/action/component/list-radio.d.ts +18 -0
- package/lib/interaction/action/component/list-radio.js +91 -1
- package/lib/interaction/action/component/list-radio.js.map +1 -1
- package/lib/interface.js.map +1 -1
- package/package.json +5 -2
- package/src/chart/controller/annotation.ts +31 -18
- package/src/chart/controller/scrollbar.ts +17 -13
- package/src/chart/controller/slider.ts +12 -2
- package/src/core.ts +1 -1
- package/src/index.ts +8 -0
- package/src/interaction/action/component/list-focus.ts +17 -5
- package/src/interaction/action/component/list-radio.ts +105 -0
- package/src/interface.ts +1 -1
|
@@ -55,7 +55,7 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
|
|
|
55
55
|
this.view.off(VIEW_LIFE_CIRCLE.BEFORE_CHANGE_SIZE, this.resetMeasure);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
public init() {}
|
|
58
|
+
public init() { }
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* 渲染
|
|
@@ -240,7 +240,11 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
|
|
|
240
240
|
const { type } = this.getValidScrollbarCfg();
|
|
241
241
|
const isHorizontal = type !== 'vertical';
|
|
242
242
|
const values = valuesOfKey(this.data, this.xScaleCfg.field);
|
|
243
|
-
|
|
243
|
+
|
|
244
|
+
// 如果是 xScale 数值类型,则进行排序
|
|
245
|
+
const xScaleValues = this.view.getXScale().isLinear ? values.sort((a, b) => Number(a) - Number(b)) : values;
|
|
246
|
+
|
|
247
|
+
const xValues = isHorizontal ? xScaleValues : xScaleValues.reverse();
|
|
244
248
|
this.yScalesCfg.forEach((cfg) => {
|
|
245
249
|
this.view.scale(cfg.field, {
|
|
246
250
|
formatter: cfg.formatter,
|
|
@@ -281,11 +285,11 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
|
|
|
281
285
|
const config = this.getScrollbarComponentCfg();
|
|
282
286
|
const realConfig = this.trackLen
|
|
283
287
|
? {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
288
|
+
...config,
|
|
289
|
+
trackLen: this.trackLen,
|
|
290
|
+
thumbLen: this.thumbLen,
|
|
291
|
+
thumbOffset: (this.trackLen - this.thumbLen) * this.ratio,
|
|
292
|
+
}
|
|
289
293
|
: { ...config };
|
|
290
294
|
this.scrollbar.component.update(realConfig);
|
|
291
295
|
|
|
@@ -320,13 +324,13 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
|
|
|
320
324
|
const [paddingTop, paddingRight, paddingBottom, paddingLeft] = padding;
|
|
321
325
|
const position = isHorizontal
|
|
322
326
|
? {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
327
|
+
x: coordinateBBox.minX + paddingLeft,
|
|
328
|
+
y: viewBBox.maxY - height - paddingBottom,
|
|
329
|
+
}
|
|
326
330
|
: {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
331
|
+
x: viewBBox.maxX - width - paddingRight,
|
|
332
|
+
y: coordinateBBox.minY + paddingTop,
|
|
333
|
+
};
|
|
330
334
|
const step = this.getStep();
|
|
331
335
|
const cnt = this.getCnt();
|
|
332
336
|
const trackLen = isHorizontal
|
|
@@ -272,7 +272,13 @@ export default class Slider extends Controller<SliderOption> {
|
|
|
272
272
|
const data = this.view.getOptions().data;
|
|
273
273
|
const xScale = this.view.getXScale();
|
|
274
274
|
const isHorizontal = true;
|
|
275
|
-
|
|
275
|
+
let values = valuesOfKey(data, xScale.field);
|
|
276
|
+
|
|
277
|
+
// 如果是 xScale 数值类型,则进行排序
|
|
278
|
+
if (xScale.isLinear) {
|
|
279
|
+
values = values.sort();
|
|
280
|
+
}
|
|
281
|
+
|
|
276
282
|
const xValues = isHorizontal ? values : values.reverse();
|
|
277
283
|
const dataSize = size(data);
|
|
278
284
|
|
|
@@ -314,7 +320,11 @@ export default class Slider extends Controller<SliderOption> {
|
|
|
314
320
|
}
|
|
315
321
|
const isHorizontal = true;
|
|
316
322
|
const values = valuesOfKey(data, xScale.field);
|
|
317
|
-
|
|
323
|
+
|
|
324
|
+
// 如果是 xScale 数值类型,则进行排序
|
|
325
|
+
const xScaleValues = this.view.getXScale().isLinear ? values.sort((a, b) => Number(a) - Number(b)) : values;
|
|
326
|
+
|
|
327
|
+
const xValues = isHorizontal ? xScaleValues : xScaleValues.reverse();
|
|
318
328
|
const xTickCount = size(xValues);
|
|
319
329
|
|
|
320
330
|
const minIndex = Math.floor(min * (xTickCount - 1));
|
package/src/core.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -576,6 +576,14 @@ registerInteraction('legend-filter', {
|
|
|
576
576
|
action: ['list-unchecked:toggle', 'data-filter:filter', 'list-radio:show'],
|
|
577
577
|
},
|
|
578
578
|
// 正反选数据: 只有当 radio === truthy 的时候才会有 legend-item-radio 这个元素
|
|
579
|
+
{
|
|
580
|
+
trigger: 'legend-item-radio:mouseenter',
|
|
581
|
+
action: ['list-radio:showTip'],
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
trigger: 'legend-item-radio:mouseleave',
|
|
585
|
+
action: ['list-radio:hideTip'],
|
|
586
|
+
},
|
|
579
587
|
{
|
|
580
588
|
trigger: 'legend-item-radio:click',
|
|
581
589
|
action: ['list-focus:toggle', 'data-filter:filter', 'list-radio:show'],
|
|
@@ -9,13 +9,25 @@ class ListFocus extends ListState {
|
|
|
9
9
|
const { list, item: clickedItem } = triggerInfo;
|
|
10
10
|
const items = list.getItems();
|
|
11
11
|
const checkedItems = items.filter((t) => !list.hasState(t, STATUS_UNCHECKED));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const uncheckedItems = items.filter((t) => list.hasState(t, STATUS_UNCHECKED));
|
|
13
|
+
const checkedItem = checkedItems[0]
|
|
14
|
+
/**
|
|
15
|
+
* 1. 初始化,全部 checked。此时,点击 radio, clickItem 进入聚焦
|
|
16
|
+
* 2. 当前只选中一个
|
|
17
|
+
* 2.1 且选中 item 等于 clickItem,退出聚焦,全部重新选中
|
|
18
|
+
* 2.2 替换聚焦的 item
|
|
19
|
+
* 3. 其它,同 2.2
|
|
20
|
+
*/
|
|
21
|
+
if (items.length === checkedItems.length) {
|
|
22
|
+
for (const item of items) list.setItemState(item, STATUS_UNCHECKED, item.id !== clickedItem.id);
|
|
23
|
+
} else if (items.length - uncheckedItems.length === 1) {
|
|
24
|
+
if (checkedItem.id === clickedItem.id) {
|
|
25
|
+
for (const item of items) list.setItemState(item, STATUS_UNCHECKED, false);
|
|
15
26
|
} else {
|
|
16
|
-
const
|
|
17
|
-
list.setItemState(item, STATUS_UNCHECKED, status);
|
|
27
|
+
for (const item of items) list.setItemState(item, STATUS_UNCHECKED, item.id !== clickedItem.id);
|
|
18
28
|
}
|
|
29
|
+
} else {
|
|
30
|
+
for (const item of items) list.setItemState(item, STATUS_UNCHECKED, item.id !== clickedItem.id);
|
|
19
31
|
}
|
|
20
32
|
}
|
|
21
33
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import ListState from './list-state';
|
|
2
|
+
import { isEqual } from '@antv/util';
|
|
3
|
+
import { TOOLTIP_CSS_CONST } from '@antv/component';
|
|
4
|
+
import { HtmlTooltip } from '../../../dependents';
|
|
5
|
+
import { Point } from '../../../interface';
|
|
2
6
|
|
|
3
7
|
const STATUS_SHOW = 'showRadio';
|
|
8
|
+
const TIP_ID = 'legend-radio-tip';
|
|
4
9
|
|
|
5
10
|
class ListRadio extends ListState {
|
|
6
11
|
public show() {
|
|
@@ -18,6 +23,106 @@ class ListRadio extends ListState {
|
|
|
18
23
|
list.setItemState(item, STATUS_SHOW, false);
|
|
19
24
|
}
|
|
20
25
|
}
|
|
26
|
+
|
|
27
|
+
private timeStamp: number = 0;
|
|
28
|
+
private location: Point;
|
|
29
|
+
private tooltip;
|
|
30
|
+
|
|
31
|
+
public destroy() {
|
|
32
|
+
super.destroy();
|
|
33
|
+
this.tooltip && this.tooltip.destroy();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 显示 Tooltip (展示在上方)
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
public showTip() {
|
|
41
|
+
const context = this.context;
|
|
42
|
+
const ev = context.event;
|
|
43
|
+
const lastTimeStamp = this.timeStamp;
|
|
44
|
+
const timeStamp = +new Date();
|
|
45
|
+
|
|
46
|
+
const target = this.context.event.target;
|
|
47
|
+
if (timeStamp - lastTimeStamp > 16 && target.get('name') === 'legend-item-radio') {
|
|
48
|
+
const preLoc = this.location;
|
|
49
|
+
const curLoc = { x: ev.x, y: ev.y };
|
|
50
|
+
this.timeStamp = timeStamp;
|
|
51
|
+
this.location = curLoc;
|
|
52
|
+
if (!preLoc || !isEqual(preLoc, curLoc)) {
|
|
53
|
+
this.showTooltip(curLoc);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 隐藏 Tooltip。
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
public hideTip() {
|
|
63
|
+
this.hideTooltip();
|
|
64
|
+
this.location = null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected showTooltip(curLoc: Point) {
|
|
68
|
+
const context = this.context;
|
|
69
|
+
const ev = context.event;
|
|
70
|
+
const target = ev.target;
|
|
71
|
+
|
|
72
|
+
if (target && target.get('tip')) {
|
|
73
|
+
if (!this.tooltip) {
|
|
74
|
+
this.renderTooltip(); // 延迟生成
|
|
75
|
+
}
|
|
76
|
+
// 展示 tooltip
|
|
77
|
+
const { x: offsetX, y: offsetY } = context.view.getCanvas().get('el').getBoundingClientRect();
|
|
78
|
+
this.tooltip.update({
|
|
79
|
+
title: target.get('tip'),
|
|
80
|
+
...curLoc,
|
|
81
|
+
x: curLoc.x + offsetX,
|
|
82
|
+
y: curLoc.y + offsetY,
|
|
83
|
+
});
|
|
84
|
+
this.tooltip.show();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
protected hideTooltip() {
|
|
89
|
+
this.tooltip && this.tooltip.hide();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private renderTooltip() {
|
|
93
|
+
const tooltipStyles = {
|
|
94
|
+
[TOOLTIP_CSS_CONST.CONTAINER_CLASS]: {
|
|
95
|
+
padding: '6px 8px',
|
|
96
|
+
transform: 'translate(-50%, -80%)',
|
|
97
|
+
background: 'rgba(0,0,0,0.75)',
|
|
98
|
+
color: '#fff',
|
|
99
|
+
'border-radius': '2px',
|
|
100
|
+
// 避免遮挡,如果还不够的话,再考虑开放用户配置
|
|
101
|
+
'z-index': 100,
|
|
102
|
+
},
|
|
103
|
+
[TOOLTIP_CSS_CONST.TITLE_CLASS]: {
|
|
104
|
+
'font-size': '12px',
|
|
105
|
+
'line-height': '14px',
|
|
106
|
+
'margin-bottom': 0,
|
|
107
|
+
'word-break': 'break-all',
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
if (document.getElementById(TIP_ID)) {
|
|
111
|
+
document.body.removeChild(document.getElementById(TIP_ID));
|
|
112
|
+
}
|
|
113
|
+
const tooltip = new HtmlTooltip({
|
|
114
|
+
parent: document.body,
|
|
115
|
+
// tooltip 限制的区域
|
|
116
|
+
region: null,
|
|
117
|
+
visible: false,
|
|
118
|
+
crosshairs: null,
|
|
119
|
+
domStyles: tooltipStyles,
|
|
120
|
+
containerId: TIP_ID,
|
|
121
|
+
});
|
|
122
|
+
tooltip.init();
|
|
123
|
+
tooltip.setCapture(false); // 不允许捕获事件
|
|
124
|
+
this.tooltip = tooltip;
|
|
125
|
+
}
|
|
21
126
|
}
|
|
22
127
|
|
|
23
128
|
export default ListRadio;
|
package/src/interface.ts
CHANGED