UNPKG

1.38 kBTypeScriptView Raw
1import { BBox, IGroup, IShape } from '../dependents';
2import { LabelItem } from '../geometry/label/interface';
3import { AnimateOption, GeometryLabelLayoutCfg } from '../interface';
4/**
5 * Labels 实例创建时,传入构造函数的参数定义
6 */
7export interface LabelsGroupCfg {
8 /** label 容器 */
9 container: IGroup;
10 /** label 布局配置 */
11 layout?: GeometryLabelLayoutCfg | GeometryLabelLayoutCfg[];
12}
13/**
14 * Geometry labels 渲染组件
15 */
16export default class Labels {
17 /** 用于指定 labels 布局的类型 */
18 layout: GeometryLabelLayoutCfg | GeometryLabelLayoutCfg[];
19 /** 图形容器 */
20 container: IGroup;
21 /** 动画配置 */
22 animate: AnimateOption | false;
23 /** label 绘制的区域 */
24 region: BBox;
25 /** 存储当前 shape 的映射表,键值为 shape id */
26 shapesMap: Record<string, IGroup>;
27 constructor(cfg: LabelsGroupCfg);
28 /**
29 * 渲染文本
30 */
31 render(items: LabelItem[], shapes: Record<string, IShape | IGroup>, isUpdate?: boolean): Promise<void>;
32 /** 清除当前 labels */
33 clear(): void;
34 /** 销毁 */
35 destroy(): void;
36 private renderLabel;
37 private doLayout;
38 private renderLabelLine;
39 /**
40 * 绘制标签背景
41 * @param labelItems
42 */
43 private renderLabelBackground;
44 private createOffscreenGroup;
45 private adjustLabel;
46}