Skip to content

Commit

Permalink
[OHIF-248] hideHandlesIfMoving (#1257)
Browse files Browse the repository at this point in the history
* hideHandlesOnEdit

* feat: 🎸 hideHandlesOnMove hides handles whilst they are edited

* Highlight ellipse active when mouse over handle.

* Reset defaults.

* Fix unit tests
  • Loading branch information
JamesAPetts authored Jul 2, 2020
1 parent c9e6fa3 commit e2c2906
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/drawing/drawHandles.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export default function(context, evtDetail, handles, options = {}) {
if (options.drawHandlesIfActive === true && !handle.active) {
continue;
}
if (options.hideHandlesIfMoving && handle.moving) {
continue;
}

const lineWidth = handle.active
? toolStyle.getActiveWidth()
Expand Down
2 changes: 2 additions & 0 deletions src/manipulators/moveHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default function(
);

handle.active = true;
handle.moving = true;
annotation.active = true;
state.isToolLocked = true;

Expand Down Expand Up @@ -270,6 +271,7 @@ function _endHandler(
const element = evtDetail.element;

handle.active = false;
handle.moving = false;
annotation.active = false;
annotation.invalidated = true;
runAnimation.value = false;
Expand Down
2 changes: 2 additions & 0 deletions src/manipulators/moveNewHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default function(

annotation.active = true;

handle.moving = true;
handle.active = true;
state.isToolLocked = true;

Expand Down Expand Up @@ -252,6 +253,7 @@ function _moveEndHandler(
annotation.active = false;
annotation.invalidated = true;
handle.active = false;
handle.moving = false;
handle.x = targetLocation.x;
handle.y = targetLocation.y;

Expand Down
4 changes: 4 additions & 0 deletions src/tools/annotation/AngleTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export default class AngleTool extends BaseAnnotationTool {
svgCursor: angleCursor,
configuration: {
drawHandles: true,
drawHandlesOnHover: false,
hideHandlesIfMoving: false,
renderDashed: false,
},
};
Expand Down Expand Up @@ -142,6 +144,7 @@ export default class AngleTool extends BaseAnnotationTool {
const {
handleRadius,
drawHandlesOnHover,
hideHandlesIfMoving,
renderDashed,
} = this.configuration;
// If we have no toolData for this element, return immediately as there is nothing to do
Expand Down Expand Up @@ -200,6 +203,7 @@ export default class AngleTool extends BaseAnnotationTool {
color,
handleRadius,
drawHandlesIfActive: drawHandlesOnHover,
hideHandlesIfMoving,
};

if (this.configuration.drawHandles) {
Expand Down
7 changes: 5 additions & 2 deletions src/tools/annotation/ArrowAnnotateTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export default class ArrowAnnotateTool extends BaseAnnotationTool {
configuration: {
getTextCallback,
changeTextCallback,
drawHandles: false,
drawHandlesOnHover: true,
drawHandles: true,
drawHandlesOnHover: false,
hideHandlesIfMoving: false,
arrowFirst: true,
renderDashed: false,
},
Expand Down Expand Up @@ -102,6 +103,7 @@ export default class ArrowAnnotateTool extends BaseAnnotationTool {
const {
handleRadius,
drawHandlesOnHover,
hideHandlesIfMoving,
renderDashed,
} = this.configuration;

Expand Down Expand Up @@ -170,6 +172,7 @@ export default class ArrowAnnotateTool extends BaseAnnotationTool {
color,
handleRadius,
drawHandlesIfActive: drawHandlesOnHover,
hideHandlesIfMoving,
};

if (this.configuration.drawHandles) {
Expand Down
1 change: 1 addition & 0 deletions src/tools/annotation/BidirectionalTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class BidirectionalTool extends BaseAnnotationTool {
shadow: '',
drawHandles: true,
drawHandlesOnHover: true,
hideHandlesIfMoving: false,
renderDashed: false,
additionalData: [],
},
Expand Down
3 changes: 3 additions & 0 deletions src/tools/annotation/CircleRoiTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default class CircleRoiTool extends BaseAnnotationTool {
svgCursor: circleRoiCursor,
configuration: {
renderDashed: false,
hideHandlesIfMoving: false,
},
};

Expand Down Expand Up @@ -171,6 +172,7 @@ export default class CircleRoiTool extends BaseAnnotationTool {
const {
handleRadius,
drawHandlesOnHover,
hideHandlesIfMoving,
renderDashed,
} = this.configuration;
const newContext = getNewContext(canvasContext.canvas);
Expand Down Expand Up @@ -201,6 +203,7 @@ export default class CircleRoiTool extends BaseAnnotationTool {
color,
handleRadius,
drawHandlesIfActive: drawHandlesOnHover,
hideHandlesIfMoving,
};

setShadow(context, this.configuration);
Expand Down
4 changes: 4 additions & 0 deletions src/tools/annotation/CobbAngleTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default class CobbAngleTool extends BaseAnnotationTool {
svgCursor: cobbAngleCursor,
configuration: {
drawHandles: true,
drawHandlesOnHover: false,
hideHandlesIfMoving: false,
renderDashed: false,
},
};
Expand Down Expand Up @@ -164,6 +166,7 @@ export default class CobbAngleTool extends BaseAnnotationTool {
const {
handleRadius,
drawHandlesOnHover,
hideHandlesIfMoving,
renderDashed,
} = this.configuration;
// If we have no toolData for this element, return immediately as there is nothing to do
Expand Down Expand Up @@ -222,6 +225,7 @@ export default class CobbAngleTool extends BaseAnnotationTool {
color,
handleRadius,
drawHandlesIfActive: drawHandlesOnHover,
hideHandlesIfMoving,
};

if (this.configuration.drawHandles) {
Expand Down
16 changes: 16 additions & 0 deletions src/tools/annotation/EllipticalRoiTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import BaseAnnotationTool from '../base/BaseAnnotationTool.js';
import { getToolState } from './../../stateManagement/toolState.js';
import toolStyle from './../../stateManagement/toolStyle.js';
import toolColors from './../../stateManagement/toolColors.js';
import getHandleNearImagePoint from '../../manipulators/getHandleNearImagePoint';

// Drawing
import {
Expand Down Expand Up @@ -48,6 +49,8 @@ export default class EllipticalRoiTool extends BaseAnnotationTool {
configuration: {
// showMinMax: false,
// showHounsfieldUnits: true,
drawHandlesOnHover: false,
hideHandlesIfMoving: false,
renderDashed: false,
},
svgCursor: ellipticalRoiCursor,
Expand Down Expand Up @@ -116,6 +119,17 @@ export default class EllipticalRoiTool extends BaseAnnotationTool {
return false;
}

const handleNearImagePoint = getHandleNearImagePoint(
element,
data.handles,
coords,
6
);

if (handleNearImagePoint) {
return true;
}

const distance = interactionType === 'mouse' ? 15 : 25;
const startCanvas = external.cornerstone.pixelToCanvas(
element,
Expand Down Expand Up @@ -183,6 +197,7 @@ export default class EllipticalRoiTool extends BaseAnnotationTool {
const {
handleRadius,
drawHandlesOnHover,
hideHandlesIfMoving,
renderDashed,
} = this.configuration;
const context = getNewContext(eventData.canvasContext.canvas);
Expand Down Expand Up @@ -212,6 +227,7 @@ export default class EllipticalRoiTool extends BaseAnnotationTool {
color,
handleRadius,
drawHandlesIfActive: drawHandlesOnHover,
hideHandlesIfMoving,
};

setShadow(context, this.configuration);
Expand Down
4 changes: 1 addition & 3 deletions src/tools/annotation/EllipticalRoiTool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ describe('EllipticalRoiTool.js', () => {
// Todo: Not sure we want all of our methods to check for valid params.
it('emits a console warning when measurementData without start/end handles are supplied', () => {
const instantiatedTool = new EllipticalRoiTool();
const noHandlesMeasurementData = {
handles: {},
};
const noHandlesMeasurementData = {};
const logger = getLogger();

instantiatedTool.pointNearTool(element, noHandlesMeasurementData, coords);
Expand Down
4 changes: 4 additions & 0 deletions src/tools/annotation/LengthTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class LengthTool extends BaseAnnotationTool {
svgCursor: lengthCursor,
configuration: {
drawHandles: true,
drawHandlesOnHover: false,
hideHandlesIfMoving: false,
renderDashed: false,
},
};
Expand Down Expand Up @@ -142,6 +144,7 @@ export default class LengthTool extends BaseAnnotationTool {
const {
handleRadius,
drawHandlesOnHover,
hideHandlesIfMoving,
renderDashed,
} = this.configuration;
const toolData = getToolState(evt.currentTarget, this.name);
Expand Down Expand Up @@ -191,6 +194,7 @@ export default class LengthTool extends BaseAnnotationTool {
color,
handleRadius,
drawHandlesIfActive: drawHandlesOnHover,
hideHandlesIfMoving,
};

if (this.configuration.drawHandles) {
Expand Down
4 changes: 4 additions & 0 deletions src/tools/annotation/RectangleRoiTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export default class RectangleRoiTool extends BaseAnnotationTool {
supportedInteractionTypes: ['Mouse', 'Touch'],
configuration: {
drawHandles: true,
drawHandlesOnHover: false,
hideHandlesIfMoving: false,
renderDashed: false,
// showMinMax: false,
// showHounsfieldUnits: true
Expand Down Expand Up @@ -171,6 +173,7 @@ export default class RectangleRoiTool extends BaseAnnotationTool {
const {
handleRadius,
drawHandlesOnHover,
hideHandlesIfMoving,
renderDashed,
} = this.configuration;
const context = getNewContext(eventData.canvasContext.canvas);
Expand Down Expand Up @@ -200,6 +203,7 @@ export default class RectangleRoiTool extends BaseAnnotationTool {
color,
handleRadius,
drawHandlesIfActive: drawHandlesOnHover,
hideHandlesIfMoving,
};

setShadow(context, this.configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function(
};

handle.active = true;
handle.moving = true;
state.isToolLocked = true;

element.addEventListener(EVENTS.MOUSE_DRAG, _dragCallback);
Expand Down
8 changes: 7 additions & 1 deletion src/tools/annotation/bidirectionalTool/renderToolData.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import getPixelSpacing from '../../../util/getPixelSpacing';
export default function(evt) {
const eventData = evt.detail;
const { element, canvasContext, image } = eventData;
const { handleRadius, drawHandlesOnHover, renderDashed } = this.configuration;
const {
handleRadius,
drawHandlesOnHover,
hideHandlesIfMoving,
renderDashed,
} = this.configuration;

const lineDash = getModule('globalConfiguration').configuration.lineDash;

Expand Down Expand Up @@ -102,6 +107,7 @@ export default function(evt) {
color,
handleRadius,
drawHandlesIfActive: drawHandlesOnHover,
hideHandlesIfMoving,
};

// Draw the handles
Expand Down

0 comments on commit e2c2906

Please sign in to comment.