@antv/g2 4.1.35 → 4.1.39
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 +38 -0
- package/dist/g2.min.js +3 -17
- 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 +4 -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/geometry/base.d.ts +4 -0
- package/esm/geometry/base.js +8 -3
- package/esm/geometry/base.js.map +1 -1
- package/esm/geometry/element/index.js +3 -6
- package/esm/geometry/element/index.js.map +1 -1
- package/esm/index.js +20 -3
- package/esm/index.js.map +1 -1
- package/esm/interaction/action/component/list-focus.d.ts +5 -0
- package/esm/interaction/action/component/list-focus.js +55 -0
- package/esm/interaction/action/component/list-focus.js.map +1 -0
- package/esm/interaction/action/component/list-radio.d.ts +6 -0
- package/esm/interaction/action/component/list-radio.js +26 -0
- package/esm/interaction/action/component/list-radio.js.map +1 -0
- package/esm/interface.d.ts +5 -0
- 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 +4 -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/geometry/base.d.ts +4 -0
- package/lib/geometry/base.js +8 -3
- package/lib/geometry/base.js.map +1 -1
- package/lib/geometry/element/index.js +3 -6
- package/lib/geometry/element/index.js.map +1 -1
- package/lib/index.js +20 -3
- package/lib/index.js.map +1 -1
- package/lib/interaction/action/component/list-focus.d.ts +5 -0
- package/lib/interaction/action/component/list-focus.js +57 -0
- package/lib/interaction/action/component/list-focus.js.map +1 -0
- package/lib/interaction/action/component/list-radio.d.ts +6 -0
- package/lib/interaction/action/component/list-radio.js +28 -0
- package/lib/interaction/action/component/list-radio.js.map +1 -0
- package/lib/interface.d.ts +5 -0
- package/lib/interface.js.map +1 -1
- package/package.json +1 -1
- package/src/chart/controller/annotation.ts +31 -18
- package/src/chart/controller/scrollbar.ts +18 -13
- package/src/chart/controller/slider.ts +12 -2
- package/src/core.ts +1 -1
- package/src/geometry/base.ts +13 -2
- package/src/geometry/element/index.ts +3 -5
- package/src/index.ts +20 -3
- package/src/interaction/action/component/list-focus.ts +36 -0
- package/src/interaction/action/component/list-radio.ts +23 -0
- package/src/interface.ts +5 -0
|
@@ -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,13 +240,18 @@ 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,
|
|
247
251
|
type: cfg.type as ScaleOption['type'],
|
|
248
252
|
min: cfg.min,
|
|
249
253
|
max: cfg.max,
|
|
254
|
+
tickMethod: cfg.tickMethod
|
|
250
255
|
});
|
|
251
256
|
});
|
|
252
257
|
this.view.filter(this.xScaleCfg.field, (val) => {
|
|
@@ -280,11 +285,11 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
|
|
|
280
285
|
const config = this.getScrollbarComponentCfg();
|
|
281
286
|
const realConfig = this.trackLen
|
|
282
287
|
? {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
...config,
|
|
289
|
+
trackLen: this.trackLen,
|
|
290
|
+
thumbLen: this.thumbLen,
|
|
291
|
+
thumbOffset: (this.trackLen - this.thumbLen) * this.ratio,
|
|
292
|
+
}
|
|
288
293
|
: { ...config };
|
|
289
294
|
this.scrollbar.component.update(realConfig);
|
|
290
295
|
|
|
@@ -319,13 +324,13 @@ export default class Scrollbar extends Controller<ScrollbarOption> {
|
|
|
319
324
|
const [paddingTop, paddingRight, paddingBottom, paddingLeft] = padding;
|
|
320
325
|
const position = isHorizontal
|
|
321
326
|
? {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
327
|
+
x: coordinateBBox.minX + paddingLeft,
|
|
328
|
+
y: viewBBox.maxY - height - paddingBottom,
|
|
329
|
+
}
|
|
325
330
|
: {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
331
|
+
x: viewBBox.maxX - width - paddingRight,
|
|
332
|
+
y: coordinateBBox.minY + paddingTop,
|
|
333
|
+
};
|
|
329
334
|
const step = this.getStep();
|
|
330
335
|
const cnt = this.getCnt();
|
|
331
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/geometry/base.ts
CHANGED
|
@@ -132,6 +132,8 @@ export interface GeometryCfg {
|
|
|
132
132
|
sortable?: boolean;
|
|
133
133
|
/** elements 的 zIndex 默认按顺序提升,通过 zIndexReversed 可以反序,从而数据越前,层级越高 */
|
|
134
134
|
zIndexReversed?: boolean;
|
|
135
|
+
/** 是否需要对 zIndex 进行 sort。因为耗时长,由具体场景自行决定 */
|
|
136
|
+
sortZIndex?: boolean;
|
|
135
137
|
/** 是否可见 */
|
|
136
138
|
visible?: boolean;
|
|
137
139
|
/** 主题配置 */
|
|
@@ -260,6 +262,8 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
|
|
|
260
262
|
protected multiplePieWidthRatio: number;
|
|
261
263
|
/** elements 的 zIndex 默认按顺序提升,通过 zIndexReversed 可以反序,从而数据越前,层级越高 */
|
|
262
264
|
public zIndexReversed?: boolean;
|
|
265
|
+
/** 是否需要对 zIndex 进行 sort。因为耗时长,由具体场景自行决定 */
|
|
266
|
+
public sortZIndex?: boolean;
|
|
263
267
|
|
|
264
268
|
/** 虚拟 Group,用于图形更新 */
|
|
265
269
|
private offscreenGroup: IGroup;
|
|
@@ -293,6 +297,7 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
|
|
|
293
297
|
roseWidthRatio,
|
|
294
298
|
multiplePieWidthRatio,
|
|
295
299
|
zIndexReversed,
|
|
300
|
+
sortZIndex,
|
|
296
301
|
} = cfg;
|
|
297
302
|
|
|
298
303
|
this.container = container;
|
|
@@ -313,6 +318,7 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
|
|
|
313
318
|
this.roseWidthRatio = roseWidthRatio;
|
|
314
319
|
this.multiplePieWidthRatio = multiplePieWidthRatio;
|
|
315
320
|
this.zIndexReversed = zIndexReversed;
|
|
321
|
+
this.sortZIndex = sortZIndex;
|
|
316
322
|
}
|
|
317
323
|
|
|
318
324
|
/**
|
|
@@ -1546,7 +1552,7 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
|
|
|
1546
1552
|
this.elements[i] = element;
|
|
1547
1553
|
this.elementsMap[key] = element;
|
|
1548
1554
|
if (element.shape) {
|
|
1549
|
-
element.shape.
|
|
1555
|
+
element.shape.set('zIndex', this.zIndexReversed ? this.elements.length - i : i);
|
|
1550
1556
|
}
|
|
1551
1557
|
}
|
|
1552
1558
|
|
|
@@ -1565,10 +1571,15 @@ export default class Geometry<S extends ShapePoint = ShapePoint> extends Base {
|
|
|
1565
1571
|
this.elements[i] = element;
|
|
1566
1572
|
this.elementsMap[key] = element;
|
|
1567
1573
|
if (element.shape) {
|
|
1568
|
-
element.shape.
|
|
1574
|
+
element.shape.set('zIndex', this.zIndexReversed ? this.elements.length - i : i);
|
|
1569
1575
|
}
|
|
1570
1576
|
}
|
|
1571
1577
|
|
|
1578
|
+
// 全部 setZIndex 之后,再执行 sort
|
|
1579
|
+
if (this.container) {
|
|
1580
|
+
this.container.sort();
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1572
1583
|
// 销毁被删除的 elements
|
|
1573
1584
|
for (const key of removed) {
|
|
1574
1585
|
const element = this.lastElementsMap[key];
|
|
@@ -229,11 +229,9 @@ export default class Element extends Base {
|
|
|
229
229
|
}
|
|
230
230
|
states.splice(index, 1);
|
|
231
231
|
if (stateName === 'active' || stateName === 'selected') {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
shape.setZIndex(this.elementIndex);
|
|
236
|
-
}
|
|
232
|
+
const { sortZIndex, zIndexReversed } = this.geometry;
|
|
233
|
+
const idx = zIndexReversed ? this.geometry.elements.length - this.elementIndex : this.elementIndex;
|
|
234
|
+
sortZIndex ? shape.setZIndex(idx) : shape.set('zIndex', idx);
|
|
237
235
|
}
|
|
238
236
|
}
|
|
239
237
|
|
package/src/index.ts
CHANGED
|
@@ -198,6 +198,8 @@ import ListHighlight from './interaction/action/component/list-highlight';
|
|
|
198
198
|
import ListSelected from './interaction/action/component/list-selected';
|
|
199
199
|
import ListUnchecked from './interaction/action/component/list-unchecked';
|
|
200
200
|
import ListChecked from './interaction/action/component/list-checked';
|
|
201
|
+
import ListFocus from './interaction/action/component/list-focus';
|
|
202
|
+
import ListRadio from './interaction/action/component/list-radio';
|
|
201
203
|
|
|
202
204
|
import CircleMask from './interaction/action/mask/circle';
|
|
203
205
|
import DimMask from './interaction/action/mask/dim-rect';
|
|
@@ -248,6 +250,8 @@ registerAction('list-selected', ListSelected);
|
|
|
248
250
|
registerAction('list-highlight', ListHighlight);
|
|
249
251
|
registerAction('list-unchecked', ListUnchecked);
|
|
250
252
|
registerAction('list-checked', ListChecked);
|
|
253
|
+
registerAction('list-focus', ListFocus);
|
|
254
|
+
registerAction('list-radio', ListRadio);
|
|
251
255
|
|
|
252
256
|
registerAction('legend-item-highlight', ListHighlight, {
|
|
253
257
|
componentNames: ['legend'],
|
|
@@ -560,10 +564,23 @@ registerInteraction('element-single-selected', {
|
|
|
560
564
|
// 筛选数据
|
|
561
565
|
registerInteraction('legend-filter', {
|
|
562
566
|
showEnable: [
|
|
563
|
-
{ trigger: 'legend-item:mouseenter', action: 'cursor:pointer' },
|
|
564
|
-
{ trigger: 'legend-item:mouseleave', action: 'cursor:default' },
|
|
567
|
+
{ trigger: 'legend-item:mouseenter', action: ['cursor:pointer', 'list-radio:show'] },
|
|
568
|
+
{ trigger: 'legend-item:mouseleave', action: ['cursor:default', 'list-radio:hide'] },
|
|
569
|
+
],
|
|
570
|
+
start: [
|
|
571
|
+
{
|
|
572
|
+
trigger: 'legend-item:click',
|
|
573
|
+
isEnable: (context) => {
|
|
574
|
+
return !context.isInShape('legend-item-radio');
|
|
575
|
+
},
|
|
576
|
+
action: ['list-unchecked:toggle', 'data-filter:filter', 'list-radio:show'],
|
|
577
|
+
},
|
|
578
|
+
// 正反选数据: 只有当 radio === truthy 的时候才会有 legend-item-radio 这个元素
|
|
579
|
+
{
|
|
580
|
+
trigger: 'legend-item-radio:click',
|
|
581
|
+
action: ['list-focus:toggle', 'data-filter:filter', 'list-radio:show'],
|
|
582
|
+
},
|
|
565
583
|
],
|
|
566
|
-
start: [{ trigger: 'legend-item:click', action: ['list-unchecked:toggle', 'data-filter:filter'] }],
|
|
567
584
|
});
|
|
568
585
|
|
|
569
586
|
// 筛选数据
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import ListState from './list-state';
|
|
2
|
+
|
|
3
|
+
const STATUS_UNCHECKED = 'unchecked';
|
|
4
|
+
|
|
5
|
+
class ListFocus extends ListState {
|
|
6
|
+
public toggle() {
|
|
7
|
+
const triggerInfo = this.getTriggerListInfo();
|
|
8
|
+
if (triggerInfo?.item) {
|
|
9
|
+
const { list, item: clickedItem } = triggerInfo;
|
|
10
|
+
const items = list.getItems();
|
|
11
|
+
const checkedItems = items.filter((t) => !list.hasState(t, STATUS_UNCHECKED));
|
|
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);
|
|
26
|
+
} else {
|
|
27
|
+
for (const item of items) list.setItemState(item, STATUS_UNCHECKED, item.id !== clickedItem.id);
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
for (const item of items) list.setItemState(item, STATUS_UNCHECKED, item.id !== clickedItem.id);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default ListFocus;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ListState from './list-state';
|
|
2
|
+
|
|
3
|
+
const STATUS_SHOW = 'showRadio';
|
|
4
|
+
|
|
5
|
+
class ListRadio extends ListState {
|
|
6
|
+
public show() {
|
|
7
|
+
const triggerInfo = this.getTriggerListInfo();
|
|
8
|
+
if (triggerInfo?.item) {
|
|
9
|
+
const { list, item } = triggerInfo;
|
|
10
|
+
list.setItemState(item, STATUS_SHOW, true);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public hide() {
|
|
15
|
+
const triggerInfo = this.getTriggerListInfo();
|
|
16
|
+
if (triggerInfo?.item) {
|
|
17
|
+
const { list, item } = triggerInfo;
|
|
18
|
+
list.setItemState(item, STATUS_SHOW, false);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default ListRadio;
|
package/src/interface.ts
CHANGED
|
@@ -39,6 +39,7 @@ import { View } from './chart';
|
|
|
39
39
|
import { Facet } from './facet';
|
|
40
40
|
import Element from './geometry/element';
|
|
41
41
|
import { PaddingCalCtor } from './chart/layout/padding-cal';
|
|
42
|
+
import { LegendRadio } from '@antv/component';
|
|
42
43
|
|
|
43
44
|
// ============================ 基础类型 ============================
|
|
44
45
|
/** 通用对象 */
|
|
@@ -1063,6 +1064,10 @@ export interface LegendCfg extends Omit<CategoryLegendCfg, 'marker'> {
|
|
|
1063
1064
|
* **分类图例适用**,用户自己配置图例项的内容。
|
|
1064
1065
|
*/
|
|
1065
1066
|
items?: LegendItem[];
|
|
1067
|
+
/**
|
|
1068
|
+
* **分类图里适用**,用来配置正反选功能
|
|
1069
|
+
*/
|
|
1070
|
+
radio?: LegendRadio
|
|
1066
1071
|
/**
|
|
1067
1072
|
* **分类图例适用**,是否将图例项逆序展示。
|
|
1068
1073
|
*/
|