@cornerstonejs/tools 1.72.3 → 1.72.4
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/dist/cjs/drawingSvg/drawRect.js +6 -38
- package/dist/cjs/drawingSvg/drawRect.js.map +1 -1
- package/dist/cjs/drawingSvg/drawRectByCoordinates.d.ts +3 -0
- package/dist/cjs/drawingSvg/drawRectByCoordinates.js +59 -0
- package/dist/cjs/drawingSvg/drawRectByCoordinates.js.map +1 -0
- package/dist/cjs/drawingSvg/index.d.ts +2 -1
- package/dist/cjs/drawingSvg/index.js +3 -1
- package/dist/cjs/drawingSvg/index.js.map +1 -1
- package/dist/cjs/tools/AnnotationEraserTool.js +1 -1
- package/dist/cjs/tools/AnnotationEraserTool.js.map +1 -1
- package/dist/cjs/tools/annotation/RectangleROITool.js +1 -1
- package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/esm/drawingSvg/drawRect.js +6 -38
- package/dist/esm/drawingSvg/drawRect.js.map +1 -1
- package/dist/esm/drawingSvg/drawRectByCoordinates.js +53 -0
- package/dist/esm/drawingSvg/drawRectByCoordinates.js.map +1 -0
- package/dist/esm/drawingSvg/index.js +2 -1
- package/dist/esm/drawingSvg/index.js.map +1 -1
- package/dist/esm/tools/AnnotationEraserTool.js +1 -1
- package/dist/esm/tools/AnnotationEraserTool.js.map +1 -1
- package/dist/esm/tools/annotation/RectangleROITool.js +2 -2
- package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/types/drawingSvg/drawRect.d.ts.map +1 -1
- package/dist/types/drawingSvg/drawRectByCoordinates.d.ts +4 -0
- package/dist/types/drawingSvg/drawRectByCoordinates.d.ts.map +1 -0
- package/dist/types/drawingSvg/index.d.ts +2 -1
- package/dist/types/drawingSvg/index.d.ts.map +1 -1
- package/dist/types/tools/annotation/RectangleROITool.d.ts.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/drawingSvg/drawRect.ts +14 -53
- package/src/drawingSvg/drawRectByCoordinates.ts +87 -0
- package/src/drawingSvg/index.ts +2 -0
- package/src/tools/AnnotationEraserTool.ts +1 -1
- package/src/tools/annotation/RectangleROITool.ts +2 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/tools",
|
|
3
|
-
"version": "1.72.
|
|
3
|
+
"version": "1.72.4",
|
|
4
4
|
"description": "Cornerstone3D Tools",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@cornerstonejs/core": "^1.72.
|
|
32
|
+
"@cornerstonejs/core": "^1.72.4",
|
|
33
33
|
"@icr/polyseg-wasm": "0.4.0",
|
|
34
34
|
"@types/offscreencanvas": "2019.7.3",
|
|
35
35
|
"comlink": "^4.4.1",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"type": "individual",
|
|
60
60
|
"url": "https://ohif.org/donate"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "d3800a7ce82f7ba1c585d6dc1bc701fbbfc9d732"
|
|
63
63
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Types } from '@cornerstonejs/core';
|
|
2
2
|
|
|
3
3
|
import _getHash from './_getHash';
|
|
4
|
-
import setAttributesIfNecessary from './setAttributesIfNecessary';
|
|
5
|
-
import setNewAttributesIfValid from './setNewAttributesIfValid';
|
|
6
4
|
import { SVGDrawingHelper } from '../types';
|
|
5
|
+
import drawRectByCoordinates from './drawRectByCoordinates';
|
|
7
6
|
|
|
7
|
+
// This method is obsolete due to not supporting rotation tool. Please use drawRectByCoordinates instead.
|
|
8
8
|
// <rect x="120" y="100" width="100" height="100" />
|
|
9
9
|
export default function drawRect(
|
|
10
10
|
svgDrawingHelper: SVGDrawingHelper,
|
|
@@ -15,56 +15,17 @@ export default function drawRect(
|
|
|
15
15
|
options = {},
|
|
16
16
|
dataId = ''
|
|
17
17
|
): void {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
options
|
|
18
|
+
const topLeft: Types.Point2 = [start[0], start[1]];
|
|
19
|
+
const topRight: Types.Point2 = [end[0], start[1]];
|
|
20
|
+
const bottomLeft: Types.Point2 = [start[0], end[1]];
|
|
21
|
+
const bottomRight: Types.Point2 = [end[0], end[1]];
|
|
22
|
+
|
|
23
|
+
drawRectByCoordinates(
|
|
24
|
+
svgDrawingHelper,
|
|
25
|
+
annotationUID,
|
|
26
|
+
rectangleUID,
|
|
27
|
+
[topLeft, topRight, bottomLeft, bottomRight],
|
|
28
|
+
options,
|
|
29
|
+
dataId
|
|
31
30
|
);
|
|
32
|
-
|
|
33
|
-
// for supporting both lineWidth and width options
|
|
34
|
-
const strokeWidth = lineWidth || _width;
|
|
35
|
-
|
|
36
|
-
const svgns = 'http://www.w3.org/2000/svg';
|
|
37
|
-
const svgNodeHash = _getHash(annotationUID, 'rect', rectangleUID);
|
|
38
|
-
const existingRect = svgDrawingHelper.getSvgNode(svgNodeHash);
|
|
39
|
-
|
|
40
|
-
const tlhc = [Math.min(start[0], end[0]), Math.min(start[1], end[1])];
|
|
41
|
-
const width = Math.abs(start[0] - end[0]);
|
|
42
|
-
const height = Math.abs(start[1] - end[1]);
|
|
43
|
-
|
|
44
|
-
const attributes = {
|
|
45
|
-
x: `${tlhc[0]}`,
|
|
46
|
-
y: `${tlhc[1]}`,
|
|
47
|
-
width: `${width}`,
|
|
48
|
-
height: `${height}`,
|
|
49
|
-
stroke: color,
|
|
50
|
-
fill: 'transparent',
|
|
51
|
-
'stroke-width': strokeWidth,
|
|
52
|
-
'stroke-dasharray': lineDash,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
if (existingRect) {
|
|
56
|
-
setAttributesIfNecessary(attributes, existingRect);
|
|
57
|
-
|
|
58
|
-
svgDrawingHelper.setNodeTouched(svgNodeHash);
|
|
59
|
-
} else {
|
|
60
|
-
const svgRectElement = document.createElementNS(svgns, 'rect');
|
|
61
|
-
|
|
62
|
-
if (dataId !== '') {
|
|
63
|
-
svgRectElement.setAttribute('data-id', dataId);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
setNewAttributesIfValid(attributes, svgRectElement);
|
|
67
|
-
|
|
68
|
-
svgDrawingHelper.appendNode(svgRectElement, svgNodeHash);
|
|
69
|
-
}
|
|
70
31
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
|
|
3
|
+
import _getHash from './_getHash';
|
|
4
|
+
import setAttributesIfNecessary from './setAttributesIfNecessary';
|
|
5
|
+
import setNewAttributesIfValid from './setNewAttributesIfValid';
|
|
6
|
+
import { SVGDrawingHelper } from '../types';
|
|
7
|
+
|
|
8
|
+
export default function drawRectByCoordinates(
|
|
9
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
10
|
+
annotationUID: string,
|
|
11
|
+
rectangleUID: string,
|
|
12
|
+
canvasCoordinates: Types.Point2[],
|
|
13
|
+
options = {},
|
|
14
|
+
dataId = ''
|
|
15
|
+
): void {
|
|
16
|
+
const {
|
|
17
|
+
color,
|
|
18
|
+
width: _width,
|
|
19
|
+
lineWidth,
|
|
20
|
+
lineDash,
|
|
21
|
+
} = Object.assign(
|
|
22
|
+
{
|
|
23
|
+
color: 'rgb(0, 255, 0)',
|
|
24
|
+
width: '2',
|
|
25
|
+
lineWidth: undefined,
|
|
26
|
+
lineDash: undefined,
|
|
27
|
+
},
|
|
28
|
+
options
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// for supporting both lineWidth and width options
|
|
32
|
+
|
|
33
|
+
const strokeWidth = lineWidth || _width;
|
|
34
|
+
|
|
35
|
+
const svgns = 'http://www.w3.org/2000/svg';
|
|
36
|
+
const svgNodeHash = _getHash(annotationUID, 'rect', rectangleUID);
|
|
37
|
+
const existingRect = svgDrawingHelper.getSvgNode(svgNodeHash);
|
|
38
|
+
|
|
39
|
+
const [topLeft, topRight, bottomLeft, bottomRight] = canvasCoordinates;
|
|
40
|
+
|
|
41
|
+
const width = Math.hypot(topLeft[0] - topRight[0], topLeft[1] - topRight[1]);
|
|
42
|
+
const height = Math.hypot(
|
|
43
|
+
topLeft[0] - bottomLeft[0],
|
|
44
|
+
topLeft[1] - bottomLeft[1]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const center = [
|
|
48
|
+
(bottomRight[0] + topLeft[0]) / 2,
|
|
49
|
+
(bottomRight[1] + topLeft[1]) / 2,
|
|
50
|
+
];
|
|
51
|
+
const leftEdgeCenter = [
|
|
52
|
+
(bottomLeft[0] + topLeft[0]) / 2,
|
|
53
|
+
(bottomLeft[1] + topLeft[1]) / 2,
|
|
54
|
+
];
|
|
55
|
+
const angle =
|
|
56
|
+
(Math.atan2(center[1] - leftEdgeCenter[1], center[0] - leftEdgeCenter[0]) *
|
|
57
|
+
180) /
|
|
58
|
+
Math.PI;
|
|
59
|
+
|
|
60
|
+
const attributes = {
|
|
61
|
+
x: `${center[0] - width / 2}`,
|
|
62
|
+
y: `${center[1] - height / 2}`,
|
|
63
|
+
width: `${width}`,
|
|
64
|
+
height: `${height}`,
|
|
65
|
+
stroke: color,
|
|
66
|
+
fill: 'transparent',
|
|
67
|
+
transform: `rotate(${angle} ${center[0]} ${center[1]})`,
|
|
68
|
+
'stroke-width': strokeWidth,
|
|
69
|
+
'stroke-dasharray': lineDash,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (existingRect) {
|
|
73
|
+
setAttributesIfNecessary(attributes, existingRect);
|
|
74
|
+
|
|
75
|
+
svgDrawingHelper.setNodeTouched(svgNodeHash);
|
|
76
|
+
} else {
|
|
77
|
+
const svgRectElement = document.createElementNS(svgns, 'rect');
|
|
78
|
+
|
|
79
|
+
if (dataId !== '') {
|
|
80
|
+
svgRectElement.setAttribute('data-id', dataId);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setNewAttributesIfValid(attributes, svgRectElement);
|
|
84
|
+
|
|
85
|
+
svgDrawingHelper.appendNode(svgRectElement, svgNodeHash);
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/drawingSvg/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import drawPolyline from './drawPolyline';
|
|
|
9
9
|
import drawPath from './drawPath';
|
|
10
10
|
import drawLinkedTextBox from './drawLinkedTextBox';
|
|
11
11
|
import drawRect from './drawRect';
|
|
12
|
+
import drawRectByCoordinates from './drawRectByCoordinates';
|
|
12
13
|
import drawTextBox from './drawTextBox';
|
|
13
14
|
import drawArrow from './drawArrow';
|
|
14
15
|
import drawRedactionRect from './drawRedactionRect';
|
|
@@ -27,6 +28,7 @@ export {
|
|
|
27
28
|
drawPath,
|
|
28
29
|
drawLinkedTextBox,
|
|
29
30
|
drawRect,
|
|
31
|
+
drawRectByCoordinates,
|
|
30
32
|
drawTextBox,
|
|
31
33
|
drawArrow,
|
|
32
34
|
drawRedactionRect,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import {
|
|
25
25
|
drawHandles as drawHandlesSvg,
|
|
26
26
|
drawLinkedTextBox as drawLinkedTextBoxSvg,
|
|
27
|
-
|
|
27
|
+
drawRectByCoordinates as drawRectSvg,
|
|
28
28
|
} from '../../drawingSvg';
|
|
29
29
|
import { state } from '../../store';
|
|
30
30
|
import { Events } from '../../enums';
|
|
@@ -748,8 +748,7 @@ class RectangleROITool extends AnnotationTool {
|
|
|
748
748
|
svgDrawingHelper,
|
|
749
749
|
annotationUID,
|
|
750
750
|
rectangleUID,
|
|
751
|
-
canvasCoordinates
|
|
752
|
-
canvasCoordinates[3],
|
|
751
|
+
canvasCoordinates,
|
|
753
752
|
{
|
|
754
753
|
color,
|
|
755
754
|
lineDash,
|