Skip to content

Commit 28c21f9

Browse files
committed
feat: Allow arbitrary key/value metadata on annotations, and display it in the into tooltip
1 parent d680a00 commit 28c21f9

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/components/tools/AnnotationInfo.vue

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { OverlayInfo } from '@/src/composables/annotationTool';
66
77
// These seem to work ¯\_(ツ)_/¯
88
const TOOLTIP_PADDING_X = 30;
9-
const TOOLTIP_PADDING_Y = 20;
9+
const TOOLTIP_PADDING_Y = 10;
1010
1111
const props = defineProps<{
1212
info: OverlayInfo;
@@ -17,6 +17,20 @@ const visible = computed(() => {
1717
return props.info.visible;
1818
});
1919
20+
const metadata = computed(() => {
21+
if (!props.info.visible) return [] as Array<{ key: string; value: string }>;
22+
const meta = props.toolStore.toolByID[props.info.toolID].metadata ?? {};
23+
const sortedMetadata = Object.entries(meta ?? {}).sort((a, b) =>
24+
a[0].localeCompare(b[0])
25+
);
26+
return sortedMetadata.map(([key, value]) => {
27+
return {
28+
key,
29+
value,
30+
};
31+
});
32+
});
33+
2034
const label = computed(() => {
2135
if (!props.info.visible) return '';
2236
return props.toolStore.toolByID[props.info.toolID].labelName;
@@ -50,13 +64,25 @@ const offset = computed(() => {
5064
}"
5165
class="better-contrast"
5266
>
53-
{{ label }}
67+
<div class="tooltip-text font-weight-bold">{{ label }}</div>
68+
<div v-if="metadata.length > 0">
69+
<v-divider></v-divider>
70+
<div v-for="item in metadata" :key="item.key" class="tooltip-text">
71+
{{ item.key }}: {{ item.value }}
72+
</div>
73+
</div>
5474
</v-tooltip>
5575
</template>
5676

5777
<style scoped>
5878
.better-contrast :deep(.v-overlay__content) {
5979
opacity: 1 !important;
6080
background: rgba(255, 255, 255, 0.9) !important;
81+
padding-left: 0;
82+
padding-right: 0;
83+
}
84+
85+
.tooltip-text {
86+
padding: 0 10px;
6187
}
6288
</style>

src/store/__tests__/rulers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ToolID } from '@/src/types/annotation-tool';
88

99
function createRuler(): RequiredWithPartial<
1010
Ruler,
11-
'id' | 'color' | 'strokeWidth' | 'label' | 'labelName' | 'hidden'
11+
'id' | 'color' | 'strokeWidth' | 'label' | 'labelName' | 'hidden' | 'metadata'
1212
> {
1313
return {
1414
firstPoint: [1, 1, 1],

src/types/annotation-tool.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ export type AnnotationTool = {
2828
name: string;
2929

3030
hidden?: boolean;
31+
32+
/*
33+
* Arbitrary key-value pairs associated with the annotation.
34+
*/
35+
metadata?: Record<string, string>;
3136
};

0 commit comments

Comments
 (0)