Fixing text callouts behavior for arrow target tools

This commit is contained in:
Bruno Alves de Faria 2017-11-22 08:29:54 -02:00
parent 5bf2d75d4f
commit cbc87aebf8

View File

@ -1,4 +1,4 @@
import { Viewerbase } from 'meteor/ohif:viewerbase';
import { OHIF } from 'meteor/ohif:core';
import { cornerstone, cornerstoneMath, cornerstoneTools } from 'meteor/ohif:cornerstone';
var responseByToolType = [{
@ -12,7 +12,7 @@ var responseByToolType = [{
"toolResponse": "EX"
}];
const toolDefaultStates = Viewerbase.toolManager.getToolDefaultStates();
const toolDefaultStates = OHIF.viewerbase.toolManager.getToolDefaultStates();
const textBoxConfig = toolDefaultStates.textBoxConfig;
var configuration = {
@ -137,6 +137,7 @@ function createQualitativeTargetTool(toolType) {
// create the measurement data for this tool with the end handle activated
var measurementData = {
isCreating: true,
visible: true,
active: true,
handles: {
@ -279,24 +280,67 @@ function createQualitativeTargetTool(toolType) {
// Draw the text
if (data.measurementNumber) {
var textLines = [`Target ${data.measurementNumber}`, response];
var boundingBox = cornerstoneTools.drawTextBox(
context,
textLines,
canvasTextLocation.x,
canvasTextLocation.y,
color,
config.textBox
);
data.handles.textBox.boundingBox = boundingBox;
OHIF.cornerstone.repositionTextBox(eventData, data, config.textBox);
// Draw linked line as dashed
var mid = {
x: (handleStartCanvas.x + handleEndCanvas.x) / 2,
y: (handleStartCanvas.y + handleEndCanvas.y) / 2
var link = {
start: {},
end: {}
};
var midpointCanvas = {
x: (handleStartCanvas.x + handleEndCanvas.x) / 2,
y: (handleStartCanvas.y + handleEndCanvas.y) / 2,
};
var points = [ handleStartCanvas, handleEndCanvas, midpointCanvas ];
link.end.x = canvasTextLocation.x;
link.end.y = canvasTextLocation.y;
link.start = cornerstoneMath.point.findClosestPoint(points, link.end);
var boundingBoxPoints = [ {
// Top middle point of bounding box
x: boundingBox.left + boundingBox.width / 2,
y: boundingBox.top
}, {
// Left middle point of bounding box
x: boundingBox.left,
y: boundingBox.top + boundingBox.height / 2
}, {
// Bottom middle point of bounding box
x: boundingBox.left + boundingBox.width / 2,
y: boundingBox.top + boundingBox.height
}, {
// Right middle point of bounding box
x: boundingBox.left + boundingBox.width,
y: boundingBox.top + boundingBox.height / 2
},
];
link.end = cornerstoneMath.point.findClosestPoint(boundingBoxPoints, link.start);
context.beginPath();
context.strokeStyle = color;
context.lineWidth = lineWidth;
context.setLineDash([2, 3]);
context.setLineDash([ 2, 3 ]);
context.moveTo(mid.x, mid.y);
context.lineTo(canvasTextLocation.x + 20, canvasTextLocation.y + 20);
context.moveTo(link.start.x, link.start.y);
context.lineTo(link.end.x, link.end.y);
context.stroke();
var textLines = [`Target ${data.measurementNumber}`, response];
var boundingBox = cornerstoneTools.drawTextBox(context, textLines, canvasTextLocation.x, canvasTextLocation.y, color, config.textBox);
data.handles.textBox.boundingBox = boundingBox;
}
context.restore();