-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathdrawHeight.js
More file actions
48 lines (44 loc) · 1.43 KB
/
drawHeight.js
File metadata and controls
48 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import external from './../externalModules.js';
import path from './path.js';
/**
* Draw a line between `start` and `end`.
*
* @public
* @method drawHeight
* @memberof Drawing
*
* @param {CanvasRenderingContext2D} context
* @param {HTMLElement} element - The DOM Element to draw on
* @param {Object} start - `{ x, y } in either pixel or canvas coordinates.
* @param {Object} end - `{ x, y }` in either pixel or canvas coordinates.
* @param {Object} options - See {@link path}
* @param {String} [coordSystem='pixel'] - Can be "pixel" (default) or "canvas". The coordinate
* @param {Number} initialRotation - Ellipse initial rotation
* system of the points passed in to the function. If "pixel" then cornerstone.pixelToCanvas
* is used to transform the points from pixel to canvas coordinates.
* @returns {undefined}
*/
export default function(
context,
element,
start,
end,
options,
coordSystem = 'pixel'
) {
if (coordSystem === 'pixel') {
const cornerstone = external.cornerstone;
start = cornerstone.pixelToCanvas(element, start);
end = cornerstone.pixelToCanvas(element, end);
}
// Calc midle in start and end:
const midX = end.x + (start.x - end.x) / 2;
// Let midY = end.y + (end.y - start.y) / 2;
// Render:
path(context, options, context => {
context.moveTo(start.x, start.y);
context.lineTo(midX, start.y);
context.lineTo(midX, end.y);
context.lineTo(end.x, end.y);
});
}