kfb-view 3.0.9 → 3.1.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": "3.0.9",
4
+ "version": "3.1.1",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -698,9 +698,11 @@ export class Area extends ViewerCommon {
698
698
  this[label.tool].drawMeasureInfo.call(this, label,
699
699
  this.getMeasureContent(label));
700
700
  }
701
- if (this.options.labelDrawing) {
701
+ if (this.options.labelDrawing || this.options.label?.drawing) {
702
702
  if (!this.isInCanvas(label.region, bounds)) return false;
703
- this.options.labelDrawing(this.canvas, label,
703
+ const drawingFunc = this.options.label?.drawing ||
704
+ this.options.labelDrawing;
705
+ drawingFunc(this.canvas, label,
704
706
  this.imageToViewerElementRectangle(label.region));
705
707
  }
706
708
  });
@@ -715,11 +717,12 @@ export class Area extends ViewerCommon {
715
717
  setPointsMove(label) {
716
718
  const movePoints = this.imageToViewerElementPoints(label.points);
717
719
  let lastPoint = movePoints[0];
720
+ const dist = this.options.label?.polygonWidth || 30;
718
721
  movePoints.forEach((point, index) => {
719
722
  point.canMove = false;
720
723
  label.points[index].canMove = false;
721
- if (index === 0 || (!pointInOtherPoint(lastPoint, point, 30) &&
722
- !pointInOtherPoint(movePoints[0], point, 30)) ||
724
+ if (index === 0 || (!pointInOtherPoint(lastPoint, point, dist) &&
725
+ !pointInOtherPoint(movePoints[0], point, dist)) ||
723
726
  (index === movePoints.length - 1)) {
724
727
  lastPoint = point;
725
728
  point.canMove = true;
@@ -3,7 +3,7 @@ import * as Tools from '../../tool';
3
3
  import {
4
4
  POLYGON, DOT, FLAG, MARKS,
5
5
  NO_NORMAL_REGION_TYPES,
6
- POINT_TYPES, STAR,
6
+ POINT_TYPES, STAR, ELLIPSE,
7
7
  } from '../../const/mark';
8
8
  import {
9
9
  EVENT_START_PAINTING,
@@ -142,6 +142,8 @@ export class Board extends ViewerCommon {
142
142
  const tool = this.tool;
143
143
  if (tool === POLYGON) {
144
144
  this.points.push(point);
145
+ } else if (ELLIPSE === tool) {
146
+ this.points = [point, point];
145
147
  } else {
146
148
  this.points = [point];
147
149
  }
@@ -172,7 +174,15 @@ export class Board extends ViewerCommon {
172
174
  }
173
175
  e.preventDefaultAction = true;
174
176
  const tool = this.tool;
175
- if (!NO_NORMAL_REGION_TYPES.includes(tool)) {
177
+ if (ELLIPSE === tool) {
178
+ const _x = point.x - this.points[1].x;
179
+ const _y = point.y - this.points[1].y;
180
+ const _point = {
181
+ x: this.points[1].x - _x,
182
+ y: this.points[1].y - _y,
183
+ };
184
+ this.points = [_point, this.points[1], point];
185
+ } else if (!NO_NORMAL_REGION_TYPES.includes(tool)) {
176
186
  this.points = [this.points[0] || point, point];
177
187
  } else if (tool === POLYGON) {
178
188
  this.points.push(point);
@@ -207,7 +217,23 @@ export class Board extends ViewerCommon {
207
217
  return;
208
218
  }
209
219
  const tool = this.tool;
210
- if (!NO_NORMAL_REGION_TYPES.includes(tool)) {
220
+ if (ELLIPSE === tool) {
221
+ const _x = point.x - this.points[1].x;
222
+ const _y = point.y - this.points[1].y;
223
+ const _point = {
224
+ x: this.points[1].x - _x,
225
+ y: this.points[1].y - _y,
226
+ };
227
+ this.points = [_point, point];
228
+ const firstPoint = this.imageToViewerElementCoordinates(this.points[0].x,
229
+ this.points[0].y);
230
+ const dist = getDistance(firstPoint, {x, y});
231
+ if (Math.abs(dist) < 10) {
232
+ this.points = [];
233
+ this.clearCanvas();
234
+ return;
235
+ }
236
+ } else if (!NO_NORMAL_REGION_TYPES.includes(tool)) {
211
237
  const firstPoint = this.imageToViewerElementCoordinates(this.points[0].x,
212
238
  this.points[0].y);
213
239
  const dist = getDistance(firstPoint, {x, y});
@@ -342,11 +368,12 @@ export class Board extends ViewerCommon {
342
368
  const points = this.imageToViewerElementPoints(this.points);
343
369
  let firstPoint = points[0];
344
370
  // 过滤曲线的点,点之间的距离小于10默认为一个点,取第一个
371
+ const dist = this.options.label?.polygonWidth || 30;
345
372
  this.points = this.points.filter((p, index) => {
346
373
  const _p = points[index];
347
374
  if (index === 0) return true;
348
375
  if (index === this.points.length - 1) return true;
349
- if (pointInOtherPoint(firstPoint, _p, 30)) {
376
+ if (pointInOtherPoint(firstPoint, _p, dist)) {
350
377
  const nextPoint = points[index + 1];
351
378
  if (nextPoint) {
352
379
  const deg = Math.abs(getAngle(_p, firstPoint, nextPoint));
package/src/view.js CHANGED
@@ -76,7 +76,10 @@ export default class KfbView extends EventEmitter {
76
76
  * @param {boolean=} config.measure.fontSize 标注注释文字大小
77
77
  * @param {boolean=} config.measure.defaultShow 标注是否默认永久显示,false表示只在选中时显示
78
78
  * @param {boolean=} config.measure.scale 标注默认永久显示时的倍率,
79
- * @param {boolean=} config.labelDrawing 标注绘制回调,
79
+ * @param {Object} config.label 标注配置
80
+ * @param {number=} config.label.polygonWidth 曲线点识别宽度,
81
+ * @param {function=} config.label.drawing 标注绘制回调,
82
+ * @param {function=} config.labelDrawing 标注绘制回调 @deprecated Use label.drawing instead
80
83
  * @param {array} config.labelList 标注列表
81
84
  */
82
85
  constructor(config) {
@@ -282,6 +285,7 @@ function initComponentsOptions(kv, type) {
282
285
  options: {
283
286
  scale: config.scale,
284
287
  labelDrawing: config.labelDrawing,
288
+ label: config.label || {},
285
289
  measure: {
286
290
  backgroundColor: 'rgba(0,0,0,.5)',
287
291
  color: '#FFF',