@if (loadingWordCloud) {
Forschungsthemen werden geladen ...
- } @else if (wordCloudOptions) {
-
+ } @else if (wordCloudWords.length) {
+
+ @for (word of wordCloudWords; track word.name) {
+
+ }
+
} @else if (wordCloudEmpty) {
Keine Forschungsthemen gefunden.
}
diff --git a/webapp/src/app/modules/person-overview/person-overview.component.scss b/webapp/src/app/modules/person-overview/person-overview.component.scss
index 7e0732ce..f41a127d 100644
--- a/webapp/src/app/modules/person-overview/person-overview.component.scss
+++ b/webapp/src/app/modules/person-overview/person-overview.component.scss
@@ -11,8 +11,37 @@
.word-cloud-chart {
width: 100%;
- height: 420px;
+ min-height: 420px;
+ display: flex;
+ flex-wrap: wrap;
+ align-content: center;
+ align-items: baseline;
+ justify-content: center;
+ gap: 0.35em 1em;
+ padding: 1.5rem 1rem;
+ box-sizing: border-box;
+}
+
+.word-cloud-word {
+ appearance: none;
+ border: none;
+ background: none;
+ padding: 0;
+ margin: 0;
+ font-family: 'Open Sans', Arial, sans-serif;
+ line-height: 1.1;
cursor: pointer;
+ transition: transform 0.15s ease;
+
+ &:hover:not(:disabled),
+ &:focus-visible {
+ transform: scale(1.08);
+ outline: none;
+ }
+
+ &:disabled {
+ cursor: default;
+ }
}
.word-cloud-state,
diff --git a/webapp/src/app/modules/person-overview/person-overview.component.ts b/webapp/src/app/modules/person-overview/person-overview.component.ts
index 3d30ee16..912efc06 100644
--- a/webapp/src/app/modules/person-overview/person-overview.component.ts
+++ b/webapp/src/app/modules/person-overview/person-overview.component.ts
@@ -2,12 +2,13 @@ import { CommonModule } from '@angular/common';
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
+import { MatTooltipModule } from '@angular/material/tooltip';
import { combineLatest, distinctUntilChanged, map } from 'rxjs';
-import { NgxEchartsDirective } from 'ngx-echarts';
-import type { EChartsOption } from 'echarts';
-import 'echarts-wordcloud';
import { TopicCount, TopicsByYear, WorksService } from '../../api';
+import { topicHierarchyColor } from '../../shared/utils/topic-colors';
+import { TopicLegendTopic } from '../../shared/utils/topic-legend';
+import { buildTopicHierarchyTooltip } from '../../shared/utils/topic-tooltip';
import {
ResearchTimelineComponent,
TimelineViewMode,
@@ -17,10 +18,20 @@ import {
TopicTimelineTopic,
} from './components/research-timeline/research-timeline.component';
+export interface WordCloudWord {
+ name: string;
+ value: number;
+ topicId: string | undefined;
+ color: string;
+ fontSize: number;
+ fontWeight: number;
+ tooltip: string;
+}
+
@Component({
selector: 'app-person-overview',
standalone: true,
- imports: [CommonModule, ResearchTimelineComponent, NgxEchartsDirective],
+ imports: [CommonModule, ResearchTimelineComponent, MatTooltipModule],
templateUrl: './person-overview.component.html',
styleUrl: './person-overview.component.scss',
})
@@ -56,7 +67,8 @@ export class PersonOverviewComponent implements OnInit {
timelineLegendVisible = true;
timelineLegendExpanded = false;
- wordCloudOptions: EChartsOption | null = null;
+ wordCloudWords: WordCloudWord[] = [];
+ wordCloudLegendTopics: TopicLegendTopic[] = [];
loadingWordCloud = false;
wordCloudEmpty = false;
@@ -64,6 +76,12 @@ export class PersonOverviewComponent implements OnInit {
name: string;
topicId: string;
year: number | undefined;
+ fieldId: string | undefined;
+ fieldName: string | undefined;
+ domainId: string | undefined;
+ domainName: string | undefined;
+ subfieldId: string | undefined;
+ subfieldName: string | undefined;
}> = [];
ngOnInit(): void {
@@ -199,17 +217,14 @@ export class PersonOverviewComponent implements OnInit {
this.loadCompleteTopicTimeline(this.currentAuthorId);
}
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- onWordClick(event: any): void {
- const topicId = event?.data?.topicId;
- const topicName = event?.data?.name;
- if (!topicId) return;
+ onWordClick(word: WordCloudWord): void {
+ if (!word.topicId) return;
void this.router.navigate(['../publications'], {
relativeTo: this.route,
queryParams: {
publicationPage: 1,
- publicationTopicId: topicId,
- publicationTopicName: topicName,
+ publicationTopicId: word.topicId,
+ publicationTopicName: word.name,
},
});
}
@@ -331,17 +346,10 @@ export class PersonOverviewComponent implements OnInit {
this.timelineEarlierYearsLoadFailed = false;
}
- private readonly timelineColors = [
- '#7255d9',
- '#2678e8',
- '#39a96b',
- '#f59e0b',
- '#e0527c',
- ];
-
private loadWordCloud(authorId: string): void {
if (!authorId || authorId === '0') {
- this.wordCloudOptions = null;
+ this.wordCloudWords = [];
+ this.wordCloudLegendTopics = [];
this.wordCloudEmpty = false;
this.loadingWordCloud = false;
this.rawTopicOccurrences = [];
@@ -350,7 +358,8 @@ export class PersonOverviewComponent implements OnInit {
this.loadingWordCloud = true;
this.wordCloudEmpty = false;
- this.wordCloudOptions = null;
+ this.wordCloudWords = [];
+ this.wordCloudLegendTopics = [];
this.worksService
.getAuthorWorks(authorId, 1, 100)
@@ -366,6 +375,12 @@ export class PersonOverviewComponent implements OnInit {
name: topic.display_name,
topicId: topic.id,
year,
+ fieldId: topic.field?.id ?? undefined,
+ fieldName: topic.field?.display_name ?? undefined,
+ domainId: topic.domain?.id ?? undefined,
+ domainName: topic.domain?.display_name ?? undefined,
+ subfieldId: topic.subfield?.id ?? undefined,
+ subfieldName: topic.subfield?.display_name ?? undefined,
});
}
});
@@ -374,6 +389,7 @@ export class PersonOverviewComponent implements OnInit {
this.loadingWordCloud = false;
if (this.rawTopicOccurrences.length === 0) {
+ this.wordCloudLegendTopics = [];
this.wordCloudEmpty = true;
return;
}
@@ -383,6 +399,7 @@ export class PersonOverviewComponent implements OnInit {
error: (error) => {
console.error('Word cloud could not be loaded.', error);
this.loadingWordCloud = false;
+ this.wordCloudLegendTopics = [];
this.wordCloudEmpty = true;
},
});
@@ -393,6 +410,7 @@ export class PersonOverviewComponent implements OnInit {
const end = this.timelineEndYear;
const counts = new Map
();
const nameToId = new Map();
+ const nameToColorInput = new Map();
for (const occ of this.rawTopicOccurrences) {
if (start !== undefined && (occ.year === undefined || occ.year < start))
@@ -400,11 +418,24 @@ export class PersonOverviewComponent implements OnInit {
if (end !== undefined && (occ.year === undefined || occ.year > end))
continue;
counts.set(occ.name, (counts.get(occ.name) ?? 0) + 1);
- if (!nameToId.has(occ.name)) nameToId.set(occ.name, occ.topicId);
+ if (!nameToId.has(occ.name)) {
+ nameToId.set(occ.name, occ.topicId);
+ nameToColorInput.set(occ.name, {
+ id: occ.topicId,
+ name: occ.name,
+ field_id: occ.fieldId,
+ field_name: occ.fieldName,
+ domain_id: occ.domainId,
+ domain_name: occ.domainName,
+ subfield_id: occ.subfieldId,
+ subfield_name: occ.subfieldName,
+ });
+ }
}
if (counts.size === 0) {
- this.wordCloudOptions = null;
+ this.wordCloudWords = [];
+ this.wordCloudLegendTopics = [];
this.wordCloudEmpty = true;
return;
}
@@ -414,51 +445,45 @@ export class PersonOverviewComponent implements OnInit {
const allValues = Array.from(counts.values());
const minVal = Math.min(...allValues);
const maxVal = Math.max(...allValues);
- const computeSize = (v: number): number =>
- maxVal === minVal
- ? 22
- : Math.round(12 + ((v - minVal) / (maxVal - minVal)) * (32 - 12));
+ const intensity = (v: number): number =>
+ maxVal === minVal ? 1 : (v - minVal) / (maxVal - minVal);
const sorted = Array.from(counts.entries()).sort((a, b) => b[1] - a[1]);
+ const topNames = sorted.slice(0, 30).map(([name]) => name);
- const data = sorted.slice(0, 30).map(([name, value], i) => {
- const fontSize = computeSize(value);
- const color = this.timelineColors[i % this.timelineColors.length];
+ this.wordCloudLegendTopics = topNames
+ .map((name) => nameToColorInput.get(name))
+ .filter((topic): topic is TopicLegendTopic => Boolean(topic));
+
+ const words = sorted.slice(0, 30).map(([name, value]): WordCloudWord => {
+ const t = intensity(value);
+ const colorInput = nameToColorInput.get(name);
return {
name,
value,
topicId: nameToId.get(name),
- textStyle: { color, fontSize },
- emphasis: {
- textStyle: {
- fontSize: Math.round(fontSize * 1.1),
- color,
- shadowBlur: 16,
- shadowColor: 'rgba(0, 87, 255, 0.35)',
- },
- },
+ color: topicHierarchyColor(colorInput),
+ fontSize: Math.round(12 + t * (32 - 12)),
+ fontWeight: t > 0.66 ? 800 : t > 0.33 ? 600 : 400,
+ tooltip: buildTopicHierarchyTooltip({
+ topicName: name,
+ subfieldName: colorInput?.subfield_name,
+ fieldName: colorInput?.field_name,
+ domainName: colorInput?.domain_name,
+ }),
};
});
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- this.wordCloudOptions = {
- series: [
- {
- type: 'wordCloud',
- rotationRange: [0, 0],
- rotationStep: 0,
- gridSize: 4,
- width: '100%',
- height: '100%',
- drawOutOfBound: false,
- textStyle: {
- fontFamily: 'Open Sans, sans-serif',
- fontWeight: 'bold',
- },
- data,
- },
- ],
- } as any;
+ const centred: WordCloudWord[] = [];
+ words.forEach((word, i) => {
+ if (i % 2 === 0) {
+ centred.push(word);
+ } else {
+ centred.unshift(word);
+ }
+ });
+
+ this.wordCloudWords = centred;
}
private mapTimelineElements(
diff --git a/webapp/src/app/shared/ui/topic-legend/topic-legend.component.html b/webapp/src/app/shared/ui/topic-legend/topic-legend.component.html
new file mode 100644
index 00000000..34c724d1
--- /dev/null
+++ b/webapp/src/app/shared/ui/topic-legend/topic-legend.component.html
@@ -0,0 +1,89 @@
+
+
+
+
+
+ info_outline
+
+
+
+
+
+
+ {{ group.name }}
+
+
+
+
+ {{ item.name }}
+
+
+
+
+
+
+
+
diff --git a/webapp/src/app/shared/ui/topic-legend/topic-legend.component.scss b/webapp/src/app/shared/ui/topic-legend/topic-legend.component.scss
new file mode 100644
index 00000000..fa9fca76
--- /dev/null
+++ b/webapp/src/app/shared/ui/topic-legend/topic-legend.component.scss
@@ -0,0 +1,201 @@
+:host {
+ display: block;
+}
+
+.topic-legend {
+ --topic-legend-accent: #0057ff;
+
+ width: min(760px, 100%);
+ box-sizing: border-box;
+ margin-top: 16px;
+ padding: 13px 16px;
+ border: 1px solid #dbe5f6;
+ border-radius: 8px;
+ background: #ffffff;
+}
+
+.topic-legend-header,
+.topic-legend-title,
+.topic-legend-visibility-toggle,
+.topic-legend-body,
+.topic-legend-content,
+.topic-legend-group,
+.topic-legend-field,
+.topic-legend-items {
+ display: flex;
+ align-items: center;
+}
+
+.topic-legend-header {
+ justify-content: space-between;
+ gap: 16px;
+}
+
+.topic-legend-title {
+ gap: 5px;
+ color: #07163d;
+ font-size: 12px;
+ font-weight: 800;
+ line-height: 1.25;
+}
+
+.topic-legend-info {
+ flex: 0 0 auto;
+ width: 14px;
+ height: 14px;
+ color: #7d8aa8;
+ font-size: 14px;
+ line-height: 14px;
+}
+
+.topic-legend-visibility-toggle,
+.topic-legend-more-toggle {
+ border: 0;
+ background: transparent;
+ color: var(--topic-legend-accent);
+ cursor: pointer;
+ font-family: inherit;
+ font-weight: 700;
+
+ &:hover {
+ text-decoration: none;
+ }
+
+ &:focus-visible {
+ outline: 2px solid var(--topic-legend-accent);
+ outline-offset: 2px;
+ border-radius: 4px;
+ }
+}
+
+.topic-legend-visibility-toggle {
+ flex: 0 0 auto;
+ gap: 4px;
+ padding: 0;
+ font-size: 11px;
+ line-height: 1.2;
+
+ mat-icon {
+ width: 14px;
+ height: 14px;
+ font-size: 14px;
+ line-height: 14px;
+ }
+}
+
+.topic-legend-body {
+ align-items: flex-start;
+ gap: 9px;
+ margin-top: 17px;
+}
+
+.topic-legend-body-inline-info {
+ margin-top: 0;
+}
+
+.topic-legend-content {
+ flex-wrap: wrap;
+ gap: 8px;
+ min-width: 0;
+}
+
+.topic-legend-group {
+ gap: 9px;
+ max-width: 100%;
+ min-width: 0;
+ min-height: 28px;
+ padding: 5px 9px;
+ border: 1px solid #dbe5f6;
+ border-radius: 999px;
+ background: #fbfdff;
+}
+
+.topic-legend-field {
+ flex: 0 1 auto;
+ min-width: 0;
+ gap: 5px;
+ color: #07163d;
+ font-size: 11px;
+ font-weight: 800;
+ line-height: 1.2;
+ cursor: help;
+}
+
+.topic-legend-field span:last-child,
+.topic-legend-item {
+ overflow-wrap: anywhere;
+}
+
+.topic-legend-dot {
+ flex: 0 0 auto;
+ width: 9px;
+ height: 9px;
+ border: 1px solid rgba(255, 255, 255, 0.85);
+ border-radius: 50%;
+ box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.2);
+}
+
+.topic-legend-items {
+ flex: 0 1 auto;
+ flex-wrap: wrap;
+ gap: 6px 11px;
+ min-width: 0;
+}
+
+.topic-legend-item {
+ color: #53617e;
+ font-size: 11px;
+ font-weight: 600;
+ line-height: 1.25;
+ cursor: help;
+}
+
+.topic-legend-more-toggle {
+ flex: 0 0 auto;
+ padding: 0;
+ font-size: 11px;
+ line-height: 1.25;
+}
+
+.topic-legend-compact {
+ width: fit-content;
+ max-width: 100%;
+ margin: 0 0 16px;
+ padding: 8px 10px;
+
+ .topic-legend-body {
+ gap: 9px;
+ }
+
+ .topic-legend-content {
+ gap: 7px;
+ }
+
+ .topic-legend-group {
+ gap: 6px;
+ flex-wrap: wrap;
+ min-height: 24px;
+ padding: 3px 7px;
+ }
+
+ .topic-legend-field,
+ .topic-legend-item {
+ font-size: 10px;
+ }
+
+ .topic-legend-dot {
+ width: 8px;
+ height: 8px;
+ }
+
+ .topic-legend-more-toggle {
+ min-height: 24px;
+ padding: 0 2px;
+ font-size: 11px;
+ white-space: nowrap;
+
+ &:hover {
+ text-decoration: underline;
+ }
+ }
+}
diff --git a/webapp/src/app/shared/ui/topic-legend/topic-legend.component.ts b/webapp/src/app/shared/ui/topic-legend/topic-legend.component.ts
new file mode 100644
index 00000000..171ac204
--- /dev/null
+++ b/webapp/src/app/shared/ui/topic-legend/topic-legend.component.ts
@@ -0,0 +1,76 @@
+import { CommonModule } from '@angular/common';
+import { Component, EventEmitter, Input, Output } from '@angular/core';
+import { MatIconModule } from '@angular/material/icon';
+import { MatTooltipModule } from '@angular/material/tooltip';
+import { TopicLegendGroup, TopicLegendItem } from '../../utils/topic-legend';
+
+export type TopicLegendVariant = 'default' | 'compact';
+
+@Component({
+ selector: 'app-topic-legend',
+ standalone: true,
+ imports: [CommonModule, MatIconModule, MatTooltipModule],
+ templateUrl: './topic-legend.component.html',
+ styleUrl: './topic-legend.component.scss',
+})
+export class TopicLegendComponent {
+ @Input() groups: TopicLegendGroup[] = [];
+ @Input() title = 'Farben nach Fachgebiet';
+ @Input() infoTooltip =
+ 'Fachgebiete bestimmen die Farbe. Themenbereiche werden darunter gruppiert.';
+ @Input() visible = true;
+ @Input() expanded = false;
+ @Input() showTitle = true;
+ @Input() showVisibilityToggle = true;
+ @Input() collapsedGroupLimit = 3;
+ @Input() variant: TopicLegendVariant = 'default';
+
+ @Output() visibleChange = new EventEmitter();
+ @Output() expandedChange = new EventEmitter();
+
+ get hasGroups(): boolean {
+ return this.groups.length > 0;
+ }
+
+ get hasHeader(): boolean {
+ return this.showTitle || this.showVisibilityToggle;
+ }
+
+ get visibleGroups(): TopicLegendGroup[] {
+ if (this.expanded) {
+ return this.groups;
+ }
+
+ return this.groups.slice(0, this.collapsedGroupLimit);
+ }
+
+ get hiddenLegendItemCount(): number {
+ if (this.expanded) {
+ return 0;
+ }
+
+ return this.groups
+ .slice(this.collapsedGroupLimit)
+ .reduce((count, group) => count + group.items.length, 0);
+ }
+
+ get showExpandedToggle(): boolean {
+ return this.expanded || this.hiddenLegendItemCount > 0;
+ }
+
+ toggleVisibility(): void {
+ this.visibleChange.emit(!this.visible);
+ }
+
+ toggleExpanded(): void {
+ this.expandedChange.emit(!this.expanded);
+ }
+
+ trackByGroup(_: number, group: TopicLegendGroup): string {
+ return group.id;
+ }
+
+ trackByItem(_: number, item: TopicLegendItem): string {
+ return item.id;
+ }
+}
diff --git a/webapp/src/app/shared/utils/topic-colors.ts b/webapp/src/app/shared/utils/topic-colors.ts
index 7dfbfc9d..1d2b69d9 100644
--- a/webapp/src/app/shared/utils/topic-colors.ts
+++ b/webapp/src/app/shared/utils/topic-colors.ts
@@ -1,8 +1,6 @@
export interface TopicHierarchyColorInput {
id?: string | null;
name?: string | null;
- subfield_id?: string | null;
- subfield_name?: string | null;
field_id?: string | null;
field_name?: string | null;
domain_id?: string | null;
@@ -52,30 +50,8 @@ const DOMAIN_FALLBACK_HUES: Record = {
'social sciences': 24,
};
-interface SubfieldColorVariant {
- hueOffset: number;
- saturation: number;
- lightness: number;
-}
-
-const SUBFIELD_COLOR_VARIANTS: readonly SubfieldColorVariant[] = [
- { hueOffset: -6, saturation: 92, lightness: 27 },
- { hueOffset: 6, saturation: 82, lightness: 48 },
- { hueOffset: -2, saturation: 90, lightness: 35 },
- { hueOffset: 7, saturation: 78, lightness: 42 },
- { hueOffset: -8, saturation: 86, lightness: 31 },
- { hueOffset: 3, saturation: 94, lightness: 24 },
- { hueOffset: 8, saturation: 84, lightness: 38 },
- { hueOffset: -4, saturation: 80, lightness: 45 },
- { hueOffset: 0, saturation: 92, lightness: 30 },
- { hueOffset: 8, saturation: 76, lightness: 50 },
- { hueOffset: -7, saturation: 88, lightness: 40 },
- { hueOffset: 4, saturation: 80, lightness: 33 },
- { hueOffset: -8, saturation: 82, lightness: 47 },
- { hueOffset: 2, saturation: 96, lightness: 26 },
- { hueOffset: 8, saturation: 86, lightness: 36 },
- { hueOffset: -2, saturation: 78, lightness: 43 },
-];
+const FIELD_COLOR_SATURATION = 86;
+const FIELD_COLOR_LIGHTNESS = 36;
export function topicHierarchyColor(
topic: TopicHierarchyColorInput | undefined | null,
@@ -86,29 +62,22 @@ export function topicHierarchyColor(
const fieldKey = normalizeColorKey(topic.field_name);
const domainKey = normalizeColorKey(topic.domain_name);
- const fieldIdentity =
- topic.field_id ?? fieldKey ?? topic.domain_id ?? domainKey;
- const subfieldIdentity =
- topic.subfield_id ??
- normalizeColorKey(topic.subfield_name) ??
+ const fieldIdentity = topic.field_id ?? fieldKey;
+ const fallbackIdentity =
+ fieldIdentity ??
+ topic.domain_id ??
+ domainKey ??
topic.id ??
normalizeColorKey(topic.name) ??
- fieldIdentity ??
'topic';
const baseHue =
(fieldKey ? FIELD_HUES[fieldKey] : undefined) ??
(domainKey ? DOMAIN_FALLBACK_HUES[domainKey] : undefined) ??
- stableHue(fieldIdentity ?? subfieldIdentity);
+ stableHue(fallbackIdentity);
+ const hue = normalizeHue(baseHue);
- const variantHash = stableHash(subfieldIdentity);
- const variant =
- SUBFIELD_COLOR_VARIANTS[variantHash % SUBFIELD_COLOR_VARIANTS.length];
- const hue = normalizeHue(baseHue + variant.hueOffset);
- const saturation = variant.saturation;
- const lightness = variant.lightness;
-
- return `hsl(${hue} ${saturation}% ${lightness}%)`;
+ return `hsl(${hue} ${FIELD_COLOR_SATURATION}% ${FIELD_COLOR_LIGHTNESS}%)`;
}
function normalizeColorKey(
diff --git a/webapp/src/app/shared/utils/topic-legend.ts b/webapp/src/app/shared/utils/topic-legend.ts
new file mode 100644
index 00000000..a54779c3
--- /dev/null
+++ b/webapp/src/app/shared/utils/topic-legend.ts
@@ -0,0 +1,152 @@
+import { topicHierarchyColor, TopicHierarchyColorInput } from './topic-colors';
+
+export interface TopicLegendTopic extends TopicHierarchyColorInput {
+ subfield_id?: string | null;
+ subfield_name?: string | null;
+ subfield_description?: string | null;
+ field_description?: string | null;
+ domain_description?: string | null;
+}
+
+export interface TopicLegendItem {
+ id: string;
+ name: string;
+ description: string;
+ tooltip: string;
+}
+
+export interface TopicLegendGroup {
+ id: string;
+ name: string;
+ description: string;
+ domainName: string;
+ domainDescription: string;
+ color: string;
+ tooltip: string;
+ items: TopicLegendItem[];
+}
+
+export function buildTopicLegendGroups(
+ topics: readonly TopicLegendTopic[],
+): TopicLegendGroup[] {
+ const groups = new Map();
+
+ for (const topic of topics) {
+ const subfieldName = normalizeLegendValue(topic.subfield_name);
+
+ if (!subfieldName) {
+ continue;
+ }
+
+ const fieldName =
+ normalizeLegendValue(topic.field_name) ?? 'Ohne Fachgebiet';
+ const fieldDescription =
+ normalizeLegendValue(topic.field_description) ?? '';
+ const domainName = normalizeLegendValue(topic.domain_name) ?? '';
+ const domainDescription =
+ normalizeLegendValue(topic.domain_description) ?? '';
+ const subfieldDescription =
+ normalizeLegendValue(topic.subfield_description) ?? '';
+ const fieldKey = topic.field_id ?? normalizeLegendKey(fieldName);
+ const subfieldKey = topic.subfield_id ?? normalizeLegendKey(subfieldName);
+
+ if (!groups.has(fieldKey)) {
+ groups.set(fieldKey, {
+ id: fieldKey,
+ name: fieldName,
+ description: fieldDescription,
+ domainName,
+ domainDescription,
+ color: topicHierarchyColor(topic),
+ tooltip: buildTopicLegendTooltip([
+ {
+ label: 'Fachgebiet',
+ value: fieldName,
+ description: fieldDescription,
+ },
+ {
+ label: 'Wissenschaftsbereich',
+ value: domainName,
+ description: domainDescription,
+ },
+ ]),
+ items: [],
+ });
+ }
+
+ const group = groups.get(fieldKey);
+
+ if (!group || group.items.some((item) => item.id === subfieldKey)) {
+ continue;
+ }
+
+ group.items.push({
+ id: subfieldKey,
+ name: subfieldName,
+ description: subfieldDescription,
+ tooltip: buildTopicLegendTooltip([
+ {
+ label: 'Themenbereich',
+ value: subfieldName,
+ description: subfieldDescription,
+ },
+ {
+ label: 'Fachgebiet',
+ value: fieldName,
+ description: fieldDescription,
+ },
+ {
+ label: 'Wissenschaftsbereich',
+ value: domainName,
+ description: domainDescription,
+ },
+ ]),
+ });
+ }
+
+ return [...groups.values()]
+ .map((group) => ({
+ ...group,
+ items: group.items.sort((left, right) =>
+ left.name.localeCompare(right.name),
+ ),
+ }))
+ .sort((left, right) => left.name.localeCompare(right.name));
+}
+
+function buildTopicLegendTooltip(
+ entries: Array<{ label: string; value: string; description: string }>,
+): string {
+ const lines: string[] = [];
+
+ for (const entry of entries) {
+ if (!entry.value && !entry.description) {
+ continue;
+ }
+
+ if (lines.length > 0) {
+ lines.push('');
+ }
+
+ if (entry.value) {
+ lines.push(`${entry.label}: ${entry.value}`);
+ }
+
+ if (entry.description) {
+ lines.push('');
+ lines.push(`Beschreibung: ${entry.description}`);
+ }
+ }
+
+ return lines.join('\n');
+}
+
+function normalizeLegendValue(value: string | null | undefined): string | null {
+ const normalized = value?.trim();
+
+ return normalized || null;
+}
+
+function normalizeLegendKey(value: string): string {
+ return value.trim().toLowerCase();
+}