import type { DisplayObjectConfig, Group } from '@antv/g'; import { mergeOptions } from '../../utils/style'; import { BaseShape } from './base-shape'; import type { LabelStyleProps } from './label'; import { Label } from './label'; /** * 徽标样式 * * Badge style */ export interface BadgeStyleProps extends LabelStyleProps {} /** * 徽标 * * Badge * @remarks * 徽标是一种特殊的标签,通常用于展示数量或状态信息。 * * Badge is a special label, usually used to display quantity or status information. */ export class Badge extends BaseShape { static defaultStyleProps: Partial = { padding: [2, 4, 2, 4], fontSize: 10, wordWrap: false, backgroundRadius: '50%', backgroundOpacity: 1, }; constructor(options: DisplayObjectConfig) { super(mergeOptions({ style: Badge.defaultStyleProps }, options)); } protected getBadgeStyle(attributes: Required) { return this.getGraphicStyle(attributes); } public render(attributes: Required = this.parsedAttributes, container: Group = this) { this.upsert('label', Label, this.getBadgeStyle(attributes), container); } public getGeometryBounds() { const labelShape = this.getShape>('label'); const shape = labelShape.getShape('background') || labelShape.getShape('text'); return shape.getGeometryBounds(); } }