Skip to content

Commit

Permalink
Merge pull request #3702 from inception-project/feature/3701-Improve-…
Browse files Browse the repository at this point in the history
…grouped-by-label-visuals

#3701 - Improve grouped-by-label visuals
  • Loading branch information
reckart authored Jan 8, 2023
2 parents f1bcc78 + c65e531 commit a76a2a5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,39 @@
{#each sortedLabels as label}
{@const spans = groupedSpans[`${label}`] || []}
{@const relations = groupedRelations[`${label}`] || []}
<li class="list-group-item py-1 px-0">
<div class="px-2 py-1 bg.-light fw-bold">
<li class="list-group-item py-1 px-0 border-0">
<div class="px-2 py-1 bg.-light fw-bold sticky-top bg-body">
{label || 'No label'}
</div>
<ul class="ps-3 pe-0">
{#each spans as span}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<li class="list-group-item list-group-item-action py-1 px-2" on:click={() => scrollToSpan(span)}>
<div class="float-end">
<LabelBadge annotation={span} {ajaxClient} />
<li class="list-group-item list-group-item-action p-0 d-flex">
<div class="text-secondary bg-light border-end px-2 d-flex align-items-center">
<div class="annotation-type-marker">␣</div>
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="flex-grow-1 py-1 px-2" on:click={() => scrollToSpan(span)}>
<div class="float-end">
<LabelBadge annotation={span} {ajaxClient} showText={false} />
</div>

<SpanText {data} span={span} />
</div>

<SpanText {data} span={span} />
</li>
{/each}
{#each relations as relation}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<li class="list-group-item list-group-item-action py-1 px-2" on:click={() => scrollToRelation(relation)}>
<div class="float-end">
<LabelBadge annotation={relation} {ajaxClient} />
<li class="list-group-item list-group-item-action p-0 d-flex">
<div class="text-secondary bg-light border-end px-2 d-flex align-items-center">
<div class="annotation-type-marker">→</div>
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="flex-grow-1 py-1 px-2" on:click={() => scrollToRelation(relation)}>
<div class="float-end">
<LabelBadge annotation={relation} {ajaxClient} showText={false} />
</div>

<SpanText {data} span={relation.arguments[0].target} />
</div>

<SpanText {data} span={relation.arguments[0].target} />
</li>
{/each}
</ul>
Expand All @@ -85,6 +95,9 @@
</div>

<style lang="scss">
.annotation-type-marker {
width: 1em;
text-align: center;
}
</style>

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
import {
AnnotatedText,
Annotation,
DiamAjax,
Offsets,
Relation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
export let annotation: Annotation;
export let ajaxClient: DiamAjax;
export let showText: boolean = true;
$: backgroundColor = annotation.color || "var(--bs-secondary)";
$: textColor = bgToFgColor(backgroundColor);
Expand All @@ -38,7 +39,7 @@
title={`${annotation.vid}@${annotation.layer.name}`}
role="button" style="color: {textColor}; background-color: {backgroundColor}"
>
{annotation.label || "No label"}
{showText ? annotation.label || "No label" : "\u00A0"}
</span>

<style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
$: begin = span.offsets[0][0]
$: end = span.offsets[0][1]
$: text = data.text.substring(begin, end)
$: text = data.text.substring(begin, end).trim()
</script>

{#if text.length === 0}
<span class="text-muted">(empty span)</span>
{:else}
<span>{text.substring(0, 50)+(text.length > 50 ? '' : '')}</span>
{/if}

<style>
</style>
9 changes: 8 additions & 1 deletion inception/inception-diam-editor/src/main/ts/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,18 @@ export function groupBy<T> (data: IterableIterator<T>, keyMapper: (s: T) => stri
export function groupSpansByLabel (data: AnnotatedText): Record<string, Span[]> {
const groups = groupBy(data?.spans.values(), (s) => s.label || '')
for (const items of Object.values(groups)) {
items.sort((a, b) => compareOffsets(a.offsets[0], b.offsets[0]))
items.sort((a, b) => compareSpanText(data, a, b) || compareOffsets(a.offsets[0], b.offsets[0]))
}
return groups
}

export function compareSpanText (data: AnnotatedText, a: Span, b: Span): number {
const textA = data.text?.substring(a.offsets[0][0], a.offsets[0][1]) || ''
const textB = data.text?.substring(b.offsets[0][0], b.offsets[0][1]) || ''

return textA.localeCompare(textB)
}

/**
* Groups relations by label.
*
Expand Down

0 comments on commit a76a2a5

Please sign in to comment.