-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ArrowAnnotate): use svg marker to draw the arrow #1732
Open
daker
wants to merge
1
commit into
cornerstonejs:main
Choose a base branch
from
daker:fix-arrowannotate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+55
−62
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -11,34 +11,50 @@ export default function drawLine( | |
lineUID: string, | ||
start: Types.Point2, | ||
end: Types.Point2, | ||
options = {}, | ||
options: { | ||
color?: string; | ||
width?: number; | ||
lineWidth?: number; | ||
lineDash?: string; | ||
markerStartId?: string; | ||
markerEndId?: string; | ||
shadow?: boolean; | ||
}, | ||
dataId = '' | ||
): 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, shadow } = Object.assign( | ||
{ | ||
color: 'rgb(0, 255, 0)', | ||
width: '2', | ||
lineWidth: undefined, | ||
lineDash: undefined, | ||
shadow: undefined, | ||
}, | ||
options | ||
); | ||
const { | ||
color = 'rgb(0, 255, 0)', | ||
width = 10, | ||
lineWidth, | ||
lineDash, | ||
markerStartId = null, | ||
markerEndId = null, | ||
shadow = false, | ||
} = options; | ||
|
||
// for supporting both lineWidth and width options | ||
const strokeWidth = lineWidth || width; | ||
|
||
const svgns = 'http://www.w3.org/2000/svg'; | ||
const svgNodeHash = _getHash(annotationUID, 'line', lineUID); | ||
const existingLine = svgDrawingHelper.getSvgNode(svgNodeHash); | ||
const dropShadowStyle = shadow | ||
? `filter:url(#shadow-${svgDrawingHelper.svgLayerElement.id});` | ||
: ''; | ||
const layerId = svgDrawingHelper.svgLayerElement.id; | ||
const dropShadowStyle = shadow ? `filter:url(#shadow-${layerId});` : ''; | ||
const arrow = svgDrawingHelper.svgLayerElement.querySelector( | ||
`#${markerEndId}-${layerId}` | ||
); | ||
|
||
if (arrow) { | ||
arrow.setAttribute('fill', color); | ||
const newstrokeWidth = strokeWidth >= 4 ? 3 : 6; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is |
||
arrow.setAttribute('markerWidth', `${newstrokeWidth}`); | ||
arrow.setAttribute('markerHeight', `${newstrokeWidth}`); | ||
} | ||
|
||
const attributes = { | ||
x1: `${start[0]}`, | ||
|
@@ -49,6 +65,8 @@ export default function drawLine( | |
style: dropShadowStyle, | ||
'stroke-width': strokeWidth, | ||
'stroke-dasharray': lineDash, | ||
'marker-start': markerStartId ? `url(#${markerStartId}-${layerId})` : '', | ||
'marker-end': markerEndId ? `url(#${markerEndId}-${layerId})` : '', | ||
}; | ||
|
||
if (existingLine) { | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we changing the
width
here? Could this break people's tools since we're changing it from 2 to 10?