@antv/component 2.1.3 → 2.1.5
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/dist/component.min.js +1 -1
- package/esm/animation/fadeIn.d.ts +1 -1
- package/esm/animation/fadeOut.d.ts +1 -1
- package/esm/animation/utils.d.ts +3 -3
- package/esm/ui/axis/axis.d.ts +1 -1
- package/esm/ui/axis/axis.js +1 -1
- package/esm/ui/axis/axis.js.map +1 -1
- package/esm/ui/axis/guides/grid.d.ts +1 -1
- package/esm/ui/axis/guides/labels.d.ts +2 -1
- package/esm/ui/axis/guides/labels.js +4 -4
- package/esm/ui/axis/guides/labels.js.map +1 -1
- package/esm/ui/axis/guides/ticks.d.ts +1 -1
- package/esm/ui/axis/guides/title.d.ts +1 -1
- package/esm/ui/axis/overlap/autoEllipsis.js +1 -1
- package/esm/ui/axis/overlap/autoWrap.d.ts +2 -2
- package/esm/ui/axis/overlap/autoWrap.js +5 -2
- package/esm/ui/axis/overlap/autoWrap.js.map +1 -1
- package/esm/ui/axis/overlap/index.d.ts +1 -1
- package/esm/ui/axis/overlap/index.js +3 -3
- package/esm/ui/axis/overlap/index.js.map +1 -1
- package/esm/ui/axis/types.d.ts +1 -1
- package/esm/ui/grid/index.d.ts +1 -1
- package/esm/ui/legend/category/item.d.ts +7 -0
- package/esm/ui/legend/category/item.js +64 -1
- package/esm/ui/legend/category/item.js.map +1 -1
- package/esm/ui/legend/category/items.d.ts +9 -0
- package/esm/ui/legend/category/items.js +2 -2
- package/esm/ui/legend/category/items.js.map +1 -1
- package/esm/util/keyframe-interpolate.d.ts +1 -1
- package/lib/animation/fadeIn.d.ts +1 -1
- package/lib/animation/fadeOut.d.ts +1 -1
- package/lib/animation/utils.d.ts +3 -3
- package/lib/ui/axis/axis.d.ts +1 -1
- package/lib/ui/axis/axis.js +1 -1
- package/lib/ui/axis/axis.js.map +1 -1
- package/lib/ui/axis/guides/grid.d.ts +1 -1
- package/lib/ui/axis/guides/labels.d.ts +2 -1
- package/lib/ui/axis/guides/labels.js +4 -4
- package/lib/ui/axis/guides/labels.js.map +1 -1
- package/lib/ui/axis/guides/ticks.d.ts +1 -1
- package/lib/ui/axis/guides/title.d.ts +1 -1
- package/lib/ui/axis/overlap/autoEllipsis.js +1 -1
- package/lib/ui/axis/overlap/autoWrap.d.ts +2 -2
- package/lib/ui/axis/overlap/autoWrap.js +5 -2
- package/lib/ui/axis/overlap/autoWrap.js.map +1 -1
- package/lib/ui/axis/overlap/index.d.ts +1 -1
- package/lib/ui/axis/overlap/index.js +3 -3
- package/lib/ui/axis/overlap/index.js.map +1 -1
- package/lib/ui/axis/types.d.ts +1 -1
- package/lib/ui/grid/index.d.ts +1 -1
- package/lib/ui/legend/category/item.d.ts +7 -0
- package/lib/ui/legend/category/item.js +63 -0
- package/lib/ui/legend/category/item.js.map +1 -1
- package/lib/ui/legend/category/items.d.ts +9 -0
- package/lib/ui/legend/category/items.js +2 -2
- package/lib/ui/legend/category/items.js.map +1 -1
- package/lib/util/keyframe-interpolate.d.ts +1 -1
- package/package.json +2 -3
- package/src/ui/axis/axis.ts +1 -1
- package/src/ui/axis/guides/labels.ts +5 -4
- package/src/ui/axis/overlap/autoEllipsis.ts +1 -1
- package/src/ui/axis/overlap/autoWrap.ts +11 -4
- package/src/ui/axis/overlap/index.ts +8 -3
- package/src/ui/axis/types.ts +1 -1
- package/src/ui/legend/category/item.ts +69 -0
- package/src/ui/legend/category/items.ts +8 -1
|
@@ -170,8 +170,8 @@ function applyTextStyle(node: DisplayObject, style: Partial<TextStyleProps>) {
|
|
|
170
170
|
if (node.nodeName === 'text') node.attr(style);
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
function overlapHandler(attr: Required<AxisStyleProps
|
|
174
|
-
processOverlap(this.node().childNodes as DisplayObject[], attr, {
|
|
173
|
+
function overlapHandler(attr: Required<AxisStyleProps>, main: DisplayObject) {
|
|
174
|
+
processOverlap(this.node().childNodes as DisplayObject[], attr, main, {
|
|
175
175
|
hide,
|
|
176
176
|
show,
|
|
177
177
|
rotate: (label, angle) => {
|
|
@@ -219,7 +219,8 @@ export function renderLabels(
|
|
|
219
219
|
container: Selection,
|
|
220
220
|
data: AxisDatum[],
|
|
221
221
|
attr: Required<AxisStyleProps>,
|
|
222
|
-
animate: StandardAnimationOption
|
|
222
|
+
animate: StandardAnimationOption,
|
|
223
|
+
main: DisplayObject
|
|
223
224
|
) {
|
|
224
225
|
const finalData = filterExec(data, attr.labelFilter);
|
|
225
226
|
const style = subStyleProps<AxisLabelStyleProps>(attr, 'label');
|
|
@@ -262,7 +263,7 @@ export function renderLabels(
|
|
|
262
263
|
.transitions();
|
|
263
264
|
// handle overlapping after transitions finished
|
|
264
265
|
onAnimatesFinished(transitions, () => {
|
|
265
|
-
overlapHandler.call(container, attr);
|
|
266
|
+
overlapHandler.call(container, attr, main);
|
|
266
267
|
});
|
|
267
268
|
return transitions;
|
|
268
269
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getCallbackValue } from '../../../util';
|
|
2
|
+
import type { DisplayObject, Text } from '../../../shapes';
|
|
2
3
|
import { isAxisHorizontal } from '../guides/line';
|
|
3
4
|
import { AxisStyleProps, LinearAxisStyleProps, WrapOverlapCfg } from '../types';
|
|
4
5
|
import { boundTest } from '../utils/test';
|
|
@@ -17,9 +18,15 @@ function inferTextBaseline(attr: AxisStyleProps) {
|
|
|
17
18
|
return 'middle';
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export default function wrapLabels(
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
export default function wrapLabels(
|
|
22
|
+
labels: Text[],
|
|
23
|
+
overlapCfg: WrapOverlapCfg,
|
|
24
|
+
attr: AxisStyleProps,
|
|
25
|
+
utils: Utils,
|
|
26
|
+
main: DisplayObject
|
|
27
|
+
) {
|
|
28
|
+
const { maxLines = 3, recoverWhenFailed = true, margin = [0, 0, 0, 0] } = overlapCfg;
|
|
29
|
+
const wordWrapWidth = getCallbackValue(overlapCfg.wordWrapWidth ?? 50, [main]);
|
|
23
30
|
const defaultLines = labels.map((label) => label.attr('maxLines') || 1);
|
|
24
31
|
|
|
25
32
|
const minLines = Math.min(...defaultLines);
|
|
@@ -30,16 +30,21 @@ export function canProcessOverlap(
|
|
|
30
30
|
if (attr.labelOverlap.length < 1) return false;
|
|
31
31
|
if (type === 'hide') return !isInOffscreenGroup(labels[0]);
|
|
32
32
|
if (type === 'rotate') return !labels.some((label) => !!label.attr('transform')?.includes('rotate'));
|
|
33
|
-
if (type === 'ellipsis' || type === 'wrap') return labels.filter((item) => item.querySelector('text')).length
|
|
33
|
+
if (type === 'ellipsis' || type === 'wrap') return labels.filter((item) => item.querySelector('text')).length >= 1;
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export function processOverlap(
|
|
37
|
+
export function processOverlap(
|
|
38
|
+
labels: DisplayObject[],
|
|
39
|
+
attr: Required<AxisStyleProps>,
|
|
40
|
+
main: DisplayObject,
|
|
41
|
+
utils: OverlapUtilsType
|
|
42
|
+
) {
|
|
38
43
|
const { labelOverlap = [] } = attr;
|
|
39
44
|
if (!labelOverlap.length) return;
|
|
40
45
|
labelOverlap.forEach((overlapCfg) => {
|
|
41
46
|
const { type } = overlapCfg;
|
|
42
47
|
const util = OverlapUtils.get(type);
|
|
43
|
-
if (canProcessOverlap(labels, attr, type)) util?.(labels as any[], overlapCfg, attr, utils);
|
|
48
|
+
if (canProcessOverlap(labels, attr, type)) util?.(labels as any[], overlapCfg, attr, utils, main);
|
|
44
49
|
});
|
|
45
50
|
}
|
package/src/ui/axis/types.ts
CHANGED
|
@@ -44,7 +44,7 @@ export interface HideOverlapCfg extends Overlap {
|
|
|
44
44
|
}
|
|
45
45
|
export interface WrapOverlapCfg extends Overlap {
|
|
46
46
|
type: 'wrap';
|
|
47
|
-
wordWrapWidth?: number
|
|
47
|
+
wordWrapWidth?: Callable<number, [DisplayObject]>;
|
|
48
48
|
maxLines?: number;
|
|
49
49
|
recoverWhenFailed?: boolean;
|
|
50
50
|
}
|
|
@@ -24,7 +24,11 @@ import {
|
|
|
24
24
|
scaleToPixel,
|
|
25
25
|
select,
|
|
26
26
|
subStyleProps,
|
|
27
|
+
deepAssign,
|
|
27
28
|
} from '../../../util';
|
|
29
|
+
import { Poptip } from '../../poptip';
|
|
30
|
+
import type { PoptipStyleProps } from '../../poptip/types';
|
|
31
|
+
import type { PoptipRender } from './items';
|
|
28
32
|
|
|
29
33
|
type ItemMarkerStyle = { size?: number } & PathStyleProps;
|
|
30
34
|
type ItemTextStyle = Omit<TextStyleProps, 'text'>;
|
|
@@ -45,6 +49,7 @@ export type CategoryItemStyleProps = GroupStyleProps &
|
|
|
45
49
|
width?: number;
|
|
46
50
|
x?: number;
|
|
47
51
|
y?: number;
|
|
52
|
+
poptip?: PoptipStyleProps & PoptipRender;
|
|
48
53
|
};
|
|
49
54
|
|
|
50
55
|
export type CategoryItemOptions = ComponentOptions<CategoryItemStyleProps>;
|
|
@@ -64,6 +69,25 @@ const CLASS_NAMES = classNames(
|
|
|
64
69
|
'legend-category-item'
|
|
65
70
|
);
|
|
66
71
|
|
|
72
|
+
const DEFAULT_POPTIP_PROPS: PoptipStyleProps = {
|
|
73
|
+
offset: [0, 20],
|
|
74
|
+
domStyles: {
|
|
75
|
+
'.component-poptip': {
|
|
76
|
+
opacity: '1',
|
|
77
|
+
padding: '8px 12px',
|
|
78
|
+
background: '#fff',
|
|
79
|
+
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)',
|
|
80
|
+
},
|
|
81
|
+
'.component-poptip-arrow': {
|
|
82
|
+
display: 'none',
|
|
83
|
+
},
|
|
84
|
+
'.component-poptip-text': {
|
|
85
|
+
color: '#000',
|
|
86
|
+
lineHeight: '20px',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
67
91
|
function styleOfMarker(group: Group): BaseStyleProps {
|
|
68
92
|
const marker = group.querySelector(CLASS_NAMES.marker.class);
|
|
69
93
|
if (marker) return marker.style;
|
|
@@ -85,6 +109,8 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
85
109
|
});
|
|
86
110
|
}
|
|
87
111
|
|
|
112
|
+
private poptipGroup!: Poptip;
|
|
113
|
+
|
|
88
114
|
private markerGroup!: Selection<Group>;
|
|
89
115
|
|
|
90
116
|
private labelGroup!: Selection<Group>;
|
|
@@ -224,6 +250,48 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
224
250
|
});
|
|
225
251
|
}
|
|
226
252
|
|
|
253
|
+
private createPoptip() {
|
|
254
|
+
const { poptip } = this.attributes;
|
|
255
|
+
const { render, ...poptipStyle } = poptip || {};
|
|
256
|
+
const poptipGroup = new Poptip({ style: deepAssign(DEFAULT_POPTIP_PROPS, poptipStyle) });
|
|
257
|
+
this.poptipGroup = poptipGroup;
|
|
258
|
+
return poptipGroup;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private bindPoptip(node: DisplayObject) {
|
|
262
|
+
const { poptip } = this.attributes;
|
|
263
|
+
if (!poptip) return;
|
|
264
|
+
const poptipGroup = this.poptipGroup || this.createPoptip();
|
|
265
|
+
poptipGroup.bind(node, () => {
|
|
266
|
+
const { labelText, valueText, markerFill } = this.attributes;
|
|
267
|
+
const label = typeof labelText === 'string' ? labelText : (labelText as DisplayObject)?.attr('text');
|
|
268
|
+
const value = typeof valueText === 'string' ? valueText : (valueText as DisplayObject)?.attr('text');
|
|
269
|
+
if (typeof poptip.render === 'function') {
|
|
270
|
+
return { html: poptip.render({ label, value, color: markerFill as string }) };
|
|
271
|
+
}
|
|
272
|
+
let html = '';
|
|
273
|
+
if (typeof label === 'string' || typeof label === 'number') {
|
|
274
|
+
html += `<div class="component-poptip-label">${label}</div>`;
|
|
275
|
+
}
|
|
276
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
277
|
+
html += `<div class="component-poptip-value">${value}</div>`;
|
|
278
|
+
}
|
|
279
|
+
return { html };
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private renderPoptip(ctn: Selection) {
|
|
284
|
+
const { poptip } = this.attributes;
|
|
285
|
+
if (!poptip) return;
|
|
286
|
+
const valueNode = ctn.maybeAppendByClassName(CLASS_NAMES.value, 'g').node();
|
|
287
|
+
const labelNode = ctn.maybeAppendByClassName(CLASS_NAMES.label, 'g').node();
|
|
288
|
+
[valueNode, labelNode].forEach((node) => {
|
|
289
|
+
if (node) {
|
|
290
|
+
this.bindPoptip(node);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
227
295
|
private renderBackground(container: Selection) {
|
|
228
296
|
const { width, height } = this.shape;
|
|
229
297
|
const style = subStyleProps(this.attributes, 'background');
|
|
@@ -264,6 +332,7 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
264
332
|
this.renderLabel(ctn);
|
|
265
333
|
this.renderValue(ctn);
|
|
266
334
|
this.renderBackground(ctn);
|
|
335
|
+
this.renderPoptip(ctn);
|
|
267
336
|
this.adjustLayout();
|
|
268
337
|
}
|
|
269
338
|
}
|
|
@@ -20,6 +20,7 @@ import { Navigator } from '../../navigator';
|
|
|
20
20
|
import { ifHorizontal } from '../utils';
|
|
21
21
|
import type { CategoryItemStyleProps } from './item';
|
|
22
22
|
import { CategoryItem } from './item';
|
|
23
|
+
import type { PoptipStyleProps } from '../../poptip/types';
|
|
23
24
|
|
|
24
25
|
interface CategoryItemsDatum {
|
|
25
26
|
[keys: string]: any;
|
|
@@ -30,6 +31,10 @@ type CallableItemStyle = CallableStyleProps<
|
|
|
30
31
|
CallbackParameter<CategoryItemsDatum>
|
|
31
32
|
>;
|
|
32
33
|
|
|
34
|
+
export type PoptipRender = {
|
|
35
|
+
render?: (params: { label: string | number; value: string | number; color?: string }) => string;
|
|
36
|
+
};
|
|
37
|
+
|
|
33
38
|
export type CategoryItemsStyleProps = GroupStyleProps &
|
|
34
39
|
PrefixStyleProps<CallableItemStyle, 'item'> &
|
|
35
40
|
PrefixStyleProps<NavigatorStyleProps, 'nav'> & {
|
|
@@ -49,6 +54,7 @@ export type CategoryItemsStyleProps = GroupStyleProps &
|
|
|
49
54
|
click?: (el: Selection) => void;
|
|
50
55
|
mouseenter?: (el: Selection) => void;
|
|
51
56
|
mouseleave?: (el: Selection) => void;
|
|
57
|
+
poptip?: PoptipStyleProps & PoptipRender;
|
|
52
58
|
};
|
|
53
59
|
|
|
54
60
|
export type CategoryItemsOptions = ComponentOptions<CategoryItemsStyleProps>;
|
|
@@ -123,7 +129,7 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
private get renderData() {
|
|
126
|
-
const { data, layout } = this.attributes;
|
|
132
|
+
const { data, layout, poptip } = this.attributes;
|
|
127
133
|
const style = subStyleProps<CategoryItemStyleProps>(this.attributes, 'item');
|
|
128
134
|
|
|
129
135
|
const d = data.map((datum, index) => {
|
|
@@ -135,6 +141,7 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
135
141
|
layout,
|
|
136
142
|
labelText,
|
|
137
143
|
valueText,
|
|
144
|
+
poptip,
|
|
138
145
|
...Object.fromEntries(
|
|
139
146
|
Object.entries(style).map(([key, val]) => [key, getCallbackValue(val, [datum, index, data])])
|
|
140
147
|
),
|