kfb-view 2.2.9 → 2.3.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kfb-view",
3
3
  "description": "一个在线kfb的阅片软件",
4
- "version": "2.2.9",
4
+ "version": "2.3.1",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -6,7 +6,7 @@ import {
6
6
  LINE_TYPES, MARKS,
7
7
  NO_NORMAL_REGION_TYPES,
8
8
  REGION_TYPES,
9
- STAR, IMAGE,
9
+ STAR, IMAGE, RECTANGLE,
10
10
  } from '../../const/mark';
11
11
  import {
12
12
  baseNumber, getAngle, getDistance, getPoint,
@@ -66,6 +66,69 @@ export class Area extends ViewerCommon {
66
66
  });
67
67
  }
68
68
 
69
+ /**
70
+ * 画线
71
+ * @param {Object} point
72
+ * @param {number} index
73
+ * @param {Boolean=} active 是否是激活状态
74
+ */
75
+ drawLine(point, index, active) {
76
+ const ctx = this.canvas.getContext('2d');
77
+ ctx.beginPath();
78
+ const strokeStyle = !active ?
79
+ this.options.thumb.color :
80
+ this.options.thumb.activeColor;
81
+ const lineWidth = (!active ?
82
+ this.options.thumb.radius :
83
+ this.options.thumb.activeRadius) * 2;
84
+ ctx.strokeStyle = strokeStyle || '#01d0b0';
85
+ ctx.lineWidth = 2;
86
+ if (index === 0) {
87
+ ctx.moveTo(point.x - 5, point.y - 5);
88
+ ctx.lineTo(point.x - 5 + lineWidth, point.y - 5);
89
+ ctx.moveTo(point.x - 5, point.y - 5);
90
+ ctx.lineTo(point.x - 5, point.y - 5 + lineWidth);
91
+ } else if (index === 1) {
92
+ ctx.moveTo(point.x, point.y - 5);
93
+ ctx.lineTo(point.x - lineWidth / 2, point.y - 5);
94
+ ctx.moveTo(point.x, point.y - 5);
95
+ ctx.lineTo(point.x + lineWidth / 2, point.y - 5);
96
+ } else if (index === 2) {
97
+ ctx.moveTo(point.x + 5, point.y - 5);
98
+ ctx.lineTo(point.x + 5 - lineWidth, point.y - 5);
99
+ ctx.moveTo(point.x + 5, point.y - 5);
100
+ ctx.lineTo(point.x + 5, point.y - 5 + lineWidth);
101
+ } else if (index === 3) {
102
+ ctx.moveTo(point.x - 5, point.y);
103
+ ctx.lineTo(point.x - 5, point.y - lineWidth / 2);
104
+ ctx.moveTo(point.x - 5, point.y);
105
+ ctx.lineTo(point.x - 5, point.y + lineWidth / 2);
106
+ } else if (index === 4 && active) {
107
+ this.drawPoint(point, active);
108
+ } else if (index === 5) {
109
+ ctx.moveTo(point.x + 5, point.y);
110
+ ctx.lineTo(point.x + 5, point.y - lineWidth / 2);
111
+ ctx.moveTo(point.x + 5, point.y);
112
+ ctx.lineTo(point.x + 5, point.y + lineWidth / 2);
113
+ } else if (index === 6) {
114
+ ctx.moveTo(point.x - 5, point.y + 5);
115
+ ctx.lineTo(point.x - 5, point.y + 5 - lineWidth);
116
+ ctx.moveTo(point.x - 5, point.y + 5);
117
+ ctx.lineTo(point.x - 5 + lineWidth, point.y + 5);
118
+ } else if (index === 7) {
119
+ ctx.moveTo(point.x, point.y + 5);
120
+ ctx.lineTo(point.x - lineWidth / 2, point.y + 5);
121
+ ctx.moveTo(point.x, point.y + 5);
122
+ ctx.lineTo(point.x + lineWidth / 2, point.y + 5);
123
+ } else if (index === 8) {
124
+ ctx.moveTo(point.x + 5, point.y + 5);
125
+ ctx.lineTo(point.x + 5, point.y + 5 - lineWidth);
126
+ ctx.moveTo(point.x + 5, point.y + 5);
127
+ ctx.lineTo(point.x + 5 - lineWidth, point.y + 5);
128
+ }
129
+ ctx.stroke();
130
+ }
131
+
69
132
  /**
70
133
  * 设置List
71
134
  * @param {Object} list
@@ -256,6 +319,26 @@ export class Area extends ViewerCommon {
256
319
  });
257
320
  }
258
321
 
322
+ onCanvasMove({x, y}) {
323
+ const selectLabel = this.labelList.find(
324
+ ({tool, select}) => tool === RECTANGLE && select);
325
+ if (selectLabel) {
326
+ const region = selectLabel.region;
327
+ const startPoint = this.imageToViewerElementCoordinates(region.x,
328
+ region.y);
329
+ const endPoint = this.imageToViewerElementCoordinates(
330
+ region.x + region.width, region.y + region.height);
331
+ const pointList = getRectPoint(startPoint, endPoint);
332
+ const moveIndex = pointList.findIndex(
333
+ (point) => pointInOtherPoint(point, {x, y}));
334
+ if (moveIndex === 4) {
335
+ this.drawPoint(pointList[4], !!this.movePoint);
336
+ } else {
337
+ this.change();
338
+ }
339
+ }
340
+ }
341
+
259
342
  /**
260
343
  * 监听鼠标释放事件
261
344
  * @param {Object} e
@@ -489,6 +572,18 @@ export class Area extends ViewerCommon {
489
572
  y: (points[0].y + points[1].y) / 2,
490
573
  }, position === 4);
491
574
  this.drawPoint(points[1], position === 7);
575
+ } else if (type === RECTANGLE) {
576
+ const sp = {
577
+ x: points[0].x < points[1].x ? points[0].x : points[1].x,
578
+ y: points[0].y < points[1].y ? points[0].y : points[1].y,
579
+ };
580
+ const ep = {
581
+ x: points[0].x > points[1].x ? points[0].x : points[1].x,
582
+ y: points[0].y > points[1].y ? points[0].y : points[1].y,
583
+ };
584
+ getRectPoint(sp, ep).forEach((point, i) => {
585
+ this.drawLine(point, i, position === i);
586
+ });
492
587
  } else if (REGION_TYPES.includes(type)) {
493
588
  getRectPoint(points[0], points[1]).forEach((point, i) => {
494
589
  this.drawPoint(point, position === i);
@@ -190,14 +190,30 @@ export class ViewerCommon extends EventEmitter {
190
190
  if (label.points.length <= 1) return content;
191
191
  const scale = this.getImageZoom(true) / label.scale;
192
192
  const region = pointsToRegion(label.points);
193
- const startPoint = {x: region.x, y: region.y};
194
- const endPoint = {x: region.x + region.width, y: region.y + region.height};
193
+ const _startPoint = {x: region.x, y: region.y};
194
+ const _endPoint = {x: region.x + region.width, y: region.y + region.height};
195
+ const startPoint = {
196
+ x: _startPoint.x < _endPoint.x ? _startPoint.x : _endPoint.x,
197
+ y: _startPoint.y < _endPoint.y ? _startPoint.y : _endPoint.y,
198
+ };
199
+ const endPoint = {
200
+ x: _startPoint.x > _endPoint.x ? _startPoint.x : _endPoint.x,
201
+ y: _startPoint.y > _endPoint.y ? _startPoint.y : _endPoint.y,
202
+ };
195
203
  /* const p1 = label.points[0];
196
204
  const p2 = label.points[label.points.length - 1];*/
197
205
  switch (label.tool) {
198
206
  case ARROW:
199
207
  case BILATERAL:
200
208
  case LINE: {
209
+ const startPoint = {
210
+ x: _startPoint.x < _endPoint.x ? _startPoint.x : _endPoint.x,
211
+ y: _startPoint.x < _endPoint.x ? _startPoint.y : _endPoint.y,
212
+ };
213
+ const endPoint = {
214
+ x: _startPoint.x > _endPoint.x ? _startPoint.x : _endPoint.x,
215
+ y: _startPoint.x > _endPoint.x ? _startPoint.y : _endPoint.y,
216
+ };
201
217
  const w = Math.abs(endPoint.x - startPoint.x);
202
218
  const h = Math.abs(endPoint.y - startPoint.y);
203
219
  const center = {
@@ -4,6 +4,7 @@ export class LabelModel {
4
4
  constructor(data = {}) {
5
5
  if (!data) data = {};
6
6
  this.id = data.id; // id标识
7
+ this.parent_id = data.parent_id; // 父id标识
7
8
  this.lineWidth = !data.lineWidth ?
8
9
  (data.tool === STAR ? 15 :
9
10
  data.tool === FLAG ? 30 : data.tool === DOT ? 10 : 2) :
package/src/view.js CHANGED
@@ -411,6 +411,9 @@ function initEvent(kv) {
411
411
  new openSeadragon.MouseTracker({
412
412
  element: kv.viewer.canvas,
413
413
  moveHandler: function(event) {
414
+ if (kv.area?.onCanvasMove) {
415
+ kv.area.onCanvasMove(event.position);
416
+ }
414
417
  if (isRightDown && kv.board?.isInDraw) {
415
418
  console.log('nonprimary drag');
416
419
  let delta = event.position.minus(dragPosition);