kfb-view 3.2.8 → 3.3.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/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/shape/index.js +12 -13
- package/src/model/label.model.js +1 -0
- package/src/tool/Image.js +26 -7
- package/src/view.js +23 -11
package/package.json
CHANGED
|
@@ -60,6 +60,7 @@ export class Shape extends ViewerCommon {
|
|
|
60
60
|
// 区域标注列表
|
|
61
61
|
const labelList = this.labelList.filter((item) => {
|
|
62
62
|
if (item.show === false) return false;
|
|
63
|
+
if (item.custom) return false;
|
|
63
64
|
if (!this[item.tool]) return false;
|
|
64
65
|
if (!this.isInCanvas(item.region, bounds)) return false;
|
|
65
66
|
if ((REGION_TYPES.includes(item.tool) || item.isClose && item.tool ===
|
|
@@ -105,12 +106,14 @@ export class Shape extends ViewerCommon {
|
|
|
105
106
|
clearTimeout(this.delaytimer);
|
|
106
107
|
this.delaytimer = undefined;
|
|
107
108
|
}
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
// 优先绘制图片标注
|
|
110
|
+
imageLabel.forEach((item) => {
|
|
111
|
+
this.drawLabel(item);
|
|
112
|
+
});
|
|
113
|
+
this.deepDrawLabel(sameFixWidthLabel, sameNormalLabel, regionLabelList, 1, bounds);
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
deepDrawLabel(sameFixWidthLabel, sameNormalLabel, regionLabelList,
|
|
113
|
-
imageLabel, count, bounds) {
|
|
116
|
+
deepDrawLabel(sameFixWidthLabel, sameNormalLabel, regionLabelList, count, bounds) {
|
|
114
117
|
let currentDrawCount = 0; // 当前已绘制数量
|
|
115
118
|
const ctx = this.canvas.getContext('2d');
|
|
116
119
|
const remainFixLabel = {};
|
|
@@ -118,7 +121,7 @@ export class Shape extends ViewerCommon {
|
|
|
118
121
|
const labels = sameFixWidthLabel[key];
|
|
119
122
|
ctx.beginPath();
|
|
120
123
|
labels.forEach((item) => {
|
|
121
|
-
if (currentDrawCount >=
|
|
124
|
+
if (currentDrawCount >= 4000) { // 一次最多绘制4000个点,多余标注延迟绘制
|
|
122
125
|
if (remainFixLabel[key]) {
|
|
123
126
|
remainFixLabel[key].push(item);
|
|
124
127
|
} else {
|
|
@@ -127,7 +130,7 @@ export class Shape extends ViewerCommon {
|
|
|
127
130
|
} else {
|
|
128
131
|
this.drawLabel(item);
|
|
129
132
|
}
|
|
130
|
-
currentDrawCount
|
|
133
|
+
currentDrawCount = currentDrawCount + item.points.length;
|
|
131
134
|
});
|
|
132
135
|
const firstLabel = labels?.[0];
|
|
133
136
|
if (firstLabel?.fillStyle) {
|
|
@@ -142,7 +145,7 @@ export class Shape extends ViewerCommon {
|
|
|
142
145
|
const labels = sameNormalLabel[key];
|
|
143
146
|
ctx.beginPath();
|
|
144
147
|
labels.forEach((item) => {
|
|
145
|
-
if (currentDrawCount >=
|
|
148
|
+
if (currentDrawCount >= 4000) { // 一次最多绘制4000个点,多余标注延迟绘制
|
|
146
149
|
if (remainNormalLabel[key]) {
|
|
147
150
|
remainNormalLabel[key].push(item);
|
|
148
151
|
} else {
|
|
@@ -151,7 +154,7 @@ export class Shape extends ViewerCommon {
|
|
|
151
154
|
} else {
|
|
152
155
|
this.drawLabel(item);
|
|
153
156
|
}
|
|
154
|
-
currentDrawCount
|
|
157
|
+
currentDrawCount = currentDrawCount + item.points.length;
|
|
155
158
|
});
|
|
156
159
|
const firstLabel = labels?.[0];
|
|
157
160
|
ctx.lineWidth = firstLabel.lineWidth;
|
|
@@ -162,9 +165,6 @@ export class Shape extends ViewerCommon {
|
|
|
162
165
|
Object.keys(remainNormalLabel).length === 0) {
|
|
163
166
|
console.log(`end deep draw label, draw count: ${count}`);
|
|
164
167
|
this.delaytimer = undefined;
|
|
165
|
-
imageLabel.forEach((item) => {
|
|
166
|
-
this.drawLabel(item);
|
|
167
|
-
});
|
|
168
168
|
regionLabelList.forEach((item) => {
|
|
169
169
|
this.combination.setContent(this.canvas, item);
|
|
170
170
|
this.combination.draw({
|
|
@@ -177,8 +177,7 @@ export class Shape extends ViewerCommon {
|
|
|
177
177
|
});
|
|
178
178
|
} else {
|
|
179
179
|
this.delaytimer = setTimeout(() => {
|
|
180
|
-
this.deepDrawLabel(remainFixLabel, remainNormalLabel, regionLabelList,
|
|
181
|
-
imageLabel, count + 1,
|
|
180
|
+
this.deepDrawLabel(remainFixLabel, remainNormalLabel, regionLabelList, count + 1,
|
|
182
181
|
bounds);
|
|
183
182
|
}, 100);
|
|
184
183
|
}
|
package/src/model/label.model.js
CHANGED
|
@@ -25,6 +25,7 @@ export class LabelModel {
|
|
|
25
25
|
this.resize = data.resize; // 是否可拖动大小
|
|
26
26
|
this.isROI = data.isROI ?? false; // 是否是ROI
|
|
27
27
|
this.isClose = data.isClose ?? true; // 是否是闭合标注
|
|
28
|
+
this.custom = data.custom ?? false; // 是否是自定义的标注
|
|
28
29
|
this.select = data.select ?? false; // 是否是选中状态
|
|
29
30
|
this.show = data.show ?? true; // 是否显示
|
|
30
31
|
this.__other__ = data.__other__ || {}; // 其他信息
|
package/src/tool/Image.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Brush} from './Brush';
|
|
2
|
-
import {
|
|
2
|
+
import {getDistance, getRectPoints} from '../util/calculate';
|
|
3
3
|
import {EventEmitter} from '../util/event-emitter';
|
|
4
4
|
|
|
5
5
|
const et = new EventEmitter();
|
|
@@ -22,22 +22,41 @@ class Image extends Brush {
|
|
|
22
22
|
* @param {number} points[].x - 绘制的点x坐标
|
|
23
23
|
* @param {number} points[].y - 绘制的点y坐标
|
|
24
24
|
* @param {number=} scale
|
|
25
|
+
* @param {number=} angle
|
|
25
26
|
*/
|
|
26
|
-
draw(points, scale = 1) {
|
|
27
|
-
|
|
27
|
+
draw(points, scale = 1, angle = 0) {
|
|
28
|
+
if (points.length === 2) {
|
|
29
|
+
points = getRectPoints(points);
|
|
30
|
+
}
|
|
31
|
+
const width = getDistance(points[1], points[0]);
|
|
32
|
+
const height = getDistance(points[2], points[0]);
|
|
33
|
+
const region = {
|
|
34
|
+
...points[0],
|
|
35
|
+
width,
|
|
36
|
+
height,
|
|
37
|
+
};
|
|
28
38
|
if (this.options.imgLoadSuccess) {
|
|
29
|
-
this.drawImage(this.options.img, region);
|
|
39
|
+
this.drawImage(this.options.img, region, angle);
|
|
30
40
|
} else if (this.options.img) {
|
|
31
41
|
const img = this.options.img;
|
|
32
42
|
et.$once('load', () => {
|
|
33
|
-
this.drawImage(img, region);
|
|
43
|
+
this.drawImage(img, region, angle);
|
|
34
44
|
}, true, img);
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
|
|
38
|
-
drawImage(img, region) {
|
|
48
|
+
drawImage(img, region, angle = 0) {
|
|
39
49
|
const ctx = this.canvas.getContext('2d');
|
|
40
|
-
ctx.
|
|
50
|
+
ctx.beginPath();
|
|
51
|
+
ctx.save();
|
|
52
|
+
ctx.translate(region.x, region.y);
|
|
53
|
+
if (angle < 0) {
|
|
54
|
+
angle += 360;
|
|
55
|
+
}
|
|
56
|
+
const _rotation = angle % 360;
|
|
57
|
+
ctx.rotate(_rotation * Math.PI / 180);
|
|
58
|
+
ctx.drawImage(img, 0, 0, region.width, region.height);
|
|
59
|
+
ctx.restore();
|
|
41
60
|
}
|
|
42
61
|
}
|
|
43
62
|
|
package/src/view.js
CHANGED
|
@@ -2,7 +2,7 @@ import openSeadragon from './plugin/openseadragon/openseadragon';
|
|
|
2
2
|
import './util/canvas';
|
|
3
3
|
import {EventEmitter} from './util/event-emitter';
|
|
4
4
|
import {$, dataType, deepClone} from './util';
|
|
5
|
-
import {pointsToRegion} from './util/calculate';
|
|
5
|
+
import {pointsToRegion, regionToPoint} from './util/calculate';
|
|
6
6
|
import * as COMPONENTS from './const/component';
|
|
7
7
|
import * as EVENTS from './const/event';
|
|
8
8
|
import * as Components from './components';
|
|
@@ -133,11 +133,17 @@ export default class KfbView extends EventEmitter {
|
|
|
133
133
|
* @param {Array} list
|
|
134
134
|
*/
|
|
135
135
|
initLabelList(list) {
|
|
136
|
-
this.labelList = list.map((item) =>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
this.labelList = list.map((item) => {
|
|
137
|
+
if (!item.points?.length) {
|
|
138
|
+
const {startPoint, endPoint} = regionToPoint(item.region);
|
|
139
|
+
item.points = [startPoint, endPoint];
|
|
140
|
+
}
|
|
141
|
+
return new LabelModel({
|
|
142
|
+
...item,
|
|
143
|
+
region: item.region || pointsToRegion(item.points),
|
|
144
|
+
__data__: deepClone(item),
|
|
145
|
+
});
|
|
146
|
+
});
|
|
141
147
|
this.board?.setLabelList?.(this.labelList);
|
|
142
148
|
this.shape?.setLabelList?.(this.labelList);
|
|
143
149
|
this.area?.setLabelList?.(this.labelList);
|
|
@@ -145,11 +151,17 @@ export default class KfbView extends EventEmitter {
|
|
|
145
151
|
|
|
146
152
|
appendLabelList(list) {
|
|
147
153
|
this.labelList = [
|
|
148
|
-
...this.labelList, ...list.map((item) =>
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
...this.labelList, ...list.map((item) => {
|
|
155
|
+
if (!item.points?.length) {
|
|
156
|
+
const {startPoint, endPoint} = regionToPoint(item.region);
|
|
157
|
+
item.points = [startPoint, endPoint];
|
|
158
|
+
}
|
|
159
|
+
return new LabelModel({
|
|
160
|
+
...item,
|
|
161
|
+
region: item.region || pointsToRegion(item.points),
|
|
162
|
+
__data__: deepClone(item),
|
|
163
|
+
});
|
|
164
|
+
})];
|
|
153
165
|
this.board?.setLabelList?.(this.labelList);
|
|
154
166
|
this.shape?.setLabelList?.(this.labelList);
|
|
155
167
|
this.area?.setLabelList?.(this.labelList);
|