UNPKG

4.04 kBTypeScriptView Raw
1import { AnnotationBaseOption as BaseOption, ArcOption, ComponentOption, ShapeAnnotationOption, DataMarkerOption, DataRegionOption, HtmlAnnotationOption, ImageOption, LineOption, RegionFilterOption, RegionOption, TextOption } from '../../interface';
2import View from '../view';
3import { Controller } from './base';
4/**
5 * Annotation controller, 主要作用:
6 * 1. 创建 Annotation: line、text、arc ...
7 * 2. 生命周期: init、layout、render、clear、destroy
8 */
9export default class Annotation extends Controller<BaseOption[]> {
10 private foregroundContainer;
11 private backgroundContainer;
12 private cache;
13 constructor(view: View);
14 get name(): string;
15 init(): void;
16 /**
17 * 因为 annotation 需要依赖坐标系信息,所以 render 阶段为空方法,实际的创建逻辑都在 layout 中
18 */
19 layout(): void;
20 render(): void;
21 /**
22 * 更新
23 */
24 update(): void;
25 /**
26 * 清空
27 * @param includeOption 是否清空 option 配置项
28 */
29 clear(includeOption?: boolean): void;
30 destroy(): void;
31 /**
32 * 复写基类的方法
33 */
34 getComponents(): ComponentOption[];
35 /**
36 * 清除当前的组件
37 */
38 private clearComponents;
39 /**
40 * region filter 比较特殊的渲染时机
41 * @param doWhat
42 */
43 private onAfterRender;
44 private createAnnotation;
45 annotation(option: any): void;
46 /**
47 * 创建 Arc
48 * @param option
49 * @returns AnnotationController
50 */
51 arc(option: ArcOption): this;
52 /**
53 * 创建 image
54 * @param option
55 * @returns AnnotationController
56 */
57 image(option: ImageOption): this;
58 /**
59 * 创建 Line
60 * @param option
61 * @returns AnnotationController
62 */
63 line(option: LineOption): this;
64 /**
65 * 创建 Region
66 * @param option
67 * @returns AnnotationController
68 */
69 region(option: RegionOption): this;
70 /**
71 * 创建 Text
72 * @param option
73 * @returns AnnotationController
74 */
75 text(option: TextOption): this;
76 /**
77 * 创建 DataMarker
78 * @param option
79 * @returns AnnotationController
80 */
81 dataMarker(option: DataMarkerOption): this;
82 /**
83 * 创建 DataRegion
84 * @param option
85 * @returns AnnotationController
86 */
87 dataRegion(option: DataRegionOption): void;
88 /**
89 * 创建 RegionFilter
90 * @param option
91 * @returns AnnotationController
92 */
93 regionFilter(option: RegionFilterOption): void;
94 /**
95 * 创建 ShapeAnnotation
96 * @param option
97 */
98 shape(option: ShapeAnnotationOption): void;
99 /**
100 * 创建 HtmlAnnotation
101 * @param option
102 */
103 html(option: HtmlAnnotationOption): void;
104 /**
105 * parse the point position to [x, y]
106 * @param p Position
107 * @returns { x, y }
108 */
109 private parsePosition;
110 /**
111 * parse all the points between start and end
112 * @param start
113 * @param end
114 * @return Point[]
115 */
116 private getRegionPoints;
117 /**
118 * parse percent position
119 * @param position
120 */
121 private parsePercentPosition;
122 /**
123 * get coordinate bbox
124 */
125 private getCoordinateBBox;
126 /**
127 * get annotation component config by different type
128 * @param type
129 * @param option 用户的配置
130 * @param theme
131 */
132 private getAnnotationCfg;
133 /**
134 * is annotation render on top
135 * @param option
136 * @return whethe on top
137 */
138 private isTop;
139 /**
140 * get the container by option.top
141 * default is on top
142 * @param option
143 * @returns the container
144 */
145 private getComponentContainer;
146 private getAnnotationTheme;
147 /**
148 * 创建或者更新 annotation
149 * @param option
150 */
151 private updateOrCreate;
152 /**
153 * 更新缓存,以及销毁组件
154 * @param updated 更新或者创建的组件
155 */
156 private syncCache;
157 /**
158 * 获得缓存组件的 key
159 * @param option
160 */
161 private getCacheKey;
162}