@labelbee/lb-annotation 1.8.0 → 1.9.0-alpha.2

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.
Files changed (96) hide show
  1. package/README.md +65 -0
  2. package/dist/index.js +20 -9
  3. package/dist/types/constant/tool.d.ts +3 -1
  4. package/dist/types/core/index.d.ts +24 -4
  5. package/dist/types/core/pointCloud/OrbitControls.d.ts +60 -0
  6. package/dist/types/core/pointCloud/PCDLoader.d.ts +11 -0
  7. package/dist/types/core/pointCloud/annotation.d.ts +47 -0
  8. package/dist/types/core/pointCloud/cache.d.ts +16 -0
  9. package/dist/types/core/pointCloud/index.d.ts +325 -0
  10. package/dist/types/core/scheduler.d.ts +71 -0
  11. package/dist/types/core/toolOperation/basicToolOperation.d.ts +20 -2
  12. package/dist/types/core/toolOperation/eventListener.d.ts +2 -2
  13. package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +80 -0
  14. package/dist/types/core/toolOperation/polygonOperation.d.ts +21 -7
  15. package/dist/types/core/toolOperation/segmentByRect.d.ts +31 -0
  16. package/dist/types/index.d.ts +9 -3
  17. package/dist/types/newCore/CanvasScheduler.d.ts +31 -0
  18. package/dist/types/newCore/index.d.ts +1 -0
  19. package/dist/types/utils/MathUtils.d.ts +6 -0
  20. package/dist/types/utils/tool/CommonToolUtils.d.ts +0 -13
  21. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +20 -0
  22. package/dist/types/utils/tool/PolygonUtils.d.ts +1 -0
  23. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -0
  24. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -0
  25. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -0
  26. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -0
  27. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -0
  28. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -0
  29. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -0
  30. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -0
  31. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -0
  32. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -0
  33. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -0
  34. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -0
  35. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -0
  36. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -0
  37. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -0
  38. package/es/constant/annotation.js +68 -0
  39. package/es/constant/annotationTask.js +25 -0
  40. package/es/constant/defaultConfig.js +260 -0
  41. package/es/constant/keyCode.js +36 -0
  42. package/es/constant/style.js +67 -0
  43. package/es/constant/tool.js +183 -0
  44. package/es/core/index.js +145 -0
  45. package/es/core/pointCloud/OrbitControls.js +661 -0
  46. package/es/core/pointCloud/PCDLoader.js +238 -0
  47. package/es/core/pointCloud/annotation.js +98 -0
  48. package/es/core/pointCloud/cache.js +42 -0
  49. package/es/core/pointCloud/index.js +771 -0
  50. package/es/core/scheduler.js +184 -0
  51. package/es/core/toolOperation/LineToolOperation.js +1369 -0
  52. package/es/core/toolOperation/TextToolOperation.js +129 -0
  53. package/es/core/toolOperation/ViewOperation.js +410 -0
  54. package/es/core/toolOperation/basicToolOperation.js +817 -0
  55. package/es/core/toolOperation/checkOperation.js +206 -0
  56. package/es/core/toolOperation/eventListener.js +35 -0
  57. package/es/core/toolOperation/measureOperation.js +39 -0
  58. package/es/core/toolOperation/pointCloud2dOperation.js +197 -0
  59. package/es/core/toolOperation/pointOperation.js +603 -0
  60. package/es/core/toolOperation/polygonOperation.js +1201 -0
  61. package/es/core/toolOperation/rectOperation.js +1170 -0
  62. package/es/core/toolOperation/segmentByRect.js +172 -0
  63. package/es/core/toolOperation/tagOperation.js +215 -0
  64. package/es/core/toolOperation/textAttributeClass.js +201 -0
  65. package/es/index.js +25 -14
  66. package/es/locales/constants.js +21 -0
  67. package/es/locales/en_US/message.js +22 -0
  68. package/es/locales/index.js +17 -0
  69. package/es/locales/zh_CN/message.js +22 -0
  70. package/es/newCore/CanvasScheduler.js +31 -0
  71. package/es/utils/ActionsHistory.js +78 -0
  72. package/es/utils/ImgUtils.js +20 -0
  73. package/es/utils/MathUtils.js +283 -0
  74. package/es/utils/VectorUtils.js +23 -0
  75. package/es/utils/tool/AttributeUtils.js +196 -0
  76. package/es/utils/tool/AxisUtils.js +254 -0
  77. package/es/utils/tool/CanvasUtils.js +60 -0
  78. package/es/utils/tool/CommonToolUtils.js +172 -0
  79. package/es/utils/tool/CurrentOperation.js +35 -0
  80. package/es/utils/tool/DblClickEventListener.js +100 -0
  81. package/es/utils/tool/DrawUtils.js +424 -0
  82. package/es/utils/tool/EnhanceCommonToolUtils.js +39 -0
  83. package/es/utils/tool/ImgPosUtils.js +56 -0
  84. package/es/utils/tool/LineToolUtils.js +255 -0
  85. package/es/utils/tool/MarkerUtils.js +9 -0
  86. package/es/utils/tool/PolygonUtils.js +458 -0
  87. package/es/utils/tool/RectUtils.js +153 -0
  88. package/es/utils/tool/RenderDomClass.js +68 -0
  89. package/es/utils/tool/RenderDomUtils.js +29 -0
  90. package/es/utils/tool/StyleUtils.js +29 -0
  91. package/es/utils/tool/TagUtils.js +127 -0
  92. package/es/utils/tool/UnitUtils.js +10 -0
  93. package/es/utils/tool/ZoomUtils.js +70 -0
  94. package/es/utils/tool/polygonTool.js +126 -0
  95. package/es/utils/uuid.js +24 -0
  96. package/package.json +6 -4
@@ -0,0 +1,129 @@
1
+ import uuid from '../../utils/uuid.js';
2
+ import EKeyCode from '../../constant/keyCode.js';
3
+ import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
4
+ import { BasicToolOperation } from './basicToolOperation.js';
5
+
6
+ class TextToolOperation extends BasicToolOperation {
7
+ constructor(props) {
8
+ super(props);
9
+ this.getSingleResult = (sourceID) => {
10
+ const initValue = {};
11
+ if (this.config.configList.length > 0) {
12
+ this.config.configList.forEach((i) => {
13
+ var _a;
14
+ initValue[i.key] = (_a = i.default) != null ? _a : "";
15
+ });
16
+ }
17
+ return {value: initValue, id: uuid(), sourceID: sourceID != null ? sourceID : CommonToolUtils.getSourceID()};
18
+ };
19
+ this.getInitResultList = (dataSourceStep, basicResultList) => {
20
+ if (dataSourceStep > 0) {
21
+ return basicResultList.map((i) => this.getSingleResult(i.id));
22
+ }
23
+ return [this.getSingleResult()];
24
+ };
25
+ this.textList = [];
26
+ this.setShowDefaultCursor(true);
27
+ this.setConfig(props.config);
28
+ this.initTextDisplayContainer();
29
+ }
30
+ get dataList() {
31
+ return this.textList;
32
+ }
33
+ get textValueContainerID() {
34
+ return "textValueContainer";
35
+ }
36
+ get textValueContainer() {
37
+ return document.getElementById(this.textValueContainerID);
38
+ }
39
+ get currentPageResult() {
40
+ return this.textList;
41
+ }
42
+ setResult(textResultList) {
43
+ var _a;
44
+ this.textList = textResultList;
45
+ this.toggleTextContainerVisible(true);
46
+ const values = (_a = this.textList[0]) == null ? void 0 : _a.value;
47
+ if (values) {
48
+ Object.keys(values).forEach((k) => {
49
+ this.renderText(k, values[k]);
50
+ });
51
+ }
52
+ this.emit("valueUpdated");
53
+ this.toggleTextContainerVisible(!!values);
54
+ }
55
+ updateTextValue(k, v) {
56
+ this.textList[0].value[k] = v;
57
+ this.renderText(k, v);
58
+ this.emit("valueUpdated");
59
+ }
60
+ renderText(key, value) {
61
+ const textDom = document.getElementById(`textKey${key}`);
62
+ if (textDom) {
63
+ textDom.innerText = value;
64
+ }
65
+ }
66
+ getTextDomID(key) {
67
+ return `textKey${key}`;
68
+ }
69
+ initTextDisplayContainer() {
70
+ const dom = document.createElement("div");
71
+ const domStyle = {
72
+ position: "absolute",
73
+ right: "0",
74
+ top: "0",
75
+ "z-index": "20",
76
+ "max-width": "20%",
77
+ "font-family": "SourceHanSansCN-Regular",
78
+ background: "rgb(102, 230, 255)",
79
+ color: "white",
80
+ "word-break": "break-all",
81
+ "line-height": "24px",
82
+ "white-space": "pre-wrap",
83
+ "max-height": "80%",
84
+ "overflow-y": "auto",
85
+ opacity: "0.6"
86
+ };
87
+ dom.setAttribute("style", Object.keys(domStyle).reduce((pre, key) => {
88
+ pre += `${key}: ${domStyle[key]};`;
89
+ return pre;
90
+ }, ""));
91
+ dom.setAttribute("id", this.textValueContainerID);
92
+ this.config.configList.forEach((i) => {
93
+ const div = document.createElement("div");
94
+ const label = document.createElement("div");
95
+ const value = document.createElement("div");
96
+ div.setAttribute("style", "padding: 8px 16px");
97
+ label.innerText = `${i.key}:`;
98
+ value.innerText = "";
99
+ value.setAttribute("id", this.getTextDomID(i.key));
100
+ div.appendChild(label);
101
+ div.appendChild(value);
102
+ dom.appendChild(div);
103
+ });
104
+ this.container.appendChild(dom);
105
+ }
106
+ exportData() {
107
+ return [this.textList, this.basicImgInfo];
108
+ }
109
+ destroyCanvas() {
110
+ super.destroyCanvas();
111
+ if (this.textValueContainer) {
112
+ this.container.removeChild(this.textValueContainer);
113
+ }
114
+ }
115
+ onKeyDown(e) {
116
+ super.onKeyDown(e);
117
+ if (e.keyCode === EKeyCode.Z) {
118
+ this.toggleTextContainerVisible();
119
+ }
120
+ }
121
+ toggleTextContainerVisible(isVisible) {
122
+ if (this.textValueContainer) {
123
+ const display = (isVisible !== void 0 ? !isVisible : this.textValueContainer.style.display === "block") ? "none" : "block";
124
+ this.textValueContainer.style.display = display;
125
+ }
126
+ }
127
+ }
128
+
129
+ export { TextToolOperation as default };
@@ -0,0 +1,410 @@
1
+ import _ from 'lodash';
2
+ import rgba from 'color-rgba';
3
+ import DrawUtils from '../../utils/tool/DrawUtils.js';
4
+ import AxisUtils from '../../utils/tool/AxisUtils.js';
5
+ import RectUtils from '../../utils/tool/RectUtils.js';
6
+ import PolygonUtils from '../../utils/tool/PolygonUtils.js';
7
+ import MathUtils from '../../utils/MathUtils.js';
8
+ import RenderDomClass from '../../utils/tool/RenderDomClass.js';
9
+ import { DEFAULT_FONT, ELineTypes, SEGMENT_NUMBER } from '../../constant/tool.js';
10
+ import { DEFAULT_TEXT_OFFSET, TEXT_ATTRIBUTE_OFFSET, DEFAULT_TEXT_SHADOW } from '../../constant/annotation.js';
11
+ import { BasicToolOperation } from './basicToolOperation.js';
12
+
13
+ var __defProp = Object.defineProperty;
14
+ var __defProps = Object.defineProperties;
15
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
16
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
17
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
18
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
19
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
20
+ var __spreadValues = (a, b) => {
21
+ for (var prop in b || (b = {}))
22
+ if (__hasOwnProp.call(b, prop))
23
+ __defNormalProp(a, prop, b[prop]);
24
+ if (__getOwnPropSymbols)
25
+ for (var prop of __getOwnPropSymbols(b)) {
26
+ if (__propIsEnum.call(b, prop))
27
+ __defNormalProp(a, prop, b[prop]);
28
+ }
29
+ return a;
30
+ };
31
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
32
+ const newScope = 3;
33
+ const DEFAULT_RADIUS = 3;
34
+ const DEFAULT_STROKE_COLOR = "#6371FF";
35
+ class ViewOperation extends BasicToolOperation {
36
+ constructor(props) {
37
+ super(__spreadProps(__spreadValues({}, props), {showDefaultCursor: true}));
38
+ this.style = {};
39
+ this.annotations = [];
40
+ this.getHoverRectID = (e) => {
41
+ var _a, _b;
42
+ const coordinate = this.getCoordinateUnderZoom(e);
43
+ const originCoordinate = AxisUtils.changePointByZoom(coordinate, 1 / this.zoom);
44
+ if (((_a = this.annotations) == null ? void 0 : _a.length) <= 0 || !((_b = this.annotations) == null ? void 0 : _b.length)) {
45
+ return;
46
+ }
47
+ let id = "";
48
+ let minArea = Number.MAX_SAFE_INTEGER;
49
+ for (let i = 0; i < this.annotations.length; i++) {
50
+ const annotation = this.annotations[i];
51
+ switch (annotation.type) {
52
+ case "rect": {
53
+ const rect = annotation.annotation;
54
+ if (RectUtils.isInRect(coordinate, rect, newScope, this.zoom)) {
55
+ const area = rect.width * rect.height;
56
+ if (area < minArea) {
57
+ id = rect.id;
58
+ minArea = area;
59
+ }
60
+ }
61
+ break;
62
+ }
63
+ case "polygon": {
64
+ const polygon = annotation.annotation;
65
+ if (PolygonUtils.isInPolygon(originCoordinate, polygon.pointList)) {
66
+ const area = PolygonUtils.getPolygonArea(polygon.pointList);
67
+ if (area < minArea) {
68
+ id = polygon.id;
69
+ minArea = area;
70
+ }
71
+ }
72
+ break;
73
+ }
74
+ }
75
+ }
76
+ return id;
77
+ };
78
+ var _a;
79
+ this.style = (_a = props.style) != null ? _a : {stroke: DEFAULT_STROKE_COLOR, thickness: 3};
80
+ this.annotations = props.annotations;
81
+ this.loading = false;
82
+ this.renderDomInstance = new RenderDomClass({
83
+ container: this.container,
84
+ height: this.canvas.height
85
+ });
86
+ }
87
+ setLoading(loading) {
88
+ this.loading = loading;
89
+ this.render();
90
+ }
91
+ onMouseLeave() {
92
+ super.onMouseLeave();
93
+ this.mouseHoverID = void 0;
94
+ this.emit("onChange", "hover", []);
95
+ }
96
+ onMouseDown(e) {
97
+ if (super.onMouseDown(e) || this.forbidMouseOperation || !this.imgInfo) {
98
+ return true;
99
+ }
100
+ const newMouseSelectedID = this.mouseHoverID;
101
+ if (e.button === 0) {
102
+ let selectedID = [];
103
+ if (newMouseSelectedID) {
104
+ selectedID = [newMouseSelectedID];
105
+ }
106
+ this.emit("onChange", "selected", selectedID);
107
+ this.render();
108
+ }
109
+ }
110
+ onMouseMove(e) {
111
+ if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
112
+ return;
113
+ }
114
+ const oldMouseHoverID = this.mouseHoverID;
115
+ const newMouseHoverID = this.getHoverRectID(e);
116
+ if (oldMouseHoverID !== newMouseHoverID) {
117
+ this.mouseHoverID = newMouseHoverID;
118
+ let hoverID = [];
119
+ if (newMouseHoverID) {
120
+ hoverID = [newMouseHoverID];
121
+ }
122
+ this.emit("onChange", "hover", hoverID);
123
+ this.render();
124
+ }
125
+ }
126
+ updateData(annotations) {
127
+ this.annotations = annotations;
128
+ this.render();
129
+ }
130
+ getSpecificStyle(obj) {
131
+ const specificStyle = _.pick(obj, ["stroke", "thickness", "fill", "radius"]);
132
+ const newStyle = __spreadValues(__spreadValues({}, this.style), specificStyle);
133
+ if (newStyle.stroke) {
134
+ Object.assign(newStyle, {
135
+ color: newStyle.stroke
136
+ });
137
+ }
138
+ return newStyle;
139
+ }
140
+ getRenderText(result, hiddenText = false) {
141
+ let headerText = "";
142
+ let bottomText = "";
143
+ if (!result || hiddenText === true) {
144
+ return {headerText, bottomText};
145
+ }
146
+ if (result == null ? void 0 : result.order) {
147
+ headerText = `${result.order}`;
148
+ }
149
+ if (result == null ? void 0 : result.label) {
150
+ if (headerText) {
151
+ headerText = `${headerText}_${result.label}`;
152
+ } else {
153
+ headerText = `${result.label}`;
154
+ }
155
+ }
156
+ if (result == null ? void 0 : result.attribute) {
157
+ if (headerText) {
158
+ headerText = `${headerText} ${result.attribute}`;
159
+ } else {
160
+ headerText = `${result.attribute}`;
161
+ }
162
+ }
163
+ if (result == null ? void 0 : result.textAttribute) {
164
+ bottomText = result == null ? void 0 : result.textAttribute;
165
+ }
166
+ return {headerText, bottomText};
167
+ }
168
+ getReferenceOptions(isReference) {
169
+ return isReference ? {lineCap: "butt", lineDash: [20, 20]} : {};
170
+ }
171
+ render() {
172
+ try {
173
+ super.render();
174
+ if (this.loading === true) {
175
+ return;
176
+ }
177
+ this.renderDomInstance.render(this.annotations.filter((v) => v.type === "text" && v.annotation.position === "rt").map((v) => v.annotation));
178
+ this.annotations.forEach((annotation) => {
179
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
180
+ switch (annotation.type) {
181
+ case "rect": {
182
+ const rect = annotation.annotation;
183
+ const {hiddenText = false, isReference, hiddenRectSize = false} = rect;
184
+ const {zoom} = this;
185
+ const renderRect = AxisUtils.changeRectByZoom(rect, this.zoom, this.currentPos);
186
+ const {x, y, width, height} = renderRect;
187
+ const style = this.getSpecificStyle(rect);
188
+ if (rect.id === this.mouseHoverID || style.fill) {
189
+ const fillArr = rgba((_b = (_a = style == null ? void 0 : style.fill) != null ? _a : style == null ? void 0 : style.stroke) != null ? _b : DEFAULT_STROKE_COLOR);
190
+ const fill = `rgba(${fillArr[0]}, ${fillArr[1]}, ${fillArr[2]},${fillArr[3] * 0.8})`;
191
+ DrawUtils.drawRectWithFill(this.canvas, renderRect, {color: fill});
192
+ }
193
+ DrawUtils.drawRect(this.canvas, renderRect, __spreadValues(__spreadProps(__spreadValues({}, style), {
194
+ hiddenText: true
195
+ }), this.getReferenceOptions(isReference)));
196
+ const {headerText, bottomText} = this.getRenderText(rect, rect == null ? void 0 : rect.hiddenText);
197
+ if (headerText) {
198
+ DrawUtils.drawText(this.canvas, {x, y: y - 6}, headerText, __spreadProps(__spreadValues({
199
+ color: style.stroke,
200
+ font: "normal normal 900 14px SourceHanSansCN-Regular"
201
+ }, DEFAULT_TEXT_SHADOW), {
202
+ textMaxWidth: 300
203
+ }));
204
+ }
205
+ const rectSize = `${Math.round(width / zoom)} * ${Math.round(height / zoom)}`;
206
+ const textSizeWidth = rectSize.length * 7;
207
+ if (!hiddenText && !hiddenRectSize) {
208
+ DrawUtils.drawText(this.canvas, {x: x + width - textSizeWidth, y: y + height + 15}, rectSize, __spreadValues({
209
+ color: style.stroke,
210
+ font: "normal normal 600 14px Arial"
211
+ }, DEFAULT_TEXT_SHADOW));
212
+ }
213
+ if (bottomText) {
214
+ const marginTop = 20;
215
+ const textWidth = Math.max(20, width - textSizeWidth);
216
+ DrawUtils.drawText(this.canvas, {x, y: y + height + marginTop}, rect.textAttribute, __spreadValues({
217
+ color: style.stroke,
218
+ font: "italic normal 900 14px Arial",
219
+ textMaxWidth: textWidth
220
+ }, DEFAULT_TEXT_SHADOW));
221
+ }
222
+ break;
223
+ }
224
+ case "polygon": {
225
+ const polygon = annotation.annotation;
226
+ if (!(((_c = polygon == null ? void 0 : polygon.pointList) == null ? void 0 : _c.length) >= 3)) {
227
+ return;
228
+ }
229
+ const {lineType = ELineTypes.Line} = polygon;
230
+ const renderPolygon = AxisUtils.changePointListByZoom((_d = polygon == null ? void 0 : polygon.pointList) != null ? _d : [], this.zoom, this.currentPos);
231
+ const style = this.getSpecificStyle(polygon);
232
+ if (polygon.id === this.mouseHoverID || style.fill) {
233
+ const fillArr = rgba((_f = (_e = style == null ? void 0 : style.fill) != null ? _e : style == null ? void 0 : style.stroke) != null ? _f : DEFAULT_STROKE_COLOR);
234
+ const fill = `rgba(${fillArr[0]}, ${fillArr[1]}, ${fillArr[2]},${fillArr[3] * 0.8})`;
235
+ DrawUtils.drawPolygonWithFill(this.canvas, renderPolygon, {color: fill, lineType});
236
+ }
237
+ const polygonRenderOptions = __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, style), {
238
+ isClose: true
239
+ }), this.getReferenceOptions(polygon == null ? void 0 : polygon.isReference)), {
240
+ lineType,
241
+ strokeColor: style.stroke
242
+ });
243
+ let newPointList = [];
244
+ if (polygon.showKeyPoint) {
245
+ newPointList = DrawUtils.drawPolygonWithKeyPoint(this.canvas, renderPolygon, polygonRenderOptions);
246
+ } else {
247
+ newPointList = DrawUtils.drawPolygon(this.canvas, renderPolygon, polygonRenderOptions);
248
+ }
249
+ const isShowDirection = (polygon == null ? void 0 : polygon.showDirection) === true && ((_g = polygon == null ? void 0 : polygon.pointList) == null ? void 0 : _g.length) > 2;
250
+ if (isShowDirection) {
251
+ let startPoint = renderPolygon[0];
252
+ let endPoint = MathUtils.getLineCenterPoint([renderPolygon[0], renderPolygon[1]]);
253
+ if (lineType === ELineTypes.Curve) {
254
+ const pos = Math.floor(SEGMENT_NUMBER / 2);
255
+ startPoint = newPointList[pos];
256
+ endPoint = newPointList[pos + 1];
257
+ }
258
+ DrawUtils.drawArrowByCanvas(this.canvas, startPoint, endPoint, {
259
+ color: style.stroke,
260
+ thickness: style.thickness
261
+ });
262
+ DrawUtils.drawCircle(this.canvas, renderPolygon[0], style.thickness + 6, {
263
+ color: style.stroke,
264
+ thickness: style.thickness
265
+ });
266
+ }
267
+ const {headerText, bottomText} = this.getRenderText(polygon, polygon == null ? void 0 : polygon.hiddenText);
268
+ if (headerText) {
269
+ DrawUtils.drawText(this.canvas, renderPolygon[0], headerText, __spreadValues({
270
+ color: style.stroke
271
+ }, DEFAULT_TEXT_OFFSET));
272
+ }
273
+ if (bottomText) {
274
+ const endPoint = renderPolygon[renderPolygon.length - 1];
275
+ DrawUtils.drawText(this.canvas, {x: endPoint.x + TEXT_ATTRIBUTE_OFFSET.x, y: endPoint.y + TEXT_ATTRIBUTE_OFFSET.y}, bottomText, __spreadValues({
276
+ color: style.stroke
277
+ }, DEFAULT_TEXT_OFFSET));
278
+ }
279
+ break;
280
+ }
281
+ case "line": {
282
+ const line = annotation.annotation;
283
+ if (!(((_h = line == null ? void 0 : line.pointList) == null ? void 0 : _h.length) >= 2)) {
284
+ return;
285
+ }
286
+ const {lineType = ELineTypes.Line} = line;
287
+ const renderLine = AxisUtils.changePointListByZoom((_i = line == null ? void 0 : line.pointList) != null ? _i : [], this.zoom, this.currentPos);
288
+ const style = this.getSpecificStyle(line);
289
+ const newPointList = DrawUtils.drawPolygon(this.canvas, renderLine, __spreadProps(__spreadValues(__spreadValues({}, style), this.getReferenceOptions(line == null ? void 0 : line.isReference)), {
290
+ lineType
291
+ }));
292
+ const isShowDirection = (line == null ? void 0 : line.showDirection) === true && ((_j = line == null ? void 0 : line.pointList) == null ? void 0 : _j.length) > 2;
293
+ if (isShowDirection) {
294
+ let startPoint = renderLine[0];
295
+ let endPoint = MathUtils.getLineCenterPoint([renderLine[0], renderLine[1]]);
296
+ if (lineType === ELineTypes.Curve) {
297
+ const pos = Math.floor(SEGMENT_NUMBER / 2);
298
+ startPoint = newPointList[pos];
299
+ endPoint = newPointList[pos + 1];
300
+ }
301
+ DrawUtils.drawArrowByCanvas(this.canvas, startPoint, endPoint, {
302
+ color: style.stroke,
303
+ thickness: style.thickness
304
+ });
305
+ DrawUtils.drawCircle(this.canvas, renderLine[0], style.thickness + 6, {
306
+ color: style.stroke,
307
+ thickness: style.thickness
308
+ });
309
+ }
310
+ const {headerText, bottomText} = this.getRenderText(line, line == null ? void 0 : line.hiddenText);
311
+ if (headerText) {
312
+ DrawUtils.drawText(this.canvas, renderLine[0], headerText, __spreadValues({
313
+ color: style.stroke
314
+ }, DEFAULT_TEXT_OFFSET));
315
+ }
316
+ if (bottomText) {
317
+ const endPoint = renderLine[renderLine.length - 1];
318
+ DrawUtils.drawText(this.canvas, {x: endPoint.x + TEXT_ATTRIBUTE_OFFSET.x, y: endPoint.y + TEXT_ATTRIBUTE_OFFSET.y}, bottomText, __spreadValues({
319
+ color: style.stroke
320
+ }, DEFAULT_TEXT_OFFSET));
321
+ }
322
+ break;
323
+ }
324
+ case "point": {
325
+ const point = annotation.annotation;
326
+ const renderPoint = AxisUtils.changePointByZoom(point, this.zoom, this.currentPos);
327
+ const style = this.getSpecificStyle(point);
328
+ const radius = (_k = style.radius) != null ? _k : DEFAULT_RADIUS;
329
+ DrawUtils.drawCircle(this.canvas, renderPoint, radius, style);
330
+ const {headerText, bottomText} = this.getRenderText(point, point == null ? void 0 : point.hiddenText);
331
+ if (headerText) {
332
+ DrawUtils.drawText(this.canvas, {x: renderPoint.x + radius / 2, y: renderPoint.y - radius - 4}, headerText, {
333
+ textAlign: "center",
334
+ color: style.stroke
335
+ });
336
+ }
337
+ if (bottomText) {
338
+ DrawUtils.drawText(this.canvas, {x: renderPoint.x + radius, y: renderPoint.y + radius + 24}, bottomText, __spreadValues({
339
+ color: style.stroke
340
+ }, DEFAULT_TEXT_OFFSET));
341
+ }
342
+ break;
343
+ }
344
+ case "text": {
345
+ const textAnnotation = annotation.annotation;
346
+ const {
347
+ text,
348
+ x,
349
+ y,
350
+ textMaxWidth,
351
+ color = "white",
352
+ background = "rgba(0, 0, 0, 0.6)",
353
+ lineHeight = 25,
354
+ font = DEFAULT_FONT,
355
+ position
356
+ } = textAnnotation;
357
+ const paddingTB = 10;
358
+ const paddingLR = 10;
359
+ const renderPoint = AxisUtils.changePointByZoom({x, y}, this.zoom, this.currentPos);
360
+ const {
361
+ width,
362
+ height,
363
+ fontHeight = 0
364
+ } = MathUtils.getTextArea(this.canvas, textAnnotation.text, textMaxWidth, font, lineHeight);
365
+ if (position === "rt") {
366
+ break;
367
+ }
368
+ DrawUtils.drawRectWithFill(this.canvas, {
369
+ x: renderPoint.x,
370
+ y: renderPoint.y,
371
+ width: width + paddingLR * 2,
372
+ height: height + paddingTB * 2,
373
+ id: "",
374
+ sourceID: "",
375
+ valid: true,
376
+ textAttribute: "",
377
+ attribute: ""
378
+ }, {
379
+ color: background
380
+ });
381
+ DrawUtils.drawText(this.canvas, {
382
+ x: renderPoint.x + paddingLR,
383
+ y: renderPoint.y + fontHeight + paddingTB
384
+ }, text, {
385
+ color,
386
+ lineHeight,
387
+ font,
388
+ textMaxWidth
389
+ });
390
+ break;
391
+ }
392
+ default: {
393
+ }
394
+ }
395
+ (_m = (_l = annotation.annotation) == null ? void 0 : _l.renderEnhance) == null ? void 0 : _m.call(_l, {
396
+ ctx: this.ctx,
397
+ canvas: this.canvas,
398
+ currentPos: this.currentPos,
399
+ zoom: this.zoom,
400
+ data: annotation,
401
+ toolInstance: this
402
+ });
403
+ });
404
+ } catch (e) {
405
+ console.error("ViewOperation Render Error", e);
406
+ }
407
+ }
408
+ }
409
+
410
+ export { ViewOperation as default };