-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from PaulHax/tool-hover
Annotation Tool Hover
- Loading branch information
Showing
25 changed files
with
580 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<script setup lang="ts" generic="ToolID extends string"> | ||
/* global ToolID:readonly */ | ||
import { computed, ref } from 'vue'; | ||
import { useElementSize } from '@vueuse/core'; | ||
import { AnnotationToolStore } from '@/src/store/tools/useAnnotationTool'; | ||
import { OverlayInfo } from '@/src/composables/annotationTool'; | ||
// These seem to work ¯\_(ツ)_/¯ | ||
const TOOLTIP_PADDING_X = 30; | ||
const TOOLTIP_PADDING_Y = 20; | ||
const props = defineProps<{ | ||
info: OverlayInfo<ToolID>; | ||
toolStore: AnnotationToolStore<ToolID>; | ||
}>(); | ||
const visible = computed(() => { | ||
return props.info.visible; | ||
}); | ||
const label = computed(() => { | ||
if (!props.info.visible) return ''; | ||
return props.toolStore.toolByID[props.info.toolID].labelName; | ||
}); | ||
const tooltip = ref(); | ||
const content = computed(() => { | ||
return tooltip.value?.contentEl; | ||
}); | ||
const { width, height } = useElementSize(content); | ||
const offset = computed(() => { | ||
return { | ||
// Tooltip location is above cursor and centered | ||
// Don't know how to get ref to parent v-tooltip element, so adding fudge padding. | ||
x: (width.value + TOOLTIP_PADDING_X) / 2, | ||
y: height.value + TOOLTIP_PADDING_Y, | ||
}; | ||
}); | ||
</script> | ||
|
||
<template> | ||
<v-tooltip | ||
ref="tooltip" | ||
v-if="info.visible" | ||
v-model="visible" | ||
:style="{ | ||
left: `${info.displayXY[0] - offset.x}px`, | ||
top: `${info.displayXY[1] - offset.y}px`, | ||
zIndex: 500, // stay under context menu | ||
}" | ||
class="better-contrast" | ||
> | ||
{{ label }} | ||
</v-tooltip> | ||
</template> | ||
|
||
<style scoped> | ||
.better-contrast :deep(.v-overlay__content) { | ||
opacity: 1 !important; | ||
background: rgba(255, 255, 255, 0.9) !important; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<script setup lang="ts"> | ||
import { computed, ref, watch, toRefs } from 'vue'; | ||
import { ANNOTATION_TOOL_HANDLE_RADIUS } from '@/src/constants'; | ||
import { useViewStore } from '@/src/store/views'; | ||
import { worldToSVG } from '@/src/utils/vtk-helpers'; | ||
import { nonNullable } from '@/src/utils/index'; | ||
import vtkLPSView2DProxy from '@/src/vtk/LPSView2DProxy'; | ||
import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox'; | ||
import { Bounds, Vector3 } from '@kitware/vtk.js/types'; | ||
import { onVTKEvent } from '@/src/composables/onVTKEvent'; | ||
const props = defineProps<{ | ||
points: Array<Vector3>; | ||
viewId: string; | ||
}>(); | ||
const viewStore = useViewStore(); | ||
const viewProxy = computed( | ||
() => viewStore.getViewProxy<vtkLPSView2DProxy>(props.viewId)! | ||
); | ||
const visible = computed(() => { | ||
return props.points.length > 0; | ||
}); | ||
const rectangle = ref({ | ||
x: 0, | ||
y: 0, | ||
width: 0, | ||
height: 0, | ||
}); | ||
const updateRectangle = () => { | ||
const viewRenderer = viewProxy.value.getRenderer(); | ||
const screenBounds = [...vtkBoundingBox.INIT_BOUNDS] as Bounds; | ||
props.points | ||
.map((point) => { | ||
const point2D = worldToSVG(point, viewRenderer); | ||
return point2D; | ||
}) | ||
.filter(nonNullable) | ||
.forEach(([x, y]) => { | ||
vtkBoundingBox.addPoint(screenBounds, x, y, 0); | ||
}); | ||
const [x, y] = vtkBoundingBox.getMinPoint(screenBounds); | ||
const [maxX, maxY] = vtkBoundingBox.getMaxPoint(screenBounds); | ||
// Plus 2 to account for the stroke width | ||
const handleRadius = (ANNOTATION_TOOL_HANDLE_RADIUS + 2) / devicePixelRatio; | ||
const handleDiameter = 2 * handleRadius; | ||
rectangle.value = { | ||
x: x - handleRadius, | ||
y: y - handleRadius, | ||
width: maxX - x + handleDiameter, | ||
height: maxY - y + handleDiameter, | ||
}; | ||
}; | ||
const { points } = toRefs(props); | ||
watch(points, updateRectangle, { immediate: true, deep: true }); | ||
onVTKEvent(viewProxy, 'onModified', updateRectangle); | ||
</script> | ||
|
||
<template> | ||
<rect | ||
v-if="visible" | ||
:x="rectangle.x" | ||
:y="rectangle.y" | ||
:width="rectangle.width" | ||
:height="rectangle.height" | ||
stroke-width="2" | ||
fill="transparent" | ||
stroke="lightgray" | ||
/> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.