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
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
1
|
## Kfb-View ##
|
|
2
|
-
|
|
3
|
-
使用之前需安装html-loader,否则无法正常显示
|
|
4
|
-
```
|
|
5
|
-
npm install -D html-loader
|
|
6
|
-
```
|
|
7
|
-
|
|
8
|
-
### webpack ###
|
|
9
|
-
```
|
|
10
|
-
{
|
|
11
|
-
test: /\.html$/,
|
|
12
|
-
use: [{
|
|
13
|
-
loader: 'html-loader',
|
|
14
|
-
options: {
|
|
15
|
-
minimize: true,
|
|
16
|
-
removeComments: false,
|
|
17
|
-
collapseWhitespace: false,
|
|
18
|
-
},
|
|
19
|
-
}],
|
|
20
|
-
}
|
|
21
|
-
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {ViewerCommon} from '../common/common';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
POLYGON, DOT,
|
|
4
4
|
FLAG,
|
|
5
5
|
FONT,
|
|
6
6
|
LINE_TYPES, MARKS,
|
|
@@ -94,7 +94,7 @@ export class Area extends ViewerCommon {
|
|
|
94
94
|
pointList = getRectPoint(startPoint, endPoint);
|
|
95
95
|
moveIndex = pointList.findIndex(
|
|
96
96
|
(point) => pointInOtherPoint(point, {x, y}));
|
|
97
|
-
} else if (item.tool ===
|
|
97
|
+
} else if (item.tool === POLYGON) {
|
|
98
98
|
// 曲线,每个有效的点都可以移动
|
|
99
99
|
pointList = this.setPointsMove(item);
|
|
100
100
|
moveIndex = pointList.findIndex(
|
|
@@ -166,15 +166,15 @@ export class Area extends ViewerCommon {
|
|
|
166
166
|
// moveIndex>-1,表示选中的是图形中可移动的点
|
|
167
167
|
if (~moveIndex) {
|
|
168
168
|
this.movePoint = {position: moveIndex, label: item};
|
|
169
|
-
} else if ((item.tool !==
|
|
169
|
+
} else if ((item.tool !== POLYGON &&
|
|
170
170
|
isPointInMatrix(pointList[0], pointList[2], pointList[6], pointList[8],
|
|
171
171
|
{x, y})) ||
|
|
172
|
-
(item.tool ===
|
|
172
|
+
(item.tool === POLYGON && isPointInPolygon({x, y}, pointList))) {
|
|
173
173
|
selectList.push(item);
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
176
|
// 如果点击canvas,同时选中了多个标签,那么显示规则为,
|
|
177
|
-
// 优先级FONT>STAR>FLAG>LINE>RECT>
|
|
177
|
+
// 优先级FONT>STAR>FLAG>LINE>RECT>POLYGON
|
|
178
178
|
// 如果是LINE或RECT或ELLIPSE或CURVE则优先显示范围小的
|
|
179
179
|
if (this.movePoint) {
|
|
180
180
|
this.movePoint.label.select = true;
|
|
@@ -298,7 +298,7 @@ export class Area extends ViewerCommon {
|
|
|
298
298
|
_endPoint = {x: pointList[8].x + distX, y: pointList[8].y + distY};
|
|
299
299
|
break;
|
|
300
300
|
}
|
|
301
|
-
} else if (tool ===
|
|
301
|
+
} else if (tool === POLYGON) {
|
|
302
302
|
const points = this.imageToViewerElementPoints(label.points).
|
|
303
303
|
map((item, index) => ({
|
|
304
304
|
...item,
|
|
@@ -398,7 +398,7 @@ export class Area extends ViewerCommon {
|
|
|
398
398
|
label.lineWidth += distY / scale;
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
|
-
if (tool !==
|
|
401
|
+
if (tool !== POLYGON) {
|
|
402
402
|
label.points = [
|
|
403
403
|
this.viewerElementToImageCoordinates(_startPoint.x, _startPoint.y),
|
|
404
404
|
this.viewerElementToImageCoordinates(_endPoint.x, _endPoint.y)];
|
|
@@ -437,7 +437,7 @@ export class Area extends ViewerCommon {
|
|
|
437
437
|
getRectPoint(points[0], points[1]).forEach((point) => {
|
|
438
438
|
this.drawPoint(point, {thumbRadius: 5});
|
|
439
439
|
});
|
|
440
|
-
} else if (type ===
|
|
440
|
+
} else if (type === POLYGON) {
|
|
441
441
|
points.forEach((point) => {
|
|
442
442
|
if (point.canMove) {
|
|
443
443
|
this.drawPoint(point, {thumbRadius: 5});
|
|
@@ -505,7 +505,7 @@ export class Area extends ViewerCommon {
|
|
|
505
505
|
x: startPoint.x + dist,
|
|
506
506
|
y: startPoint.y,
|
|
507
507
|
}], label.tool);
|
|
508
|
-
} else if (label.tool ===
|
|
508
|
+
} else if (label.tool === POLYGON) {
|
|
509
509
|
if (this.draging) {
|
|
510
510
|
const points = this.imageToViewerElementPoints(label.points);
|
|
511
511
|
this.drawThumbPoint(points, label.tool);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ViewerCommon} from '../common/common';
|
|
2
2
|
import * as Tools from '../../tool';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
POLYGON, DOT, FLAG, MARKS,
|
|
5
5
|
NO_NORMAL_REGION_TYPES,
|
|
6
6
|
POINT_TYPES, STAR,
|
|
7
7
|
} from '../../const/mark';
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
EVENT_IN_PAINTING,
|
|
12
12
|
} from '../../const/event';
|
|
13
13
|
import {
|
|
14
|
-
isPointInMatrix,
|
|
15
14
|
pointInOtherPoint,
|
|
16
15
|
pointsToRegion,
|
|
17
16
|
} from '../../util/calculate';
|
|
@@ -52,7 +51,10 @@ export class Board extends ViewerCommon {
|
|
|
52
51
|
if (!options.tool) {
|
|
53
52
|
throw new Error('options.tool must not bu null');
|
|
54
53
|
}
|
|
55
|
-
if (
|
|
54
|
+
if (options.tool === 'curve') {
|
|
55
|
+
throw new Error(`Curve is obsolete. Please use polygon instead`);
|
|
56
|
+
}
|
|
57
|
+
if (!MARKS.includes(options.tool)) {
|
|
56
58
|
throw new Error(`${options.tool} is not a effective drawing tool`);
|
|
57
59
|
}
|
|
58
60
|
this.viewer.canvas.focus();
|
|
@@ -80,7 +82,10 @@ export class Board extends ViewerCommon {
|
|
|
80
82
|
if (!options.tool) {
|
|
81
83
|
throw new Error('options.tool must not bu null');
|
|
82
84
|
}
|
|
83
|
-
if (
|
|
85
|
+
if (options.tool === 'curve') {
|
|
86
|
+
throw new Error(`Curve is obsolete. Please use polygon instead`);
|
|
87
|
+
}
|
|
88
|
+
if (!MARKS.includes(options.tool)) {
|
|
84
89
|
throw new Error(`${options.tool} is not a effective drawing tool`);
|
|
85
90
|
}
|
|
86
91
|
this.viewer.canvas.focus();
|
|
@@ -123,7 +128,7 @@ export class Board extends ViewerCommon {
|
|
|
123
128
|
return;
|
|
124
129
|
}
|
|
125
130
|
const tool = this.tool;
|
|
126
|
-
if (tool ===
|
|
131
|
+
if (tool === POLYGON) {
|
|
127
132
|
this.points.push(point);
|
|
128
133
|
} else {
|
|
129
134
|
this.points = [point];
|
|
@@ -149,7 +154,7 @@ export class Board extends ViewerCommon {
|
|
|
149
154
|
const tool = this.tool;
|
|
150
155
|
if (!NO_NORMAL_REGION_TYPES.includes(tool)) {
|
|
151
156
|
this.points = [this.points[0] || point, point];
|
|
152
|
-
} else if (tool ===
|
|
157
|
+
} else if (tool === POLYGON) {
|
|
153
158
|
this.points.push(point);
|
|
154
159
|
} else if (POINT_TYPES.includes(tool)) {
|
|
155
160
|
this.points = [point, point];
|
|
@@ -179,7 +184,7 @@ export class Board extends ViewerCommon {
|
|
|
179
184
|
return;
|
|
180
185
|
} else if (POINT_TYPES.includes(tool)) {
|
|
181
186
|
this.points = [point, point];
|
|
182
|
-
} else if (tool ===
|
|
187
|
+
} else if (tool === POLYGON) {
|
|
183
188
|
const points = this.imageToViewerElementPoints(this.points);
|
|
184
189
|
let firstPoint = points[0];
|
|
185
190
|
// 是否是闭合曲线
|
|
@@ -229,7 +234,7 @@ export class Board extends ViewerCommon {
|
|
|
229
234
|
return;
|
|
230
235
|
}
|
|
231
236
|
const tool = this.tool;
|
|
232
|
-
if (tool ===
|
|
237
|
+
if (tool === POLYGON && this.points.length > 0) {
|
|
233
238
|
this.points.pop();
|
|
234
239
|
this.points.push(point);
|
|
235
240
|
this.clearCanvas();
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import {EventEmitter} from '../../util/event-emitter';
|
|
2
2
|
import {Thumb} from '../../tool/Thumb';
|
|
3
3
|
import {
|
|
4
|
-
acreage, getAngle,
|
|
5
|
-
getRectPoint, isPointInEllipse, isPointInMatrix,
|
|
6
|
-
perimeter,
|
|
7
|
-
pointsToRegion,
|
|
4
|
+
acreage, getAngle, perimeter, pointsToRegion,
|
|
5
|
+
getRectPoint, isPointInEllipse, isPointInMatrix, isPointInPolygon,
|
|
8
6
|
} from '../../util/calculate';
|
|
9
7
|
import {Point, Rect} from '../../plugin/openseadragon/openseadragon';
|
|
10
8
|
import {
|
|
11
9
|
ARROW,
|
|
12
10
|
BILATERAL,
|
|
13
|
-
|
|
11
|
+
POLYGON,
|
|
14
12
|
ELLIPSE,
|
|
15
13
|
LINE,
|
|
16
14
|
RECTANGLE,
|
|
17
15
|
} from '../../const/mark';
|
|
18
|
-
import {isPointInPolygon} from '../..';
|
|
19
16
|
|
|
20
17
|
/**
|
|
21
18
|
* 通用方法类
|
|
@@ -89,7 +86,7 @@ export class ViewerCommon extends EventEmitter {
|
|
|
89
86
|
if (tool === RECTANGLE) {
|
|
90
87
|
return isPointInMatrix(p1, p2, p3, p4, point);
|
|
91
88
|
}
|
|
92
|
-
if (tool ===
|
|
89
|
+
if (tool === POLYGON && isClose) {
|
|
93
90
|
return isPointInPolygon(point, points);
|
|
94
91
|
}
|
|
95
92
|
return false;
|
|
@@ -272,7 +269,7 @@ export class ViewerCommon extends EventEmitter {
|
|
|
272
269
|
};
|
|
273
270
|
}
|
|
274
271
|
break;
|
|
275
|
-
case
|
|
272
|
+
case POLYGON: {
|
|
276
273
|
const points = label.points;
|
|
277
274
|
const rightTop = getRectPoint(startPoint, endPoint)[2];
|
|
278
275
|
const p = this.imageToViewerElementCoordinates(rightTop.x,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {Point} from '../../plugin/openseadragon/openseadragon';
|
|
2
1
|
import {ViewerCommon} from '../common/common';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -56,11 +55,8 @@ export class Graduation extends ViewerCommon {
|
|
|
56
55
|
* @param {number} px
|
|
57
56
|
*/
|
|
58
57
|
setScaleLine(txt, px) {
|
|
59
|
-
const startPoint =
|
|
60
|
-
|
|
61
|
-
const endPoint =
|
|
62
|
-
this.viewport.imageToViewerElementCoordinates(
|
|
63
|
-
new Point(px, 0));
|
|
58
|
+
const startPoint = this.imageToViewerElementCoordinates(0, 0);
|
|
59
|
+
const endPoint = this.imageToViewerElementCoordinates(px, 0);
|
|
64
60
|
const width = Math.abs(endPoint.x - startPoint.x);
|
|
65
61
|
if (this.options.custom) {
|
|
66
62
|
this.$emit('graduation-change', {width, txt});
|
|
@@ -81,7 +77,7 @@ export class Graduation extends ViewerCommon {
|
|
|
81
77
|
if (left) {
|
|
82
78
|
x = left;
|
|
83
79
|
} else if (right) {
|
|
84
|
-
x = width - right;
|
|
80
|
+
x = width - right - lineWidth;
|
|
85
81
|
}
|
|
86
82
|
if (top) {
|
|
87
83
|
y = top;
|
|
@@ -100,6 +96,6 @@ export class Graduation extends ViewerCommon {
|
|
|
100
96
|
ctx.fillStyle = '#454545';
|
|
101
97
|
const t = txt.toFixed(0) + this.options.unit;
|
|
102
98
|
const fontWidth = ctx.measureText(t).width;
|
|
103
|
-
ctx.fillText(t, x + lineWidth / 2 - fontWidth / 2, y - 10);
|
|
99
|
+
ctx.fillText(t, x + lineWidth / 2 - fontWidth / 2, top ? y + 10 : y - 10);
|
|
104
100
|
}
|
|
105
101
|
}
|
package/src/components/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {EVENT_NAVIGATOR_VESTIGE} from '../../const/event';
|
|
|
8
8
|
* 视图导航器
|
|
9
9
|
* @class
|
|
10
10
|
*/
|
|
11
|
-
export class
|
|
11
|
+
export class Navigator extends EventEmitter {
|
|
12
12
|
/**
|
|
13
13
|
* 初始化导航器数据
|
|
14
14
|
* @param {Object=} rest openseadragon的导航器参数
|
|
@@ -36,13 +36,11 @@ export class ViewerNavigator extends EventEmitter {
|
|
|
36
36
|
this.element.innerHTML = navigatorHtml;
|
|
37
37
|
const navigatorMain = this.element.getElementsByClassName(
|
|
38
38
|
'navigator-main')[0];
|
|
39
|
-
this.imgTop = 0;
|
|
40
|
-
this.imgLeft = 0;
|
|
41
39
|
this.canvas = this.createNavigatorCanvas();
|
|
42
|
-
navigatorMain.
|
|
40
|
+
navigatorMain.appendChild(this.canvas);
|
|
43
41
|
this.handleMouseDrag(navigatorMain);
|
|
44
42
|
|
|
45
|
-
const rect =
|
|
43
|
+
const rect = this.element.getElementsByClassName('view-rect')[0];
|
|
46
44
|
this.rect = rect;
|
|
47
45
|
this.$on('rect-change', (e) => {
|
|
48
46
|
const vLine = navigatorMain.getElementsByClassName('v-line')[0];
|
|
@@ -83,8 +81,6 @@ export class ViewerNavigator extends EventEmitter {
|
|
|
83
81
|
this.pointList = pointList;
|
|
84
82
|
const colorCanvas = this.element.getElementsByClassName(
|
|
85
83
|
'navigator-color-rect')[0];
|
|
86
|
-
colorCanvas.width = this.canvas.width;
|
|
87
|
-
colorCanvas.height = this.canvas.height;
|
|
88
84
|
const ctx = colorCanvas.getContext('2d');
|
|
89
85
|
this.pointList.forEach((item) => {
|
|
90
86
|
this.drawRect(ctx, item);
|
|
@@ -298,11 +294,9 @@ export class ViewerNavigator extends EventEmitter {
|
|
|
298
294
|
const imgWidth = img.width;
|
|
299
295
|
const imgHeight = img.height;
|
|
300
296
|
let scale = 1;
|
|
301
|
-
if (imgWidth
|
|
297
|
+
if (imgWidth >= imgHeight) {
|
|
302
298
|
scale = imgWidth / this.width;
|
|
303
299
|
const trueHeight = imgHeight / scale;
|
|
304
|
-
/* const top = (this.height - trueHeight) / 2;
|
|
305
|
-
this.imgTop = top;*/
|
|
306
300
|
canvas.width = this.width;
|
|
307
301
|
canvas.height = trueHeight;
|
|
308
302
|
ctx.drawImage(img, 0, 0, canvas.width, trueHeight);
|
|
@@ -310,13 +304,15 @@ export class ViewerNavigator extends EventEmitter {
|
|
|
310
304
|
if (imgHeight > imgWidth) {
|
|
311
305
|
scale = imgHeight / this.height;
|
|
312
306
|
const trueWidth = imgWidth / scale;
|
|
313
|
-
/* const left = (this.width - trueWidth) / 2;
|
|
314
|
-
this.imgLeft = left;*/
|
|
315
307
|
canvas.height = this.height;
|
|
316
308
|
canvas.width = trueWidth;
|
|
317
309
|
ctx.drawImage(img, 0, 0, trueWidth, canvas.height);
|
|
318
310
|
}
|
|
319
311
|
this.setViewRect(this.element.getElementsByClassName('view-rect')[0]);
|
|
312
|
+
const colorCanvas = this.element.getElementsByClassName(
|
|
313
|
+
'navigator-color-rect')[0];
|
|
314
|
+
colorCanvas.width = this.canvas.width;
|
|
315
|
+
colorCanvas.height = this.canvas.height;
|
|
320
316
|
};
|
|
321
317
|
img.src = this.options.thumbnail; // 设置图片源地
|
|
322
318
|
return canvas;
|
|
@@ -330,11 +326,9 @@ export class ViewerNavigator extends EventEmitter {
|
|
|
330
326
|
const imgWidth = img.width;
|
|
331
327
|
const imgHeight = img.height;
|
|
332
328
|
let scale = 1;
|
|
333
|
-
if (imgWidth
|
|
329
|
+
if (imgWidth >= imgHeight) {
|
|
334
330
|
scale = imgWidth / this.width;
|
|
335
331
|
const trueHeight = imgHeight / scale;
|
|
336
|
-
const top = (this.height - trueHeight) / 2;
|
|
337
|
-
this.imgTop = top;
|
|
338
332
|
this.canvas.width = this.width;
|
|
339
333
|
this.canvas.height = trueHeight;
|
|
340
334
|
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
@@ -343,14 +337,16 @@ export class ViewerNavigator extends EventEmitter {
|
|
|
343
337
|
if (imgHeight > imgWidth) {
|
|
344
338
|
scale = imgHeight / this.height;
|
|
345
339
|
const trueWidth = imgWidth / scale;
|
|
346
|
-
const left = (this.width - trueWidth) / 2;
|
|
347
|
-
this.imgLeft = left;
|
|
348
340
|
this.canvas.height = this.height;
|
|
349
341
|
this.canvas.width = trueWidth;
|
|
350
342
|
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
351
343
|
ctx.drawImage(img, 0, 0, trueWidth, this.canvas.height);
|
|
352
344
|
}
|
|
353
345
|
this.setViewRect(this.element.getElementsByClassName('view-rect')[0]);
|
|
346
|
+
const colorCanvas = this.element.getElementsByClassName(
|
|
347
|
+
'navigator-color-rect')[0];
|
|
348
|
+
colorCanvas.width = this.canvas.width;
|
|
349
|
+
colorCanvas.height = this.canvas.height;
|
|
354
350
|
};
|
|
355
351
|
img.src = this.options.thumbnail; // 设置图片源地
|
|
356
352
|
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
.openseadragon-navigator {
|
|
2
2
|
position: absolute;
|
|
3
3
|
z-index: 1;
|
|
4
|
-
}
|
|
5
4
|
|
|
6
|
-
.navigator-main {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
.navigator-main {
|
|
6
|
+
position: relative;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
display: block;
|
|
9
|
+
font-size: 0;
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
.v-line {
|
|
12
|
+
height: 100%;
|
|
13
|
+
width: 1px;
|
|
14
|
+
line-height: 1px;
|
|
15
|
+
position: absolute;
|
|
16
|
+
top: 0;
|
|
17
|
+
background-color: rgb(255, 0, 0);
|
|
18
|
+
}
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
.h-line {
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 1px;
|
|
23
|
+
line-height: 1px;
|
|
24
|
+
position: absolute;
|
|
25
|
+
left: 0;
|
|
26
|
+
background-color: rgb(255, 0, 0);
|
|
27
|
+
}
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
.view-rect {
|
|
30
|
+
top: -1px;
|
|
31
|
+
border: 1px solid rgb(255, 0, 0);
|
|
32
|
+
background-color: rgb(255, 255, 255);
|
|
33
|
+
position: absolute;
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
opacity: 0.5;
|
|
36
|
+
box-sizing: border-box;
|
|
37
|
+
}
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
.navigator-color-rect {
|
|
40
|
+
position: absolute;
|
|
41
|
+
top: 0;
|
|
42
|
+
left: 0;
|
|
43
|
+
z-index: 1;
|
|
44
|
+
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
POLYGON, HAS_REGION_TYPES, MARKS,
|
|
3
3
|
NO_NORMAL_REGION_TYPES,
|
|
4
4
|
} from '../../const/mark';
|
|
5
5
|
import {ViewerCommon} from '../common/common';
|
|
6
6
|
import * as Tools from '../../tool';
|
|
7
|
-
import {isPointInPolygon} from '../..';
|
|
8
7
|
import {Combination} from '../../tool/Combination';
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -104,7 +103,7 @@ export class Shape extends ViewerCommon {
|
|
|
104
103
|
if (!NO_NORMAL_REGION_TYPES.includes(item.tool)) {
|
|
105
104
|
this[item.tool].draw(points, this.viewport.getRotation(),
|
|
106
105
|
this.imageToViewerElementRectangle(item.region));
|
|
107
|
-
} else if (item.tool ===
|
|
106
|
+
} else if (item.tool === POLYGON) {
|
|
108
107
|
this[item.tool].draw(points);
|
|
109
108
|
this[item.tool].drawEndPoints(points);
|
|
110
109
|
} else {
|
package/src/const/mark.js
CHANGED
|
@@ -3,7 +3,7 @@ export const ARROW = 'Arrow';
|
|
|
3
3
|
export const BILATERAL = 'Bilateral';
|
|
4
4
|
export const RECTANGLE = 'Rectangle';
|
|
5
5
|
export const ELLIPSE = 'Ellipse';
|
|
6
|
-
export const
|
|
6
|
+
export const POLYGON = 'Polygon';
|
|
7
7
|
export const FONT = 'Font';
|
|
8
8
|
export const STAR = 'Star';
|
|
9
9
|
export const FLAG = 'Flag';
|
|
@@ -12,15 +12,15 @@ export const DOT = 'Dot';
|
|
|
12
12
|
export const POINT_TYPES = [FONT, STAR, FLAG, DOT];
|
|
13
13
|
export const REGION_TYPES = [RECTANGLE, ELLIPSE];
|
|
14
14
|
export const LINE_TYPES = [LINE, ARROW, BILATERAL];
|
|
15
|
-
export const NO_NORMAL_REGION_TYPES = [
|
|
16
|
-
export const HAS_REGION_TYPES = [...REGION_TYPES,
|
|
15
|
+
export const NO_NORMAL_REGION_TYPES = [POLYGON, FONT, STAR, FLAG, DOT];
|
|
16
|
+
export const HAS_REGION_TYPES = [...REGION_TYPES, POLYGON];
|
|
17
17
|
export const MARKS = [
|
|
18
18
|
LINE,
|
|
19
19
|
ARROW,
|
|
20
20
|
BILATERAL,
|
|
21
21
|
RECTANGLE,
|
|
22
22
|
ELLIPSE,
|
|
23
|
-
|
|
23
|
+
POLYGON,
|
|
24
24
|
FONT,
|
|
25
25
|
STAR,
|
|
26
26
|
FLAG,
|
package/src/tool/Arrow.js
CHANGED
package/src/tool/Bilateral.js
CHANGED
package/src/tool/Combination.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Brush} from './Brush';
|
|
2
|
-
import {
|
|
2
|
+
import {POLYGON, ELLIPSE, RECTANGLE} from '../const/mark';
|
|
3
3
|
import {pointsToRegion} from '../util/calculate';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -10,7 +10,7 @@ class Combination extends Brush {
|
|
|
10
10
|
/**
|
|
11
11
|
* 绘制
|
|
12
12
|
* @param {Object} parent - 绘制的点
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {Array} parent.points - 绘制的点x
|
|
14
14
|
* @param {string} parent.tool - 工具
|
|
15
15
|
* @param {Array} children
|
|
16
16
|
* @param {number} rotation
|
|
@@ -27,12 +27,11 @@ class Combination extends Brush {
|
|
|
27
27
|
};
|
|
28
28
|
ctx.translate(centerPoint.x, centerPoint.y);
|
|
29
29
|
ctx.rotate(rotation * Math.PI / 180);
|
|
30
|
-
if (tool ===
|
|
31
|
-
ctx.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
ctx.lineTo(points[0].x - centerPoint.x, points[0].y - centerPoint.y);
|
|
30
|
+
if (tool === POLYGON) {
|
|
31
|
+
ctx.drawPolygon(points.map((p) => ({
|
|
32
|
+
x: p.x - centerPoint.x,
|
|
33
|
+
y: p.y - centerPoint.y,
|
|
34
|
+
})), true, false);
|
|
36
35
|
} else if (tool === RECTANGLE) {
|
|
37
36
|
ctx.moveTo(points[0].x - centerPoint.x, points[0].y - centerPoint.y);
|
|
38
37
|
ctx.lineTo(points[0].x + region.width - centerPoint.x,
|
|
@@ -43,21 +42,7 @@ class Combination extends Brush {
|
|
|
43
42
|
points[0].y + region.height - centerPoint.y);
|
|
44
43
|
ctx.lineTo(points[0].x - centerPoint.x, points[0].y - centerPoint.y);
|
|
45
44
|
} else if (tool === ELLIPSE) {
|
|
46
|
-
|
|
47
|
-
const y = 0;
|
|
48
|
-
const a = region.width / 2;
|
|
49
|
-
const b = region.height / 2;
|
|
50
|
-
// 选择a、b中的较大者作为arc方法的半径参数
|
|
51
|
-
const r = (a > b) ? a : b;
|
|
52
|
-
const ratioX = a / r; // 横轴缩放比率
|
|
53
|
-
const ratioY = b / r; // 纵轴缩放比率
|
|
54
|
-
ctx.save();
|
|
55
|
-
ctx.scale(ratioX, ratioY); // 进行缩放(均匀压缩)
|
|
56
|
-
// 从椭圆的左端点开始顺时针绘制
|
|
57
|
-
ctx.moveTo((x + a) / ratioX, y / ratioY);
|
|
58
|
-
ctx.arc(x / ratioX, y / ratioY, r, 0, 2 * Math.PI, false);
|
|
59
|
-
ctx.closePath();
|
|
60
|
-
ctx.restore();
|
|
45
|
+
ctx.drawOval(0, 0, region.width / 2, region.height / 2, false);
|
|
61
46
|
}
|
|
62
47
|
ctx.closePath();
|
|
63
48
|
ctx.restore();
|
|
@@ -70,13 +55,11 @@ class Combination extends Brush {
|
|
|
70
55
|
};
|
|
71
56
|
ctx.translate(centerPoint.x, centerPoint.y);
|
|
72
57
|
ctx.rotate(rotation * Math.PI / 180);
|
|
73
|
-
if (tool ===
|
|
74
|
-
points.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
ctx.lineTo(points[0].x - centerPoint.x, points[0].y - centerPoint.y);
|
|
58
|
+
if (tool === POLYGON) {
|
|
59
|
+
ctx.drawPolygon(points.map((p) => ({
|
|
60
|
+
x: p.x - centerPoint.x,
|
|
61
|
+
y: p.y - centerPoint.y,
|
|
62
|
+
})), true, true);
|
|
80
63
|
} else if (tool === RECTANGLE) {
|
|
81
64
|
ctx.moveTo(points[0].x - centerPoint.x, points[0].y - centerPoint.y);
|
|
82
65
|
ctx.lineTo(points[0].x - centerPoint.x,
|
|
@@ -87,21 +70,7 @@ class Combination extends Brush {
|
|
|
87
70
|
points[0].y - centerPoint.y);
|
|
88
71
|
ctx.lineTo(points[0].x - centerPoint.x, points[0].y - centerPoint.y);
|
|
89
72
|
} else if (tool === ELLIPSE) {
|
|
90
|
-
|
|
91
|
-
const y = 0;
|
|
92
|
-
const a = region.width / 2;
|
|
93
|
-
const b = region.height / 2;
|
|
94
|
-
// 选择a、b中的较大者作为arc方法的半径参数
|
|
95
|
-
const r = (a > b) ? a : b;
|
|
96
|
-
const ratioX = a / r; // 横轴缩放比率
|
|
97
|
-
const ratioY = b / r; // 纵轴缩放比率
|
|
98
|
-
ctx.save();
|
|
99
|
-
ctx.scale(ratioX, ratioY); // 进行缩放(均匀压缩)
|
|
100
|
-
// 从椭圆的左端点开始逆时针绘制
|
|
101
|
-
ctx.moveTo((x + a) / ratioX, y / ratioY);
|
|
102
|
-
ctx.arc(x / ratioX, y / ratioY, r, 0, 2 * Math.PI, true);
|
|
103
|
-
ctx.closePath();
|
|
104
|
-
ctx.restore();
|
|
73
|
+
ctx.drawOval(0, 0, region.width / 2, region.height / 2, true);
|
|
105
74
|
}
|
|
106
75
|
ctx.closePath();
|
|
107
76
|
ctx.restore();
|
package/src/tool/Dot.js
CHANGED
package/src/tool/Ellipse.js
CHANGED
package/src/tool/Flag.js
CHANGED
package/src/tool/Font.js
CHANGED