kfb-view 2.3.9 → 2.4.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.3.9",
4
+ "version": "2.4.1",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -60,8 +60,8 @@ export class ViewerCommon extends EventEmitter {
60
60
  {x: rect.x + rect.width, y: rect.y + rect.height})[4];
61
61
  }
62
62
 
63
- moveToLabel(point) {
64
- this.viewport.panTo(new Point(point.x, point.y), false);
63
+ moveToLabel(point, flag = false) {
64
+ this.viewport.panTo(new Point(point.x, point.y), flag);
65
65
  }
66
66
 
67
67
  /**
@@ -1,4 +1,5 @@
1
1
  import {
2
+ HAS_NO_FILL_TYPES,
2
3
  HAS_REGION_TYPES, IMAGE,
3
4
  MARKS, POINT_TYPES, POLYGON, REGION_TYPES,
4
5
  } from '../../const/mark';
@@ -51,8 +52,12 @@ export class Shape extends ViewerCommon {
51
52
  this.clearCanvas();
52
53
  const bounds = this.viewport.viewportToImageRectangle(
53
54
  this.viewport.getBounds());
54
- // 区域标注列表
55
+ // strokeStyle, lineWidth, fillStyle 相同认为是一个路径下的图形,一起绘制,优化性能
56
+ const sameFixWidthLabel = {}; // star, flag, star, font lineWidth固定为2
57
+ const sameNormalLabel = {};
55
58
  const regionLabelList = [];
59
+ const imageLabel = [];
60
+ // 区域标注列表
56
61
  const labelList = this.labelList.filter((item) => {
57
62
  if (item.show === false) return false;
58
63
  if (!this[item.tool]) return false;
@@ -64,18 +69,9 @@ export class Shape extends ViewerCommon {
64
69
  child: [],
65
70
  self: item,
66
71
  });
67
- }
68
- return true;
69
- });
70
- // strokeStyle, lineWidth, fillStyle 相同认为是一个路径下的图形,一起绘制,优化性能
71
- const sameFixWidthLabel = {}; // star, flag, star, font lineWidth固定为2
72
- const sameNormalLabel = {};
73
- const imageLabel = [];
74
- labelList.forEach((item) => {
75
- item.viewerElementPoints = this.imageToViewerElementPoints(item.points);
76
- if (item.tool === IMAGE) {
72
+ } else if (item.tool === IMAGE) {
77
73
  imageLabel.push(item);
78
- return;
74
+ return false;
79
75
  }
80
76
  const key = `${item.strokeStyle ?? ''}_${item.lineWidth ??
81
77
  ''}_${item.fillStyle ?? ''}`;
@@ -93,14 +89,18 @@ export class Shape extends ViewerCommon {
93
89
  sameNormalLabel[regionKey] = [item];
94
90
  }
95
91
  }
96
- const parent = regionLabelList.find(
97
- (parent) => HAS_REGION_TYPES.includes(parent.tool) && parent.self !==
98
- item && item.points.every(
99
- (point) => this.isContainerInRegion(point, parent)));
100
- if (parent) {
101
- parent.child.push(item);
102
- }
92
+ return !HAS_NO_FILL_TYPES.includes(item.tool);
103
93
  });
94
+ if (regionLabelList.length > 0) {
95
+ labelList.forEach((item) => {
96
+ const parent = regionLabelList.find(
97
+ (label) => label.self !== item && item.points.every(
98
+ (point) => this.isContainerInRegion(point, label)));
99
+ if (parent) {
100
+ parent.child.push(item);
101
+ }
102
+ });
103
+ }
104
104
  if (this.delaytimer) {
105
105
  clearTimeout(this.delaytimer);
106
106
  this.delaytimer = undefined;
@@ -118,7 +118,7 @@ export class Shape extends ViewerCommon {
118
118
  const labels = sameFixWidthLabel[key];
119
119
  ctx.beginPath();
120
120
  labels.forEach((item) => {
121
- if (currentDrawCount >= 5000) { // 一次最多绘制5000个标注,多余标注延迟绘制
121
+ if (currentDrawCount >= 2000) { // 一次最多绘制2000个标注,多余标注延迟绘制
122
122
  if (remainFixLabel[key]) {
123
123
  remainFixLabel[key].push(item);
124
124
  } else {
@@ -142,7 +142,7 @@ export class Shape extends ViewerCommon {
142
142
  const labels = sameNormalLabel[key];
143
143
  ctx.beginPath();
144
144
  labels.forEach((item) => {
145
- if (currentDrawCount >= 5000) { // 一次最多绘制5000个标注,多余标注延迟绘制
145
+ if (currentDrawCount >= 2000) { // 一次最多绘制2000个标注,多余标注延迟绘制
146
146
  if (remainNormalLabel[key]) {
147
147
  remainNormalLabel[key].push(item);
148
148
  } else {
@@ -162,6 +162,9 @@ export class Shape extends ViewerCommon {
162
162
  Object.keys(remainNormalLabel).length === 0) {
163
163
  console.log(`end deep draw label, draw count: ${count}`);
164
164
  this.delaytimer = undefined;
165
+ imageLabel.forEach((item) => {
166
+ this.drawLabel(item);
167
+ });
165
168
  regionLabelList.forEach((item) => {
166
169
  this.combination.setContent(this.canvas, item);
167
170
  this.combination.draw({
@@ -172,9 +175,6 @@ export class Shape extends ViewerCommon {
172
175
  tool,
173
176
  })), this.viewport.getRotation());
174
177
  });
175
- imageLabel.forEach((item) => {
176
- this.drawLabel(item);
177
- });
178
178
  } else {
179
179
  this.delaytimer = setTimeout(() => {
180
180
  this.deepDrawLabel(remainFixLabel, remainNormalLabel, regionLabelList,
@@ -185,6 +185,7 @@ export class Shape extends ViewerCommon {
185
185
  }
186
186
 
187
187
  drawLabel(item) {
188
+ item.viewerElementPoints = this.imageToViewerElementPoints(item.points);
188
189
  const points = item.viewerElementPoints;
189
190
  this[item.tool].setContent(this.canvas, item);
190
191
  if (REGION_TYPES.includes(item.tool)) {
@@ -110,10 +110,12 @@ export class Tailoring extends ViewerCommon {
110
110
  ctx.beginPath();
111
111
  ctx.fillStyle = this.color;
112
112
  ctx.font = '18px Arial';
113
+ const width = (rightTop.x - leftTop.x).toFixed(2) / 1;
114
+ const height = (rightBottom.y - rightTop.y).toFixed(2) / 1;
113
115
  ctx.fillText(
114
116
  this.contents?.[2] ?
115
- this.contents[2](rightTop.x - leftTop.x, rightBottom.y - rightTop.y) :
116
- (`区域大小为:${rightTop.x - leftTop.x}*${rightBottom.y - rightTop.y}`),
117
+ this.contents[2](width, height) :
118
+ (`区域大小为:${width}*${height}`),
117
119
  leftTop.x, leftTop.y - 50);
118
120
  ctx.fillText(this.contents?.[0] ?? `双击区域内表示完成截图`, leftTop.x,
119
121
  leftTop.y - 30);
package/src/const/mark.js CHANGED
@@ -15,6 +15,7 @@ export const REGION_TYPES = [RECTANGLE, ELLIPSE];
15
15
  export const LINE_TYPES = [LINE, ARROW, BILATERAL];
16
16
  export const NO_NORMAL_REGION_TYPES = [POLYGON, FONT, STAR, FLAG, DOT];
17
17
  export const HAS_REGION_TYPES = [...REGION_TYPES, POLYGON];
18
+ export const HAS_NO_FILL_TYPES = [...LINE_TYPES, FONT, FLAG, IMAGE];
18
19
  export const MARKS = [
19
20
  LINE,
20
21
  ARROW,
package/src/view.js CHANGED
@@ -331,7 +331,8 @@ function initEvent(kv) {
331
331
  kv.tailoring.onCanvasDrag(e.position);
332
332
  } else if (kv.area?.movePoint) {
333
333
  kv.area.onCanvasDrag(e.position, e);
334
- kv.change();
334
+ kv.area.change();
335
+ kv?.shape?.change?.();
335
336
  }
336
337
  });
337
338
  kv.viewer.addHandler('canvas-release', (e) => {