kfb-view 2.0.17 → 2.1.7
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/.idea/workspace.xml +175 -53
- package/config/webpack.dev.conf.js +2 -1
- package/example/index.js +14 -11
- package/example/style/index.css +0 -9
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/readme.md +0 -20
- package/src/components/area/index.js +9 -9
- package/src/components/board/index.js +13 -8
- package/src/components/common/common.js +5 -8
- package/src/components/graduation/index.js +4 -8
- package/src/components/index.js +1 -1
- package/src/components/navigator/index.js +13 -17
- package/src/components/navigator/navigator.scss +37 -37
- package/src/components/shape/index.js +2 -3
- package/src/const/mark.js +4 -4
- package/src/tool/Arrow.js +0 -2
- package/src/tool/Bilateral.js +0 -2
- package/src/tool/Combination.js +14 -45
- package/src/tool/Dot.js +0 -2
- package/src/tool/Ellipse.js +0 -2
- package/src/tool/Flag.js +0 -2
- package/src/tool/Font.js +0 -2
- package/src/tool/Line.js +0 -2
- package/src/tool/{Curve.js → Polygon.js} +2 -34
- package/src/tool/Rectangle.js +0 -2
- package/src/tool/Star.js +0 -2
- package/src/tool/Thumb.js +0 -2
- package/src/tool/index.js +1 -1
- package/src/util/calculate.js +2 -2
- package/src/util/canvas.js +39 -4
- package/src/util/event-emitter.js +1 -1
- package/src/view.js +21 -38
|
@@ -4,7 +4,7 @@ import {Brush} from './Brush';
|
|
|
4
4
|
* 曲线类
|
|
5
5
|
* @class
|
|
6
6
|
*/
|
|
7
|
-
class
|
|
7
|
+
class Polygon extends Brush {
|
|
8
8
|
/**
|
|
9
9
|
* 绘制结束点
|
|
10
10
|
* @param {Object[]} points - 绘制的点
|
|
@@ -43,40 +43,8 @@ class Curve extends Brush {
|
|
|
43
43
|
}
|
|
44
44
|
ctx.stroke();
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 绘制
|
|
49
|
-
* @param {Object[]} points - 绘制的点
|
|
50
|
-
* @param {number} points[].x - 绘制的点x坐标
|
|
51
|
-
* @param {number} points[].y - 绘制的点y坐标
|
|
52
|
-
* @param {Array} children
|
|
53
|
-
*/
|
|
54
|
-
drawCombination(points, children) {
|
|
55
|
-
const ctx = this.canvas.getContext('2d');
|
|
56
|
-
ctx.beginPath();
|
|
57
|
-
ctx.lineWidth = this.options.lineWidth || 2;
|
|
58
|
-
ctx.strokeStyle = this.options.strokeStyle || '#0000FF';
|
|
59
|
-
ctx.moveTo(points[0].x, points[0].y);
|
|
60
|
-
points.forEach((point) => {
|
|
61
|
-
ctx.lineTo(point.x, point.y);
|
|
62
|
-
});
|
|
63
|
-
ctx.lineTo(points[0].x, points[0].y);
|
|
64
|
-
ctx.closePath();
|
|
65
|
-
children.forEach((childrenPoints) => {
|
|
66
|
-
childrenPoints.reverse();
|
|
67
|
-
childrenPoints.forEach((point) => {
|
|
68
|
-
ctx.lineTo(point.x, point.y);
|
|
69
|
-
});
|
|
70
|
-
ctx.lineTo(childrenPoints[0].x, childrenPoints[0].y);
|
|
71
|
-
ctx.closePath();
|
|
72
|
-
});
|
|
73
|
-
ctx.fillStyle = this.options.fillStyle;
|
|
74
|
-
ctx.fill();
|
|
75
|
-
}
|
|
76
46
|
}
|
|
77
47
|
|
|
78
48
|
export {
|
|
79
|
-
|
|
49
|
+
Polygon,
|
|
80
50
|
};
|
|
81
|
-
|
|
82
|
-
export const curve = new Curve();
|
package/src/tool/Rectangle.js
CHANGED
package/src/tool/Star.js
CHANGED
package/src/tool/Thumb.js
CHANGED
package/src/tool/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export {Brush} from './Brush';
|
|
|
2
2
|
export {Arrow} from './Arrow';
|
|
3
3
|
export {Bilateral} from './Bilateral';
|
|
4
4
|
export {Line} from './Line';
|
|
5
|
-
export {
|
|
5
|
+
export {Polygon} from './Polygon';
|
|
6
6
|
export {Ellipse} from './Ellipse';
|
|
7
7
|
export {Rectangle} from './Rectangle';
|
|
8
8
|
export {Font} from './Font';
|
package/src/util/calculate.js
CHANGED
|
@@ -324,7 +324,7 @@ function acreage(type, startPoint, endPoint, imageCapRes = 1) {
|
|
|
324
324
|
if (type === 'Ellipse') {
|
|
325
325
|
ag = distX * distY / 4 * Math.PI;
|
|
326
326
|
}
|
|
327
|
-
/* if (type === '
|
|
327
|
+
/* if (type === 'polygon') {
|
|
328
328
|
}*/
|
|
329
329
|
return ag;
|
|
330
330
|
}
|
|
@@ -352,7 +352,7 @@ function perimeter(type, startPoint, endPoint, imageCapRes = 1) {
|
|
|
352
352
|
const b = distX >= distY ? distY : distX;
|
|
353
353
|
pt = 4 * (a - b) + 2 * Math.PI * b;
|
|
354
354
|
}
|
|
355
|
-
/* if (type === '
|
|
355
|
+
/* if (type === 'polygon') {
|
|
356
356
|
|
|
357
357
|
}*/
|
|
358
358
|
return pt;
|
package/src/util/canvas.js
CHANGED
|
@@ -53,21 +53,56 @@ CanvasRenderingContext2D.prototype.drawArrow = function drawArrow(
|
|
|
53
53
|
* @param {number} y 椭圆中心纵坐标
|
|
54
54
|
* @param {number} a 椭圆横半轴长
|
|
55
55
|
* @param {number} b 椭圆纵半轴长
|
|
56
|
+
* @param {boolean=} [anticlockwise=true] false为顺时针,true为逆时针
|
|
56
57
|
*/
|
|
57
|
-
CanvasRenderingContext2D.prototype.drawOval = function drawOval(
|
|
58
|
+
CanvasRenderingContext2D.prototype.drawOval = function drawOval(
|
|
59
|
+
x, y, a, b, anticlockwise = true) {
|
|
58
60
|
this.save();
|
|
59
61
|
// 选择a、b中的较大者作为arc方法的半径参数
|
|
60
62
|
const r = (a > b) ? a : b;
|
|
61
63
|
const ratioX = a / r; // 横轴缩放比率
|
|
62
64
|
const ratioY = b / r; // 纵轴缩放比率
|
|
63
65
|
this.scale(ratioX, ratioY); // 进行缩放(均匀压缩)
|
|
64
|
-
this.beginPath();
|
|
65
66
|
// 从椭圆的左端点开始逆时针绘制
|
|
66
67
|
this.moveTo((x + a) / ratioX, y / ratioY);
|
|
67
|
-
this.arc(x / ratioX, y / ratioY, r, 0, 2 * Math.PI);
|
|
68
|
+
this.arc(x / ratioX, y / ratioY, r, 0, 2 * Math.PI, anticlockwise);
|
|
68
69
|
this.closePath();
|
|
69
70
|
this.restore();
|
|
70
|
-
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 画多边形
|
|
75
|
+
* @param {Array} points 多边形所有的点
|
|
76
|
+
* @param {boolean=} [close=true] 是否是闭合多边形
|
|
77
|
+
* @param {boolean=} [anticlockwise=true] false为顺时针,true为逆时针
|
|
78
|
+
*/
|
|
79
|
+
CanvasRenderingContext2D.prototype.drawPolygon = function drawPolygon(
|
|
80
|
+
points, close = true, anticlockwise = true) {
|
|
81
|
+
let _points = [...points];
|
|
82
|
+
// Green公式,判断连续点组成的多边形是逆时针还是顺时针
|
|
83
|
+
let d = 0;
|
|
84
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
85
|
+
d += -0.5 * (points[i + 1].y + points[i].y) *
|
|
86
|
+
(points[i + 1].x - points[i].x);
|
|
87
|
+
}
|
|
88
|
+
// 顺时针
|
|
89
|
+
if (d > 0) {
|
|
90
|
+
if (anticlockwise) {
|
|
91
|
+
_points.reverse();
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
// 逆时针
|
|
95
|
+
if (!anticlockwise) {
|
|
96
|
+
_points.reverse();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.moveTo(_points[0].x, _points[0].y);
|
|
100
|
+
_points.forEach((point) => {
|
|
101
|
+
this.lineTo(point.x, point.y);
|
|
102
|
+
});
|
|
103
|
+
if (close) {
|
|
104
|
+
this.lineTo(_points[0].x, _points[0].y);
|
|
105
|
+
}
|
|
71
106
|
};
|
|
72
107
|
|
|
73
108
|
// eslint-disable-next-line require-jsdoc
|
|
@@ -61,7 +61,7 @@ export class EventEmitter {
|
|
|
61
61
|
*/
|
|
62
62
|
$off(eventName, callback, options, target = document) {
|
|
63
63
|
let eventList = this.eventList.filter((ev) =>
|
|
64
|
-
(ev.target === target || !target) &&
|
|
64
|
+
(ev.target === target || !target || target === document) &&
|
|
65
65
|
(ev.eventName === eventName || !eventName) &&
|
|
66
66
|
(ev.options === options || options == null) &&
|
|
67
67
|
(ev.callback === callback || !callback));
|
package/src/view.js
CHANGED
|
@@ -6,14 +6,7 @@ import {pointsToRegion} 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';
|
|
9
|
-
import {
|
|
10
|
-
ARROW,
|
|
11
|
-
BILATERAL,
|
|
12
|
-
CURVE, DOT,
|
|
13
|
-
ELLIPSE, FLAG, FONT,
|
|
14
|
-
LINE,
|
|
15
|
-
RECTANGLE, STAR,
|
|
16
|
-
} from './const/mark';
|
|
9
|
+
import {MARKS} from './const/mark';
|
|
17
10
|
import {LabelModel} from './model/label.model';
|
|
18
11
|
|
|
19
12
|
/**
|
|
@@ -95,10 +88,6 @@ export default class KfbView extends EventEmitter {
|
|
|
95
88
|
* @param {Array} list
|
|
96
89
|
*/
|
|
97
90
|
initLabelList(list) {
|
|
98
|
-
this.updateLabelList(list);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
updateLabelList(list) {
|
|
102
91
|
this.labelList = list.map((item) => new LabelModel({
|
|
103
92
|
...item,
|
|
104
93
|
region: item.region || pointsToRegion(item.points),
|
|
@@ -119,7 +108,7 @@ export default class KfbView extends EventEmitter {
|
|
|
119
108
|
this.$options.width = width;
|
|
120
109
|
this.$options.height = height;
|
|
121
110
|
Object.values(COMPONENTS).forEach((name) => {
|
|
122
|
-
if (this[name]
|
|
111
|
+
if (this[name]?.resetCanvasSize) {
|
|
123
112
|
this[name].resetCanvasSize({width, height});
|
|
124
113
|
}
|
|
125
114
|
});
|
|
@@ -130,7 +119,7 @@ export default class KfbView extends EventEmitter {
|
|
|
130
119
|
*/
|
|
131
120
|
change() {
|
|
132
121
|
Object.values(COMPONENTS).forEach((name) => {
|
|
133
|
-
if (this[name]
|
|
122
|
+
if (this[name]?.change) {
|
|
134
123
|
this[name].change();
|
|
135
124
|
}
|
|
136
125
|
});
|
|
@@ -142,10 +131,12 @@ export default class KfbView extends EventEmitter {
|
|
|
142
131
|
destroy() {
|
|
143
132
|
this.$off();
|
|
144
133
|
this.viewer?.destroy?.();
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
134
|
+
this.viewer = undefined;
|
|
135
|
+
this.$el = undefined;
|
|
136
|
+
Object.values(COMPONENTS).forEach((name) => {
|
|
137
|
+
this[name]?.destroy?.();
|
|
138
|
+
this[name] = undefined;
|
|
139
|
+
});
|
|
149
140
|
}
|
|
150
141
|
}
|
|
151
142
|
|
|
@@ -209,20 +200,20 @@ function initComponents(kv) {
|
|
|
209
200
|
|
|
210
201
|
function initNavigator(kv) {
|
|
211
202
|
const config = kv.$options;
|
|
212
|
-
config.navigator = config.navigator || {disabled:
|
|
203
|
+
config.navigator = config.navigator || {disabled: false};
|
|
213
204
|
if (config.navigator.disabled !== true) {
|
|
214
205
|
if (!config.navigator.style) {
|
|
215
206
|
config.navigator.style = 'bottom: 0;left: 0;';
|
|
216
207
|
}
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
kv
|
|
221
|
-
kv.navigator = new Components.
|
|
208
|
+
const navigator = document.createElement('div');
|
|
209
|
+
navigator.setAttribute('class', 'openseadragon-navigator');
|
|
210
|
+
navigator.style.cssText += config.navigator.style;
|
|
211
|
+
kv.viewer.container.appendChild(navigator);
|
|
212
|
+
kv.navigator = new Components.Navigator({
|
|
222
213
|
viewer: kv.viewer,
|
|
223
214
|
containerHeight: config.height,
|
|
224
215
|
containerWidth: config.width,
|
|
225
|
-
element:
|
|
216
|
+
element: navigator,
|
|
226
217
|
...config.navigator,
|
|
227
218
|
});
|
|
228
219
|
}
|
|
@@ -348,7 +339,7 @@ function handlerLabelEvent(e, kv) {
|
|
|
348
339
|
label.show = false;
|
|
349
340
|
kv.$emit(EVENTS.EVENT_HIDDEN_LABEL, label);
|
|
350
341
|
}
|
|
351
|
-
if (e.key === 'Delete' || e.key === 'Backspace'
|
|
342
|
+
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
352
343
|
const index = kv.labelList.findIndex((label) => label.select);
|
|
353
344
|
if (!~index) return;
|
|
354
345
|
kv.$emit(EVENTS.EVENT_DELETE_LABEL, kv.labelList[index]);
|
|
@@ -356,18 +347,10 @@ function handlerLabelEvent(e, kv) {
|
|
|
356
347
|
}
|
|
357
348
|
}
|
|
358
349
|
|
|
359
|
-
KfbView.marks = {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
RECTANGLE,
|
|
364
|
-
ELLIPSE,
|
|
365
|
-
CURVE,
|
|
366
|
-
FONT,
|
|
367
|
-
STAR,
|
|
368
|
-
FLAG,
|
|
369
|
-
DOT,
|
|
370
|
-
};
|
|
350
|
+
KfbView.marks = {};
|
|
351
|
+
MARKS.forEach((key) => {
|
|
352
|
+
KfbView.marks[key.toLocaleUpperCase()] = key;
|
|
353
|
+
});
|
|
371
354
|
|
|
372
355
|
KfbView.events = {
|
|
373
356
|
...EVENTS,
|