Skip to content

Commit

Permalink
fix(bidirectional): Refactor to remove some eventListeners and to fix…
Browse files Browse the repository at this point in the history
… the data once we addNewMeasurement
  • Loading branch information
galelis committed Mar 14, 2019
1 parent 87ca6a0 commit 2bc8692
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 77 deletions.
41 changes: 14 additions & 27 deletions src/tools/annotation/bidirectionalTool/addNewMeasurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,6 @@ export default function(evt, interactionType) {
const doneCallback = () => {
measurementData.active = false;
external.cornerstone.updateImage(element);

const measurementModifiedHandler = () => {
const modifiedEventData = {
toolName: this.name,
element,
measurementData,
};

calculateLongestAndShortestDiameters(eventData, measurementData);

external.cornerstone.triggerEvent(
element,
EVENTS.MEASUREMENT_MODIFIED,
modifiedEventData
);

element.removeEventListener(
external.cornerstone.EVENTS.IMAGE_RENDERED,
measurementModifiedHandler
);
};

// Wait on image render before triggering the modified event
element.addEventListener(
external.cornerstone.EVENTS.IMAGE_RENDERED,
measurementModifiedHandler
);
};

// Associate this data with this imageId so we can render it and manipulate it
Expand Down Expand Up @@ -89,6 +62,20 @@ export default function(evt, interactionType) {
perpendicularStart.locked = false;

external.cornerstone.updateImage(element);

const modifiedEventData = {
toolType: this.name,
element,
measurementData,
};

calculateLongestAndShortestDiameters(eventData, measurementData);

external.cornerstone.triggerEvent(
element,
EVENTS.MEASUREMENT_MODIFIED,
modifiedEventData
);
},
},
interactionType
Expand Down
29 changes: 2 additions & 27 deletions src/tools/annotation/bidirectionalTool/moveHandle/moveHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,13 @@ export default function(
measurementData: data,
};

calculateLongestAndShortestDiameters(mouseEventData, data);

external.cornerstone.triggerEvent(
element,
EVENTS.MEASUREMENT_MODIFIED,
modifiedEventData
);

const measurementModifiedHandler = () => {
const modifiedEventData = {
toolType,
element,
measurementData: data,
};

calculateLongestAndShortestDiameters(mouseEventData, data);

external.cornerstone.triggerEvent(
element,
EVENTS.MEASUREMENT_MODIFIED,
modifiedEventData
);

element.removeEventListener(
external.cornerstone.EVENTS.IMAGE_RENDERED,
measurementModifiedHandler
);
};

// Wait on image render before triggering the modified event
element.addEventListener(
external.cornerstone.EVENTS.IMAGE_RENDERED,
measurementModifiedHandler
);
};

handle.active = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,18 @@ export default function(

external.cornerstone.updateImage(element);

const measurementModifiedHandler = () => {
const modifiedEventData = {
toolType,
element,
measurementData: data,
};

calculateLongestAndShortestDiameters(mouseEventData, data);

external.cornerstone.triggerEvent(
element,
EVENTS.MEASUREMENT_MODIFIED,
modifiedEventData
);

element.removeEventListener(
external.cornerstone.EVENTS.IMAGE_RENDERED,
measurementModifiedHandler
);
const modifiedEventData = {
toolType,
element,
measurementData: data,
};

// Wait on image render before triggering the modified event
element.addEventListener(
external.cornerstone.EVENTS.IMAGE_RENDERED,
measurementModifiedHandler
calculateLongestAndShortestDiameters(mouseEventData, data);

external.cornerstone.triggerEvent(
element,
EVENTS.MEASUREMENT_MODIFIED,
modifiedEventData
);
};

Expand Down

0 comments on commit 2bc8692

Please sign in to comment.