OHIF-155: tools: textBox anchor (center)
This commit is contained in:
parent
dd7c47bdb7
commit
e7cd285f9c
@ -28,7 +28,7 @@ OHIF.cornerstone.pixelToPage = (element, position) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
OHIF.cornerstone.repositionTextBox = (eventData, measurementData) => {
|
OHIF.cornerstone.repositionTextBox = (eventData, measurementData, config) => {
|
||||||
// Stop here if it's not a measurement creating
|
// Stop here if it's not a measurement creating
|
||||||
if (!measurementData.isCreating) {
|
if (!measurementData.isCreating) {
|
||||||
return;
|
return;
|
||||||
@ -126,6 +126,37 @@ OHIF.cornerstone.repositionTextBox = (eventData, measurementData) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getTextBoxOffset(config, cornerAxis, toolAxis, boxSize) {
|
||||||
|
config = config || {};
|
||||||
|
const centering = config.centering || {};
|
||||||
|
const centerX = !!centering.x;
|
||||||
|
const centerY = !!centering.y;
|
||||||
|
const halfBoxSizeX = boxSize.x / 2;
|
||||||
|
const halfBoxSizeY = boxSize.y / 2;
|
||||||
|
const offset = {
|
||||||
|
x: [],
|
||||||
|
y: []
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cornerAxis === 'x') {
|
||||||
|
const offsetY = centerY ? 0 : halfBoxSizeY;
|
||||||
|
|
||||||
|
offset.x[-1] = centerX ? halfBoxSizeX : 0;
|
||||||
|
offset.x[1] = centerX ? -halfBoxSizeX : -boxSize.x;
|
||||||
|
offset.y[-1] = offsetY;
|
||||||
|
offset.y[1] = offsetY;
|
||||||
|
} else {
|
||||||
|
const offsetX = centerX ? 0 : halfBoxSizeX;
|
||||||
|
|
||||||
|
offset.x[-1] = offsetX;
|
||||||
|
offset.x[1] = offsetX;
|
||||||
|
offset.y[-1] = centerY ? halfBoxSizeY : 0;
|
||||||
|
offset.y[1] = centerY ? -halfBoxSizeY : -boxSize.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
const handles = measurementData.handles;
|
const handles = measurementData.handles;
|
||||||
const textBox = handles.textBox;
|
const textBox = handles.textBox;
|
||||||
|
|
||||||
@ -202,13 +233,11 @@ OHIF.cornerstone.repositionTextBox = (eventData, measurementData) => {
|
|||||||
const boxSize = getTextBoxSizeInPixels(element, bounds);
|
const boxSize = getTextBoxSizeInPixels(element, bounds);
|
||||||
|
|
||||||
textBox[cornerAxis] = cornerAxisPosition;
|
textBox[cornerAxis] = cornerAxisPosition;
|
||||||
textBox[toolAxis] = tool[toolAxis] - (boxSize[toolAxis] / 2);
|
textBox[toolAxis] = tool[toolAxis];
|
||||||
|
|
||||||
// Adjust the text box position reducing its size from the corner axis
|
// Adjust the text box position reducing its size from the corner axis
|
||||||
const isDirectionPositive = directions[cornerAxis] > 0;
|
const textBoxOffset = getTextBoxOffset(config, cornerAxis, toolAxis, boxSize);
|
||||||
if ((foundPlace && !isDirectionPositive) || (!foundPlace && isDirectionPositive)) {
|
textBox[cornerAxis] += textBoxOffset[cornerAxis][directions[cornerAxis]];
|
||||||
textBox[cornerAxis] -= boxSize[cornerAxis];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preventing the text box from partially going outside the canvas area
|
// Preventing the text box from partially going outside the canvas area
|
||||||
const topLeft = cornerstone.pixelToCanvas(element, textBox);
|
const topLeft = cornerstone.pixelToCanvas(element, textBox);
|
||||||
|
|||||||
@ -7,12 +7,15 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
|||||||
|
|
||||||
var toolType = 'bidirectional';
|
var toolType = 'bidirectional';
|
||||||
|
|
||||||
const shadowConfig = Viewerbase.toolManager.getToolDefaultStates().shadowConfig;
|
const toolDefaultStates = Viewerbase.toolManager.getToolDefaultStates();
|
||||||
|
const shadowConfig = toolDefaultStates.shadowConfig;
|
||||||
|
const textBoxConfig = toolDefaultStates.textBoxConfig;
|
||||||
|
|
||||||
var configuration = {
|
var configuration = {
|
||||||
getMeasurementLocationCallback: getMeasurementLocationCallback,
|
getMeasurementLocationCallback: getMeasurementLocationCallback,
|
||||||
changeMeasurementLocationCallback: changeMeasurementLocationCallback,
|
changeMeasurementLocationCallback: changeMeasurementLocationCallback,
|
||||||
...shadowConfig
|
...shadowConfig,
|
||||||
|
textBox: textBoxConfig
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used to cancel tool placement
|
// Used to cancel tool placement
|
||||||
@ -1018,11 +1021,11 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
|||||||
|
|
||||||
var boundingBox = cornerstoneTools.drawTextBox(context,
|
var boundingBox = cornerstoneTools.drawTextBox(context,
|
||||||
textLines,
|
textLines,
|
||||||
canvasTextLocation.x, canvasTextLocation.y, color);
|
canvasTextLocation.x, canvasTextLocation.y, color, config.textBox);
|
||||||
|
|
||||||
data.handles.textBox.boundingBox = boundingBox;
|
data.handles.textBox.boundingBox = boundingBox;
|
||||||
|
|
||||||
OHIF.cornerstone.repositionTextBox(eventData, data);
|
OHIF.cornerstone.repositionTextBox(eventData, data, config.textBox);
|
||||||
|
|
||||||
// Draw linked line as dashed
|
// Draw linked line as dashed
|
||||||
var link = {
|
var link = {
|
||||||
|
|||||||
@ -7,7 +7,9 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
|||||||
|
|
||||||
const toolType = 'nonTarget';
|
const toolType = 'nonTarget';
|
||||||
|
|
||||||
const shadowConfig = Viewerbase.toolManager.getToolDefaultStates().shadowConfig;
|
const toolDefaultStates = Viewerbase.toolManager.getToolDefaultStates();
|
||||||
|
const shadowConfig = toolDefaultStates.shadowConfig;
|
||||||
|
const textBoxConfig = toolDefaultStates.textBoxConfig;
|
||||||
|
|
||||||
const configuration = {
|
const configuration = {
|
||||||
getMeasurementLocationCallback: getMeasurementLocationCallback,
|
getMeasurementLocationCallback: getMeasurementLocationCallback,
|
||||||
@ -15,7 +17,9 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
|||||||
drawHandles: false,
|
drawHandles: false,
|
||||||
drawHandlesOnHover: true,
|
drawHandlesOnHover: true,
|
||||||
arrowFirst: true,
|
arrowFirst: true,
|
||||||
...shadowConfig
|
textBox: textBoxConfig,
|
||||||
|
...shadowConfig,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used to cancel tool placement
|
// Used to cancel tool placement
|
||||||
@ -253,10 +257,11 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
|||||||
// Draw the text
|
// Draw the text
|
||||||
if (data.measurementNumber) {
|
if (data.measurementNumber) {
|
||||||
|
|
||||||
var boundingBox = cornerstoneTools.drawTextBox(context, `Non-Target ${data.measurementNumber}`, canvasTextLocation.x, canvasTextLocation.y, color);
|
var textLine = `Non-Target ${data.measurementNumber}`;
|
||||||
|
var boundingBox = cornerstoneTools.drawTextBox(context, textLine, canvasTextLocation.x, canvasTextLocation.y, color, config.textBox);
|
||||||
data.handles.textBox.boundingBox = boundingBox;
|
data.handles.textBox.boundingBox = boundingBox;
|
||||||
|
|
||||||
OHIF.cornerstone.repositionTextBox(eventData, data);
|
OHIF.cornerstone.repositionTextBox(eventData, data, config.textBox);
|
||||||
|
|
||||||
// Draw linked line as dashed
|
// Draw linked line as dashed
|
||||||
var link = {
|
var link = {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import { Viewerbase } from 'meteor/ohif:viewerbase';
|
||||||
|
|
||||||
(function($, cornerstone, cornerstoneMath, cornerstoneTools) {
|
(function($, cornerstone, cornerstoneMath, cornerstoneTools) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -12,12 +14,16 @@
|
|||||||
"toolResponse": "EX"
|
"toolResponse": "EX"
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
const toolDefaultStates = Viewerbase.toolManager.getToolDefaultStates();
|
||||||
|
const textBoxConfig = toolDefaultStates.textBoxConfig;
|
||||||
|
|
||||||
var configuration = {
|
var configuration = {
|
||||||
getMeasurementLocationCallback: getMeasurementLocationCallback,
|
getMeasurementLocationCallback: getMeasurementLocationCallback,
|
||||||
changeMeasurementLocationCallback: changeMeasurementLocationCallback,
|
changeMeasurementLocationCallback: changeMeasurementLocationCallback,
|
||||||
drawHandles: false,
|
drawHandles: false,
|
||||||
drawHandlesOnHover: false,
|
drawHandlesOnHover: false,
|
||||||
arrowFirst: true
|
arrowFirst: true,
|
||||||
|
textBox: textBoxConfig
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used to cancel tool placement
|
// Used to cancel tool placement
|
||||||
@ -290,7 +296,8 @@
|
|||||||
context.lineTo(canvasTextLocation.x + 20, canvasTextLocation.y + 20);
|
context.lineTo(canvasTextLocation.x + 20, canvasTextLocation.y + 20);
|
||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
var boundingBox = cornerstoneTools.drawTextBox(context, `Target ${data.measurementNumber}`, canvasTextLocation.x, canvasTextLocation.y, color);
|
var textLine = `Target ${data.measurementNumber}`;
|
||||||
|
var boundingBox = cornerstoneTools.drawTextBox(context, textLine, canvasTextLocation.x, canvasTextLocation.y, color, config.textBox);
|
||||||
data.handles.textBox.boundingBox = boundingBox;
|
data.handles.textBox.boundingBox = boundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,6 +38,12 @@ let toolDefaultStates = {
|
|||||||
shadowColor: '#000000',
|
shadowColor: '#000000',
|
||||||
shadowOffsetX: 0,
|
shadowOffsetX: 0,
|
||||||
shadowOffsetY: 0
|
shadowOffsetY: 0
|
||||||
|
},
|
||||||
|
textBoxConfig: {
|
||||||
|
centering: {
|
||||||
|
x: true,
|
||||||
|
y: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user