@antv/component 2.1.7 → 2.1.8
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/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.js +8 -1
- package/esm/ui/axis/guides/grid.js.map +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.js +10 -3
- package/esm/ui/axis/guides/ticks.js.map +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/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 +2 -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.js +11 -3
- 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 +1 -0
- package/esm/ui/legend/constant.js +1 -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/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.js +8 -1
- package/lib/ui/axis/guides/grid.js.map +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.js +10 -3
- package/lib/ui/axis/guides/ticks.js.map +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/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 +2 -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.js +11 -3
- 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 +1 -0
- package/lib/ui/legend/constant.js +3 -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/package.json +2 -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 +17 -7
- package/src/ui/legend/category.ts +12 -3
- package/src/ui/legend/classname-map.ts +45 -0
- package/src/ui/legend/constant.ts +2 -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,7 @@ export type CategoryItemsStyleProps = GroupStyleProps &
|
|
|
57
64
|
poptip?: PoptipStyleProps & PoptipRender;
|
|
58
65
|
focus?: boolean;
|
|
59
66
|
focusMarkerSize?: number;
|
|
67
|
+
classNamePrefix?: string;
|
|
60
68
|
};
|
|
61
69
|
|
|
62
70
|
export type CategoryItemsOptions = ComponentOptions<CategoryItemsStyleProps>;
|
|
@@ -131,7 +139,7 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
private get renderData() {
|
|
134
|
-
const { data, layout, poptip, focus, focusMarkerSize } = this.attributes;
|
|
142
|
+
const { data, layout, poptip, focus, focusMarkerSize, classNamePrefix } = this.attributes;
|
|
135
143
|
const style = subStyleProps<CategoryItemStyleProps>(this.attributes, 'item');
|
|
136
144
|
|
|
137
145
|
const d = data.map((datum, index) => {
|
|
@@ -146,6 +154,7 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
146
154
|
poptip,
|
|
147
155
|
focus,
|
|
148
156
|
focusMarkerSize,
|
|
157
|
+
classNamePrefix,
|
|
149
158
|
...Object.fromEntries(
|
|
150
159
|
Object.entries(style).map(([key, val]) => [key, getCallbackValue(val, [datum, index, data])])
|
|
151
160
|
),
|
|
@@ -250,17 +259,18 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
250
259
|
}
|
|
251
260
|
|
|
252
261
|
private renderItems(container: Group) {
|
|
253
|
-
const { click, mouseenter, mouseleave } = this.attributes;
|
|
262
|
+
const { click, mouseenter, mouseleave, classNamePrefix } = this.attributes;
|
|
254
263
|
this.flattenPage(container);
|
|
255
264
|
const dispatchCustomEvent = this.dispatchCustomEvent.bind(this);
|
|
265
|
+
const itemClassName = getLegendClassName(CLASS_NAMES.item.name, CLASSNAME_SUFFIX_MAP.item, classNamePrefix);
|
|
256
266
|
select(container)
|
|
257
267
|
.selectAll(CLASS_NAMES.item.class)
|
|
258
268
|
.data(this.renderData, (d) => d.id)
|
|
259
269
|
.join(
|
|
260
270
|
(enter) =>
|
|
261
271
|
enter
|
|
262
|
-
.append(({ style }) => new CategoryItem({ style }))
|
|
263
|
-
.attr('className',
|
|
272
|
+
.append(({ style, ...rest }) => new CategoryItem({ style }, rest))
|
|
273
|
+
.attr('className', itemClassName)
|
|
264
274
|
.on('click', function () {
|
|
265
275
|
click?.(this);
|
|
266
276
|
dispatchCustomEvent('itemClick', { item: this });
|
|
@@ -311,9 +321,9 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
|
|
|
311
321
|
}
|
|
312
322
|
|
|
313
323
|
private renderNavigator(container: Selection) {
|
|
314
|
-
const { orientation } = this.attributes;
|
|
324
|
+
const { orientation, classNamePrefix } = this.attributes;
|
|
315
325
|
const navStyle = subStyleProps(this.attributes, 'nav');
|
|
316
|
-
const style = deepAssign({ orientation }, navStyle);
|
|
326
|
+
const style = deepAssign({ orientation, classNamePrefix }, navStyle);
|
|
317
327
|
const that = this;
|
|
318
328
|
container
|
|
319
329
|
.selectAll(CLASS_NAMES.navigator.class)
|
|
@@ -23,13 +23,13 @@ export class Category extends Component<CategoryStyleProps> {
|
|
|
23
23
|
private items!: Selection<CategoryItems>;
|
|
24
24
|
|
|
25
25
|
private renderTitle(container: Selection, width: number, height: number) {
|
|
26
|
-
const { showTitle, titleText } = this.attributes;
|
|
26
|
+
const { showTitle, titleText, classNamePrefix } = this.attributes;
|
|
27
27
|
const style = subStyleProps<TitleStyleProps>(this.attributes, 'title');
|
|
28
28
|
const [titleStyle, groupStyle] = splitStyle(style);
|
|
29
29
|
|
|
30
30
|
this.titleGroup = container.maybeAppendByClassName<Group>(CLASS_NAMES.titleGroup, 'g').styles(groupStyle);
|
|
31
31
|
|
|
32
|
-
const finalTitleStyle = { width, height, ...titleStyle, text: showTitle ? titleText : '' };
|
|
32
|
+
const finalTitleStyle = { width, height, ...titleStyle, text: showTitle ? titleText : '', classNamePrefix };
|
|
33
33
|
this.title = this.titleGroup
|
|
34
34
|
.maybeAppendByClassName(CLASS_NAMES.title, () => new Title({ style: finalTitleStyle as TitleStyleProps }))
|
|
35
35
|
.update(finalTitleStyle) as Selection<Title>;
|
|
@@ -84,8 +84,17 @@ export class Category extends Component<CategoryStyleProps> {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
render(attributes: Required<CategoryStyleProps>, container: Group) {
|
|
87
|
-
const { width, height, x = 0, y = 0 } = this.attributes;
|
|
87
|
+
const { width, height, x = 0, y = 0, classNamePrefix } = this.attributes;
|
|
88
88
|
const ctn = select(container);
|
|
89
|
+
|
|
90
|
+
// Set root container className
|
|
91
|
+
const baseClassName = container.className || 'legend-category';
|
|
92
|
+
if (classNamePrefix) {
|
|
93
|
+
container.attr('className', `${baseClassName} ${classNamePrefix}legend`);
|
|
94
|
+
} else if (!container.className) {
|
|
95
|
+
container.attr('className', 'legend-category');
|
|
96
|
+
}
|
|
97
|
+
|
|
89
98
|
container.style.transform = `translate(${x}, ${y})`;
|
|
90
99
|
|
|
91
100
|
this.renderTitle(ctn, width!, height!);
|
|
@@ -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,
|
|
@@ -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')
|
|
@@ -25,7 +25,8 @@ import type { IndicatorStyleProps } from '../indicator';
|
|
|
25
25
|
import { Indicator } from '../indicator';
|
|
26
26
|
import { Handle as SliderHandle } from '../slider/handle';
|
|
27
27
|
import { Title } from './title';
|
|
28
|
-
import { CLASS_NAMES, CONTINUOUS_DEFAULT_OPTIONS, STEP_RATIO } from './constant';
|
|
28
|
+
import { CLASS_NAMES, CLASSNAME_SUFFIX_MAP, CONTINUOUS_DEFAULT_OPTIONS, STEP_RATIO } from './constant';
|
|
29
|
+
import { getLegendClassName } from './utils/classname';
|
|
29
30
|
import type { HandleStyleProps, HandleType } from './continuous/handle';
|
|
30
31
|
import { Handle } from './continuous/handle';
|
|
31
32
|
import type { RibbonStyleProps } from './continuous/ribbon';
|
|
@@ -76,6 +77,15 @@ export class Continuous extends Component<ContinuousStyleProps> {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
public render(attributes: Required<ContinuousStyleProps>, container: Group) {
|
|
80
|
+
// Set root container className
|
|
81
|
+
const { classNamePrefix } = attributes;
|
|
82
|
+
const baseClassName = container.className || 'legend-continuous';
|
|
83
|
+
if (classNamePrefix) {
|
|
84
|
+
container.attr('className', `${baseClassName} ${classNamePrefix}legend`);
|
|
85
|
+
} else if (!container.className) {
|
|
86
|
+
container.attr('className', 'legend-continuous');
|
|
87
|
+
}
|
|
88
|
+
|
|
79
89
|
// 渲染顺序
|
|
80
90
|
// 1. 绘制 title, 获得可用空间
|
|
81
91
|
// 2. 绘制 label, handle
|
|
@@ -153,9 +163,9 @@ export class Continuous extends Component<ContinuousStyleProps> {
|
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
private renderTitle(container: Selection) {
|
|
156
|
-
const { showTitle, titleText, width, height } = this.attributes;
|
|
166
|
+
const { showTitle, titleText, width, height, classNamePrefix } = this.attributes;
|
|
157
167
|
const style = subStyleProps<TextStyleProps>(this.attributes, 'title');
|
|
158
|
-
const finalTitleStyle = { ...style, width, height, text: titleText };
|
|
168
|
+
const finalTitleStyle = { ...style, width, height, text: titleText, classNamePrefix };
|
|
159
169
|
const that = this;
|
|
160
170
|
container
|
|
161
171
|
.selectAll(CLASS_NAMES.title.class)
|
|
@@ -263,7 +273,7 @@ export class Continuous extends Component<ContinuousStyleProps> {
|
|
|
263
273
|
}
|
|
264
274
|
|
|
265
275
|
private renderRibbon(container: Selection) {
|
|
266
|
-
const { data, type, orientation, color, block } = this.attributes;
|
|
276
|
+
const { data, type, orientation, color, block, classNamePrefix } = this.attributes;
|
|
267
277
|
const ribbonStyle = subStyleProps(this.attributes, 'ribbon');
|
|
268
278
|
const { min, max } = this.range;
|
|
269
279
|
const { x, y } = this.ribbonBBox;
|
|
@@ -279,11 +289,22 @@ export class Continuous extends Component<ContinuousStyleProps> {
|
|
|
279
289
|
block,
|
|
280
290
|
partition: data.map((d) => (d.value - min) / (max - min)),
|
|
281
291
|
range: this.ribbonRange,
|
|
292
|
+
classNamePrefix,
|
|
282
293
|
},
|
|
283
294
|
ribbonStyle
|
|
284
295
|
);
|
|
285
296
|
|
|
286
|
-
|
|
297
|
+
const ribbonClassName = getLegendClassName(CLASS_NAMES.ribbon.name, CLASSNAME_SUFFIX_MAP.ribbon, classNamePrefix);
|
|
298
|
+
this.ribbon = container
|
|
299
|
+
.maybeAppendByClassName(
|
|
300
|
+
CLASS_NAMES.ribbon,
|
|
301
|
+
() =>
|
|
302
|
+
new Ribbon({
|
|
303
|
+
style,
|
|
304
|
+
className: ribbonClassName,
|
|
305
|
+
})
|
|
306
|
+
)
|
|
307
|
+
.update(style);
|
|
287
308
|
}
|
|
288
309
|
|
|
289
310
|
private getHandleClassName(type: HandleType) {
|
|
@@ -292,14 +313,19 @@ export class Continuous extends Component<ContinuousStyleProps> {
|
|
|
292
313
|
}
|
|
293
314
|
|
|
294
315
|
private renderHandles() {
|
|
295
|
-
const { showHandle, orientation } = this.attributes;
|
|
316
|
+
const { showHandle, orientation, classNamePrefix } = this.attributes;
|
|
296
317
|
const handleStyle = subStyleProps<HandleStyleProps>(this.attributes, 'handle');
|
|
297
318
|
const [min, max] = this.selection;
|
|
298
|
-
const style = { ...handleStyle, orientation };
|
|
319
|
+
const style = { ...handleStyle, orientation, classNamePrefix };
|
|
299
320
|
const { shape = 'slider' } = handleStyle;
|
|
300
321
|
const HandleCtor = shape === 'basic' ? Handle : SliderHandle;
|
|
301
322
|
|
|
302
323
|
const that = this;
|
|
324
|
+
const baseHandleClassName = getLegendClassName(
|
|
325
|
+
CLASS_NAMES.handle.name,
|
|
326
|
+
CLASSNAME_SUFFIX_MAP.handle,
|
|
327
|
+
classNamePrefix
|
|
328
|
+
);
|
|
303
329
|
this.handlesGroup
|
|
304
330
|
.selectAll(CLASS_NAMES.handle.class)
|
|
305
331
|
.data(
|
|
@@ -314,10 +340,10 @@ export class Continuous extends Component<ContinuousStyleProps> {
|
|
|
314
340
|
.join(
|
|
315
341
|
(enter) =>
|
|
316
342
|
enter
|
|
317
|
-
.append(() => new HandleCtor({ style }))
|
|
343
|
+
.append(() => new HandleCtor({ style, className: baseHandleClassName }))
|
|
318
344
|
.attr(
|
|
319
345
|
'className',
|
|
320
|
-
({ type }: any) => `${
|
|
346
|
+
({ type }: any) => `${baseHandleClassName} ${that.getHandleClassName(type as HandleType)}`
|
|
321
347
|
)
|
|
322
348
|
.each(function ({ type, value: labelText }) {
|
|
323
349
|
this.update({ labelText });
|
|
@@ -343,6 +369,51 @@ export class Continuous extends Component<ContinuousStyleProps> {
|
|
|
343
369
|
const [min, max] = this.selection;
|
|
344
370
|
this.setHandlePosition('start', min);
|
|
345
371
|
this.setHandlePosition('end', max);
|
|
372
|
+
|
|
373
|
+
// Update SliderHandle sub-elements className after rendering
|
|
374
|
+
const { classNamePrefix, showHandle } = this.attributes;
|
|
375
|
+
const { shape = 'slider' } = subStyleProps<HandleStyleProps>(this.attributes, 'handle');
|
|
376
|
+
if (showHandle && shape === 'slider' && classNamePrefix) {
|
|
377
|
+
if (this.startHandle) this.updateSliderHandleClassNames(this.startHandle, classNamePrefix);
|
|
378
|
+
if (this.endHandle) this.updateSliderHandleClassNames(this.endHandle, classNamePrefix);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Update SliderHandle sub-elements className to use legend prefix
|
|
384
|
+
* SliderHandle generates: handle-icon-rect, handle-icon-line, handle-label
|
|
385
|
+
* Should add legend className: g2-legend-handle-marker, g2-legend-handle-label
|
|
386
|
+
*/
|
|
387
|
+
private updateSliderHandleClassNames(handle: any, classNamePrefix: string) {
|
|
388
|
+
// Get the actual DOM node from the component
|
|
389
|
+
const container = handle.container || handle;
|
|
390
|
+
|
|
391
|
+
// Update icon elements (rect and lines) to use handleMarker suffix
|
|
392
|
+
const iconRect = container.querySelector('.handle-icon-rect');
|
|
393
|
+
if (iconRect) {
|
|
394
|
+
const markerClassName = getLegendClassName(
|
|
395
|
+
'handle-icon-rect',
|
|
396
|
+
CLASSNAME_SUFFIX_MAP.handleMarker,
|
|
397
|
+
classNamePrefix
|
|
398
|
+
);
|
|
399
|
+
iconRect.setAttribute('class', markerClassName);
|
|
400
|
+
|
|
401
|
+
// Line elements are children of rect element
|
|
402
|
+
const iconLines = iconRect.querySelectorAll('line');
|
|
403
|
+
iconLines.forEach((line: any) => {
|
|
404
|
+
const currentClass = line.getAttribute('class') || '';
|
|
405
|
+
const baseClass = currentClass.split(' ')[0]; // e.g., 'handle-icon-line-1'
|
|
406
|
+
const markerClassName = getLegendClassName(baseClass, CLASSNAME_SUFFIX_MAP.handleMarker, classNamePrefix);
|
|
407
|
+
line.setAttribute('class', markerClassName);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Update label element to use handleLabel suffix
|
|
412
|
+
const label = container.querySelector('.handle-label');
|
|
413
|
+
if (label) {
|
|
414
|
+
const labelClassName = getLegendClassName('handle-label', CLASSNAME_SUFFIX_MAP.handleLabel, classNamePrefix);
|
|
415
|
+
label.setAttribute('class', labelClassName);
|
|
416
|
+
}
|
|
346
417
|
}
|
|
347
418
|
|
|
348
419
|
private cacheHandleBBox: DOMRect | null = null;
|
|
@@ -380,8 +451,23 @@ export class Continuous extends Component<ContinuousStyleProps> {
|
|
|
380
451
|
}
|
|
381
452
|
|
|
382
453
|
private renderIndicator(container: Selection) {
|
|
454
|
+
const { classNamePrefix } = this.attributes;
|
|
383
455
|
const style = subStyleProps<IndicatorStyleProps>(this.attributes, 'indicator');
|
|
384
|
-
|
|
456
|
+
const indicatorClassName = getLegendClassName(
|
|
457
|
+
CLASS_NAMES.indicator.name,
|
|
458
|
+
CLASSNAME_SUFFIX_MAP.indicator,
|
|
459
|
+
classNamePrefix
|
|
460
|
+
);
|
|
461
|
+
this.indicator = container
|
|
462
|
+
.maybeAppendByClassName(
|
|
463
|
+
CLASS_NAMES.indicator,
|
|
464
|
+
() =>
|
|
465
|
+
new Indicator({
|
|
466
|
+
style,
|
|
467
|
+
className: indicatorClassName,
|
|
468
|
+
})
|
|
469
|
+
)
|
|
470
|
+
.update(style);
|
|
385
471
|
// this.hideIndicator();
|
|
386
472
|
}
|
|
387
473
|
|
|
@@ -2,6 +2,8 @@ import { Component } from '../../../core';
|
|
|
2
2
|
import type { Group } from '../../../shapes';
|
|
3
3
|
import { DisplayObject, Text } from '../../../shapes';
|
|
4
4
|
import { BBox, Selection, classNames, ifShow, parsePosition, parseSeriesAttr, select, splitStyle } from '../../../util';
|
|
5
|
+
import { getLegendClassName } from '../utils/classname';
|
|
6
|
+
import { CLASSNAME_SUFFIX_MAP } from '../constant';
|
|
5
7
|
import type { TitleOptions, TitleStyleProps } from './types';
|
|
6
8
|
|
|
7
9
|
export type { TitleOptions, TitleStyleProps };
|
|
@@ -144,14 +146,16 @@ export class Title extends Component<TitleStyleProps> {
|
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
public render(attributes: Required<TitleStyleProps>, container: Group) {
|
|
147
|
-
const { width, height, position, spacing, ...restStyle } = attributes;
|
|
149
|
+
const { width, height, position, spacing, classNamePrefix, ...restStyle } = attributes;
|
|
148
150
|
|
|
149
151
|
const [titleStyle] = splitStyle(restStyle);
|
|
150
152
|
const { x, y, textAlign, textBaseline } = getTitleLayout(attributes);
|
|
151
153
|
|
|
152
154
|
ifShow(!!restStyle.text, select(container), (group) => {
|
|
155
|
+
const titleClassName = getLegendClassName(CLASS_NAMES.text.name, CLASSNAME_SUFFIX_MAP.title, classNamePrefix);
|
|
153
156
|
this.title = group
|
|
154
157
|
.maybeAppendByClassName(CLASS_NAMES.text, 'text')
|
|
158
|
+
.attr('className', titleClassName)
|
|
155
159
|
.styles(titleStyle)
|
|
156
160
|
.call(mayApplyStyle, { x, y, textAlign, textBaseline })
|
|
157
161
|
.node();
|