feat(research-timeline): add secondary action to topic tooltip

This commit is contained in:
2026-08-17 14:04:12 +02:00
parent ae80f0f812
commit ce218cbfa1
4 changed files with 166 additions and 2 deletions
@@ -171,8 +171,15 @@
type="button"
class="main-topic-button"
[disabled]="!getMainTopicItem(item)?.id"
[attr.aria-label]="
getTopicAriaLabel(getMainTopicItem(item), [item.year])
"
[appComponentTooltip]="AppTopicTooltipComponent"
[tooltipInputs]="{ topicId: getMainTopicItem(item)?.id }"
[tooltipInputs]="
getTopicTooltipInputs(getMainTopicItem(item), [
item.year,
])
"
[tooltipMaxWidth]="'500px'"
(click)="
selectTopic(getMainTopicItem(item), [item.year])
@@ -217,6 +224,16 @@
[color]="getTopicColor(topic)"
[disabled]="!topic.id"
[active]="isTopicActiveByLegend(topic)"
[secondaryActionLabel]="
getTopicAction(topic, [item.year])?.label ?? null
"
[secondaryActionLink]="
getTopicAction(topic, [item.year])?.link ?? null
"
[secondaryActionQueryParams]="
getTopicAction(topic, [item.year])?.queryParams ??
null
"
(chipClick)="selectTopic(topic, [item.year])">
</app-topic-chip>
</ng-container>
@@ -288,8 +305,19 @@
type="button"
class="main-topic-button"
[disabled]="!phase.primaryTopic.id"
[attr.aria-label]="
getTopicAriaLabel(
phase.primaryTopic,
getPhaseYears(phase)
)
"
[appComponentTooltip]="AppTopicTooltipComponent"
[tooltipInputs]="{ topicId: phase.primaryTopic.id }"
[tooltipInputs]="
getTopicTooltipInputs(
phase.primaryTopic,
getPhaseYears(phase)
)
"
[tooltipMaxWidth]="'500px'"
(click)="
selectTopic(phase.primaryTopic, getPhaseYears(phase))
@@ -317,6 +345,16 @@
[color]="getTopicColor(topic)"
[disabled]="!topic.id"
[active]="isTopicActiveByLegend(topic)"
[secondaryActionLabel]="
getTopicAction(topic, getPhaseYears(phase))?.label ?? null
"
[secondaryActionLink]="
getTopicAction(topic, getPhaseYears(phase))?.link ?? null
"
[secondaryActionQueryParams]="
getTopicAction(topic, getPhaseYears(phase))
?.queryParams ?? null
"
(chipClick)="selectTopic(topic, getPhaseYears(phase))">
</app-topic-chip>
</ng-container>
@@ -396,6 +434,16 @@
[color]="getTopicColor(topic)"
[disabled]="!topic.id"
[active]="isTopicActiveByLegend(topic)"
[secondaryActionLabel]="
getTopicAction(topic, [year.year])?.label ?? null
"
[secondaryActionLink]="
getTopicAction(topic, [year.year])?.link ?? null
"
[secondaryActionQueryParams]="
getTopicAction(topic, [year.year])?.queryParams ??
null
"
(chipClick)="selectTopic(topic, [year.year])">
</app-topic-chip>
</ng-container>
@@ -30,6 +30,7 @@ import {
toggleTopicLegendSubfieldSelection,
} from '../../../../resolvers/utils/topic-legend';
import { buildTopicHierarchyTooltip } from '../../../../resolvers/utils/topic-tooltip';
import { workQueryParamKeys } from '../../../../resolvers/work-page.resolver';
export interface TopicTimelineTopic {
id?: string;
@@ -92,6 +93,19 @@ interface TimelineScrollAnchor {
scrollLeft: number;
}
interface TimelineTopicAction {
label: string;
link: unknown[];
queryParams: Record<string, string | number | number[]>;
}
interface TimelineTopicTooltipInputs {
topicId: string | undefined;
secondaryActionLabel: string | null;
secondaryActionLink: unknown[] | null;
secondaryActionQueryParams: Record<string, string | number | number[]> | null;
}
@Component({
selector: 'app-research-timeline',
standalone: true,
@@ -123,6 +137,8 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
@Input() subfieldLegendVisible = true;
@Input() subfieldLegendExpanded = false;
@Input() wordCloudLegendTopics: TopicLegendTopic[] = [];
@Input() personPublicationsLink: unknown[] | null = null;
@Input() personName = '';
@Output() viewModeChange = new EventEmitter<TimelineViewMode>();
@Output() yearRangeChange = new EventEmitter<TimelineYearRange>();
@@ -146,6 +162,11 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
private readonly displayedPhaseTopicLimit = 4;
private readonly scrollRestoreThreshold = 24;
private readonly expandedPhaseIds = new Set<string>();
private readonly topicActionCache = new Map<string, TimelineTopicAction>();
private readonly tooltipInputsCache = new Map<
string,
TimelineTopicTooltipInputs
>();
activeLegendFieldIds: ReadonlySet<string> = new Set();
activeLegendSubfieldIds: ReadonlySet<string> = new Set();
@@ -169,6 +190,11 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
if (changes['elements'] || changes['startYear'] || changes['endYear']) {
this.applyInputYearRange();
}
if (changes['personName'] || changes['personPublicationsLink']) {
this.topicActionCache.clear();
this.tooltipInputsCache.clear();
}
}
ngAfterViewChecked(): void {
@@ -330,6 +356,85 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
return phase.years.map((year) => year.year);
}
getTopicAction(
topic: TopicTimelineTopic | undefined,
years: number[],
): TimelineTopicAction | null {
if (!this.personPublicationsLink || !topic?.id || years.length === 0) {
return null;
}
const selectedYears = this.normalizeSelectedYears(years);
const cacheKey = `${topic.id}|${selectedYears.join(',')}`;
const cached = this.topicActionCache.get(cacheKey);
if (cached) {
return cached;
}
const person = this.personName || 'dieser Person';
const action: TimelineTopicAction = {
label: `Publikationen von ${person} ${this.formatYearRange(selectedYears)}`,
link: this.personPublicationsLink,
queryParams: {
[workQueryParamKeys.page]: 0,
[workQueryParamKeys.years]: selectedYears,
[workQueryParamKeys.topicId]: topic.id,
},
};
this.topicActionCache.set(cacheKey, action);
return action;
}
getTopicTooltipInputs(
topic: TopicTimelineTopic | undefined,
years: number[],
): TimelineTopicTooltipInputs {
const action = this.getTopicAction(topic, years);
const cacheKey = `${topic?.id ?? ''}|${years.join(',')}`;
const cached = this.tooltipInputsCache.get(cacheKey);
if (cached) {
return cached;
}
const inputs: TimelineTopicTooltipInputs = {
topicId: topic?.id,
secondaryActionLabel: action?.label ?? null,
secondaryActionLink: action?.link ?? null,
secondaryActionQueryParams: action?.queryParams ?? null,
};
this.tooltipInputsCache.set(cacheKey, inputs);
return inputs;
}
getTopicAriaLabel(
topic: TopicTimelineTopic | undefined,
years: number[],
): string | null {
if (!topic?.id || years.length === 0) {
return null;
}
const person = this.personName || 'dieser Person';
const selectedYears = this.normalizeSelectedYears(years);
return `Publikationen von ${person} zum Thema ${topic.name} ${this.formatYearRange(selectedYears)}`;
}
private formatYearRange(years: number[]): string {
const firstYear = years[0];
const lastYear = years[years.length - 1];
return firstYear === lastYear
? `(${firstYear})`
: `(${firstYear}–${lastYear})`;
}
getYearPublicationTooltip(item: TopicTimelineElement): string {
return this.getPublicationTooltip(
item.publication_count,
@@ -12,6 +12,8 @@
[subfieldLegendVisible]="timelineLegendVisible"
[subfieldLegendExpanded]="timelineLegendExpanded"
[wordCloudLegendTopics]="wordCloudLegendTopics"
[personName]="personName"
[personPublicationsLink]="personPublicationsLink"
(viewModeChange)="onTimelineViewModeChange($event)"
(yearRangeChange)="onTimelineYearRangeChange($event)"
(subfieldLegendVisibleChange)="onTimelineLegendVisibleChange($event)"
@@ -1,6 +1,7 @@
import { Component, computed, input, output } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { MatTooltipModule } from '@angular/material/tooltip';
import { Params } from '@angular/router';
import { Topic } from '../../../api';
import { ComponentTooltipDirective } from '../../../directives/component-tooltip.directive';
import { AppTopicTooltipComponent } from '../app-topic-tooltip/app-topic-tooltip.component';
@@ -102,6 +103,10 @@ export class TopicChipComponent {
descriptionTooltipTarget = input<TopicChipTooltipTarget>('label');
topicId = input<string | null | undefined>(undefined);
topic = input<Topic | null | undefined>(undefined);
secondaryActionLabel = input<string | null>(null);
secondaryActionIcon = input<string>('person_search');
secondaryActionLink = input<unknown[] | string | null>(null);
secondaryActionQueryParams = input<Params | null>(null);
chipClick = output<void>();
@@ -188,6 +193,10 @@ export class TopicChipComponent {
return {
topic: this.topicObject(),
topicId: this.topicId() ?? this.topic()?.id ?? undefined,
secondaryActionLabel: this.secondaryActionLabel(),
secondaryActionIcon: this.secondaryActionIcon(),
secondaryActionLink: this.secondaryActionLink(),
secondaryActionQueryParams: this.secondaryActionQueryParams(),
};
});