share topic legend between timeline and interesting-for

This commit is contained in:
2026-06-24 23:52:56 +02:00
parent 1205ebb1c0
commit 17037668d8
4 changed files with 518 additions and 0 deletions
@@ -0,0 +1,89 @@
<section
*ngIf="hasGroups"
class="topic-legend"
[class.topic-legend-compact]="variant === 'compact'"
[class.topic-legend-expanded]="expanded"
aria-label="Aktuell sichtbare Themenbereiche">
<div *ngIf="hasHeader" class="topic-legend-header">
<div *ngIf="showTitle" class="topic-legend-title">
<span>{{ title }}</span>
<mat-icon
class="topic-legend-info"
[matTooltip]="infoTooltip"
matTooltipPosition="above"
aria-label="Informationen zur Farblegende">
info_outline
</mat-icon>
</div>
<button
*ngIf="showVisibilityToggle"
type="button"
class="topic-legend-visibility-toggle"
[attr.aria-expanded]="visible"
(click)="toggleVisibility()">
<span>{{ visible ? 'Legende ausblenden' : 'Legende einblenden' }}</span>
<mat-icon aria-hidden="true">
{{ visible ? 'expand_less' : 'expand_more' }}
</mat-icon>
</button>
</div>
<div
*ngIf="visible"
class="topic-legend-body"
[class.topic-legend-body-inline-info]="!hasHeader">
<mat-icon
*ngIf="!hasHeader"
class="topic-legend-info topic-legend-info-inline"
[matTooltip]="infoTooltip"
matTooltipPosition="above"
aria-label="Informationen zur Farblegende">
info_outline
</mat-icon>
<div class="topic-legend-content">
<div
*ngFor="let group of visibleGroups; trackBy: trackByGroup"
class="topic-legend-group">
<span
class="topic-legend-field"
[matTooltip]="group.tooltip"
[matTooltipDisabled]="!group.tooltip"
matTooltipClass="topic-chip-tooltip"
matTooltipPosition="above">
<span
class="topic-legend-dot"
[style.background]="group.color"
aria-hidden="true"></span>
<span>{{ group.name }}</span>
</span>
<span class="topic-legend-items">
<span
*ngFor="let item of group.items; trackBy: trackByItem"
class="topic-legend-item"
[matTooltip]="item.tooltip"
[matTooltipDisabled]="!item.tooltip"
matTooltipClass="topic-chip-tooltip"
matTooltipPosition="above">
{{ item.name }}
</span>
</span>
</div>
<button
*ngIf="showExpandedToggle"
type="button"
class="topic-legend-more-toggle"
[attr.aria-expanded]="expanded"
(click)="toggleExpanded()">
{{
expanded
? 'Weniger anzeigen'
: '+' + hiddenLegendItemCount + ' weitere'
}}
</button>
</div>
</div>
</section>
@@ -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;
}
}
}
@@ -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<boolean>();
@Output() expandedChange = new EventEmitter<boolean>();
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;
}
}
+152
View File
@@ -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<string, TopicLegendGroup>();
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();
}