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