Skip to content

Commit

Permalink
feat: Add bottom/right orientation markers (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
igoroctaviano authored Jun 11, 2021
1 parent 52703b9 commit f0b2815
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/CornerstoneViewport/CornerstoneViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CornerstoneViewport extends Component {
style: PropTypes.object,
className: PropTypes.string,
isOverlayVisible: PropTypes.bool,
orientationMarkers: PropTypes.arrayOf(PropTypes.string),
};

static defaultProps = {
Expand All @@ -101,6 +102,7 @@ class CornerstoneViewport extends Component {
resizeRefreshMode: 'debounce',
tools: [],
onNewImageDebounceTime: 0,
orientationMarkers: ['top', 'left'],
};

constructor(props) {
Expand Down Expand Up @@ -375,7 +377,7 @@ class CornerstoneViewport extends Component {
* @memberof CornerstoneViewport
*/
getOrientationMarkersOverlay() {
const { imageIds } = this.props;
const { imageIds, orientationMarkers } = this.props;
const {
imageIdIndex,
rotationDegrees,
Expand Down Expand Up @@ -403,6 +405,7 @@ class CornerstoneViewport extends Component {
rotationDegrees={rotationDegrees}
isFlippedVertically={isFlippedVertically}
isFlippedHorizontally={isFlippedHorizontally}
orientationMarkers={orientationMarkers}
/>
);
}
Expand Down
10 changes: 10 additions & 0 deletions src/ViewportOrientationMarkers/ViewportOrientationMarkers.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@
top: 47%;
left: 5px;
}

.ViewportOrientationMarkers .right-mid {
top: 47%;
left: 97%;
}

.ViewportOrientationMarkers .bottom-mid {
top: 97%;
left: 47%;
}
29 changes: 27 additions & 2 deletions src/ViewportOrientationMarkers/ViewportOrientationMarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ function getOrientationMarkers(
const markers = {
top: oppositeColumnString,
left: oppositeRowString,
right: rowString,
bottom: columnString,
};

// If any vertical or horizontal flips are applied, change the orientation strings ahead of
// the rotation applications
if (isFlippedVertically) {
markers.top = invertOrientationString(markers.top);
markers.bottom = invertOrientationString(markers.bottom);
}

if (isFlippedHorizontally) {
markers.left = invertOrientationString(markers.left);
markers.right = invertOrientationString(markers.right);
}

// Swap the labels accordingly if the viewport has been rotated
Expand All @@ -53,16 +57,22 @@ function getOrientationMarkers(
return {
top: markers.left,
left: invertOrientationString(markers.top),
right: invertOrientationString(markers.bottom),
bottom: markers.right, // left
};
} else if (rotationDegrees === -90 || rotationDegrees === 270) {
return {
top: invertOrientationString(markers.left),
left: markers.top,
bottom: markers.left,
right: markers.bottom,
};
} else if (rotationDegrees === 180 || rotationDegrees === -180) {
return {
top: invertOrientationString(markers.top),
left: invertOrientationString(markers.left),
bottom: invertOrientationString(markers.bottom),
right: invertOrientationString(markers.right),
};
}

Expand All @@ -76,6 +86,11 @@ class ViewportOrientationMarkers extends PureComponent {
rotationDegrees: PropTypes.number.isRequired,
isFlippedVertically: PropTypes.bool.isRequired,
isFlippedHorizontally: PropTypes.bool.isRequired,
orientationMarkers: PropTypes.arrayOf(PropTypes.string),
};

static defaultProps = {
orientationMarkers: ['top', 'left'],
};

render() {
Expand All @@ -85,6 +100,7 @@ class ViewportOrientationMarkers extends PureComponent {
rotationDegrees,
isFlippedVertically,
isFlippedHorizontally,
orientationMarkers,
} = this.props;

if (!rowCosines || !columnCosines) {
Expand All @@ -99,10 +115,19 @@ class ViewportOrientationMarkers extends PureComponent {
isFlippedHorizontally
);

const getMarkers = orientationMarkers =>
orientationMarkers.map((m, index) => (
<div
className={`${m}-mid orientation-marker`}
key={`${m}-mid orientation-marker`}
>
{markers[m]}
</div>
));

return (
<div className="ViewportOrientationMarkers noselect">
<div className="top-mid orientation-marker">{markers.top}</div>
<div className="left-mid orientation-marker">{markers.left}</div>
{getMarkers(orientationMarkers)}
</div>
);
}
Expand Down

0 comments on commit f0b2815

Please sign in to comment.