Skip to content

Commit 1296258

Browse files
authored
fix: πŸ› Make crosshair handle thickness configurable. fix bug (#121)
* fix: πŸ› Make crosshair handle thickness configurable. fix bug Make crosshair handle thickness configurable, and make it look less like a child drew them by default. Fix a bug where you could scroll the crosshairs offscreen.
1 parent 3bab781 commit 1296258

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

β€Žsrc/VTKViewport/vtkInteractorStyleRotatableMPRCrosshairs.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,39 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) {
437437
p[1] + unitVector[1] * displayCoordintateScrollIncrement,
438438
];
439439

440+
// Clip to box defined by the crosshairs extent
441+
442+
let lowX;
443+
let highX;
444+
let lowY;
445+
let highY;
446+
447+
if (lowToHighPoints[0].x < lowToHighPoints[1].x) {
448+
lowX = lowToHighPoints[0].x;
449+
highX = lowToHighPoints[1].x;
450+
} else {
451+
lowX = lowToHighPoints[1].x;
452+
highX = lowToHighPoints[0].x;
453+
}
454+
455+
if (lowToHighPoints[0].y < lowToHighPoints[1].y) {
456+
lowY = lowToHighPoints[0].y;
457+
highY = lowToHighPoints[1].y;
458+
} else {
459+
lowY = lowToHighPoints[1].y;
460+
highY = lowToHighPoints[0].y;
461+
}
462+
463+
newCenterPointSVG[0] = Math.min(
464+
Math.max(newCenterPointSVG[0], lowX),
465+
highX
466+
);
467+
468+
newCenterPointSVG[1] = Math.min(
469+
Math.max(newCenterPointSVG[1], lowY),
470+
highY
471+
);
472+
440473
// translate to the display coordinates.
441474
const displayCoordinate = {
442475
x: newCenterPointSVG[0] / scale,

β€Žsrc/VTKViewport/vtkSVGRotatableCrosshairsWidget.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ function vtkSVGRotatableCrosshairsWidget(publicAPI, model) {
179179
strokeColors,
180180
strokeWidth,
181181
strokeDashArray,
182+
rotateHandleRadius,
182183
apis,
183184
apiIndex,
184185
selectedStrokeWidth,
@@ -242,6 +243,27 @@ function vtkSVGRotatableCrosshairsWidget(publicAPI, model) {
242243
? selectedStrokeWidth
243244
: strokeWidth;
244245

246+
const firstLineShowCrosshairs =
247+
firstLine.selected || firstLineRotateSelected;
248+
const secondLineShowCrosshairs =
249+
secondLine.selected || secondLineRotateSelected;
250+
251+
const firstLineRotateHandleRadius = firstLineShowCrosshairs
252+
? rotateHandleRadius
253+
: 0;
254+
255+
const secondLineRotateHandleRadius = secondLineShowCrosshairs
256+
? rotateHandleRadius
257+
: 0;
258+
259+
const firstLineRotateHandleFill = firstLineRotateSelected
260+
? referenceLines[0].color
261+
: 'none';
262+
263+
const secondLineRotateHandleFill = secondLineRotateSelected
264+
? referenceLines[1].color
265+
: 'none';
266+
245267
if (model.display) {
246268
node.innerHTML = `
247269
<g id="container" fill-opacity="1" stroke-dasharray="none" stroke="none" stroke-opacity="1" fill="none">
@@ -280,11 +302,11 @@ function vtkSVGRotatableCrosshairsWidget(publicAPI, model) {
280302
<!--First line rotateHandle 0 -->
281303
<circle cx="${firstLineRotateHandles[0].x}" cy="${
282304
firstLineRotateHandles[0].y
283-
}" r="10" fill="none" />
305+
}" r="${firstLineRotateHandleRadius}" fill="${firstLineRotateHandleFill}" />
284306
<!--First line rotateHandle 1 -->
285307
<circle cx="${firstLineRotateHandles[1].x}" cy="${
286308
firstLineRotateHandles[1].y
287-
}" r="10" fill="none" />
309+
}" r="${firstLineRotateHandleRadius}" fill="${firstLineRotateHandleFill}" />
288310
</g>
289311
<g
290312
stroke-dasharray="${strokeDashArray}"
@@ -318,11 +340,11 @@ function vtkSVGRotatableCrosshairsWidget(publicAPI, model) {
318340
<!--Second line rotateHandle 0 -->
319341
<circle cx="${secondLineRotateHandles[0].x}" cy="${
320342
secondLineRotateHandles[0].y
321-
}" r="10" fill="none" />
343+
}" r="${secondLineRotateHandleRadius}" fill="${secondLineRotateHandleFill}" />
322344
<!--Second line rotateHandle 1 -->
323345
<circle cx="${secondLineRotateHandles[1].x}" cy="${
324346
secondLineRotateHandles[1].y
325-
}" r="10" fill="none" />
347+
}" r="${secondLineRotateHandleRadius}" fill="${secondLineRotateHandleFill}" />
326348
</g>
327349
<circle cx="${width - 20}" cy="${20}" r="10" fill="${
328350
strokeColors[apiIndex]
@@ -491,8 +513,9 @@ const DEFAULT_VALUES = {
491513
apis: [null, null, null],
492514
referenceLines: [null, null],
493515
strokeColors: ['#e83a0e', '#ede90c', '#07e345'],
494-
strokeWidth: 2,
495-
selectedStrokeWidth: 5,
516+
strokeWidth: 1,
517+
rotateHandleRadius: 5,
518+
selectedStrokeWidth: 3,
496519
centerRadius: 20,
497520
strokeDashArray: '',
498521
display: true,

0 commit comments

Comments
Β (0)