kfb-view 3.1.5 → 3.2.1
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 +2 -1
- package/src/components/area/index.js +9 -9
- package/src/components/board/index.js +8 -8
- package/src/components/common/common.js +26 -27
- package/src/components/graduation/index.js +45 -21
- package/src/components/navigator/index.js +66 -123
- package/src/components/tailoring/index.js +3 -3
- package/src/const/event.js +1 -0
- package/src/util/calculate.js +5 -0
- package/src/util/event-emitter.js +37 -17
- package/src/util/index.js +14 -0
- package/src/view.js +17 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kfb-view",
|
|
3
3
|
"description": "一个在线kfb的阅片软件",
|
|
4
|
-
"version": "3.1
|
|
4
|
+
"version": "3.2.1",
|
|
5
5
|
"author": "qifeng.fan <qifeng.fan@hzztai.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "lib/kfb-view.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"lint": "eslint --ext .js src"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"mitt": "^3.0.1"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"axios": "^1.6.5",
|
|
@@ -255,8 +255,8 @@ export class Area extends ViewerCommon {
|
|
|
255
255
|
// 如果是LINE或RECT或ELLIPSE或POLYGON则优先显示范围小的
|
|
256
256
|
if (this.movePoint) {
|
|
257
257
|
this.movePoint.label.select = true;
|
|
258
|
-
this.$emit(EVENT_SELECT_LABEL, this.movePoint.label);
|
|
259
|
-
this.$emit(EVENT_AREA_MOVE_START, this.movePoint.label);
|
|
258
|
+
this.mitt.$emit(EVENT_SELECT_LABEL, this.movePoint.label);
|
|
259
|
+
this.mitt.$emit(EVENT_AREA_MOVE_START, this.movePoint.label);
|
|
260
260
|
this.draging = true;
|
|
261
261
|
} else if (selectList.length > 0) {
|
|
262
262
|
selectList.sort((a, b) => {
|
|
@@ -277,9 +277,9 @@ export class Area extends ViewerCommon {
|
|
|
277
277
|
selectLabel.select = true;
|
|
278
278
|
}
|
|
279
279
|
selectLabel ?
|
|
280
|
-
this.$emit(EVENT_SELECT_LABEL, selectLabel) :
|
|
280
|
+
this.mitt.$emit(EVENT_SELECT_LABEL, selectLabel) :
|
|
281
281
|
!this.movePoint && prevSelectLabel ?
|
|
282
|
-
this.$emit(EVENT_CANCEL_SELECT_LABEL, prevSelectLabel) : '';
|
|
282
|
+
this.mitt.$emit(EVENT_CANCEL_SELECT_LABEL, prevSelectLabel) : '';
|
|
283
283
|
this.change();
|
|
284
284
|
}
|
|
285
285
|
|
|
@@ -303,13 +303,13 @@ export class Area extends ViewerCommon {
|
|
|
303
303
|
...p,
|
|
304
304
|
canMove: true,
|
|
305
305
|
});
|
|
306
|
-
this.$emit(EVENT_ADD_POLYGON_POINT, label);
|
|
306
|
+
this.mitt.$emit(EVENT_ADD_POLYGON_POINT, label);
|
|
307
307
|
this.change();
|
|
308
308
|
} else {
|
|
309
|
-
this.$emit(EVENT_DB_CLICK_LABEL, label);
|
|
309
|
+
this.mitt.$emit(EVENT_DB_CLICK_LABEL, label);
|
|
310
310
|
}
|
|
311
311
|
} else {
|
|
312
|
-
this.$emit(EVENT_DB_CLICK_LABEL, label);
|
|
312
|
+
this.mitt.$emit(EVENT_DB_CLICK_LABEL, label);
|
|
313
313
|
}
|
|
314
314
|
});
|
|
315
315
|
}
|
|
@@ -356,7 +356,7 @@ export class Area extends ViewerCommon {
|
|
|
356
356
|
const dist = getDistance(this.currentPressPoint, {x, y});
|
|
357
357
|
if (Math.abs(dist) > 1) {
|
|
358
358
|
const label = this.movePoint.label;
|
|
359
|
-
this.$emit(EVENT_AREA_MOVE_END, label);
|
|
359
|
+
this.mitt.$emit(EVENT_AREA_MOVE_END, label);
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
this.movePoint = undefined;
|
|
@@ -557,7 +557,7 @@ export class Area extends ViewerCommon {
|
|
|
557
557
|
this.viewerElementToImageCoordinates(_endPoint.x, _endPoint.y)];
|
|
558
558
|
}
|
|
559
559
|
label.region = pointsToRegion(label.points);
|
|
560
|
-
this.$emit(EVENT_AREA_MOVING, label);
|
|
560
|
+
this.mitt.$emit(EVENT_AREA_MOVING, label);
|
|
561
561
|
this.lastPoint = {x, y};
|
|
562
562
|
}
|
|
563
563
|
|
|
@@ -157,7 +157,7 @@ export class Board extends ViewerCommon {
|
|
|
157
157
|
strokeStyle: this.options.thumb.color,
|
|
158
158
|
fillStyle: this.options.thumb.bgColor,
|
|
159
159
|
});
|
|
160
|
-
this.$emit(EVENT_START_PAINTING, this.getPaintOptions());
|
|
160
|
+
this.mitt.$emit(EVENT_START_PAINTING, this.getPaintOptions());
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
@@ -200,7 +200,7 @@ export class Board extends ViewerCommon {
|
|
|
200
200
|
strokeStyle: this.options.thumb.color,
|
|
201
201
|
fillStyle: this.options.thumb.bgColor,
|
|
202
202
|
});
|
|
203
|
-
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
203
|
+
this.mitt.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
/**
|
|
@@ -268,7 +268,7 @@ export class Board extends ViewerCommon {
|
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
-
this.$emit(EVENT_END_PAINTING, this.getPaintOptions());
|
|
271
|
+
this.mitt.$emit(EVENT_END_PAINTING, this.getPaintOptions());
|
|
272
272
|
// 是否只绘制一次
|
|
273
273
|
if (this[this.tool].options.once) {
|
|
274
274
|
this.endDraw();
|
|
@@ -300,10 +300,10 @@ export class Board extends ViewerCommon {
|
|
|
300
300
|
return;
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
-
this.$emit(EVENT_END_PAINTING, this.getPaintOptions());
|
|
303
|
+
this.mitt.$emit(EVENT_END_PAINTING, this.getPaintOptions());
|
|
304
304
|
// 是否只绘制一次
|
|
305
305
|
if (this[this.tool].options.once) {
|
|
306
|
-
this.$emit(EVENT_STOP_PAINTING, this.getPaintOptions());
|
|
306
|
+
this.mitt.$emit(EVENT_STOP_PAINTING, this.getPaintOptions());
|
|
307
307
|
this.endDraw();
|
|
308
308
|
} else if (this[this.tool].options.clear) { // 是否结束绘画时清空画布
|
|
309
309
|
this.points = [];
|
|
@@ -340,7 +340,7 @@ export class Board extends ViewerCommon {
|
|
|
340
340
|
strokeStyle: this.options.thumb.color,
|
|
341
341
|
fillStyle: this.options.thumb.bgColor,
|
|
342
342
|
});
|
|
343
|
-
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
343
|
+
this.mitt.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
|
@@ -351,7 +351,7 @@ export class Board extends ViewerCommon {
|
|
|
351
351
|
onCanvasKey(e) {
|
|
352
352
|
const {originalEvent} = e;
|
|
353
353
|
if (originalEvent.key === 'Escape' && this.isInDraw) {
|
|
354
|
-
this.$emit(EVENT_STOP_PAINTING, this.getPaintOptions());
|
|
354
|
+
this.mitt.$emit(EVENT_STOP_PAINTING, this.getPaintOptions());
|
|
355
355
|
this.endDraw();
|
|
356
356
|
}
|
|
357
357
|
if (originalEvent.key === 'Delete' || originalEvent.key ===
|
|
@@ -472,6 +472,6 @@ export class Board extends ViewerCommon {
|
|
|
472
472
|
strokeStyle: this.options.thumb.color,
|
|
473
473
|
fillStyle: this.options.thumb.bgColor,
|
|
474
474
|
});
|
|
475
|
-
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
475
|
+
this.mitt.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
476
476
|
}
|
|
477
477
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {EventEmitter} from '../../util/event-emitter';
|
|
2
1
|
import {Thumb} from '../../tool/Thumb';
|
|
3
2
|
import {
|
|
4
3
|
acreage,
|
|
@@ -20,12 +19,13 @@ import {
|
|
|
20
19
|
LINE,
|
|
21
20
|
RECTANGLE,
|
|
22
21
|
} from '../../const/mark';
|
|
22
|
+
import {getUnitNumber} from '../../util';
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* 通用方法类
|
|
26
26
|
* @class
|
|
27
27
|
*/
|
|
28
|
-
export class ViewerCommon
|
|
28
|
+
export class ViewerCommon {
|
|
29
29
|
/**
|
|
30
30
|
* 构造函数
|
|
31
31
|
* @param {Object} viewer
|
|
@@ -34,12 +34,13 @@ export class ViewerCommon extends EventEmitter {
|
|
|
34
34
|
* @param {Object} options
|
|
35
35
|
*/
|
|
36
36
|
constructor(viewer, canvas, cache, options) {
|
|
37
|
-
|
|
37
|
+
const {mitt, ...rest} = options || {};
|
|
38
|
+
this.mitt = mitt;
|
|
38
39
|
this.viewer = viewer;
|
|
39
40
|
this.cache = cache;
|
|
40
41
|
this.viewport = viewer.viewport;
|
|
41
42
|
this.canvas = canvas;
|
|
42
|
-
this.options =
|
|
43
|
+
this.options = rest || {};
|
|
43
44
|
this.thumb = new Thumb();
|
|
44
45
|
this.thumb.setCanvas(canvas);
|
|
45
46
|
}
|
|
@@ -254,8 +255,7 @@ export class ViewerCommon extends EventEmitter {
|
|
|
254
255
|
top: p.y + distY * scale,
|
|
255
256
|
angle: deg,
|
|
256
257
|
texts: [
|
|
257
|
-
`长:${(Math.sqrt(w * w + h * h) * this.options.imageCapRes).toFixed(
|
|
258
|
-
2)}${this.options.unit}`],
|
|
258
|
+
`长:${this.getUnitNumber((Math.sqrt(w * w + h * h) * this.options.imageCapRes).toFixed(2))}`],
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
261
|
break;
|
|
@@ -263,9 +263,9 @@ export class ViewerCommon extends EventEmitter {
|
|
|
263
263
|
const w = Math.abs(endPoint.x - startPoint.x) / 2;
|
|
264
264
|
const h = Math.abs(endPoint.y - startPoint.y) / 2;
|
|
265
265
|
const pt = perimeter(ELLIPSE, startPoint, endPoint,
|
|
266
|
-
this.options.imageCapRes);
|
|
266
|
+
this.options.imageCapRes).toFixed(2);
|
|
267
267
|
const ac = acreage(ELLIPSE, startPoint, endPoint,
|
|
268
|
-
this.options.imageCapRes);
|
|
268
|
+
this.options.imageCapRes).toFixed(2);
|
|
269
269
|
const rightTop = getRectPoint(startPoint, endPoint)[2];
|
|
270
270
|
const p = this.imageToViewerElementCoordinates(rightTop.x,
|
|
271
271
|
rightTop.y);
|
|
@@ -274,12 +274,10 @@ export class ViewerCommon extends EventEmitter {
|
|
|
274
274
|
top: p.y,
|
|
275
275
|
angle: 0,
|
|
276
276
|
texts: [
|
|
277
|
-
`长轴:${(w * this.options.imageCapRes).toFixed(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
`周长:${(pt).toFixed(2)}${this.options.unit}`,
|
|
282
|
-
`面积:${(ac).toFixed(2)}${this.options.unit}²`],
|
|
277
|
+
`长轴:${this.getUnitNumber((w * this.options.imageCapRes).toFixed(2))}`,
|
|
278
|
+
`短轴:${this.getUnitNumber((h * this.options.imageCapRes).toFixed(2))}`,
|
|
279
|
+
`周长:${this.getUnitNumber(pt)}`,
|
|
280
|
+
`面积:${this.getUnitNumber(ac)}²`],
|
|
283
281
|
};
|
|
284
282
|
}
|
|
285
283
|
break;
|
|
@@ -287,9 +285,9 @@ export class ViewerCommon extends EventEmitter {
|
|
|
287
285
|
const w = Math.abs(endPoint.x - startPoint.x);
|
|
288
286
|
const h = Math.abs(endPoint.y - startPoint.y);
|
|
289
287
|
const pt = perimeter(RECTANGLE, startPoint, endPoint,
|
|
290
|
-
this.options.imageCapRes);
|
|
288
|
+
this.options.imageCapRes).toFixed(2);
|
|
291
289
|
const ac = acreage(RECTANGLE, startPoint, endPoint,
|
|
292
|
-
this.options.imageCapRes);
|
|
290
|
+
this.options.imageCapRes).toFixed(2);
|
|
293
291
|
const rightTop = getRectPoint(startPoint, endPoint)[2];
|
|
294
292
|
const p = this.imageToViewerElementCoordinates(rightTop.x,
|
|
295
293
|
rightTop.y);
|
|
@@ -298,12 +296,10 @@ export class ViewerCommon extends EventEmitter {
|
|
|
298
296
|
top: p.y,
|
|
299
297
|
angle: 0,
|
|
300
298
|
texts: [
|
|
301
|
-
`长:${(w * this.options.imageCapRes).toFixed(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
`周长:${(pt).toFixed(2)}${this.options.unit}`,
|
|
306
|
-
`面积:${(ac).toFixed(2)}${this.options.unit}²`],
|
|
299
|
+
`长:${this.getUnitNumber((w * this.options.imageCapRes).toFixed(2))}`,
|
|
300
|
+
`宽:${this.getUnitNumber((h * this.options.imageCapRes).toFixed(2))}`,
|
|
301
|
+
`周长:${this.getUnitNumber(pt)}`,
|
|
302
|
+
`面积:${this.getUnitNumber(ac)}²`],
|
|
307
303
|
};
|
|
308
304
|
}
|
|
309
305
|
break;
|
|
@@ -322,10 +318,9 @@ export class ViewerCommon extends EventEmitter {
|
|
|
322
318
|
top: p.y,
|
|
323
319
|
angle: 0,
|
|
324
320
|
texts: [
|
|
325
|
-
`周长:${(pt * this.options.imageCapRes).toFixed(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
this.options.imageCapRes).toFixed(2)}${this.options.unit}²`],
|
|
321
|
+
`周长:${this.getUnitNumber((pt * this.options.imageCapRes).toFixed(2))}`,
|
|
322
|
+
`面积:${this.getUnitNumber(calculatePolygonArea(points,
|
|
323
|
+
this.options.imageCapRes).toFixed(2))}²`],
|
|
329
324
|
};
|
|
330
325
|
}
|
|
331
326
|
break;
|
|
@@ -348,6 +343,10 @@ export class ViewerCommon extends EventEmitter {
|
|
|
348
343
|
};
|
|
349
344
|
}
|
|
350
345
|
|
|
346
|
+
getUnitNumber(number) {
|
|
347
|
+
return getUnitNumber(number, this.options.units, this.options.binary);
|
|
348
|
+
}
|
|
349
|
+
|
|
351
350
|
/**
|
|
352
351
|
* 判断region是否在canvas中
|
|
353
352
|
* @param {Object} region
|
|
@@ -419,6 +418,6 @@ export class ViewerCommon extends EventEmitter {
|
|
|
419
418
|
* 销毁事件
|
|
420
419
|
*/
|
|
421
420
|
destroy() {
|
|
422
|
-
this.$off();
|
|
421
|
+
this.mitt.$off();
|
|
423
422
|
}
|
|
424
423
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {ViewerCommon} from '../common/common';
|
|
2
|
+
import {EVENT_GRADUATION_CHANGE} from '../../const/event';
|
|
3
|
+
import {getUnitNumber} from '../../util';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* 刻度线
|
|
@@ -14,26 +16,24 @@ export class Graduation extends ViewerCommon {
|
|
|
14
16
|
*/
|
|
15
17
|
constructor({viewer, canvas, cache, options}) {
|
|
16
18
|
super(viewer, canvas, cache, options);
|
|
17
|
-
this.scales = options.scales ||
|
|
18
|
-
[0.1, 0.4, 0.6, 1, 2, 4, 8, 10, 20, 40, 60, 100, 140, 200];
|
|
19
19
|
this.microns = options.microns ||
|
|
20
|
-
[5000, 2000, 1250, 1000, 500, 250, 200, 100,
|
|
20
|
+
[5000, 2000, 1500, 1250, 1000, 800, 500, 400, 250, 200, 150, 125, 100, 80, 60, 40, 20, 10, 8, 5];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* 倍率大小改变
|
|
25
25
|
*/
|
|
26
26
|
change() {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const index =
|
|
27
|
+
const microns = this.microns;
|
|
28
|
+
const rect = this.viewerElementToImageRectangle({x: 0, y: 0, width: 50, height: 50});
|
|
29
|
+
const max = rect.height * this.options.imageCapRes;
|
|
30
|
+
const index = this.microns.findIndex((i) => i <= max);
|
|
31
31
|
if (!~index) {
|
|
32
|
-
this.setScaleLine(
|
|
33
|
-
|
|
32
|
+
this.setScaleLine(microns[microns.length - 1],
|
|
33
|
+
microns[microns.length - 1] / this.options.imageCapRes);
|
|
34
34
|
} else {
|
|
35
|
-
this.setScaleLine(
|
|
36
|
-
|
|
35
|
+
this.setScaleLine(microns[index],
|
|
36
|
+
microns[index] / this.options.imageCapRes);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -46,8 +46,9 @@ export class Graduation extends ViewerCommon {
|
|
|
46
46
|
const startPoint = this.imageToViewerElementCoordinates(0, 0);
|
|
47
47
|
const endPoint = this.imageToViewerElementCoordinates(px, 0);
|
|
48
48
|
const width = Math.abs(endPoint.x - startPoint.x);
|
|
49
|
+
console.log(width, txt);
|
|
49
50
|
if (this.options.custom) {
|
|
50
|
-
this.$emit(
|
|
51
|
+
this.mitt.$emit(EVENT_GRADUATION_CHANGE, {width, txt});
|
|
51
52
|
} else {
|
|
52
53
|
this.paintGraduation({width, txt});
|
|
53
54
|
}
|
|
@@ -78,16 +79,39 @@ export class Graduation extends ViewerCommon {
|
|
|
78
79
|
ctx.beginPath();
|
|
79
80
|
ctx.strokeStyle = '#000000';
|
|
80
81
|
ctx.lineWidth = 3;
|
|
81
|
-
ctx.moveTo(x, y - 8);
|
|
82
|
-
ctx.lineTo(x, y);
|
|
83
|
-
ctx.lineTo(x + lineWidth, y);
|
|
84
|
-
ctx.lineTo(x + lineWidth, y - 8);
|
|
85
|
-
ctx.stroke();
|
|
86
|
-
ctx.beginPath();
|
|
87
82
|
ctx.fillStyle = '#000000';
|
|
88
|
-
ctx.font = 'bold
|
|
89
|
-
const
|
|
83
|
+
ctx.font = 'bold 14px Arial';
|
|
84
|
+
const tick = this.options.tick || {
|
|
85
|
+
height: 8,
|
|
86
|
+
number: 5,
|
|
87
|
+
};
|
|
88
|
+
const unitIndex = this.getUnitIndex(txt * tick.number, this.options.units, this.options.binary);
|
|
89
|
+
const t = getUnitNumber(txt * tick.number, this.options.units, this.options.binary, unitIndex);
|
|
90
90
|
const fontWidth = ctx.measureText(t).width;
|
|
91
|
-
ctx.fillText(t, x + lineWidth
|
|
91
|
+
ctx.fillText(t, x + lineWidth * tick.number - fontWidth / 2, y + 20);
|
|
92
|
+
new Array(tick.number).fill(1).forEach((i, index) => {
|
|
93
|
+
ctx.moveTo(x + lineWidth * index, y - tick.height);
|
|
94
|
+
ctx.lineTo(x + lineWidth * index, y);
|
|
95
|
+
ctx.lineTo(x + lineWidth * (index + 1), y);
|
|
96
|
+
ctx.lineTo(x + lineWidth * (index + 1), y - tick.height);
|
|
97
|
+
const t = getUnitNumber(txt * index, this.options.units, this.options.binary, unitIndex).
|
|
98
|
+
replace(this.options.units[unitIndex], '');
|
|
99
|
+
const fontWidth = ctx.measureText(t).width;
|
|
100
|
+
ctx.fillText(t, x + lineWidth * index - fontWidth / 2, y + 20);
|
|
101
|
+
});
|
|
102
|
+
ctx.stroke();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
getUnitIndex(number, units, binary) {
|
|
106
|
+
let i = number;
|
|
107
|
+
let index = 0;
|
|
108
|
+
while (i >= binary) {
|
|
109
|
+
i = i / binary;
|
|
110
|
+
index++;
|
|
111
|
+
}
|
|
112
|
+
if (!units[index]) {
|
|
113
|
+
index = units.length - 1;
|
|
114
|
+
}
|
|
115
|
+
return index;
|
|
92
116
|
}
|
|
93
117
|
}
|