kfb-view 3.2.0 → 3.2.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.2.0",
4
+ "version": "3.2.1",
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
 
@@ -47,6 +46,7 @@ export class Graduation extends ViewerCommon {
47
46
  const startPoint = this.imageToViewerElementCoordinates(0, 0);
48
47
  const endPoint = this.imageToViewerElementCoordinates(px, 0);
49
48
  const width = Math.abs(endPoint.x - startPoint.x);
49
+ console.log(width, txt);
50
50
  if (this.options.custom) {
51
51
  this.mitt.$emit(EVENT_GRADUATION_CHANGE, {width, txt});
52
52
  } else {
@@ -79,16 +79,39 @@ export class Graduation extends ViewerCommon {
79
79
  ctx.beginPath();
80
80
  ctx.strokeStyle = '#000000';
81
81
  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
82
  ctx.fillStyle = '#000000';
89
- ctx.font = 'bold 16px Arial';
90
- const t = txt.toFixed(0) + this.options.unit;
83
+ ctx.font = 'bold 14px Arial';
84
+ const tick = this.options.tick || {
85
+ height: 8,
86
+ number: 5,
87
+ };
88
+ const unitIndex = this.getUnitIndex(txt * tick.number, this.options.units, this.options.binary);
89
+ const t = getUnitNumber(txt * tick.number, this.options.units, this.options.binary, unitIndex);
91
90
  const fontWidth = ctx.measureText(t).width;
92
- ctx.fillText(t, x + lineWidth / 2 - fontWidth / 2, top ? y + 12 : y - 12);
91
+ ctx.fillText(t, x + lineWidth * tick.number - fontWidth / 2, y + 20);
92
+ new Array(tick.number).fill(1).forEach((i, index) => {
93
+ ctx.moveTo(x + lineWidth * index, y - tick.height);
94
+ ctx.lineTo(x + lineWidth * index, y);
95
+ ctx.lineTo(x + lineWidth * (index + 1), y);
96
+ ctx.lineTo(x + lineWidth * (index + 1), y - tick.height);
97
+ const t = getUnitNumber(txt * index, this.options.units, this.options.binary, unitIndex).
98
+ replace(this.options.units[unitIndex], '');
99
+ const fontWidth = ctx.measureText(t).width;
100
+ ctx.fillText(t, x + lineWidth * index - fontWidth / 2, y + 20);
101
+ });
102
+ ctx.stroke();
103
+ }
104
+
105
+ getUnitIndex(number, units, binary) {
106
+ let i = number;
107
+ let index = 0;
108
+ while (i >= binary) {
109
+ i = i / binary;
110
+ index++;
111
+ }
112
+ if (!units[index]) {
113
+ index = units.length - 1;
114
+ }
115
+ return index;
93
116
  }
94
117
  }
package/src/util/index.js CHANGED
@@ -64,9 +64,23 @@ function delayedTrigger(callback, time = 1000) {
64
64
  };
65
65
  }
66
66
 
67
+ function getUnitNumber(number, units, binary, index = 0) {
68
+ let i = number;
69
+ while (i >= binary) {
70
+ i = i / binary;
71
+ index++;
72
+ }
73
+ if (!units[index]) {
74
+ index = units.length - 1;
75
+ }
76
+ return (number / Math.pow(binary, index)).toFixed(2) / 1 + units[index];
77
+ }
78
+
79
+
67
80
  export {
68
81
  $,
69
82
  dataType,
70
83
  deepClone,
71
84
  delayedTrigger,
85
+ getUnitNumber,
72
86
  };
package/src/view.js CHANGED
@@ -35,7 +35,9 @@ export default class KfbView extends EventEmitter {
35
35
  * @param {number[]=} config.navigator.vestige.zooms 浏览痕迹触发倍率
36
36
  * @param {Object} config.pxConversion 像素转换参数
37
37
  * @param {number} config.pxConversion.imageCapRes 像素转换倍率
38
+ * @param {string[]=} config.pxConversion.units 单位组
38
39
  * @param {string} config.pxConversion.unit 单位
40
+ * @param {number} config.pxConversion.binary 几进制, 2, 16, 24, 1000
39
41
  * @param {Object} config.area 交互区域,触发点击、拖动等事件
40
42
  * @param {boolean=} config.area.disabled 是否禁用area
41
43
  * @param {boolean=} config.area.drag 是否允许拖动
@@ -63,7 +65,9 @@ export default class KfbView extends EventEmitter {
63
65
  * @param {boolean=} config.graduation.disabled 是否禁用刻度
64
66
  * @param {boolean=} config.graduation.show 是否显刻度
65
67
  * @param {boolean=} config.graduation.custom 是否自定义刻度,抛出graduation-change事件
66
- * @param {array=} config.graduation.scales 倍率数组
68
+ * @param {Object} config.graduation.tick 刻度线参数
69
+ * @param {number=} config.graduation.tick.height 刻度线高度
70
+ * @param {number=} config.graduation.tick.number 刻度线段落
67
71
  * @param {array=} config.graduation.microns 刻度长度数组,在对应倍率范围内显示的刻度长度
68
72
  * @param {boolean=} config.grid.disabled 是否禁用网格线
69
73
  * @param {boolean=} config.grid.show 是否显示网格线
@@ -285,7 +289,7 @@ function createCanvas(kv) {
285
289
 
286
290
  function initComponentsOptions(kv, type) {
287
291
  const config = kv.$options;
288
- const pxConversion = config.pxConversion || {imageCapRes: 1, unit: ''};
292
+ const pxConversion = config.pxConversion || {imageCapRes: 1, units: []};
289
293
  return {
290
294
  kv,
291
295
  viewer: kv.viewer,
@@ -306,6 +310,7 @@ function initComponentsOptions(kv, type) {
306
310
  },
307
311
  ...config[type],
308
312
  ...pxConversion,
313
+ units: pxConversion.units ?? [pxConversion.unit ?? ''], // 兼容之前只显示一个的单位
309
314
  thumb: config.thumb ? {
310
315
  radius: 5,
311
316
  activeRadius: 7,