@cornerstonejs/tools 2.17.2 → 2.17.3

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,20 +1,47 @@
1
1
  import drawLine from './drawLine';
2
+ const svgns = 'http://www.w3.org/2000/svg';
2
3
  export default function drawArrow(svgDrawingHelper, annotationUID, arrowUID, start, end, options = {}) {
3
4
  if (isNaN(start[0]) || isNaN(start[1]) || isNaN(end[0]) || isNaN(end[1])) {
4
5
  return;
5
6
  }
6
- const { color, width, lineWidth, lineDash } = Object.assign({
7
- color: 'rgb(0, 255, 0)',
8
- width: '2',
9
- lineWidth: undefined,
10
- lineDash: undefined,
11
- }, options);
12
- drawLine(svgDrawingHelper, annotationUID, arrowUID, start, end, {
13
- color,
14
- width,
15
- lineWidth,
16
- lineDash,
17
- });
7
+ const { viaMarker = false, color = 'rgb(0, 255, 0)', markerSize = 10, } = options;
8
+ if (!viaMarker) {
9
+ legacyDrawArrow(svgDrawingHelper, annotationUID, arrowUID, start, end, options);
10
+ return;
11
+ }
12
+ const layerId = svgDrawingHelper.svgLayerElement.id;
13
+ const markerBaseId = `arrow-${annotationUID}`;
14
+ const markerFullId = `${markerBaseId}-${layerId}`;
15
+ const defs = svgDrawingHelper.svgLayerElement.querySelector('defs');
16
+ let arrowMarker = defs.querySelector(`#${markerFullId}`);
17
+ if (!arrowMarker) {
18
+ arrowMarker = document.createElementNS(svgns, 'marker');
19
+ arrowMarker.setAttribute('id', markerFullId);
20
+ arrowMarker.setAttribute('viewBox', '0 0 10 10');
21
+ arrowMarker.setAttribute('refX', '8');
22
+ arrowMarker.setAttribute('refY', '5');
23
+ arrowMarker.setAttribute('markerWidth', `${markerSize}`);
24
+ arrowMarker.setAttribute('markerHeight', `${markerSize}`);
25
+ arrowMarker.setAttribute('orient', 'auto');
26
+ const arrowPath = document.createElementNS(svgns, 'path');
27
+ arrowPath.setAttribute('d', 'M 0 0 L 10 5 L 0 10 z');
28
+ arrowPath.setAttribute('fill', color);
29
+ arrowMarker.appendChild(arrowPath);
30
+ defs.appendChild(arrowMarker);
31
+ }
32
+ else {
33
+ arrowMarker.setAttribute('markerWidth', `${markerSize}`);
34
+ arrowMarker.setAttribute('markerHeight', `${markerSize}`);
35
+ const arrowPath = arrowMarker.querySelector('path');
36
+ if (arrowPath) {
37
+ arrowPath.setAttribute('fill', color);
38
+ }
39
+ }
40
+ options.markerEndId = markerFullId;
41
+ drawLine(svgDrawingHelper, annotationUID, arrowUID, start, end, options);
42
+ }
43
+ function legacyDrawArrow(svgDrawingHelper, annotationUID, arrowUID, start, end, options = {}) {
44
+ const { color = 'rgb(0, 255, 0)', width = 2, lineWidth, lineDash } = options;
18
45
  const headLength = 10;
19
46
  const angle = Math.atan2(end[1] - start[1], end[0] - start[0]);
20
47
  const firstLine = {
@@ -31,14 +58,22 @@ export default function drawArrow(svgDrawingHelper, annotationUID, arrowUID, sta
31
58
  ],
32
59
  end: end,
33
60
  };
61
+ drawLine(svgDrawingHelper, annotationUID, arrowUID, start, end, {
62
+ color,
63
+ width,
64
+ lineWidth,
65
+ lineDash,
66
+ });
34
67
  drawLine(svgDrawingHelper, annotationUID, '2', firstLine.start, firstLine.end, {
35
68
  color,
36
69
  width,
37
70
  lineWidth,
71
+ lineDash,
38
72
  });
39
73
  drawLine(svgDrawingHelper, annotationUID, '3', secondLine.start, secondLine.end, {
40
74
  color,
41
75
  width,
42
76
  lineWidth,
77
+ lineDash,
43
78
  });
44
79
  }
@@ -28,15 +28,18 @@ export default function drawHeight(svgDrawingHelper, annotationUID, heightUID, s
28
28
  color,
29
29
  width,
30
30
  lineWidth,
31
+ lineDash,
31
32
  });
32
33
  drawLine(svgDrawingHelper, annotationUID, '2', secondLine.start, secondLine.end, {
33
34
  color,
34
35
  width,
35
36
  lineWidth,
37
+ lineDash,
36
38
  });
37
39
  drawLine(svgDrawingHelper, annotationUID, '3', threeLine.start, threeLine.end, {
38
40
  color,
39
41
  width,
40
42
  lineWidth,
43
+ lineDash,
41
44
  });
42
45
  }
@@ -5,20 +5,13 @@ export default function drawLine(svgDrawingHelper, annotationUID, lineUID, start
5
5
  if (isNaN(start[0]) || isNaN(start[1]) || isNaN(end[0]) || isNaN(end[1])) {
6
6
  return;
7
7
  }
8
- const { color, width, lineWidth, lineDash, shadow } = Object.assign({
9
- color: 'rgb(0, 255, 0)',
10
- width: '2',
11
- lineWidth: undefined,
12
- lineDash: undefined,
13
- shadow: undefined,
14
- }, options);
8
+ const { color = 'rgb(0, 255, 0)', width = 10, lineWidth, lineDash, markerStartId = null, markerEndId = null, shadow = false, } = options;
15
9
  const strokeWidth = lineWidth || width;
16
10
  const svgns = 'http://www.w3.org/2000/svg';
17
11
  const svgNodeHash = _getHash(annotationUID, 'line', lineUID);
18
12
  const existingLine = svgDrawingHelper.getSvgNode(svgNodeHash);
19
- const dropShadowStyle = shadow
20
- ? `filter:url(#shadow-${svgDrawingHelper.svgLayerElement.id});`
21
- : '';
13
+ const layerId = svgDrawingHelper.svgLayerElement.id;
14
+ const dropShadowStyle = shadow ? `filter:url(#shadow-${layerId});` : '';
22
15
  const attributes = {
23
16
  x1: `${start[0]}`,
24
17
  y1: `${start[1]}`,
@@ -28,6 +21,8 @@ export default function drawLine(svgDrawingHelper, annotationUID, lineUID, start
28
21
  style: dropShadowStyle,
29
22
  'stroke-width': strokeWidth,
30
23
  'stroke-dasharray': lineDash,
24
+ 'marker-start': markerStartId ? `url(#${markerStartId})` : '',
25
+ 'marker-end': markerEndId ? `url(#${markerEndId})` : '',
31
26
  };
32
27
  if (existingLine) {
33
28
  setAttributesIfNecessary(attributes, existingLine);
@@ -8,4 +8,6 @@ export default function drawPolyline(svgDrawingHelper: SVGDrawingHelper, annotat
8
8
  lineWidth?: number;
9
9
  lineDash?: string;
10
10
  closePath?: boolean;
11
+ markerStartId?: string;
12
+ markerEndId?: string;
11
13
  }): void;
@@ -5,7 +5,7 @@ export default function drawPolyline(svgDrawingHelper, annotationUID, polylineUI
5
5
  if (points.length < 2) {
6
6
  return;
7
7
  }
8
- const { color = 'rgb(0, 255, 0)', width = 10, fillColor = 'none', fillOpacity = 0, lineWidth, lineDash, closePath = false, } = options;
8
+ const { color = 'rgb(0, 255, 0)', width = 10, fillColor = 'none', fillOpacity = 0, lineWidth, lineDash, closePath = false, markerStartId = null, markerEndId = null, } = options;
9
9
  const strokeWidth = lineWidth || width;
10
10
  const svgns = 'http://www.w3.org/2000/svg';
11
11
  const svgNodeHash = _getHash(annotationUID, 'polyline', polylineUID);
@@ -25,6 +25,8 @@ export default function drawPolyline(svgDrawingHelper, annotationUID, polylineUI
25
25
  'fill-opacity': fillOpacity,
26
26
  'stroke-width': strokeWidth,
27
27
  'stroke-dasharray': lineDash,
28
+ 'marker-start': markerStartId ? `url(#${markerStartId})` : '',
29
+ 'marker-end': markerEndId ? `url(#${markerEndId})` : '',
28
30
  };
29
31
  if (existingPolyLine) {
30
32
  setAttributesIfNecessary(attributes, existingPolyLine);
@@ -19,6 +19,7 @@ class ToolStyle {
19
19
  textBoxLinkLineWidth: '1',
20
20
  textBoxLinkLineDash: '2,3',
21
21
  textBoxShadow: true,
22
+ markerSize: '10',
22
23
  };
23
24
  this._initializeConfig(defaultConfig);
24
25
  }
@@ -20,6 +20,7 @@ class ArrowAnnotateTool extends AnnotationTool {
20
20
  changeTextCallback,
21
21
  preventHandleOutsideImage: false,
22
22
  arrowFirst: true,
23
+ arrowHeadStyle: 'legacy',
23
24
  },
24
25
  }) {
25
26
  super(toolProps, defaultToolProps);
@@ -302,7 +303,7 @@ class ArrowAnnotateTool extends AnnotationTool {
302
303
  const { handles, text } = data;
303
304
  const { points, activeHandleIndex } = handles;
304
305
  styleSpecifier.annotationUID = annotationUID;
305
- const { color, lineWidth, lineDash } = this.getAnnotationStyle({
306
+ const { color, lineWidth, lineDash, markerSize } = this.getAnnotationStyle({
306
307
  annotation,
307
308
  styleSpecifier,
308
309
  });
@@ -333,6 +334,8 @@ class ArrowAnnotateTool extends AnnotationTool {
333
334
  color,
334
335
  width: lineWidth,
335
336
  lineDash: lineDash,
337
+ viaMarker: this.configuration.arrowHeadStyle !== 'legacy',
338
+ markerSize,
336
339
  });
337
340
  }
338
341
  else {
@@ -340,6 +343,8 @@ class ArrowAnnotateTool extends AnnotationTool {
340
343
  color,
341
344
  width: lineWidth,
342
345
  lineDash: lineDash,
346
+ viaMarker: this.configuration.arrowHeadStyle !== 'legacy',
347
+ markerSize,
343
348
  });
344
349
  }
345
350
  renderStatus = true;
@@ -158,6 +158,7 @@ class AnnotationTool extends AnnotationDisplayTool {
158
158
  const lineWidth = getStyle('lineWidth');
159
159
  const lineDash = getStyle('lineDash');
160
160
  const color = getStyle('color');
161
+ const markerSize = getStyle('markerSize');
161
162
  const shadow = getStyle('shadow');
162
163
  const textboxStyle = this.getLinkedTextBoxStyle(styleSpecifier, annotation);
163
164
  return {
@@ -171,6 +172,7 @@ class AnnotationTool extends AnnotationDisplayTool {
171
172
  fillOpacity: 0,
172
173
  shadow,
173
174
  textbox: textboxStyle,
175
+ markerSize,
174
176
  };
175
177
  }
176
178
  _imagePointNearToolOrHandle(element, annotation, canvasCoords, proximity) {
@@ -1,6 +1,6 @@
1
1
  type Modes = '' | 'Active' | 'Passive' | 'Enabled';
2
2
  type States = '' | 'Highlighted' | 'Selected' | 'Locked' | 'AutoGenerated';
3
- type Properties = 'color' | 'colorAutoGenerated' | 'lineWidth' | 'lineWidthAutoGenerated' | 'lineDash' | 'textBoxFontFamily' | 'textBoxFontSize' | 'textBoxColor' | 'textBoxBackground' | 'textBoxLinkLineWidth' | 'textBoxLinkLineDash' | 'locked' | 'fillColor' | 'fillOpacity' | 'textbox' | 'shadow' | 'visibility';
3
+ type Properties = 'color' | 'colorAutoGenerated' | 'lineWidth' | 'lineWidthAutoGenerated' | 'lineDash' | 'textBoxFontFamily' | 'textBoxFontSize' | 'textBoxColor' | 'textBoxBackground' | 'textBoxLinkLineWidth' | 'textBoxLinkLineDash' | 'locked' | 'fillColor' | 'fillOpacity' | 'textbox' | 'shadow' | 'visibility' | 'markerSize';
4
4
  export type AnnotationStyle = {
5
5
  [key in `${Properties}${States}${Modes}`]?: string | number | boolean | Record<string, unknown>;
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "2.17.2",
3
+ "version": "2.17.3",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -104,7 +104,7 @@
104
104
  "canvas": "^2.11.2"
105
105
  },
106
106
  "peerDependencies": {
107
- "@cornerstonejs/core": "^2.17.2",
107
+ "@cornerstonejs/core": "^2.17.3",
108
108
  "@kitware/vtk.js": "32.9.0",
109
109
  "@types/d3-array": "^3.0.4",
110
110
  "@types/d3-interpolate": "^3.0.1",
@@ -123,5 +123,5 @@
123
123
  "type": "individual",
124
124
  "url": "https://ohif.org/donate"
125
125
  },
126
- "gitHead": "26657751a6e715570cc44115ee8cc673aa453037"
126
+ "gitHead": "8fe548248197e61fba869257fdebdd33714e42f8"
127
127
  }