@antv/component 2.1.7 → 2.1.9
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 +18 -2
- package/esm/ui/axis/axis.js.map +1 -1
- package/esm/ui/axis/classname-map.d.ts +18 -0
- package/esm/ui/axis/classname-map.js +20 -0
- package/esm/ui/axis/classname-map.js.map +1 -0
- package/esm/ui/axis/constant.js +16 -15
- package/esm/ui/axis/constant.js.map +1 -1
- package/esm/ui/axis/guides/grid.d.ts +1 -1
- package/esm/ui/axis/guides/grid.js +8 -1
- package/esm/ui/axis/guides/grid.js.map +1 -1
- package/esm/ui/axis/guides/labels.d.ts +1 -1
- package/esm/ui/axis/guides/labels.js +11 -4
- package/esm/ui/axis/guides/labels.js.map +1 -1
- package/esm/ui/axis/guides/line.js +31 -8
- package/esm/ui/axis/guides/line.js.map +1 -1
- package/esm/ui/axis/guides/ticks.d.ts +1 -1
- package/esm/ui/axis/guides/ticks.js +10 -3
- package/esm/ui/axis/guides/ticks.js.map +1 -1
- package/esm/ui/axis/guides/title.d.ts +1 -1
- package/esm/ui/axis/guides/title.js +6 -2
- package/esm/ui/axis/guides/title.js.map +1 -1
- package/esm/ui/axis/types.d.ts +1 -0
- package/esm/ui/axis/utils/classname.d.ts +46 -0
- package/esm/ui/axis/utils/classname.js +53 -0
- package/esm/ui/axis/utils/classname.js.map +1 -0
- package/esm/ui/axis/utils/index.d.ts +1 -0
- package/esm/ui/axis/utils/index.js +1 -0
- package/esm/ui/axis/utils/index.js.map +1 -1
- package/esm/ui/grid/index.d.ts +1 -1
- package/esm/ui/legend/category/item.d.ts +3 -1
- package/esm/ui/legend/category/item.js +42 -14
- package/esm/ui/legend/category/item.js.map +1 -1
- package/esm/ui/legend/category/items.d.ts +3 -0
- package/esm/ui/legend/category/items.js +12 -9
- package/esm/ui/legend/category/items.js.map +1 -1
- package/esm/ui/legend/category.d.ts +2 -1
- package/esm/ui/legend/category.js +45 -6
- package/esm/ui/legend/category.js.map +1 -1
- package/esm/ui/legend/classname-map.d.ts +37 -0
- package/esm/ui/legend/classname-map.js +38 -0
- package/esm/ui/legend/classname-map.js.map +1 -0
- package/esm/ui/legend/constant.d.ts +6 -0
- package/esm/ui/legend/constant.js +2 -0
- package/esm/ui/legend/constant.js.map +1 -1
- package/esm/ui/legend/continuous/handle.d.ts +1 -0
- package/esm/ui/legend/continuous/handle.js +23 -3
- package/esm/ui/legend/continuous/handle.js.map +1 -1
- package/esm/ui/legend/continuous/ribbon.d.ts +1 -0
- package/esm/ui/legend/continuous/ribbon.js +11 -1
- package/esm/ui/legend/continuous/ribbon.js.map +1 -1
- package/esm/ui/legend/continuous.d.ts +6 -0
- package/esm/ui/legend/continuous.js +77 -10
- package/esm/ui/legend/continuous.js.map +1 -1
- package/esm/ui/legend/title/index.js +5 -1
- package/esm/ui/legend/title/index.js.map +1 -1
- package/esm/ui/legend/title/types.d.ts +1 -0
- package/esm/ui/legend/types.d.ts +1 -0
- package/esm/ui/legend/utils/classname.d.ts +31 -0
- package/esm/ui/legend/utils/classname.js +35 -0
- package/esm/ui/legend/utils/classname.js.map +1 -0
- package/esm/ui/legend/utils/index.d.ts +1 -0
- package/esm/ui/legend/utils/index.js +2 -0
- package/esm/ui/legend/utils/index.js.map +1 -0
- package/esm/ui/navigator/index.js +19 -4
- package/esm/ui/navigator/index.js.map +1 -1
- package/esm/ui/navigator/types.d.ts +1 -0
- package/esm/ui/slider/handle.d.ts +2 -0
- package/esm/ui/slider/handle.js +21 -6
- package/esm/ui/slider/handle.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 +18 -2
- package/lib/ui/axis/axis.js.map +1 -1
- package/lib/ui/axis/classname-map.d.ts +18 -0
- package/lib/ui/axis/classname-map.js +23 -0
- package/lib/ui/axis/classname-map.js.map +1 -0
- package/lib/ui/axis/constant.js +16 -15
- package/lib/ui/axis/constant.js.map +1 -1
- package/lib/ui/axis/guides/grid.d.ts +1 -1
- package/lib/ui/axis/guides/grid.js +8 -1
- package/lib/ui/axis/guides/grid.js.map +1 -1
- package/lib/ui/axis/guides/labels.d.ts +1 -1
- package/lib/ui/axis/guides/labels.js +11 -4
- package/lib/ui/axis/guides/labels.js.map +1 -1
- package/lib/ui/axis/guides/line.js +31 -8
- package/lib/ui/axis/guides/line.js.map +1 -1
- package/lib/ui/axis/guides/ticks.d.ts +1 -1
- package/lib/ui/axis/guides/ticks.js +10 -3
- package/lib/ui/axis/guides/ticks.js.map +1 -1
- package/lib/ui/axis/guides/title.d.ts +1 -1
- package/lib/ui/axis/guides/title.js +6 -2
- package/lib/ui/axis/guides/title.js.map +1 -1
- package/lib/ui/axis/types.d.ts +1 -0
- package/lib/ui/axis/utils/classname.d.ts +46 -0
- package/lib/ui/axis/utils/classname.js +58 -0
- package/lib/ui/axis/utils/classname.js.map +1 -0
- package/lib/ui/axis/utils/index.d.ts +1 -0
- package/lib/ui/axis/utils/index.js +1 -0
- package/lib/ui/axis/utils/index.js.map +1 -1
- package/lib/ui/grid/index.d.ts +1 -1
- package/lib/ui/legend/category/item.d.ts +3 -1
- package/lib/ui/legend/category/item.js +42 -14
- package/lib/ui/legend/category/item.js.map +1 -1
- package/lib/ui/legend/category/items.d.ts +3 -0
- package/lib/ui/legend/category/items.js +11 -8
- package/lib/ui/legend/category/items.js.map +1 -1
- package/lib/ui/legend/category.d.ts +2 -1
- package/lib/ui/legend/category.js +45 -6
- package/lib/ui/legend/category.js.map +1 -1
- package/lib/ui/legend/classname-map.d.ts +37 -0
- package/lib/ui/legend/classname-map.js +41 -0
- package/lib/ui/legend/classname-map.js.map +1 -0
- package/lib/ui/legend/constant.d.ts +6 -0
- package/lib/ui/legend/constant.js +4 -1
- package/lib/ui/legend/constant.js.map +1 -1
- package/lib/ui/legend/continuous/handle.d.ts +1 -0
- package/lib/ui/legend/continuous/handle.js +23 -3
- package/lib/ui/legend/continuous/handle.js.map +1 -1
- package/lib/ui/legend/continuous/ribbon.d.ts +1 -0
- package/lib/ui/legend/continuous/ribbon.js +11 -1
- package/lib/ui/legend/continuous/ribbon.js.map +1 -1
- package/lib/ui/legend/continuous.d.ts +6 -0
- package/lib/ui/legend/continuous.js +76 -9
- package/lib/ui/legend/continuous.js.map +1 -1
- package/lib/ui/legend/title/index.js +5 -1
- package/lib/ui/legend/title/index.js.map +1 -1
- package/lib/ui/legend/title/types.d.ts +1 -0
- package/lib/ui/legend/types.d.ts +1 -0
- package/lib/ui/legend/utils/classname.d.ts +31 -0
- package/lib/ui/legend/utils/classname.js +39 -0
- package/lib/ui/legend/utils/classname.js.map +1 -0
- package/lib/ui/legend/utils/index.d.ts +1 -0
- package/lib/ui/legend/utils/index.js +5 -0
- package/lib/ui/legend/utils/index.js.map +1 -0
- package/lib/ui/navigator/index.js +19 -4
- package/lib/ui/navigator/index.js.map +1 -1
- package/lib/ui/navigator/types.d.ts +1 -0
- package/lib/ui/slider/handle.d.ts +2 -0
- package/lib/ui/slider/handle.js +21 -6
- package/lib/ui/slider/handle.js.map +1 -1
- package/lib/util/keyframe-interpolate.d.ts +1 -1
- package/package.json +3 -2
- package/src/ui/axis/axis.ts +19 -2
- package/src/ui/axis/classname-map.ts +22 -0
- package/src/ui/axis/constant.ts +17 -15
- package/src/ui/axis/guides/grid.ts +8 -1
- package/src/ui/axis/guides/labels.ts +16 -6
- package/src/ui/axis/guides/line.ts +50 -12
- package/src/ui/axis/guides/ticks.ts +15 -5
- package/src/ui/axis/guides/title.ts +10 -4
- package/src/ui/axis/types.ts +1 -0
- package/src/ui/axis/utils/classname.ts +62 -0
- package/src/ui/axis/utils/index.ts +1 -0
- package/src/ui/legend/category/item.ts +59 -12
- package/src/ui/legend/category/items.ts +18 -7
- package/src/ui/legend/category.ts +46 -7
- package/src/ui/legend/classname-map.ts +45 -0
- package/src/ui/legend/constant.ts +3 -0
- package/src/ui/legend/continuous/handle.ts +41 -4
- package/src/ui/legend/continuous/ribbon.ts +17 -1
- package/src/ui/legend/continuous.ts +96 -10
- package/src/ui/legend/title/index.ts +5 -1
- package/src/ui/legend/title/types.ts +1 -0
- package/src/ui/legend/types.ts +1 -0
- package/src/ui/legend/utils/classname.ts +39 -0
- package/src/ui/legend/utils/index.ts +1 -0
- package/src/ui/navigator/index.ts +32 -2
- package/src/ui/navigator/types.ts +1 -0
- package/src/ui/slider/handle.ts +44 -6
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
import { Poptip } from '../../poptip';
|
|
31
31
|
import type { PoptipStyleProps } from '../../poptip/types';
|
|
32
32
|
import type { PoptipRender } from './items';
|
|
33
|
+
import { getLegendClassName } from '../utils/classname';
|
|
34
|
+
import { CLASSNAME_SUFFIX_MAP } from '../constant';
|
|
33
35
|
|
|
34
36
|
type ItemMarkerStyle = { size?: number } & PathStyleProps;
|
|
35
37
|
type ItemTextStyle = Omit<TextStyleProps, 'text'>;
|
|
@@ -53,6 +55,7 @@ export type CategoryItemStyleProps = GroupStyleProps &
|
|
|
53
55
|
poptip?: PoptipStyleProps & PoptipRender;
|
|
54
56
|
focus?: boolean;
|
|
55
57
|
focusMarkerSize?: number;
|
|
58
|
+
classNamePrefix?: string;
|
|
56
59
|
};
|
|
57
60
|
|
|
58
61
|
export type CategoryItemOptions = ComponentOptions<CategoryItemStyleProps>;
|
|
@@ -100,7 +103,10 @@ function styleOfMarker(group: Group): BaseStyleProps {
|
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
103
|
-
|
|
106
|
+
// Key fields, used to pass extra info like id, index for poptip rendering
|
|
107
|
+
public keyFields: object = {};
|
|
108
|
+
|
|
109
|
+
constructor(options: CategoryItemOptions, keyFields?: Omit<CategoryItemOptions, 'style'>) {
|
|
104
110
|
super(options, {
|
|
105
111
|
span: [1, 1],
|
|
106
112
|
marker: () => new Circle({ style: { r: 6 } }),
|
|
@@ -112,6 +118,7 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
112
118
|
labelTextBaseline: 'middle',
|
|
113
119
|
valueTextBaseline: 'middle',
|
|
114
120
|
});
|
|
121
|
+
this.keyFields = keyFields || {};
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
private poptipGroup!: Poptip;
|
|
@@ -223,19 +230,26 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
223
230
|
}
|
|
224
231
|
|
|
225
232
|
private renderMarker(container: Selection) {
|
|
226
|
-
const { marker } = this.attributes;
|
|
233
|
+
const { marker, classNamePrefix } = this.attributes;
|
|
227
234
|
const style = subStyleProps(this.attributes, 'marker');
|
|
228
235
|
this.markerGroup = container.maybeAppendByClassName(CLASS_NAMES.markerGroup, 'g').style('zIndex', 0);
|
|
229
236
|
ifShow(!!marker, this.markerGroup, () => {
|
|
230
237
|
const parent = this.markerGroup.node();
|
|
231
238
|
const oldMarker = parent.childNodes?.[0] as DisplayObject | undefined;
|
|
239
|
+
const markerClassName = getLegendClassName(CLASS_NAMES.marker.name, CLASSNAME_SUFFIX_MAP.marker, classNamePrefix);
|
|
232
240
|
const newMarker =
|
|
233
|
-
typeof marker === 'string'
|
|
234
|
-
? new Marker({ style: { symbol: marker }, className: CLASS_NAMES.marker.name })
|
|
235
|
-
: marker();
|
|
241
|
+
typeof marker === 'string' ? new Marker({ style: { symbol: marker }, className: markerClassName }) : marker();
|
|
236
242
|
|
|
237
243
|
if (!oldMarker) {
|
|
238
|
-
if (!(newMarker instanceof Marker))
|
|
244
|
+
if (!(newMarker instanceof Marker)) {
|
|
245
|
+
const markerClassName = getLegendClassName(
|
|
246
|
+
CLASS_NAMES.marker.name,
|
|
247
|
+
CLASSNAME_SUFFIX_MAP.marker,
|
|
248
|
+
classNamePrefix
|
|
249
|
+
);
|
|
250
|
+
(newMarker as any).className = markerClassName;
|
|
251
|
+
select(newMarker).styles(style);
|
|
252
|
+
}
|
|
239
253
|
parent.appendChild(newMarker);
|
|
240
254
|
} else if (newMarker.nodeName === oldMarker.nodeName) {
|
|
241
255
|
if (oldMarker instanceof Marker) oldMarker.update({ ...style, symbol: marker });
|
|
@@ -245,7 +259,15 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
245
259
|
}
|
|
246
260
|
} else {
|
|
247
261
|
oldMarker.remove();
|
|
248
|
-
|
|
262
|
+
if (!(newMarker instanceof Marker)) {
|
|
263
|
+
const markerClassName = getLegendClassName(
|
|
264
|
+
CLASS_NAMES.marker.name,
|
|
265
|
+
CLASSNAME_SUFFIX_MAP.marker,
|
|
266
|
+
classNamePrefix
|
|
267
|
+
);
|
|
268
|
+
(newMarker as any).className = markerClassName;
|
|
269
|
+
}
|
|
270
|
+
select(newMarker).styles(style);
|
|
249
271
|
parent.appendChild(newMarker);
|
|
250
272
|
}
|
|
251
273
|
|
|
@@ -258,15 +280,23 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
258
280
|
|
|
259
281
|
private renderLabel(container: Selection) {
|
|
260
282
|
const { text: label, ...style } = subStyleProps(this.attributes, 'label');
|
|
283
|
+
const { classNamePrefix } = this.attributes;
|
|
261
284
|
this.labelGroup = container.maybeAppendByClassName<Group>(CLASS_NAMES.labelGroup, 'g').style('zIndex', 0);
|
|
262
|
-
|
|
285
|
+
const labelClassName = getLegendClassName(CLASS_NAMES.label.name, CLASSNAME_SUFFIX_MAP.label, classNamePrefix);
|
|
286
|
+
const labelElement = this.labelGroup.maybeAppendByClassName(CLASS_NAMES.label, () => renderExtDo(label));
|
|
287
|
+
labelElement.node().setAttribute('class', labelClassName);
|
|
288
|
+
labelElement.styles(style);
|
|
263
289
|
}
|
|
264
290
|
|
|
265
291
|
private renderValue(container: Selection) {
|
|
266
292
|
const { text: value, ...style } = subStyleProps(this.attributes, 'value');
|
|
293
|
+
const { classNamePrefix } = this.attributes;
|
|
267
294
|
this.valueGroup = container.maybeAppendByClassName(CLASS_NAMES.valueGroup, 'g').style('zIndex', 0);
|
|
268
295
|
ifShow(this.showValue, this.valueGroup, () => {
|
|
269
|
-
|
|
296
|
+
const valueClassName = getLegendClassName(CLASS_NAMES.value.name, CLASSNAME_SUFFIX_MAP.value, classNamePrefix);
|
|
297
|
+
const valueElement = this.valueGroup.maybeAppendByClassName(CLASS_NAMES.value, () => renderExtDo(value));
|
|
298
|
+
valueElement.node().setAttribute('class', valueClassName);
|
|
299
|
+
valueElement.styles(style);
|
|
270
300
|
});
|
|
271
301
|
}
|
|
272
302
|
|
|
@@ -287,7 +317,7 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
287
317
|
const label = typeof labelText === 'string' ? labelText : (labelText as DisplayObject)?.attr('text');
|
|
288
318
|
const value = typeof valueText === 'string' ? valueText : (valueText as DisplayObject)?.attr('text');
|
|
289
319
|
if (typeof poptip.render === 'function') {
|
|
290
|
-
return { html: poptip.render({ label, value, color: markerFill as string }) };
|
|
320
|
+
return { html: poptip.render({ ...this.keyFields, label, value, color: markerFill as string }) };
|
|
291
321
|
}
|
|
292
322
|
let html = '';
|
|
293
323
|
if (typeof label === 'string' || typeof label === 'number') {
|
|
@@ -301,7 +331,7 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
301
331
|
}
|
|
302
332
|
|
|
303
333
|
private renderFocus(ctn: Selection) {
|
|
304
|
-
const { focus, focusMarkerSize } = this.attributes;
|
|
334
|
+
const { focus, focusMarkerSize, classNamePrefix } = this.attributes;
|
|
305
335
|
const defaultOptions = {
|
|
306
336
|
x: 0,
|
|
307
337
|
y: 0,
|
|
@@ -316,11 +346,17 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
316
346
|
|
|
317
347
|
this.focusGroup = ctn.maybeAppendByClassName<Group>(CLASS_NAMES.focusGroup, 'g').style('zIndex', 0);
|
|
318
348
|
ifShow(focus, this.focusGroup, () => {
|
|
349
|
+
const focusClassName = getLegendClassName(
|
|
350
|
+
CLASS_NAMES.focus.name,
|
|
351
|
+
CLASSNAME_SUFFIX_MAP.focusIcon,
|
|
352
|
+
classNamePrefix
|
|
353
|
+
);
|
|
319
354
|
const marker = new Marker({
|
|
320
355
|
style: {
|
|
321
356
|
...defaultOptions,
|
|
322
357
|
symbol: 'focus',
|
|
323
358
|
},
|
|
359
|
+
className: focusClassName,
|
|
324
360
|
});
|
|
325
361
|
const interactiveCircle = new Circle({
|
|
326
362
|
style: {
|
|
@@ -359,7 +395,18 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
|
|
|
359
395
|
const { width, height } = this.shape;
|
|
360
396
|
const style = subStyleProps(this.attributes, 'background');
|
|
361
397
|
this.background = container.maybeAppendByClassName(CLASS_NAMES.backgroundGroup, 'g').style('zIndex', -1);
|
|
362
|
-
this.background.maybeAppendByClassName(CLASS_NAMES.background, 'rect')
|
|
398
|
+
const backgroundElement = this.background.maybeAppendByClassName(CLASS_NAMES.background, 'rect');
|
|
399
|
+
backgroundElement.styles({ width, height, ...style });
|
|
400
|
+
|
|
401
|
+
const { classNamePrefix = '' } = this.attributes;
|
|
402
|
+
if (classNamePrefix) {
|
|
403
|
+
const backgroundClassName = getLegendClassName(
|
|
404
|
+
CLASS_NAMES.background.name,
|
|
405
|
+
CLASSNAME_SUFFIX_MAP.background,
|
|
406
|
+
classNamePrefix
|
|
407
|
+
);
|
|
408
|
+
backgroundElement.node().setAttribute('class', backgroundClassName);
|
|
409
|
+
}
|
|
363
410
|
}
|
|
364
411
|
|
|
365
412
|
private adjustLayout() {
|
|
@@ -21,6 +21,8 @@ import { ifHorizontal } from '../utils';
|
|
|
21
21
|
import type { CategoryItemStyleProps } from './item';
|
|
22
22
|
import { CategoryItem } from './item';
|
|
23
23
|
import type { PoptipStyleProps } from '../../poptip/types';
|
|
24
|
+
import { getLegendClassName } from '../utils/classname';
|
|
25
|
+
import { CLASSNAME_SUFFIX_MAP } from '../constant';
|
|
24
26
|
|
|
25
27
|
interface CategoryItemsDatum {
|
|
26
28
|
[keys: string]: any;
|
|
@@ -32,7 +34,12 @@ type CallableItemStyle = CallableStyleProps<
|
|
|
32
34
|
>;
|
|
33
35
|
|
|
34
36
|
export type PoptipRender = {
|
|
35
|
-
render?: (params: {
|
|
37
|
+
render?: (params: {
|
|
38
|
+
label: string | number;
|
|
39
|
+
value: string | number;
|
|
40
|
+
color?: string;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}) => string;
|
|
36
43
|
};
|
|
37
44
|
|
|
38
45
|
export type CategoryItemsStyleProps = GroupStyleProps &
|
|
@@ -57,6 +64,8 @@ export type CategoryItemsStyleProps = GroupStyleProps &
|
|
|
57
64
|
poptip?: PoptipStyleProps & PoptipRender;
|
|
58
65
|
focus?: boolean;
|
|
59
66
|
focusMarkerSize?: number;
|
|
67
|
+
classNamePrefix?: string;
|
|
68
|
+
render?: (data: CategoryItemsDatum[]) => string | HTMLElement;
|
|
60
69
|
};
|
|
61
70
|
|
|
62
71
|
export type CategoryItemsOptions = ComponentOptions<CategoryItemsStyleProps>;
|
|
@@ -131,7 +140,7 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
131
140
|
}
|
|
132
141
|
|
|
133
142
|
private get renderData() {
|
|
134
|
-
const { data, layout, poptip, focus, focusMarkerSize } = this.attributes;
|
|
143
|
+
const { data, layout, poptip, focus, focusMarkerSize, classNamePrefix } = this.attributes;
|
|
135
144
|
const style = subStyleProps<CategoryItemStyleProps>(this.attributes, 'item');
|
|
136
145
|
|
|
137
146
|
const d = data.map((datum, index) => {
|
|
@@ -146,6 +155,7 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
146
155
|
poptip,
|
|
147
156
|
focus,
|
|
148
157
|
focusMarkerSize,
|
|
158
|
+
classNamePrefix,
|
|
149
159
|
...Object.fromEntries(
|
|
150
160
|
Object.entries(style).map(([key, val]) => [key, getCallbackValue(val, [datum, index, data])])
|
|
151
161
|
),
|
|
@@ -250,17 +260,18 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
250
260
|
}
|
|
251
261
|
|
|
252
262
|
private renderItems(container: Group) {
|
|
253
|
-
const { click, mouseenter, mouseleave } = this.attributes;
|
|
263
|
+
const { click, mouseenter, mouseleave, classNamePrefix } = this.attributes;
|
|
254
264
|
this.flattenPage(container);
|
|
255
265
|
const dispatchCustomEvent = this.dispatchCustomEvent.bind(this);
|
|
266
|
+
const itemClassName = getLegendClassName(CLASS_NAMES.item.name, CLASSNAME_SUFFIX_MAP.item, classNamePrefix);
|
|
256
267
|
select(container)
|
|
257
268
|
.selectAll(CLASS_NAMES.item.class)
|
|
258
269
|
.data(this.renderData, (d) => d.id)
|
|
259
270
|
.join(
|
|
260
271
|
(enter) =>
|
|
261
272
|
enter
|
|
262
|
-
.append(({ style }) => new CategoryItem({ style }))
|
|
263
|
-
.attr('className',
|
|
273
|
+
.append(({ style, ...rest }) => new CategoryItem({ style }, rest))
|
|
274
|
+
.attr('className', itemClassName)
|
|
264
275
|
.on('click', function () {
|
|
265
276
|
click?.(this);
|
|
266
277
|
dispatchCustomEvent('itemClick', { item: this });
|
|
@@ -311,9 +322,9 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
311
322
|
}
|
|
312
323
|
|
|
313
324
|
private renderNavigator(container: Selection) {
|
|
314
|
-
const { orientation } = this.attributes;
|
|
325
|
+
const { orientation, classNamePrefix } = this.attributes;
|
|
315
326
|
const navStyle = subStyleProps(this.attributes, 'nav');
|
|
316
|
-
const style = deepAssign({ orientation }, navStyle);
|
|
327
|
+
const style = deepAssign({ orientation, classNamePrefix }, navStyle);
|
|
317
328
|
const that = this;
|
|
318
329
|
container
|
|
319
330
|
.selectAll(CLASS_NAMES.navigator.class)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component } from '../../core';
|
|
2
|
-
import type
|
|
2
|
+
import { HTML, type Group } from '../../shapes';
|
|
3
3
|
import { BBox, select, Selection, splitStyle, subStyleProps } from '../../util';
|
|
4
4
|
import type { TitleStyleProps } from './title';
|
|
5
5
|
import { getBBox, Title } from './title';
|
|
@@ -9,6 +9,12 @@ import type { CategoryOptions, CategoryStyleProps } from './types';
|
|
|
9
9
|
|
|
10
10
|
export type { CategoryOptions, CategoryStyleProps };
|
|
11
11
|
|
|
12
|
+
class HtmlLegend extends HTML {
|
|
13
|
+
update(options: any) {
|
|
14
|
+
this.attr(options);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
export class Category extends Component<CategoryStyleProps> {
|
|
13
19
|
constructor(options: CategoryOptions) {
|
|
14
20
|
super(options, CATEGORY_DEFAULT_OPTIONS);
|
|
@@ -23,18 +29,38 @@ export class Category extends Component<CategoryStyleProps> {
|
|
|
23
29
|
private items!: Selection<CategoryItems>;
|
|
24
30
|
|
|
25
31
|
private renderTitle(container: Selection, width: number, height: number) {
|
|
26
|
-
const { showTitle, titleText } = this.attributes;
|
|
32
|
+
const { showTitle, titleText, classNamePrefix } = this.attributes;
|
|
27
33
|
const style = subStyleProps<TitleStyleProps>(this.attributes, 'title');
|
|
28
34
|
const [titleStyle, groupStyle] = splitStyle(style);
|
|
29
35
|
|
|
30
36
|
this.titleGroup = container.maybeAppendByClassName<Group>(CLASS_NAMES.titleGroup, 'g').styles(groupStyle);
|
|
31
37
|
|
|
32
|
-
const finalTitleStyle = { width, height, ...titleStyle, text: showTitle ? titleText : '' };
|
|
38
|
+
const finalTitleStyle = { width, height, ...titleStyle, text: showTitle ? titleText : '', classNamePrefix };
|
|
33
39
|
this.title = this.titleGroup
|
|
34
40
|
.maybeAppendByClassName(CLASS_NAMES.title, () => new Title({ style: finalTitleStyle as TitleStyleProps }))
|
|
35
41
|
.update(finalTitleStyle) as Selection<Title>;
|
|
36
42
|
}
|
|
37
43
|
|
|
44
|
+
private renderCustom(container: Selection) {
|
|
45
|
+
const { data } = this.attributes;
|
|
46
|
+
|
|
47
|
+
const style = {
|
|
48
|
+
innerHTML: this.attributes.render(data),
|
|
49
|
+
pointerEvents: 'auto' as const,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
container
|
|
53
|
+
.maybeAppendByClassName(
|
|
54
|
+
CLASS_NAMES.html,
|
|
55
|
+
() =>
|
|
56
|
+
new HtmlLegend({
|
|
57
|
+
className: CLASS_NAMES.html.name,
|
|
58
|
+
style,
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
.update(style);
|
|
62
|
+
}
|
|
63
|
+
|
|
38
64
|
private renderItems(container: Selection, bbox: DOMRect) {
|
|
39
65
|
const { x, y, width, height } = bbox;
|
|
40
66
|
const style = subStyleProps(this.attributes, 'title', true);
|
|
@@ -84,14 +110,27 @@ export class Category extends Component<CategoryStyleProps> {
|
|
|
84
110
|
}
|
|
85
111
|
|
|
86
112
|
render(attributes: Required<CategoryStyleProps>, container: Group) {
|
|
87
|
-
const { width, height, x = 0, y = 0 } = this.attributes;
|
|
113
|
+
const { width, height, x = 0, y = 0, classNamePrefix, render } = this.attributes;
|
|
88
114
|
const ctn = select(container);
|
|
115
|
+
|
|
116
|
+
// Set root container className
|
|
117
|
+
const baseClassName = container.className || 'legend-category';
|
|
118
|
+
if (classNamePrefix) {
|
|
119
|
+
container.attr('className', `${baseClassName} ${classNamePrefix}legend`);
|
|
120
|
+
} else if (!container.className) {
|
|
121
|
+
container.attr('className', 'legend-category');
|
|
122
|
+
}
|
|
123
|
+
|
|
89
124
|
container.style.transform = `translate(${x}, ${y})`;
|
|
90
125
|
|
|
91
|
-
|
|
126
|
+
if (render as CategoryStyleProps['render']) {
|
|
127
|
+
this.renderCustom(ctn);
|
|
128
|
+
} else {
|
|
129
|
+
this.renderTitle(ctn, width!, height!);
|
|
92
130
|
|
|
93
|
-
|
|
131
|
+
this.renderItems(ctn, this.availableSpace);
|
|
94
132
|
|
|
95
|
-
|
|
133
|
+
this.adjustLayout();
|
|
134
|
+
}
|
|
96
135
|
}
|
|
97
136
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* className suffix mapping for legend elements
|
|
3
|
+
* Used to generate prefixed classNames, e.g., classNamePrefix='g2-' generates 'g2-legend-{suffix}'
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* import { CLASSNAME_SUFFIX_MAP, getLegendClassName } from './utils';
|
|
7
|
+
*
|
|
8
|
+
* const titleClassName = getLegendClassName(
|
|
9
|
+
* CLASS_NAMES.text.name,
|
|
10
|
+
* CLASSNAME_SUFFIX_MAP.title,
|
|
11
|
+
* 'g2-'
|
|
12
|
+
* );
|
|
13
|
+
* // Returns: 'title-text g2-legend-title'
|
|
14
|
+
*/
|
|
15
|
+
export const CLASSNAME_SUFFIX_MAP = {
|
|
16
|
+
// Common elements
|
|
17
|
+
title: 'title',
|
|
18
|
+
|
|
19
|
+
// Category legend elements
|
|
20
|
+
item: 'item',
|
|
21
|
+
marker: 'marker',
|
|
22
|
+
label: 'label',
|
|
23
|
+
value: 'value',
|
|
24
|
+
focusIcon: 'focus-icon',
|
|
25
|
+
background: 'background',
|
|
26
|
+
|
|
27
|
+
// Continuous legend elements
|
|
28
|
+
ribbon: 'ribbon',
|
|
29
|
+
track: 'track',
|
|
30
|
+
selection: 'selection',
|
|
31
|
+
handle: 'handle',
|
|
32
|
+
handleMarker: 'handle-marker',
|
|
33
|
+
handleLabel: 'handle-label',
|
|
34
|
+
indicator: 'indicator',
|
|
35
|
+
|
|
36
|
+
// Navigator elements (reserved)
|
|
37
|
+
prevBtn: 'prev-btn',
|
|
38
|
+
nextBtn: 'next-btn',
|
|
39
|
+
pageInfo: 'page-info',
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* className suffix type
|
|
44
|
+
*/
|
|
45
|
+
export type ClassNameSuffix = keyof typeof CLASSNAME_SUFFIX_MAP;
|
|
@@ -2,6 +2,8 @@ import { classNames, deepAssign, superStyleProps } from '../../util';
|
|
|
2
2
|
import { DEFAULT_HANDLE_CFG } from './continuous/handle';
|
|
3
3
|
import type { LegendBaseStyleProps } from './types';
|
|
4
4
|
|
|
5
|
+
export { CLASSNAME_SUFFIX_MAP, type ClassNameSuffix } from './classname-map';
|
|
6
|
+
|
|
5
7
|
export const LEGEND_BASE_DEFAULT_OPTIONS: Partial<LegendBaseStyleProps> = {
|
|
6
8
|
showTitle: true,
|
|
7
9
|
padding: 0,
|
|
@@ -60,6 +62,7 @@ export const NAME_VALUE_RATIO = 0.5;
|
|
|
60
62
|
export const CLASS_NAMES = classNames(
|
|
61
63
|
{
|
|
62
64
|
title: 'title',
|
|
65
|
+
html: 'html',
|
|
63
66
|
titleGroup: 'title-group',
|
|
64
67
|
items: 'items',
|
|
65
68
|
itemsGroup: 'items-group',
|
|
@@ -7,6 +7,8 @@ import type { Selection } from '../../../util';
|
|
|
7
7
|
import { classNames, ifShow, select, subStyleProps } from '../../../util';
|
|
8
8
|
import { Marker, MarkerStyleProps } from '../../marker';
|
|
9
9
|
import { ifHorizontal } from '../utils';
|
|
10
|
+
import { getLegendClassName } from '../utils/classname';
|
|
11
|
+
import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
|
|
10
12
|
|
|
11
13
|
export type HandleStyleProps<T = any> = GroupStyleProps &
|
|
12
14
|
PrefixObject<TextStyleProps, 'label'> &
|
|
@@ -17,6 +19,7 @@ export type HandleStyleProps<T = any> = GroupStyleProps &
|
|
|
17
19
|
/** spacing between marker and label */
|
|
18
20
|
spacing?: number;
|
|
19
21
|
shape?: 'basic' | 'slider';
|
|
22
|
+
classNamePrefix?: string;
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
export type HandleOptions = ComponentOptions<HandleStyleProps>;
|
|
@@ -64,20 +67,47 @@ export class Handle extends Component<HandleStyleProps> {
|
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
private renderMarker(container: Selection) {
|
|
67
|
-
const {
|
|
68
|
-
|
|
70
|
+
const {
|
|
71
|
+
orientation,
|
|
72
|
+
classNamePrefix,
|
|
73
|
+
markerSymbol = ifHorizontal(orientation, 'horizontalHandle', 'verticalHandle'),
|
|
74
|
+
} = this.attributes;
|
|
69
75
|
|
|
70
76
|
ifShow(!!markerSymbol, container, (group) => {
|
|
71
77
|
const handleStyle = subStyleProps(this.attributes, 'marker');
|
|
72
78
|
const markerStyle = { symbol: markerSymbol, ...handleStyle };
|
|
79
|
+
const markerClassName = getLegendClassName(
|
|
80
|
+
CLASS_NAMES.marker.name,
|
|
81
|
+
CLASSNAME_SUFFIX_MAP.handleMarker,
|
|
82
|
+
classNamePrefix
|
|
83
|
+
);
|
|
84
|
+
|
|
73
85
|
this.marker = group
|
|
74
|
-
.maybeAppendByClassName(
|
|
86
|
+
.maybeAppendByClassName(
|
|
87
|
+
CLASS_NAMES.marker,
|
|
88
|
+
() =>
|
|
89
|
+
new Marker({
|
|
90
|
+
style: markerStyle,
|
|
91
|
+
className: markerClassName,
|
|
92
|
+
})
|
|
93
|
+
)
|
|
75
94
|
.update(markerStyle);
|
|
95
|
+
|
|
96
|
+
// Update Marker's child element className (Marker component overrides className internally)
|
|
97
|
+
if (classNamePrefix) {
|
|
98
|
+
const markerElement = this.marker.node().querySelector('.marker');
|
|
99
|
+
if (markerElement) {
|
|
100
|
+
const currentClass = markerElement.getAttribute('class') || '';
|
|
101
|
+
const baseClass = currentClass.split(' ')[0]; // e.g., 'marker'
|
|
102
|
+
const legendClassName = getLegendClassName(baseClass, CLASSNAME_SUFFIX_MAP.handleMarker, classNamePrefix);
|
|
103
|
+
markerElement.setAttribute('class', legendClassName);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
76
106
|
});
|
|
77
107
|
}
|
|
78
108
|
|
|
79
109
|
private renderLabel(container: Selection) {
|
|
80
|
-
const { showLabel, orientation, spacing = 0, formatter } = this.attributes;
|
|
110
|
+
const { showLabel, orientation, spacing = 0, formatter, classNamePrefix } = this.attributes;
|
|
81
111
|
|
|
82
112
|
ifShow(showLabel, container, (group) => {
|
|
83
113
|
const { text, ...labelStyle } = subStyleProps(this.attributes, 'label');
|
|
@@ -90,8 +120,15 @@ export class Handle extends Component<HandleStyleProps> {
|
|
|
90
120
|
[width + spacing, 0, 'start', 'middle']
|
|
91
121
|
);
|
|
92
122
|
|
|
123
|
+
const labelClassName = getLegendClassName(
|
|
124
|
+
CLASS_NAMES.label.name,
|
|
125
|
+
CLASSNAME_SUFFIX_MAP.handleLabel,
|
|
126
|
+
classNamePrefix
|
|
127
|
+
);
|
|
128
|
+
|
|
93
129
|
group
|
|
94
130
|
.maybeAppendByClassName(CLASS_NAMES.label, 'text')
|
|
131
|
+
.attr('className', labelClassName)
|
|
95
132
|
.styles({ ...labelStyle, x, y, text: formatter(text).toString(), textAlign, textBaseline });
|
|
96
133
|
});
|
|
97
134
|
}
|
|
@@ -5,6 +5,8 @@ import { Component } from '../../../core';
|
|
|
5
5
|
import type { GroupStyleProps, PathStyleProps, RectStyleProps } from '../../../shapes';
|
|
6
6
|
import { Group } from '../../../shapes';
|
|
7
7
|
import { classNames, select, Selection, subStyleProps } from '../../../util';
|
|
8
|
+
import { CLASSNAME_SUFFIX_MAP } from '../constant';
|
|
9
|
+
import { getLegendClassName } from '../utils/classname';
|
|
8
10
|
import { ifHorizontal } from '../utils';
|
|
9
11
|
import { getBlockColor } from './utils';
|
|
10
12
|
|
|
@@ -23,6 +25,7 @@ export type RibbonStyleProps = GroupStyleProps &
|
|
|
23
25
|
range?: [number, number];
|
|
24
26
|
size: number;
|
|
25
27
|
type?: 'size' | 'color';
|
|
28
|
+
classNamePrefix?: string;
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
export type RibbonOptions = ComponentOptions<RibbonStyleProps>;
|
|
@@ -93,15 +96,28 @@ function getClipPath(attr: RequiredRibbonStyleProps): any[] {
|
|
|
93
96
|
|
|
94
97
|
function renderTrack(container: Selection, attr: RequiredRibbonStyleProps) {
|
|
95
98
|
const style = subStyleProps(attr, 'track');
|
|
96
|
-
|
|
99
|
+
const { classNamePrefix } = attr;
|
|
100
|
+
const trackClassName = getLegendClassName(CLASS_NAMES.track.name, CLASSNAME_SUFFIX_MAP.track, classNamePrefix);
|
|
101
|
+
|
|
102
|
+
container
|
|
103
|
+
.maybeAppendByClassName(CLASS_NAMES.track, 'path')
|
|
104
|
+
.attr('className', trackClassName)
|
|
105
|
+
.styles({ d: getTrackPath(attr), ...style });
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
function renderSelection(container: Selection, attr: RequiredRibbonStyleProps) {
|
|
100
109
|
const style = subStyleProps(attr, 'selection');
|
|
101
110
|
const fill = getColor(attr);
|
|
111
|
+
const { classNamePrefix } = attr;
|
|
112
|
+
const selectionClassName = getLegendClassName(
|
|
113
|
+
CLASS_NAMES.selection.name,
|
|
114
|
+
CLASSNAME_SUFFIX_MAP.selection,
|
|
115
|
+
classNamePrefix
|
|
116
|
+
);
|
|
102
117
|
|
|
103
118
|
const ribbon = container
|
|
104
119
|
.maybeAppendByClassName(CLASS_NAMES.selection, 'path')
|
|
120
|
+
.attr('className', selectionClassName)
|
|
105
121
|
.styles({ d: getSelectionPath(attr), fill, ...style });
|
|
106
122
|
const clipPath = ribbon
|
|
107
123
|
.maybeAppendByClassName(CLASS_NAMES.clipPath, 'path')
|