kfb-view 3.2.0 → 3.2.2

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.
@@ -1,9 +1,9 @@
1
- //! Built on 2023-05-25
1
+ //! Built on 2024-04-01
2
2
 
3
- //! Git commit: v4.1.0-0-8849681
3
+ //! Git commit: v4.1.1-1-f90d9814
4
4
 
5
5
  //! License: http://openseadragon.github.io/license/
6
6
 
7
7
  //! http://openseadragon.github.io
8
8
 
9
- //! openseadragon 4.1.0
9
+ //! openseadragon 4.1.1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kfb-view",
3
3
  "description": "一个在线kfb的阅片软件",
4
- "version": "3.2.0",
4
+ "version": "3.2.2",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -19,6 +19,7 @@ import {
19
19
  LINE,
20
20
  RECTANGLE,
21
21
  } from '../../const/mark';
22
+ import {getUnitNumber} from '../../util';
22
23
 
23
24
  /**
24
25
  * 通用方法类
@@ -254,8 +255,7 @@ export class ViewerCommon {
254
255
  top: p.y + distY * scale,
255
256
  angle: deg,
256
257
  texts: [
257
- `长:${(Math.sqrt(w * w + h * h) * this.options.imageCapRes).toFixed(
258
- 2)}${this.options.unit}`],
258
+ `长:${this.getUnitNumber((Math.sqrt(w * w + h * h) * this.options.imageCapRes).toFixed(2))}`],
259
259
  };
260
260
  }
261
261
  break;
@@ -263,9 +263,9 @@ export class ViewerCommon {
263
263
  const w = Math.abs(endPoint.x - startPoint.x) / 2;
264
264
  const h = Math.abs(endPoint.y - startPoint.y) / 2;
265
265
  const pt = perimeter(ELLIPSE, startPoint, endPoint,
266
- this.options.imageCapRes);
266
+ this.options.imageCapRes).toFixed(2);
267
267
  const ac = acreage(ELLIPSE, startPoint, endPoint,
268
- this.options.imageCapRes);
268
+ this.options.imageCapRes).toFixed(2);
269
269
  const rightTop = getRectPoint(startPoint, endPoint)[2];
270
270
  const p = this.imageToViewerElementCoordinates(rightTop.x,
271
271
  rightTop.y);
@@ -274,12 +274,10 @@ export class ViewerCommon {
274
274
  top: p.y,
275
275
  angle: 0,
276
276
  texts: [
277
- `长轴:${(w * this.options.imageCapRes).toFixed(
278
- 2)}${this.options.unit}`,
279
- `短轴:${(h * this.options.imageCapRes).toFixed(
280
- 2)}${this.options.unit}`,
281
- `周长:${(pt).toFixed(2)}${this.options.unit}`,
282
- `面积:${(ac).toFixed(2)}${this.options.unit}²`],
277
+ `长轴:${this.getUnitNumber((w * this.options.imageCapRes).toFixed(2))}`,
278
+ `短轴:${this.getUnitNumber((h * this.options.imageCapRes).toFixed(2))}`,
279
+ `周长:${this.getUnitNumber(pt)}`,
280
+ `面积:${this.getUnitNumber(ac)}²`],
283
281
  };
284
282
  }
285
283
  break;
@@ -287,9 +285,9 @@ export class ViewerCommon {
287
285
  const w = Math.abs(endPoint.x - startPoint.x);
288
286
  const h = Math.abs(endPoint.y - startPoint.y);
289
287
  const pt = perimeter(RECTANGLE, startPoint, endPoint,
290
- this.options.imageCapRes);
288
+ this.options.imageCapRes).toFixed(2);
291
289
  const ac = acreage(RECTANGLE, startPoint, endPoint,
292
- this.options.imageCapRes);
290
+ this.options.imageCapRes).toFixed(2);
293
291
  const rightTop = getRectPoint(startPoint, endPoint)[2];
294
292
  const p = this.imageToViewerElementCoordinates(rightTop.x,
295
293
  rightTop.y);
@@ -298,12 +296,10 @@ export class ViewerCommon {
298
296
  top: p.y,
299
297
  angle: 0,
300
298
  texts: [
301
- `长:${(w * this.options.imageCapRes).toFixed(
302
- 2)}${this.options.unit}`,
303
- `宽:${(h * this.options.imageCapRes).toFixed(
304
- 2)}${this.options.unit}`,
305
- `周长:${(pt).toFixed(2)}${this.options.unit}`,
306
- `面积:${(ac).toFixed(2)}${this.options.unit}²`],
299
+ `长:${this.getUnitNumber((w * this.options.imageCapRes).toFixed(2))}`,
300
+ `宽:${this.getUnitNumber((h * this.options.imageCapRes).toFixed(2))}`,
301
+ `周长:${this.getUnitNumber(pt)}`,
302
+ `面积:${this.getUnitNumber(ac)}²`],
307
303
  };
308
304
  }
309
305
  break;
@@ -322,10 +318,9 @@ export class ViewerCommon {
322
318
  top: p.y,
323
319
  angle: 0,
324
320
  texts: [
325
- `周长:${(pt * this.options.imageCapRes).toFixed(
326
- 2)}${this.options.unit}`,
327
- `面积:${calculatePolygonArea(points,
328
- this.options.imageCapRes).toFixed(2)}${this.options.unit}²`],
321
+ `周长:${this.getUnitNumber((pt * this.options.imageCapRes).toFixed(2))}`,
322
+ `面积:${this.getUnitNumber(calculatePolygonArea(points,
323
+ this.options.imageCapRes).toFixed(2))}²`],
329
324
  };
330
325
  }
331
326
  break;
@@ -348,6 +343,10 @@ export class ViewerCommon {
348
343
  };
349
344
  }
350
345
 
346
+ getUnitNumber(number) {
347
+ return getUnitNumber(number, this.options.units, this.options.binary);
348
+ }
349
+
351
350
  /**
352
351
  * 判断region是否在canvas中
353
352
  * @param {Object} region
@@ -1,5 +1,6 @@
1
1
  import {ViewerCommon} from '../common/common';
2
2
  import {EVENT_GRADUATION_CHANGE} from '../../const/event';
3
+ import {getUnitNumber} from '../../util';
3
4
 
4
5
  /**
5
6
  * 刻度线
@@ -15,26 +16,24 @@ export class Graduation extends ViewerCommon {
15
16
  */
16
17
  constructor({viewer, canvas, cache, options}) {
17
18
  super(viewer, canvas, cache, options);
18
- this.scales = options.scales ||
19
- [0.1, 0.4, 0.6, 1, 2, 4, 8, 10, 20, 40, 60, 100, 140, 200];
20
19
  this.microns = options.microns ||
21
- [5000, 2000, 1250, 1000, 500, 250, 200, 100, 50, 25, 20, 10, 5, 2];
20
+ [5000, 2000, 1500, 1250, 1000, 800, 500, 400, 250, 200, 150, 125, 100, 80, 60, 40, 20, 10, 8, 5];
22
21
  }
23
22
 
24
23
  /**
25
24
  * 倍率大小改变
26
25
  */
27
26
  change() {
28
- const scales = [...this.scales];
29
- const zoom = this.viewport.viewportToImageZoom(
30
- this.viewport.getZoom(true)) * 40;
31
- const index = scales.findIndex((scale) => scale >= zoom);
27
+ const microns = this.microns;
28
+ const rect = this.viewerElementToImageRectangle({x: 0, y: 0, width: 50, height: 50});
29
+ const max = rect.height * this.options.imageCapRes;
30
+ const index = this.microns.findIndex((i) => i <= max);
32
31
  if (!~index) {
33
- this.setScaleLine(this.microns[this.microns.length - 1],
34
- this.microns[this.microns.length - 1] / this.options.imageCapRes);
32
+ this.setScaleLine(microns[microns.length - 1],
33
+ microns[microns.length - 1] / this.options.imageCapRes);
35
34
  } else {
36
- this.setScaleLine(this.microns[index],
37
- this.microns[index] / this.options.imageCapRes);
35
+ this.setScaleLine(microns[index],
36
+ microns[index] / this.options.imageCapRes);
38
37
  }
39
38
  }
40
39
 
@@ -79,16 +78,39 @@ export class Graduation extends ViewerCommon {
79
78
  ctx.beginPath();
80
79
  ctx.strokeStyle = '#000000';
81
80
  ctx.lineWidth = 3;
82
- ctx.moveTo(x, y - 8);
83
- ctx.lineTo(x, y);
84
- ctx.lineTo(x + lineWidth, y);
85
- ctx.lineTo(x + lineWidth, y - 8);
86
- ctx.stroke();
87
- ctx.beginPath();
88
81
  ctx.fillStyle = '#000000';
89
- ctx.font = 'bold 16px Arial';
90
- const t = txt.toFixed(0) + this.options.unit;
82
+ ctx.font = 'bold 14px Arial';
83
+ const tick = this.options.tick || {
84
+ height: 8,
85
+ number: 5,
86
+ };
87
+ const unitIndex = this.getUnitIndex(txt * tick.number, this.options.units, this.options.binary);
88
+ const t = getUnitNumber(txt * tick.number, this.options.units, this.options.binary, unitIndex);
91
89
  const fontWidth = ctx.measureText(t).width;
92
- ctx.fillText(t, x + lineWidth / 2 - fontWidth / 2, top ? y + 12 : y - 12);
90
+ ctx.fillText(t, x + lineWidth * tick.number - fontWidth / 2, y + 20);
91
+ new Array(tick.number).fill(1).forEach((i, index) => {
92
+ ctx.moveTo(x + lineWidth * index, y - tick.height);
93
+ ctx.lineTo(x + lineWidth * index, y);
94
+ ctx.lineTo(x + lineWidth * (index + 1), y);
95
+ ctx.lineTo(x + lineWidth * (index + 1), y - tick.height);
96
+ const t = getUnitNumber(txt * index, this.options.units, this.options.binary, unitIndex).
97
+ replace(this.options.units[unitIndex], '');
98
+ const fontWidth = ctx.measureText(t).width;
99
+ ctx.fillText(t, x + lineWidth * index - fontWidth / 2, y + 20);
100
+ });
101
+ ctx.stroke();
102
+ }
103
+
104
+ getUnitIndex(number, units, binary) {
105
+ let i = number;
106
+ let index = 0;
107
+ while (i >= binary) {
108
+ i = i / binary;
109
+ index++;
110
+ }
111
+ if (!units[index]) {
112
+ index = units.length - 1;
113
+ }
114
+ return index;
93
115
  }
94
116
  }