kfb-view 2.3.8 → 2.4.0

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.8",
4
+ "version": "2.4.0",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -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,35 +89,28 @@ 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;
107
107
  }
108
- this.deepDrawLabel(sameFixWidthLabel, sameNormalLabel, 1, bounds);
109
- regionLabelList.forEach((item) => {
110
- this.combination.setContent(this.canvas, item);
111
- this.combination.draw({
112
- points: item.viewerElementPoints,
113
- tool: item.tool,
114
- }, item.child.map(({viewerElementPoints, tool}) => ({
115
- points: viewerElementPoints,
116
- tool,
117
- })), this.viewport.getRotation());
118
- });
119
- imageLabel.forEach((item) => {
120
- this.drawLabel(item);
121
- });
108
+ this.deepDrawLabel(sameFixWidthLabel, sameNormalLabel, regionLabelList,
109
+ imageLabel, 1, bounds);
122
110
  }
123
111
 
124
- deepDrawLabel(sameFixWidthLabel, sameNormalLabel, count, bounds) {
112
+ deepDrawLabel(sameFixWidthLabel, sameNormalLabel, regionLabelList,
113
+ imageLabel, count, bounds) {
125
114
  let currentDrawCount = 0; // 当前已绘制数量
126
115
  const ctx = this.canvas.getContext('2d');
127
116
  const remainFixLabel = {};
@@ -129,7 +118,7 @@ export class Shape extends ViewerCommon {
129
118
  const labels = sameFixWidthLabel[key];
130
119
  ctx.beginPath();
131
120
  labels.forEach((item) => {
132
- if (currentDrawCount >= 5000) { // 一次最多绘制5000个标注,多余标注延迟绘制
121
+ if (currentDrawCount >= 2000) { // 一次最多绘制2000个标注,多余标注延迟绘制
133
122
  if (remainFixLabel[key]) {
134
123
  remainFixLabel[key].push(item);
135
124
  } else {
@@ -153,7 +142,7 @@ export class Shape extends ViewerCommon {
153
142
  const labels = sameNormalLabel[key];
154
143
  ctx.beginPath();
155
144
  labels.forEach((item) => {
156
- if (currentDrawCount >= 5000) { // 一次最多绘制5000个标注,多余标注延迟绘制
145
+ if (currentDrawCount >= 2000) { // 一次最多绘制2000个标注,多余标注延迟绘制
157
146
  if (remainNormalLabel[key]) {
158
147
  remainNormalLabel[key].push(item);
159
148
  } else {
@@ -173,15 +162,30 @@ export class Shape extends ViewerCommon {
173
162
  Object.keys(remainNormalLabel).length === 0) {
174
163
  console.log(`end deep draw label, draw count: ${count}`);
175
164
  this.delaytimer = undefined;
165
+ imageLabel.forEach((item) => {
166
+ this.drawLabel(item);
167
+ });
168
+ regionLabelList.forEach((item) => {
169
+ this.combination.setContent(this.canvas, item);
170
+ this.combination.draw({
171
+ points: item.viewerElementPoints,
172
+ tool: item.tool,
173
+ }, item.child.map(({viewerElementPoints, tool}) => ({
174
+ points: viewerElementPoints,
175
+ tool,
176
+ })), this.viewport.getRotation());
177
+ });
176
178
  } else {
177
179
  this.delaytimer = setTimeout(() => {
178
- this.deepDrawLabel(remainFixLabel, remainNormalLabel, count + 1,
180
+ this.deepDrawLabel(remainFixLabel, remainNormalLabel, regionLabelList,
181
+ imageLabel, count + 1,
179
182
  bounds);
180
183
  }, 100);
181
184
  }
182
185
  }
183
186
 
184
187
  drawLabel(item) {
188
+ item.viewerElementPoints = this.imageToViewerElementPoints(item.points);
185
189
  const points = item.viewerElementPoints;
186
190
  this[item.tool].setContent(this.canvas, item);
187
191
  if (REGION_TYPES.includes(item.tool)) {
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) => {