kfb-view 3.2.4 → 3.2.5

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.4",
4
+ "version": "3.2.5",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -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, ELLIPSE, REGION_TYPES,
6
+ POINT_TYPES, STAR, REGION_TYPES,
7
7
  } from '../../const/mark';
8
8
  import {
9
9
  EVENT_START_PAINTING,
@@ -1,14 +1,12 @@
1
1
  import {Thumb} from '../../tool/Thumb';
2
2
  import {
3
- acreage,
4
- getAngle,
5
- perimeter,
6
3
  pointsToRegion,
7
4
  getRectPoint,
8
5
  isPointInEllipse,
9
6
  isPointInMatrix,
10
7
  isPointInPolygon,
11
- calculatePolygonArea, getRectPointV2,
8
+ calculatePolygonArea,
9
+ getUnitNumber,
12
10
  } from '../../util/calculate';
13
11
  import {Point, Rect} from '../../plugin/openseadragon/openseadragon';
14
12
  import {
@@ -19,7 +17,6 @@ import {
19
17
  LINE,
20
18
  RECTANGLE,
21
19
  } from '../../const/mark';
22
- import {getUnitNumber} from '../../util';
23
20
 
24
21
  /**
25
22
  * 通用方法类
@@ -248,17 +245,15 @@ export class ViewerCommon {
248
245
  top: p.y,
249
246
  angle: 0,
250
247
  texts: [
251
- `长:${this.getUnitNumber((Math.sqrt(w * w + h * h) * this.options.imageCapRes).toFixed(2))}`],
248
+ `长:${this.getUnitNumber(Math.sqrt(w * w + h * h) * this.options.imageCapRes)}`],
252
249
  };
253
250
  }
254
251
  break;
255
252
  case ELLIPSE: {
256
253
  const w = Math.abs(endPoint.x - startPoint.x) / 2;
257
254
  const h = Math.abs(endPoint.y - startPoint.y) / 2;
258
- const pt = perimeter(ELLIPSE, startPoint, endPoint,
259
- this.options.imageCapRes).toFixed(2);
260
- const ac = acreage(ELLIPSE, startPoint, endPoint,
261
- this.options.imageCapRes).toFixed(2);
255
+ const a = (w > h ? w : h) * this.options.imageCapRes;
256
+ const b = (w > h ? h : w) * this.options.imageCapRes;
262
257
  const rightTop = getRectPoint(startPoint, endPoint)[2];
263
258
  const p = this.imageToViewerElementCoordinates(rightTop.x,
264
259
  rightTop.y);
@@ -267,20 +262,18 @@ export class ViewerCommon {
267
262
  top: p.y,
268
263
  angle: 0,
269
264
  texts: [
270
- `长轴:${this.getUnitNumber((w * this.options.imageCapRes).toFixed(2))}`,
271
- `短轴:${this.getUnitNumber((h * this.options.imageCapRes).toFixed(2))}`,
272
- `周长:${this.getUnitNumber(pt)}`,
273
- `面积:${this.getUnitNumber(ac)}²`],
265
+ `长轴:${this.getUnitNumber(a)}`,
266
+ `短轴:${this.getUnitNumber(b)}`,
267
+ `周长:${this.getUnitNumber(4 * (a - b) + 2 * Math.PI * b)}`,
268
+ `面积:${this.getUnitNumber(Math.PI * a * b / this.options.binary)}²`],
274
269
  };
275
270
  }
276
271
  break;
277
272
  case RECTANGLE: {
278
- const w = Math.abs(endPoint.x - startPoint.x);
279
- const h = Math.abs(endPoint.y - startPoint.y);
280
- const pt = perimeter(RECTANGLE, startPoint, endPoint,
281
- this.options.imageCapRes).toFixed(2);
282
- const ac = acreage(RECTANGLE, startPoint, endPoint,
283
- this.options.imageCapRes).toFixed(2);
273
+ const w = Math.abs(endPoint.x - startPoint.x) * this.options.imageCapRes;
274
+ const h = Math.abs(endPoint.y - startPoint.y) * this.options.imageCapRes;
275
+ const pt = (w + h) * 2;
276
+ const ac = w * h / this.options.binary;
284
277
  const rightTop = getRectPoint(startPoint, endPoint)[2];
285
278
  const p = this.imageToViewerElementCoordinates(rightTop.x,
286
279
  rightTop.y);
@@ -289,8 +282,8 @@ export class ViewerCommon {
289
282
  top: p.y,
290
283
  angle: 0,
291
284
  texts: [
292
- `长:${this.getUnitNumber((w * this.options.imageCapRes).toFixed(2))}`,
293
- `宽:${this.getUnitNumber((h * this.options.imageCapRes).toFixed(2))}`,
285
+ `长:${this.getUnitNumber(w)}`,
286
+ `宽:${this.getUnitNumber(h)}`,
294
287
  `周长:${this.getUnitNumber(pt)}`,
295
288
  `面积:${this.getUnitNumber(ac)}²`],
296
289
  };
@@ -312,8 +305,8 @@ export class ViewerCommon {
312
305
  angle: 0,
313
306
  texts: [
314
307
  `周长:${this.getUnitNumber((pt * this.options.imageCapRes).toFixed(2))}`,
315
- `面积:${this.getUnitNumber(calculatePolygonArea(points,
316
- this.options.imageCapRes).toFixed(2))}²`],
308
+ `面积:${this.getUnitNumber(
309
+ calculatePolygonArea(points, this.options.imageCapRes) / this.options.binary)}²`],
317
310
  };
318
311
  }
319
312
  break;
@@ -336,8 +329,8 @@ export class ViewerCommon {
336
329
  };
337
330
  }
338
331
 
339
- getUnitNumber(number) {
340
- return getUnitNumber(number, this.options.units, this.options.binary);
332
+ getUnitNumber(number, index) {
333
+ return getUnitNumber(number, this.options.units, this.options.binary, index);
341
334
  }
342
335
 
343
336
  /**
@@ -1,6 +1,6 @@
1
1
  import {ViewerCommon} from '../common/common';
2
2
  import {EVENT_GRADUATION_CHANGE} from '../../const/event';
3
- import {getUnitNumber} from '../../util';
3
+ import {getUnitNumber} from '../../util/calculate';
4
4
 
5
5
  /**
6
6
  * 刻度线
@@ -382,6 +382,7 @@ function getPoint(cen, first, deg) {
382
382
  /**
383
383
  * 通过两个点计算矩形的四个点
384
384
  * @param {array} points
385
+ * @return {{x: *, y: *}}
385
386
  * */
386
387
  function getRectPoints(points) {
387
388
  return [
@@ -432,29 +433,6 @@ function getDistance(p1, p2) {
432
433
  return Math.sqrt(distX + distY);
433
434
  }
434
435
 
435
- /**
436
- * 几何图形的面积
437
- * @param {string} type
438
- * @param {Object} startPoint
439
- * @param {Object} endPoint
440
- * @param {number} imageCapRes 像素转微米系数
441
- * @return {number}
442
- */
443
- function acreage(type, startPoint, endPoint, imageCapRes = 1) {
444
- let ag = 0;
445
- const distX = Math.abs(endPoint.x - startPoint.x) * imageCapRes;
446
- const distY = Math.abs(endPoint.y - startPoint.y) * imageCapRes;
447
- if (type === 'Rectangle') {
448
- ag = distX * distY / 2;
449
- }
450
- if (type === 'Ellipse') {
451
- ag = distX * distY / 4 * Math.PI;
452
- }
453
- /* if (type === 'polygon') {
454
- }*/
455
- return ag;
456
- }
457
-
458
436
  function calculatePolygonArea(points, ratio) {
459
437
  const numVertices = points.length;
460
438
 
@@ -481,38 +459,25 @@ function calculatePolygonArea(points, ratio) {
481
459
  return Math.abs(area / 2);
482
460
  }
483
461
 
484
- /**
485
- * 几何图形的周长
486
- * @param {string} type
487
- * @param {Object} startPoint
488
- * @param {Object} endPoint
489
- * @param {number} imageCapRes 像素转微米系数
490
- * @return {number}
491
- */
492
- function perimeter(type, startPoint, endPoint, imageCapRes = 1) {
493
- let pt = 0;
494
- const distX = Math.abs(endPoint.x - startPoint.x) * imageCapRes;
495
- const distY = Math.abs(endPoint.y - startPoint.y) * imageCapRes;
496
- if (type === 'Line' || type === 'Arrow') {
497
- pt = Math.sqrt(Math.pow(distX, 2) + Math.pow(distY, 2));
462
+ const getRandomId = () => {
463
+ return (((1 + Math.random()) * 0x100000000) | 0).toString(16).substring(1);
464
+ };
465
+
466
+ function getUnitNumber(number, units, binary, index = 0) {
467
+ if (index) {
468
+ return (number / Math.pow(binary, index)).toFixed(2) / 1 + units[index];
498
469
  }
499
- if (type === 'Rectangle') {
500
- pt = (distX + distY) * 2;
470
+ let i = number;
471
+ while (i >= binary) {
472
+ i = i / binary;
473
+ index++;
501
474
  }
502
- if (type === 'Ellipse') {
503
- const a = (distX >= distY ? distX : distY) / 2;
504
- const b = (distX >= distY ? distY : distX) / 2;
505
- pt = 4 * (a - b) + 2 * Math.PI * b;
475
+ if (!units[index]) {
476
+ index = units.length - 1;
506
477
  }
507
- /* if (type === 'polygon') {
508
-
509
- }*/
510
- return pt;
478
+ return (number / Math.pow(binary, index)).toFixed(2) / 1 + units[index];
511
479
  }
512
480
 
513
- const getRandomId = () => {
514
- return (((1 + Math.random()) * 0x100000000) | 0).toString(16).substring(1);
515
- };
516
481
 
517
482
  export {
518
483
  getRectPoint,
@@ -525,8 +490,6 @@ export {
525
490
  isPointInLine,
526
491
  isNegNumber,
527
492
  baseNumber,
528
- acreage,
529
- perimeter,
530
493
  getPoint,
531
494
  getAngle,
532
495
  getDistance,
@@ -534,4 +497,5 @@ export {
534
497
  getRandomId,
535
498
  getRectPoints,
536
499
  getRectPointV2,
500
+ getUnitNumber,
537
501
  };
package/src/util/index.js CHANGED
@@ -64,26 +64,9 @@ function delayedTrigger(callback, time = 1000) {
64
64
  };
65
65
  }
66
66
 
67
- function getUnitNumber(number, units, binary, index = 0) {
68
- if (index) {
69
- return (number / Math.pow(binary, index)).toFixed(2) / 1 + units[index];
70
- }
71
- let i = number;
72
- while (i >= binary) {
73
- i = i / binary;
74
- index++;
75
- }
76
- if (!units[index]) {
77
- index = units.length - 1;
78
- }
79
- return (number / Math.pow(binary, index)).toFixed(2) / 1 + units[index];
80
- }
81
-
82
-
83
67
  export {
84
68
  $,
85
69
  dataType,
86
70
  deepClone,
87
71
  delayedTrigger,
88
- getUnitNumber,
89
72
  };