From d49bfb877ceadfd2f405893dcb4fdc24adeedcc8 Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Wed, 6 Dec 2023 07:43:02 +0100 Subject: [PATCH] #4355 - Limit label length in label rendering utility - Limit label to 300 chars plus ellipsis --- inception/inception-diam-editor/src/main/ts/src/Utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/inception/inception-diam-editor/src/main/ts/src/Utils.ts b/inception/inception-diam-editor/src/main/ts/src/Utils.ts index 6622a017bc6..cf32ca6d5d6 100644 --- a/inception/inception-diam-editor/src/main/ts/src/Utils.ts +++ b/inception/inception-diam-editor/src/main/ts/src/Utils.ts @@ -20,7 +20,13 @@ import { compareOffsets } from '@inception-project/inception-js-api/src/model/Of export function renderLabel (ann?: Annotation): string { if (!ann) return '' - return `${ann.label || `[${ann.layer.name}]`}` + const maxLength = 300 + let label = `${ann.label || `[${ann.layer.name}]`}` + label = label.replace(/\s+/g, ' ').trim() + if (label.length > maxLength) { + label = label.substring(0, maxLength).trim() + '…' + } + return label } export function uniqueLabels (data: AnnotatedText): string[] {