-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ArrowTool and remove toolName from drawing API (#88)
* feat: Add ArrowTool to annotation tools * fix: remove toolName from drawing API * fix: use lineDash in the Length tool * apply review comments
- Loading branch information
Showing
28 changed files
with
899 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
function _getHash( | ||
toolName: string, | ||
annotationUID: string, | ||
drawingElementType: string, | ||
nodeUID: string | ||
): string { | ||
return `${toolName}::${annotationUID}::${drawingElementType}::${nodeUID}`; | ||
return `${annotationUID}::${drawingElementType}::${nodeUID}`; | ||
} | ||
|
||
export default _getHash; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import type { Types } from '@cornerstonejs/core'; | ||
import drawLine from './drawLine'; | ||
|
||
export default function drawArrow( | ||
svgDrawingHelper: any, | ||
annotationUID: string, | ||
arrowUID: string, | ||
start: Types.Point2, | ||
end: Types.Point2, | ||
options = {} | ||
): void { | ||
// if length is NaN return | ||
if (isNaN(start[0]) || isNaN(start[1]) || isNaN(end[0]) || isNaN(end[1])) { | ||
return; | ||
} | ||
|
||
const { color, width, lineWidth, lineDash } = Object.assign( | ||
{ | ||
color: 'dodgerblue', | ||
width: '2', | ||
lineWidth: undefined, | ||
lineDash: undefined, | ||
}, | ||
options | ||
); | ||
|
||
// The line itself | ||
drawLine(svgDrawingHelper, annotationUID, arrowUID, start, end, { | ||
color, | ||
width, | ||
lineWidth, | ||
lineDash, | ||
}); | ||
|
||
// Drawing the head arrow with two lines | ||
// Variables to be used when creating the arrow | ||
const headLength = 10; | ||
const angle = Math.atan2(end[1] - start[1], end[0] - start[0]); | ||
|
||
const firstLine = { | ||
start: [ | ||
end[0] - headLength * Math.cos(angle - Math.PI / 7), | ||
end[1] - headLength * Math.sin(angle - Math.PI / 7), | ||
] as Types.Point2, | ||
end: end, | ||
}; | ||
|
||
const secondLine = { | ||
start: [ | ||
end[0] - headLength * Math.cos(angle + Math.PI / 7), | ||
end[1] - headLength * Math.sin(angle + Math.PI / 7), | ||
] as Types.Point2, | ||
end: end, | ||
}; | ||
|
||
drawLine( | ||
svgDrawingHelper, | ||
annotationUID, | ||
'2', | ||
firstLine.start, | ||
firstLine.end, | ||
{ | ||
color, | ||
width, | ||
lineWidth, | ||
lineDash, | ||
} | ||
); | ||
|
||
drawLine( | ||
svgDrawingHelper, | ||
annotationUID, | ||
'3', | ||
secondLine.start, | ||
secondLine.end, | ||
{ | ||
color, | ||
width, | ||
lineWidth, | ||
lineDash, | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.