@antv/component 0.8.17 → 0.8.21
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 +30 -0
- package/esm/abstract/html-component.d.ts +2 -40
- package/esm/abstract/html-component.js +0 -1
- package/esm/abstract/html-component.js.map +1 -1
- package/esm/annotation/html.d.ts +0 -35
- package/esm/axis/base.d.ts +3 -3
- package/esm/axis/base.js +5 -3
- package/esm/axis/base.js.map +1 -1
- package/esm/axis/circle.d.ts +10 -1
- package/esm/axis/circle.js +99 -0
- package/esm/axis/circle.js.map +1 -1
- package/esm/axis/line.d.ts +6 -1
- package/esm/axis/overlap/auto-ellipsis.js +3 -3
- package/esm/axis/overlap/auto-ellipsis.js.map +1 -1
- package/esm/crosshair/html.d.ts +0 -67
- package/esm/legend/category.d.ts +3 -0
- package/esm/legend/category.js +37 -2
- package/esm/legend/category.js.map +1 -1
- package/esm/scrollbar/scrollbar.js.map +1 -1
- package/esm/tooltip/html.d.ts +0 -228
- package/esm/types.d.ts +27 -0
- package/esm/util/label.js +23 -9
- package/esm/util/label.js.map +1 -1
- package/esm/util/theme.js +1 -1
- package/esm/util/theme.js.map +1 -1
- package/lib/abstract/html-component.d.ts +2 -40
- package/lib/abstract/html-component.js +0 -1
- package/lib/abstract/html-component.js.map +1 -1
- package/lib/annotation/html.d.ts +0 -35
- package/lib/axis/base.d.ts +3 -3
- package/lib/axis/base.js +5 -3
- package/lib/axis/base.js.map +1 -1
- package/lib/axis/circle.d.ts +10 -1
- package/lib/axis/circle.js +99 -0
- package/lib/axis/circle.js.map +1 -1
- package/lib/axis/line.d.ts +6 -1
- package/lib/axis/overlap/auto-ellipsis.js +3 -3
- package/lib/axis/overlap/auto-ellipsis.js.map +1 -1
- package/lib/crosshair/html.d.ts +0 -67
- package/lib/legend/category.d.ts +3 -0
- package/lib/legend/category.js +37 -2
- package/lib/legend/category.js.map +1 -1
- package/lib/scrollbar/scrollbar.js.map +1 -1
- package/lib/tooltip/html.d.ts +0 -228
- package/lib/types.d.ts +27 -0
- package/lib/util/label.js +22 -8
- package/lib/util/label.js.map +1 -1
- package/lib/util/theme.js +1 -1
- package/lib/util/theme.js.map +1 -1
- package/package.json +3 -3
- package/src/abstract/html-component.ts +0 -1
- package/src/axis/base.ts +6 -4
- package/src/axis/circle.ts +102 -2
- package/src/axis/overlap/auto-ellipsis.ts +3 -3
- package/src/legend/category.ts +65 -10
- package/src/scrollbar/scrollbar.ts +2 -2
- package/src/types.ts +35 -7
- package/src/util/label.ts +24 -9
- package/src/util/theme.ts +1 -1
package/src/axis/base.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IGroup } from '@antv/g-base';
|
|
2
2
|
import { ext } from '@antv/matrix-util';
|
|
3
|
-
import { each, filter, get, isFunction, isNil, isNumberEqual, mix, size } from '@antv/util';
|
|
3
|
+
import { each, filter, get, isFunction, isNil, isNumberEqual, mix, size, isArray } from '@antv/util';
|
|
4
4
|
import GroupComponent from '../abstract/group-component';
|
|
5
5
|
import { IList } from '../interfaces';
|
|
6
6
|
import { AxisBaseCfg, ListItem, OptimizeCfg, Point } from '../types';
|
|
@@ -70,6 +70,8 @@ abstract class AxisBase<T extends AxisBaseCfg = AxisBaseCfg> extends GroupCompon
|
|
|
70
70
|
fontWeight: 'normal',
|
|
71
71
|
},
|
|
72
72
|
offset: 10,
|
|
73
|
+
offsetX: 0,
|
|
74
|
+
offsetY: 0,
|
|
73
75
|
},
|
|
74
76
|
title: {
|
|
75
77
|
autoRotate: true,
|
|
@@ -470,7 +472,7 @@ abstract class AxisBase<T extends AxisBaseCfg = AxisBaseCfg> extends GroupCompon
|
|
|
470
472
|
// 获取 label 的配置项
|
|
471
473
|
private getLabelAttrs(tick: ListItem, index: number, ticks: ListItem[]) {
|
|
472
474
|
const labelCfg = this.get('label');
|
|
473
|
-
const { offset, rotate, formatter } = labelCfg;
|
|
475
|
+
const { offset, offsetX, offsetY, rotate, formatter } = labelCfg;
|
|
474
476
|
const point = this.getSidePoint(tick.point, offset);
|
|
475
477
|
const vector = this.getSideVector(offset, point);
|
|
476
478
|
const text = formatter ? formatter(tick.name, tick, index) : tick.name;
|
|
@@ -479,8 +481,8 @@ abstract class AxisBase<T extends AxisBaseCfg = AxisBaseCfg> extends GroupCompon
|
|
|
479
481
|
|
|
480
482
|
const attrs = mix(
|
|
481
483
|
{
|
|
482
|
-
x: point.x,
|
|
483
|
-
y: point.y,
|
|
484
|
+
x: point.x + offsetX,
|
|
485
|
+
y: point.y + offsetY,
|
|
484
486
|
text,
|
|
485
487
|
textAlign: this.getTextAnchor(vector),
|
|
486
488
|
textBaseline: this.getTextBaseline(vector),
|
package/src/axis/circle.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { IGroup } from '@antv/g-base';
|
|
2
|
+
import { each, isNil, isFunction, isObject } from '@antv/util';
|
|
1
3
|
import { vec2 } from '@antv/matrix-util';
|
|
2
|
-
import { CircleAxisCfg, Point } from '../types';
|
|
3
4
|
import AxisBase from './base';
|
|
5
|
+
import * as OverlapUtil from './overlap';
|
|
6
|
+
import type { AxisLabelAutoHideCfg } from '../types';
|
|
7
|
+
import type { CircleAxisCfg, Point, } from '../types';
|
|
4
8
|
|
|
5
9
|
class Circle extends AxisBase<CircleAxisCfg> {
|
|
6
10
|
public getDefaultCfg() {
|
|
@@ -53,7 +57,7 @@ class Circle extends AxisBase<CircleAxisCfg> {
|
|
|
53
57
|
// 获取垂直于坐标轴的向量
|
|
54
58
|
protected getSideVector(offset: number, point: Point) {
|
|
55
59
|
const center = this.get('center');
|
|
56
|
-
const vector: [
|
|
60
|
+
const vector: [number, number] = [point.x - center.x, point.y - center.y];
|
|
57
61
|
const factor = this.get('verticalFactor');
|
|
58
62
|
const vecLen = vec2.length(vector);
|
|
59
63
|
vec2.scale(vector, vector, (factor * offset) / vecLen);
|
|
@@ -76,6 +80,102 @@ class Circle extends AxisBase<CircleAxisCfg> {
|
|
|
76
80
|
y: center.y + Math.sin(angle) * radius,
|
|
77
81
|
};
|
|
78
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 是否可以执行某一 overlap
|
|
86
|
+
* @param name
|
|
87
|
+
*/
|
|
88
|
+
private canProcessOverlap(name: string) {
|
|
89
|
+
const labelCfg = this.get('label');
|
|
90
|
+
|
|
91
|
+
// 对 autoRotate,如果配置了旋转角度,直接进行固定角度旋转
|
|
92
|
+
if (name === 'autoRotate') {
|
|
93
|
+
return isNil(labelCfg.rotate);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 默认所有 overlap 都可执行
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
protected processOverlap(labelGroup) {
|
|
101
|
+
const labelCfg = this.get('label');
|
|
102
|
+
const titleCfg = this.get('title');
|
|
103
|
+
const verticalLimitLength = this.get('verticalLimitLength');
|
|
104
|
+
const labelOffset = labelCfg.offset;
|
|
105
|
+
let limitLength = verticalLimitLength;
|
|
106
|
+
let titleHeight = 0;
|
|
107
|
+
let titleSpacing = 0;
|
|
108
|
+
if (titleCfg) {
|
|
109
|
+
titleHeight = titleCfg.style.fontSize;
|
|
110
|
+
titleSpacing = titleCfg.spacing;
|
|
111
|
+
}
|
|
112
|
+
if (limitLength) {
|
|
113
|
+
limitLength = limitLength - labelOffset - titleSpacing - titleHeight;
|
|
114
|
+
}
|
|
115
|
+
const overlapOrder = this.get('overlapOrder');
|
|
116
|
+
each(overlapOrder, (name) => {
|
|
117
|
+
if (labelCfg[name] && this.canProcessOverlap(name)) {
|
|
118
|
+
this.autoProcessOverlap(name, labelCfg[name], labelGroup, limitLength);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
if (titleCfg) {
|
|
122
|
+
if (isNil(titleCfg.offset)) {
|
|
123
|
+
// 调整 title 的 offset
|
|
124
|
+
const { height: length } = labelGroup.getCanvasBBox();
|
|
125
|
+
// 如果用户没有设置 offset,则自动计算
|
|
126
|
+
titleCfg.offset = labelOffset + length + titleSpacing + titleHeight / 2;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private autoProcessOverlap(name: string, value: any, labelGroup: IGroup, limitLength: number) {
|
|
132
|
+
let hasAdjusted = false;
|
|
133
|
+
const util = OverlapUtil[name];
|
|
134
|
+
if (limitLength > 0) {
|
|
135
|
+
if (value === true) {
|
|
136
|
+
// true 形式的配置:使用 overlap 默认的的处理方法进行处理
|
|
137
|
+
hasAdjusted = util.getDefault()(false, labelGroup, limitLength);
|
|
138
|
+
} else if (isFunction(value)) {
|
|
139
|
+
// 回调函数形式的配置: 用户可以传入回调函数
|
|
140
|
+
hasAdjusted = value(false, labelGroup, limitLength);
|
|
141
|
+
} else if (isObject(value)) {
|
|
142
|
+
// object 形式的配置方式:包括 处理方法 type, 和可选参数配置 cfg
|
|
143
|
+
const overlapCfg = value as { type: string; cfg?: AxisLabelAutoHideCfg };
|
|
144
|
+
if (util[overlapCfg.type]) {
|
|
145
|
+
hasAdjusted = util[overlapCfg.type](false, labelGroup, limitLength, overlapCfg.cfg);
|
|
146
|
+
}
|
|
147
|
+
} else if (util[value]) {
|
|
148
|
+
// 字符串类型的配置:按照名称执行 overlap 处理方法
|
|
149
|
+
hasAdjusted = util[value](false, labelGroup, limitLength);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (name === 'autoRotate') {
|
|
153
|
+
// 文本旋转后,文本的对齐方式可能就不合适了
|
|
154
|
+
if (hasAdjusted) {
|
|
155
|
+
const labels = labelGroup.getChildren();
|
|
156
|
+
const verticalFactor = this.get('verticalFactor');
|
|
157
|
+
each(labels, (label) => {
|
|
158
|
+
const textAlign = label.attr('textAlign');
|
|
159
|
+
if (textAlign === 'center') {
|
|
160
|
+
// 居中的文本需要调整旋转度
|
|
161
|
+
const newAlign = verticalFactor > 0 ? 'end' : 'start';
|
|
162
|
+
label.attr('textAlign', newAlign);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
} else if (name === 'autoHide') {
|
|
167
|
+
const children = labelGroup.getChildren().slice(0); // 复制数组,删除时不会出错
|
|
168
|
+
each(children, (label) => {
|
|
169
|
+
if (!label.get('visible')) {
|
|
170
|
+
if (this.get('isRegister')) {
|
|
171
|
+
// 已经注册过了,则删除
|
|
172
|
+
this.unregisterElement(label);
|
|
173
|
+
}
|
|
174
|
+
label.remove(); // 防止 label 数量太多,所以统一删除
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
79
179
|
}
|
|
80
180
|
|
|
81
181
|
export default Circle;
|
|
@@ -4,12 +4,12 @@ import { ellipsisLabel } from '../../util/label';
|
|
|
4
4
|
|
|
5
5
|
function ellipseLabels(isVertical: boolean, labelGroup: IGroup, limitLength: number, position: string): boolean {
|
|
6
6
|
const children = labelGroup.getChildren();
|
|
7
|
-
let
|
|
7
|
+
let ellipsisFlag = false;
|
|
8
8
|
each(children, (label) => {
|
|
9
9
|
const rst = ellipsisLabel(isVertical, label, limitLength, position);
|
|
10
|
-
|
|
10
|
+
ellipsisFlag = ellipsisFlag || rst;
|
|
11
11
|
});
|
|
12
|
-
return
|
|
12
|
+
return ellipsisFlag;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function getDefault() {
|
package/src/legend/category.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { IGroup } from '@antv/g-base';
|
|
2
2
|
import { clamp, deepMix, each, filter, get, mix, isNumber, isFunction } from '@antv/util';
|
|
3
3
|
import { IList } from '../interfaces';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CategoryLegendCfg,
|
|
6
|
+
LegendPageNavigatorCfg,
|
|
7
|
+
LegendItemNameCfg,
|
|
8
|
+
LegendMarkerCfg,
|
|
9
|
+
ListItem,
|
|
10
|
+
LegendRadio,
|
|
11
|
+
} from '../types';
|
|
5
12
|
import { ellipsisLabel } from '../util/label';
|
|
6
13
|
import { getMatrixByAngle, getMatrixByTranslate } from '../util/matrix';
|
|
7
14
|
import { getStatesStyle } from '../util/state';
|
|
@@ -36,7 +43,7 @@ const textStyle = {
|
|
|
36
43
|
textAlign: 'start',
|
|
37
44
|
textBaseline: 'middle',
|
|
38
45
|
fontFamily: Theme.fontFamily,
|
|
39
|
-
fontWeight:
|
|
46
|
+
fontWeight: 'normal',
|
|
40
47
|
lineHeight: 12,
|
|
41
48
|
};
|
|
42
49
|
|
|
@@ -64,6 +71,7 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
64
71
|
maxWidth: null,
|
|
65
72
|
maxHeight: null,
|
|
66
73
|
marker: {},
|
|
74
|
+
radio: null,
|
|
67
75
|
items: [],
|
|
68
76
|
itemStates: {},
|
|
69
77
|
itemBackground: {},
|
|
@@ -92,7 +100,7 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
92
100
|
},
|
|
93
101
|
pageNavigator: DEFAULT_PAGE_NAVIGATOR,
|
|
94
102
|
itemName: {
|
|
95
|
-
spacing: 16, // 如果右边有 value 使用这个间距
|
|
103
|
+
spacing: 16, // 如果右边有 value 或者 RadioIcon 使用这个间距
|
|
96
104
|
style: textStyle,
|
|
97
105
|
},
|
|
98
106
|
marker: {
|
|
@@ -106,6 +114,7 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
106
114
|
alignRight: false, // 只有itemWidth 不为 null 时此属性有效
|
|
107
115
|
formatter: null,
|
|
108
116
|
style: textStyle,
|
|
117
|
+
spacing: 6, // 如果右边有 RadioIcon 使用在这个间距
|
|
109
118
|
},
|
|
110
119
|
itemStates: {
|
|
111
120
|
active: {
|
|
@@ -334,7 +343,7 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
334
343
|
if (itemHeight < fontSize) {
|
|
335
344
|
itemHeight = fontSize;
|
|
336
345
|
}
|
|
337
|
-
})
|
|
346
|
+
});
|
|
338
347
|
} else if (style) {
|
|
339
348
|
itemHeight = style.fontSize;
|
|
340
349
|
}
|
|
@@ -390,6 +399,7 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
390
399
|
...textStyle,
|
|
391
400
|
...(isFunction(style) ? style(item, index, this.getItems()) : style),
|
|
392
401
|
};
|
|
402
|
+
|
|
393
403
|
return this.addShape(container, {
|
|
394
404
|
type: 'text',
|
|
395
405
|
id: this.getElementId(`item-${item.id}-${textName}`),
|
|
@@ -398,6 +408,43 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
398
408
|
});
|
|
399
409
|
}
|
|
400
410
|
|
|
411
|
+
private drawRadio(container: IGroup, style: LegendRadio, item: ListItem, itemHeight: number, x: number) {
|
|
412
|
+
const r = itemHeight / 2;
|
|
413
|
+
const lineWidth = (r * 3.6) / 8;
|
|
414
|
+
const [x0, y0] = [x + r, itemHeight / 2 - r];
|
|
415
|
+
const [x1, y1] = [x0 + r, y0 + r];
|
|
416
|
+
const [x2, y2] = [x0, y1 + r];
|
|
417
|
+
const [x3, y3] = [x, y0 + r];
|
|
418
|
+
const { showRadio } = item;
|
|
419
|
+
const attrs = {
|
|
420
|
+
path: [
|
|
421
|
+
['M', x0, y0],
|
|
422
|
+
['A', r, r, 0, 0, 1, x1, y1],
|
|
423
|
+
['L', x1 - lineWidth, y1],
|
|
424
|
+
['L', x1, y1],
|
|
425
|
+
['A', r, r, 0, 0, 1, x2, y2],
|
|
426
|
+
['L', x2, y2 - lineWidth],
|
|
427
|
+
['L', x2, y2],
|
|
428
|
+
['A', r, r, 0, 0, 1, x3, y3],
|
|
429
|
+
['L', x3 + lineWidth, y3],
|
|
430
|
+
['L', x3, y3],
|
|
431
|
+
['A', r, r, 0, 0, 1, x0, y0],
|
|
432
|
+
['L', x0, y0 + lineWidth],
|
|
433
|
+
],
|
|
434
|
+
stroke: '#000000',
|
|
435
|
+
fill: '#ffffff',
|
|
436
|
+
...style,
|
|
437
|
+
opacity: showRadio ? 0.45 : 0,
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
return this.addShape(container, {
|
|
441
|
+
type: 'path',
|
|
442
|
+
id: this.getElementId(`item-${item.id}-radio`),
|
|
443
|
+
name: 'legend-item-radio',
|
|
444
|
+
attrs,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
401
448
|
// 绘制图例项
|
|
402
449
|
private drawItem(item: ListItem, index: number, itemHeight: number, itemGroup: IGroup) {
|
|
403
450
|
const groupId = `item-${item.id}`;
|
|
@@ -422,6 +469,7 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
422
469
|
const itemName = this.get('itemName');
|
|
423
470
|
const itemValue = this.get('itemValue');
|
|
424
471
|
const itemBackground = this.get('itemBackground');
|
|
472
|
+
const radio = this.get('radio');
|
|
425
473
|
const itemWidth = this.getLimitItemWidth();
|
|
426
474
|
|
|
427
475
|
let curX = 0; // 记录当前 x 的位置
|
|
@@ -446,6 +494,7 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
446
494
|
}
|
|
447
495
|
curX = nameShape.getBBox().maxX + itemName.spacing;
|
|
448
496
|
}
|
|
497
|
+
|
|
449
498
|
if (itemValue) {
|
|
450
499
|
const valueShape = this.drawItemText(subGroup, 'value', itemValue, item, itemHeight, curX, index);
|
|
451
500
|
if (itemWidth) {
|
|
@@ -459,7 +508,13 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
459
508
|
ellipsisLabel(true, valueShape, clamp(itemWidth - curX, 0, itemWidth));
|
|
460
509
|
}
|
|
461
510
|
}
|
|
511
|
+
curX = valueShape.getBBox().maxX + itemValue.spacing;
|
|
462
512
|
}
|
|
513
|
+
|
|
514
|
+
if (radio) {
|
|
515
|
+
this.drawRadio(subGroup, radio, item, itemHeight, curX);
|
|
516
|
+
}
|
|
517
|
+
|
|
463
518
|
// 添加透明的背景,便于拾取和包围盒计算
|
|
464
519
|
if (itemBackground) {
|
|
465
520
|
const bbox = subGroup.getBBox();
|
|
@@ -722,13 +777,13 @@ class Category extends LegendBase<CategoryLegendCfg> implements IList {
|
|
|
722
777
|
const translate =
|
|
723
778
|
layout === 'horizontal'
|
|
724
779
|
? {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
780
|
+
x: 0,
|
|
781
|
+
y: pageHeight * (1 - currentPageIndex),
|
|
782
|
+
}
|
|
728
783
|
: {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
784
|
+
x: pageWidth * (1 - currentPageIndex),
|
|
785
|
+
y: 0,
|
|
786
|
+
};
|
|
732
787
|
|
|
733
788
|
return getMatrixByTranslate(translate);
|
|
734
789
|
}
|
|
@@ -128,7 +128,7 @@ export class Scrollbar extends GroupComponent<ScrollbarCfg> implements ISlider {
|
|
|
128
128
|
private renderTrackShape(group: IGroup) {
|
|
129
129
|
const { trackLen, theme = { default: {} } } = this.cfg;
|
|
130
130
|
const { lineCap, trackColor, size: themeSize } = deepMix({}, DEFAULT_THEME, theme).default;
|
|
131
|
-
const size = get(this.cfg, 'size', themeSize)
|
|
131
|
+
const size = get(this.cfg, 'size', themeSize);
|
|
132
132
|
|
|
133
133
|
const attrs = this.get('isHorizontal')
|
|
134
134
|
? {
|
|
@@ -161,7 +161,7 @@ export class Scrollbar extends GroupComponent<ScrollbarCfg> implements ISlider {
|
|
|
161
161
|
private renderThumbShape(group: IGroup) {
|
|
162
162
|
const { thumbOffset, thumbLen, theme } = this.cfg;
|
|
163
163
|
const { size: themeSize, lineCap, thumbColor } = deepMix({}, DEFAULT_THEME, theme).default;
|
|
164
|
-
const size = get(this.cfg, 'size', themeSize)
|
|
164
|
+
const size = get(this.cfg, 'size', themeSize);
|
|
165
165
|
|
|
166
166
|
const attrs = this.get('isHorizontal')
|
|
167
167
|
? {
|
package/src/types.ts
CHANGED
|
@@ -177,6 +177,16 @@ export interface AxisLabelCfg {
|
|
|
177
177
|
* @type {number}
|
|
178
178
|
*/
|
|
179
179
|
offset?: number;
|
|
180
|
+
/**
|
|
181
|
+
* label 在X方向的额外偏移量
|
|
182
|
+
* @type {number}
|
|
183
|
+
*/
|
|
184
|
+
offsetX?: number;
|
|
185
|
+
/**
|
|
186
|
+
* label 在Y方向的额外偏移量
|
|
187
|
+
* @type {number}
|
|
188
|
+
*/
|
|
189
|
+
offsetY?: number;
|
|
180
190
|
/**
|
|
181
191
|
* 文本旋转角度
|
|
182
192
|
* @type {number}
|
|
@@ -259,7 +269,7 @@ export interface AxisTitleCfg {
|
|
|
259
269
|
* 文本对齐方式
|
|
260
270
|
* @type {string} start, center, end
|
|
261
271
|
*/
|
|
262
|
-
|
|
272
|
+
position?: string;
|
|
263
273
|
}
|
|
264
274
|
|
|
265
275
|
export interface BaseCfg {
|
|
@@ -583,6 +593,11 @@ export interface CategoryLegendCfg extends LegendBaseCfg {
|
|
|
583
593
|
* @type {LegendItemValueCfg}
|
|
584
594
|
*/
|
|
585
595
|
itemValue?: LegendItemValueCfg;
|
|
596
|
+
/**
|
|
597
|
+
*
|
|
598
|
+
* @type {LegendRadio}
|
|
599
|
+
*/
|
|
600
|
+
radio?: LegendRadio;
|
|
586
601
|
/**
|
|
587
602
|
* 最大宽度
|
|
588
603
|
* @type {number}
|
|
@@ -606,11 +621,11 @@ export interface CategoryLegendCfg extends LegendBaseCfg {
|
|
|
606
621
|
/**
|
|
607
622
|
* 是否翻页
|
|
608
623
|
*/
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
624
|
+
flipPage?: boolean;
|
|
625
|
+
/**
|
|
626
|
+
* 翻页行数(只适用于横向)
|
|
627
|
+
*/
|
|
628
|
+
maxRow?: number;
|
|
614
629
|
/**
|
|
615
630
|
* 分页器配置
|
|
616
631
|
* @type {LegendPageNavigatorCfg}
|
|
@@ -797,7 +812,20 @@ export interface LegendItemValueCfg {
|
|
|
797
812
|
* 图例项附加值的配置
|
|
798
813
|
* @type {ShapeAttrs}
|
|
799
814
|
*/
|
|
800
|
-
style?: ShapeAttrs
|
|
815
|
+
style?: ShapeAttrs | ShapeAttrsCallback;
|
|
816
|
+
/**
|
|
817
|
+
* 图例值和后面的间隔,可以控制和 RadioIcon 的间距
|
|
818
|
+
* @type {number}
|
|
819
|
+
*/
|
|
820
|
+
spacing?: number;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
export interface LegendRadio {
|
|
824
|
+
/**
|
|
825
|
+
* radio 的配置项
|
|
826
|
+
* @type {ShapeAttrs}
|
|
827
|
+
*/
|
|
828
|
+
style?: ShapeAttrs;
|
|
801
829
|
}
|
|
802
830
|
|
|
803
831
|
export interface LegendMarkerCfg {
|
package/src/util/label.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IElement } from '@antv/g-base';
|
|
2
|
-
import { each, isNil } from '@antv/util';
|
|
2
|
+
import { each, isNil, getEllipsisText, pick } from '@antv/util';
|
|
3
3
|
|
|
4
4
|
import { ellipsisString, strLen } from './text';
|
|
5
5
|
|
|
@@ -71,27 +71,42 @@ export function testLabel(label: IElement, limitLength: number): boolean {
|
|
|
71
71
|
|
|
72
72
|
/** 处理 text shape 的自动省略 */
|
|
73
73
|
export function ellipsisLabel(isVertical: boolean, label: IElement, limitLength: number, position: string = 'tail') {
|
|
74
|
-
const text = label.attr('text');
|
|
74
|
+
const text = label.attr('text') ?? ''; // 避免出现null、undefined
|
|
75
|
+
|
|
76
|
+
if (position === 'tail') {
|
|
77
|
+
// component 里的缩略处理做得很糟糕,文字长度测算完全不准确
|
|
78
|
+
// 这里暂时只对 tail 做处理
|
|
79
|
+
const font = pick(label.attr(), ['fontSize', 'fontFamily', 'fontWeight', 'fontStyle', 'fontVariant']);
|
|
80
|
+
const ellipsisText = getEllipsisText(text, limitLength, font, '…') as string;
|
|
81
|
+
if (text !== ellipsisText) {
|
|
82
|
+
label.attr('text', ellipsisText);
|
|
83
|
+
label.set('tip', text);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
label.set('tip', null);
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
75
90
|
const labelLength = getLabelLength(isVertical, label);
|
|
76
91
|
const codeLength = strLen(text);
|
|
77
|
-
let
|
|
92
|
+
let ellipsisFlag = false;
|
|
78
93
|
if (limitLength < labelLength) {
|
|
79
|
-
const
|
|
94
|
+
const reserveLength = Math.floor((limitLength / labelLength) * codeLength) - ELLIPSIS_CODE_LENGTH; // 计算出来的应该保存的长度
|
|
80
95
|
let newText;
|
|
81
|
-
if (
|
|
82
|
-
newText = ellipsisString(text,
|
|
96
|
+
if (reserveLength >= 0) {
|
|
97
|
+
newText = ellipsisString(text, reserveLength, position);
|
|
83
98
|
} else {
|
|
84
99
|
newText = ELLIPSIS_CODE;
|
|
85
100
|
}
|
|
86
101
|
if (newText) {
|
|
87
102
|
label.attr('text', newText);
|
|
88
|
-
|
|
103
|
+
ellipsisFlag = true;
|
|
89
104
|
}
|
|
90
105
|
}
|
|
91
|
-
if (
|
|
106
|
+
if (ellipsisFlag) {
|
|
92
107
|
label.set('tip', text);
|
|
93
108
|
} else {
|
|
94
109
|
label.set('tip', null);
|
|
95
110
|
}
|
|
96
|
-
return
|
|
111
|
+
return ellipsisFlag;
|
|
97
112
|
}
|
package/src/util/theme.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
fontFamily: `
|
|
3
|
-
|
|
3
|
+
BlinkMacSystemFont, "Segoe UI", Roboto,"Helvetica Neue",
|
|
4
4
|
Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
|
|
5
5
|
SimSun, "sans-serif"`,
|
|
6
6
|
textColor: '#2C3542',
|