-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathAnnotationInfo.vue
More file actions
86 lines (76 loc) · 2.16 KB
/
AnnotationInfo.vue
File metadata and controls
86 lines (76 loc) · 2.16 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useElementSize } from '@vueuse/core';
import { AnnotationToolStore } from '@/src/store/tools/useAnnotationTool';
import { OverlayInfo } from '@/src/composables/annotationTool';
const TOOLTIP_PADDING_X = 30;
const TOOLTIP_PADDING_Y = 16;
const props = defineProps<{
info: OverlayInfo;
toolStore: AnnotationToolStore;
}>();
const visible = computed(() => {
return props.info.visible;
});
const metadata = computed(() => {
if (!props.info.visible) return [] as Array<{ key: string; value: string }>;
const meta = props.toolStore.toolByID[props.info.toolID].metadata ?? {};
// Preserve insertion order of keys
return Object.entries(meta).map(([key, value]) => {
return {
key,
value,
};
});
});
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"
>
<div class="tooltip-text font-weight-bold">{{ label }}</div>
<div v-if="metadata.length > 0">
<v-divider></v-divider>
<div v-for="item in metadata" :key="item.key" class="tooltip-text">
{{ item.key }}: {{ item.value }}
</div>
</div>
</v-tooltip>
</template>
<style scoped>
.better-contrast :deep(.v-overlay__content) {
opacity: 1 !important;
background: rgba(255, 255, 255, 0.9) !important;
padding-left: 0;
padding-right: 0;
pointer-events: none;
}
.tooltip-text {
padding: 0 10px;
}
</style>