LT-370: Repositioning the Add label button
This commit is contained in:
parent
d2095f3cb7
commit
bcbd1a4465
@ -183,7 +183,7 @@ OHIF.mixins.formItem = new OHIF.Mixin({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the data document for validation
|
// Create the data document for validation
|
||||||
const document = OHIF.blaze.getNestedObject({
|
const document = OHIF.object.getNestedObject({
|
||||||
[key]: component.value()
|
[key]: component.value()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
28
Packages/ohif-core/client/lib/cornerstone.js
Normal file
28
Packages/ohif-core/client/lib/cornerstone.js
Normal file
@ -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;
|
||||||
|
};
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import './blaze.js';
|
import './blaze.js';
|
||||||
|
import './cornerstone.js';
|
||||||
import './object.js';
|
import './object.js';
|
||||||
import './string.js';
|
import './string.js';
|
||||||
import './ui.js';
|
import './ui.js';
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { OHIF } from 'meteor/ohif:core';
|
|||||||
OHIF.object = {};
|
OHIF.object = {};
|
||||||
|
|
||||||
// Transforms a shallow object with keys separated by "." into a nested object
|
// Transforms a shallow object with keys separated by "." into a nested object
|
||||||
OHIF.blaze.getNestedObject = shallowObject => {
|
OHIF.object.getNestedObject = shallowObject => {
|
||||||
var nestedObject = {};
|
var nestedObject = {};
|
||||||
for (var key in shallowObject) {
|
for (var key in shallowObject) {
|
||||||
var value = shallowObject[key];
|
var value = shallowObject[key];
|
||||||
@ -27,7 +27,7 @@ OHIF.blaze.getNestedObject = shallowObject => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Transforms a nested object into a shallowObject merging its keys with "." character
|
// Transforms a nested object into a shallowObject merging its keys with "." character
|
||||||
OHIF.blaze.getShallowObject = nestedObject => {
|
OHIF.object.getShallowObject = nestedObject => {
|
||||||
var shallowObject = {};
|
var shallowObject = {};
|
||||||
var putValues = function(baseKey, nestedObject, resultObject) {
|
var putValues = function(baseKey, nestedObject, resultObject) {
|
||||||
for (var key in nestedObject) {
|
for (var key in nestedObject) {
|
||||||
|
|||||||
@ -39,18 +39,24 @@ Template.measurementLocationDialog.onCreated(() => {
|
|||||||
const measurementApi = instance.data.measurementApi;
|
const measurementApi = instance.data.measurementApi;
|
||||||
const timepointApi = instance.data.timepointApi;
|
const timepointApi = instance.data.timepointApi;
|
||||||
|
|
||||||
const toggleLabel = (measurementData, eventdata, doneCallback) => {
|
const toggleLabel = (measurementData, eventData, doneCallback) => {
|
||||||
const position = _.clone(eventdata.currentPoints.page);
|
const getHandlePosition = key => _.pick(measurementData.handles[key], ['x', 'y']);
|
||||||
position.x += 20;
|
const start = getHandlePosition('start');
|
||||||
position.y += 20;
|
const end = getHandlePosition('end');
|
||||||
|
const getDirection = axis => start[axis] < end[axis] ? 1 : -1;
|
||||||
|
const position = OHIF.cornerstone.pixelToPage(eventData.element, end);
|
||||||
|
|
||||||
OHIF.measurements.toggleLabelButton({
|
OHIF.measurements.toggleLabelButton({
|
||||||
instance,
|
instance,
|
||||||
measurementId: measurementData._id,
|
measurementId: measurementData._id,
|
||||||
toolType: measurementData.toolType,
|
toolType: measurementData.toolType,
|
||||||
element: eventdata.element,
|
element: eventData.element,
|
||||||
measurementApi: instance.data.measurementApi,
|
measurementApi: instance.data.measurementApi,
|
||||||
position: position
|
position: position,
|
||||||
|
direction: {
|
||||||
|
x: getDirection('x'),
|
||||||
|
y: getDirection('y')
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<div class="measure-flow {{#if this.threeColumns}}tree-columns{{/if}} {{instance.state.get}}"
|
<div class="measure-flow {{#if this.threeColumns}}tree-columns{{/if}} {{instance.state.get}}"
|
||||||
style="top:{{choose position.y 0}}px; left:{{choose position.x 0}}px"
|
style="top:{{choose position.y 0}}px; left:{{choose position.x 0}}px"
|
||||||
tabindex="-1">
|
tabindex="-1">
|
||||||
<button class="btn-add">
|
<button class="btn-add" style="visibility: hidden">
|
||||||
{{#if this.measurement.location}}Edit{{else}}Add{{/if}} label
|
{{#if this.measurement.location}}Edit{{else}}Add{{/if}} label
|
||||||
</button>
|
</button>
|
||||||
{{#if eq instance.state.get 'selected'}}
|
{{#if eq instance.state.get 'selected'}}
|
||||||
|
|||||||
@ -76,17 +76,39 @@ Template.measureFlow.onCreated(() => {
|
|||||||
|
|
||||||
Template.measureFlow.onRendered(() => {
|
Template.measureFlow.onRendered(() => {
|
||||||
const instance = Template.instance();
|
const instance = Template.instance();
|
||||||
|
const $measureFlow = instance.$('.measure-flow');
|
||||||
|
const $btnAdd = instance.$('.btn-add');
|
||||||
|
|
||||||
// Make the measure flow bounded by the window borders
|
// Make the measure flow bounded by the window borders
|
||||||
instance.$('.measure-flow').bounded();
|
$measureFlow.bounded();
|
||||||
|
|
||||||
instance.$('.btn-add').focus();
|
$btnAdd.focus();
|
||||||
|
|
||||||
if (instance.data.autoClick) {
|
if (instance.data.autoClick) {
|
||||||
instance.$('.btn-add').hide().trigger('click', {
|
$btnAdd.trigger('click', {
|
||||||
clientX: instance.data.position.x,
|
clientX: instance.data.position.x,
|
||||||
clientY: instance.data.position.Y
|
clientY: instance.data.position.Y
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
if (instance.data.direction) {
|
||||||
|
const direction = instance.data.direction;
|
||||||
|
let { left, top } = $measureFlow.offset();
|
||||||
|
|
||||||
|
left = direction.x === -1 ? left -= $btnAdd.outerWidth() : left;
|
||||||
|
top = direction.y === -1 ? top -= $btnAdd.outerHeight() : top;
|
||||||
|
|
||||||
|
const distance = 5;
|
||||||
|
left += direction.x * distance;
|
||||||
|
top += direction.y * distance;
|
||||||
|
|
||||||
|
$measureFlow.css({
|
||||||
|
left,
|
||||||
|
top
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display the button after reposition it
|
||||||
|
$btnAdd.css('visibility', '');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,7 @@ OHIF.measurements.toggleLabelButton = options => {
|
|||||||
const data = {
|
const data = {
|
||||||
measurement,
|
measurement,
|
||||||
position: options.position,
|
position: options.position,
|
||||||
|
direction: options.direction,
|
||||||
threeColumns: true,
|
threeColumns: true,
|
||||||
hideCommon: true,
|
hideCommon: true,
|
||||||
autoClick: options.autoClick,
|
autoClick: options.autoClick,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user