diff --git a/Packages/ohif-core/client/components/base/mixins/formItem.js b/Packages/ohif-core/client/components/base/mixins/formItem.js index cbf628cd5..6b499fda7 100644 --- a/Packages/ohif-core/client/components/base/mixins/formItem.js +++ b/Packages/ohif-core/client/components/base/mixins/formItem.js @@ -183,7 +183,7 @@ OHIF.mixins.formItem = new OHIF.Mixin({ } // Create the data document for validation - const document = OHIF.blaze.getNestedObject({ + const document = OHIF.object.getNestedObject({ [key]: component.value() }); diff --git a/Packages/ohif-core/client/lib/cornerstone.js b/Packages/ohif-core/client/lib/cornerstone.js new file mode 100644 index 000000000..3e50d2ae0 --- /dev/null +++ b/Packages/ohif-core/client/lib/cornerstone.js @@ -0,0 +1,28 @@ +import { OHIF } from 'meteor/ohif:core'; + +OHIF.cornerstone = {}; + +OHIF.cornerstone.pixelToPage = (element, position) => { + const enabledElement = cornerstone.getEnabledElement(element); + const result = { + x: 0, + y: 0 + }; + + // Stop here if the cornerstone element is not enabled or position is not an object + if (!enabledElement || typeof position !== 'object') { + return result; + } + + const canvas = enabledElement.canvas; + + const canvasOffset = $(canvas).offset(); + result.x += canvasOffset.left; + result.y += canvasOffset.top; + + const canvasPosition = cornerstone.pixelToCanvas(element, position); + result.x += canvasPosition.x; + result.y += canvasPosition.y; + + return result; +}; diff --git a/Packages/ohif-core/client/lib/index.js b/Packages/ohif-core/client/lib/index.js index e5f55d38f..01579a5b0 100644 --- a/Packages/ohif-core/client/lib/index.js +++ b/Packages/ohif-core/client/lib/index.js @@ -1,4 +1,5 @@ import './blaze.js'; +import './cornerstone.js'; import './object.js'; import './string.js'; import './ui.js'; diff --git a/Packages/ohif-core/client/lib/object.js b/Packages/ohif-core/client/lib/object.js index 4cef24679..658c3e2c7 100644 --- a/Packages/ohif-core/client/lib/object.js +++ b/Packages/ohif-core/client/lib/object.js @@ -3,7 +3,7 @@ import { OHIF } from 'meteor/ohif:core'; OHIF.object = {}; // Transforms a shallow object with keys separated by "." into a nested object -OHIF.blaze.getNestedObject = shallowObject => { +OHIF.object.getNestedObject = shallowObject => { var nestedObject = {}; for (var key in shallowObject) { var value = shallowObject[key]; @@ -27,7 +27,7 @@ OHIF.blaze.getNestedObject = shallowObject => { }; // Transforms a nested object into a shallowObject merging its keys with "." character -OHIF.blaze.getShallowObject = nestedObject => { +OHIF.object.getShallowObject = nestedObject => { var shallowObject = {}; var putValues = function(baseKey, nestedObject, resultObject) { for (var key in nestedObject) { diff --git a/Packages/ohif-lesiontracker/client/components/measurementLocationDialog/measurementLocationDialog.js b/Packages/ohif-lesiontracker/client/components/measurementLocationDialog/measurementLocationDialog.js index 39809e992..b4e871a2e 100644 --- a/Packages/ohif-lesiontracker/client/components/measurementLocationDialog/measurementLocationDialog.js +++ b/Packages/ohif-lesiontracker/client/components/measurementLocationDialog/measurementLocationDialog.js @@ -39,18 +39,24 @@ Template.measurementLocationDialog.onCreated(() => { const measurementApi = instance.data.measurementApi; const timepointApi = instance.data.timepointApi; - const toggleLabel = (measurementData, eventdata, doneCallback) => { - const position = _.clone(eventdata.currentPoints.page); - position.x += 20; - position.y += 20; - + const toggleLabel = (measurementData, eventData, doneCallback) => { + const getHandlePosition = key => _.pick(measurementData.handles[key], ['x', 'y']); + const start = getHandlePosition('start'); + const end = getHandlePosition('end'); + const getDirection = axis => start[axis] < end[axis] ? 1 : -1; + const position = OHIF.cornerstone.pixelToPage(eventData.element, end); + OHIF.measurements.toggleLabelButton({ instance, measurementId: measurementData._id, toolType: measurementData.toolType, - element: eventdata.element, + element: eventData.element, measurementApi: instance.data.measurementApi, - position: position + position: position, + direction: { + x: getDirection('x'), + y: getDirection('y') + } }); }; @@ -111,4 +117,4 @@ Template.measurementLocationDialog.events({ closeHandler(dialog); } -}); \ No newline at end of file +}); diff --git a/Packages/ohif-measurements/client/components/measureFlow/measureFlow.html b/Packages/ohif-measurements/client/components/measureFlow/measureFlow.html index d258b1c03..16ff41b56 100644 --- a/Packages/ohif-measurements/client/components/measureFlow/measureFlow.html +++ b/Packages/ohif-measurements/client/components/measureFlow/measureFlow.html @@ -1,8 +1,8 @@