diff --git a/inception/inception-diam-editor/src/main/ts/src/AnnotationsByLabelList.svelte b/inception/inception-diam-editor/src/main/ts/src/AnnotationsByLabelList.svelte index 2f804762b21..4f385f269f2 100644 --- a/inception/inception-diam-editor/src/main/ts/src/AnnotationsByLabelList.svelte +++ b/inception/inception-diam-editor/src/main/ts/src/AnnotationsByLabelList.svelte @@ -32,15 +32,20 @@ import { compareSpanText, groupBy, renderLabel, uniqueLabels } from "./Utils"; import { sortByScore, recommendationsFirst } from "./AnnotationBrowserState" - export let ajaxClient: DiamAjax; - export let data: AnnotatedText; - export let pinnedGroups: string[]; + export let ajaxClient: DiamAjax + export let data: AnnotatedText + export let pinnedGroups: string[] - let groupedAnnotations: Record; - let sortedLabels: string[]; + let groupedAnnotations: Record + let groups: { label: string, collapsed: boolean }[] + let collapsedGroups = new Set() $: { - sortedLabels = [...pinnedGroups, ...uniqueLabels(data).filter(v => !pinnedGroups.includes(v))] + const sortedLabels = [...pinnedGroups, ...uniqueLabels(data).filter(v => !pinnedGroups.includes(v))] + + groups = sortedLabels.map(label => { + return { label: label, collapsed: collapsedGroups.has(label) }; + }); const relations = data?.relations.values() || [] const spans = data?.spans.values() || [] @@ -97,9 +102,32 @@ function mouseOverAnnotation(event: MouseEvent, annotation: Annotation) { event.target.dispatchEvent(new AnnotationOverEvent(annotation, event)) } + function mouseOutAnnotation(event: MouseEvent, annotation: Annotation) { event.target.dispatchEvent(new AnnotationOutEvent(annotation, event)) } + + function toggleCollapsed(group) { + if (!collapsedGroups.has(group.label)) { + collapsedGroups.add(group.label) + } + else { + collapsedGroups.delete(group.label) + } + data = data // Trigger reactive update + } + + function collapseAll() { + for (const group of groups) { + collapsedGroups.add(group.label) + } + data = data // Trigger reactive update + } + + function expandAll() { + collapsedGroups.clear() + data = data // Trigger reactive update + } {#if !data} @@ -111,7 +139,7 @@ {:else} -
+
Suggestions first
+
+ + +
- {#if sortedLabels || sortedLabels?.length} + {#if groups || groups?.length}
    - {#each sortedLabels as label} + {#each groups as group}
  • +
    toggleCollapsed(group)} > - {label || "No label"} + + {group.label || "No label"}
    -
      - {#if groupedAnnotations[label]} - {#each groupedAnnotations[label] as ann} +
        + {#if groupedAnnotations[group.label]} + {#each groupedAnnotations[group.label] as ann}
      • .list-group-item:last-child { border-bottom-width: 1px; } + + .group-collapsed { + transform: rotate(-90deg); + } diff --git a/inception/inception-diam-editor/src/main/ts/src/AnnotationsByLayerList.svelte b/inception/inception-diam-editor/src/main/ts/src/AnnotationsByLayerList.svelte index d908231e2f9..08e7f419c90 100644 --- a/inception/inception-diam-editor/src/main/ts/src/AnnotationsByLayerList.svelte +++ b/inception/inception-diam-editor/src/main/ts/src/AnnotationsByLayerList.svelte @@ -37,10 +37,15 @@ export let data: AnnotatedText; let groupedAnnotations: Record; - let sortedLayers: Layer[]; + let groups: { layer: Layer, collapsed: boolean }[] + let collapsedGroups = new Set() $: { - sortedLayers = uniqueLayers(data) + const sortedLayers = uniqueLayers(data) + + groups = sortedLayers.map(layer => { + return { layer: layer, collapsed: collapsedGroups.has(layer.id) }; + }); const relations = data?.relations.values() || [] const spans = data?.spans.values() || [] @@ -97,9 +102,32 @@ function mouseOverAnnotation(event: MouseEvent, annotation: Annotation) { event.target.dispatchEvent(new AnnotationOverEvent(annotation, event)) } + function mouseOutAnnotation(event: MouseEvent, annotation: Annotation) { event.target.dispatchEvent(new AnnotationOutEvent(annotation, event)) } + + function toggleCollapsed(group) { + if (!collapsedGroups.has(group.layer.id)) { + collapsedGroups.add(group.layer.id) + } + else { + collapsedGroups.delete(group.layer.id) + } + data = data // Trigger reactive update + } + + function collapseAll() { + for (const group of groups) { + collapsedGroups.add(group.layer.id) + } + data = data // Trigger reactive update + } + + function expandAll() { + collapsedGroups.clear() + data = data // Trigger reactive update + } {#if !data} @@ -111,7 +139,7 @@
{:else} -
+
Suggestions first
+
+ + +
- {#if sortedLayers || sortedLayers?.length} + {#if groups || groups?.length}
    - {#each sortedLayers as layer} + {#each groups as group}
  • +
    toggleCollapsed(group)} > - {layer.name} + + {group.layer.name}
    -
      - {#if groupedAnnotations[layer.name]} - {#each groupedAnnotations[layer.name] as ann} +
        + {#if groupedAnnotations[group.layer.name]} + {#each groupedAnnotations[group.layer.name] as ann}
      • .list-group-item:last-child { border-bottom-width: 1px; } + + .group-collapsed { + transform: rotate(-90deg); + }