From 1b77071dc4f239a4b9c6dc2bc46f4ff5a15bd1e4 Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Sun, 21 Jun 2026 23:26:44 +0200 Subject: [PATCH] feat(ui): show topic hierarchy in tooltips --- .../person-interesting.component.html | 3 ++ .../person-interesting.component.ts | 4 ++ .../research-timeline.component.html | 19 ++++++-- .../research-timeline.component.ts | 15 +++++- .../ui/topic-chip/topic-chip.component.html | 4 +- .../ui/topic-chip/topic-chip.component.ts | 22 ++++++--- webapp/src/app/shared/utils/topic-tooltip.ts | 48 +++++++++++++++++++ webapp/src/styles.scss | 7 +++ 8 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 webapp/src/app/shared/utils/topic-tooltip.ts diff --git a/webapp/src/app/modules/person-interesting/person-interesting.component.html b/webapp/src/app/modules/person-interesting/person-interesting.component.html index 9c2c9214..d88ebffc 100644 --- a/webapp/src/app/modules/person-interesting/person-interesting.component.html +++ b/webapp/src/app/modules/person-interesting/person-interesting.component.html @@ -35,6 +35,9 @@ [label]="tag.label" [count]="tag.count" [description]="tag.description" + [subfieldName]="tag.subfieldName" + [fieldName]="tag.fieldName" + [domainName]="tag.domainName" [color]="tag.color" [disabled]="!tag.id" countIcon="article" diff --git a/webapp/src/app/modules/person-interesting/person-interesting.component.ts b/webapp/src/app/modules/person-interesting/person-interesting.component.ts index 1ad7f595..0e0fd749 100644 --- a/webapp/src/app/modules/person-interesting/person-interesting.component.ts +++ b/webapp/src/app/modules/person-interesting/person-interesting.component.ts @@ -16,6 +16,8 @@ interface InterestTag { subfieldName: string; fieldId: string; fieldName: string; + domainId: string; + domainName: string; } interface InterestLegendGroup { @@ -61,6 +63,8 @@ export class PersonInterestingComponent { subfieldName: (topic.subfield_name ?? '').trim(), fieldId: topic.field_id ?? '', fieldName: (topic.field_name ?? '').trim(), + domainId: topic.domain_id ?? '', + domainName: (topic.domain_name ?? '').trim(), }); } diff --git a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.html b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.html index 40624f96..1038e101 100644 --- a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.html +++ b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.html @@ -255,9 +255,10 @@ type="button" class="main-topic-button" [disabled]="!getMainTopicItem(item)?.id" - [matTooltip]="getTopicDescription(getMainTopicItem(item))" + [matTooltip]="getTopicTooltip(getMainTopicItem(item))" + matTooltipClass="topic-chip-tooltip" [matTooltipDisabled]=" - !hasTopicDescription(getMainTopicItem(item)) + !hasTopicTooltip(getMainTopicItem(item)) " (click)=" selectTopic(getMainTopicItem(item), [item.year]) @@ -294,6 +295,9 @@ [label]="topic.name" [count]="topic.count" [description]="getTopicDescription(topic)" + [subfieldName]="topic.subfield_name" + [fieldName]="topic.field_name" + [domainName]="topic.domain_name" [countTooltip]="getYearTopicCountTooltip(topic, item)" [color]="getTopicColor(topic)" [disabled]="!topic.id" @@ -353,9 +357,10 @@ type="button" class="main-topic-button" [disabled]="!phase.primaryTopic.id" - [matTooltip]="getTopicDescription(phase.primaryTopic)" + [matTooltip]="getTopicTooltip(phase.primaryTopic)" + matTooltipClass="topic-chip-tooltip" [matTooltipDisabled]=" - !hasTopicDescription(phase.primaryTopic) + !hasTopicTooltip(phase.primaryTopic) " (click)=" selectTopic(phase.primaryTopic, getPhaseYears(phase)) @@ -375,6 +380,9 @@ [label]="topic.name" [count]="topic.count" [description]="getTopicDescription(topic)" + [subfieldName]="topic.subfield_name" + [fieldName]="topic.field_name" + [domainName]="topic.domain_name" [countTooltip]="getPhaseTopicCountTooltip(topic, phase)" [color]="getTopicColor(topic)" [disabled]="!topic.id" @@ -449,6 +457,9 @@ [label]="topic.name" [count]="topic.count" [description]="getTopicDescription(topic)" + [subfieldName]="topic.subfield_name" + [fieldName]="topic.field_name" + [domainName]="topic.domain_name" [countTooltip]="getYearTopicCountTooltip(topic, year)" [color]="getTopicColor(topic)" [disabled]="!topic.id" diff --git a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts index 21c99a2e..d43e7204 100644 --- a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts +++ b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts @@ -14,6 +14,7 @@ import { } from '@angular/core'; import { TopicChipComponent } from '../../../../shared/ui/topic-chip/topic-chip.component'; import { topicHierarchyColor } from '../../../../shared/utils/topic-colors'; +import { buildTopicHierarchyTooltip } from '../../../../shared/utils/topic-tooltip'; export interface TopicTimelineTopic { id?: string; @@ -408,8 +409,18 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked { return (topic?.description ?? '').trim(); } - hasTopicDescription(topic: TopicTimelineTopic | undefined): boolean { - return this.getTopicDescription(topic).length > 0; + getTopicTooltip(topic: TopicTimelineTopic | undefined): string { + return buildTopicHierarchyTooltip({ + topicName: topic?.name, + description: topic?.description, + subfieldName: topic?.subfield_name, + fieldName: topic?.field_name, + domainName: topic?.domain_name, + }); + } + + hasTopicTooltip(topic: TopicTimelineTopic | undefined): boolean { + return this.getTopicTooltip(topic).length > 0; } getYearTopicCountTooltip( diff --git a/webapp/src/app/shared/ui/topic-chip/topic-chip.component.html b/webapp/src/app/shared/ui/topic-chip/topic-chip.component.html index 9ad26847..6babd4cc 100644 --- a/webapp/src/app/shared/ui/topic-chip/topic-chip.component.html +++ b/webapp/src/app/shared/ui/topic-chip/topic-chip.component.html @@ -5,11 +5,13 @@ [attr.aria-pressed]="active ? 'true' : null" [matTooltip]="buttonTooltip" [matTooltipDisabled]="!buttonTooltip" + matTooltipClass="topic-chip-tooltip" (click)="handleClick()"> + [matTooltipDisabled]="!labelTooltip" + matTooltipClass="topic-chip-tooltip"> {{ label }} diff --git a/webapp/src/app/shared/ui/topic-chip/topic-chip.component.ts b/webapp/src/app/shared/ui/topic-chip/topic-chip.component.ts index 695b777b..7176795c 100644 --- a/webapp/src/app/shared/ui/topic-chip/topic-chip.component.ts +++ b/webapp/src/app/shared/ui/topic-chip/topic-chip.component.ts @@ -7,6 +7,7 @@ import { } from '@angular/core'; import { MatIconModule } from '@angular/material/icon'; import { MatTooltipModule } from '@angular/material/tooltip'; +import { buildTopicHierarchyTooltip } from '../../utils/topic-tooltip'; export const TOPIC_CHIP_PALETTE = [ 'purple', @@ -66,6 +67,9 @@ export class TopicChipComponent { @Input() label = ''; @Input() count: number | string | null | undefined; @Input() description: string | null | undefined = ''; + @Input() subfieldName: string | null | undefined = ''; + @Input() fieldName: string | null | undefined = ''; + @Input() domainName: string | null | undefined = ''; @Input() countTooltip: string | null | undefined = ''; @Input() countIcon: string | null | undefined; @Input() color: TopicChipColor = 'purple'; @@ -119,15 +123,11 @@ export class TopicChipComponent { } get labelTooltip(): string { - return this.descriptionTooltipTarget === 'label' - ? this.normalizedDescription - : ''; + return this.descriptionTooltipTarget === 'label' ? this.topicTooltip : ''; } get buttonTooltip(): string { - return this.descriptionTooltipTarget === 'button' - ? this.normalizedDescription - : ''; + return this.descriptionTooltipTarget === 'button' ? this.topicTooltip : ''; } get normalizedCountTooltip(): string { @@ -150,6 +150,16 @@ export class TopicChipComponent { return (this.description ?? '').trim(); } + private get topicTooltip(): string { + return buildTopicHierarchyTooltip({ + topicName: this.label, + description: this.description, + subfieldName: this.subfieldName, + fieldName: this.fieldName, + domainName: this.domainName, + }); + } + private get colorTokens(): TopicChipColorTokens | undefined { return TOPIC_CHIP_COLORS[this.color as TopicChipPaletteColor]; } diff --git a/webapp/src/app/shared/utils/topic-tooltip.ts b/webapp/src/app/shared/utils/topic-tooltip.ts new file mode 100644 index 00000000..c805d6e0 --- /dev/null +++ b/webapp/src/app/shared/utils/topic-tooltip.ts @@ -0,0 +1,48 @@ +export interface TopicHierarchyTooltipContent { + topicName: string | null | undefined; + description?: string | null | undefined; + subfieldName?: string | null | undefined; + fieldName?: string | null | undefined; + domainName?: string | null | undefined; +} + +export function buildTopicHierarchyTooltip( + content: TopicHierarchyTooltipContent, +): string { + const topicName = normalizeTooltipValue(content.topicName); + const subfieldName = normalizeTooltipValue(content.subfieldName); + const fieldName = normalizeTooltipValue(content.fieldName); + const domainName = normalizeTooltipValue(content.domainName); + const description = normalizeTooltipValue(content.description); + + if ( + !topicName || + (!subfieldName && !fieldName && !domainName && !description) + ) { + return ''; + } + + const lines = [`Topic: ${topicName}`]; + + if (subfieldName) { + lines.push(`Subfield: ${subfieldName}`); + } + + if (fieldName) { + lines.push(`Field: ${fieldName}`); + } + + if (domainName) { + lines.push(`Domain: ${domainName}`); + } + + if (description) { + lines.push(`Description: ${description}`); + } + + return lines.join('\n'); +} + +function normalizeTooltipValue(value: string | null | undefined): string { + return (value ?? '').trim(); +} diff --git a/webapp/src/styles.scss b/webapp/src/styles.scss index d2edeee7..3a14b039 100644 --- a/webapp/src/styles.scss +++ b/webapp/src/styles.scss @@ -199,6 +199,13 @@ h3 { color: var(--sg-text); } +.topic-chip-tooltip, +.topic-chip-tooltip .mdc-tooltip__surface, +.topic-chip-tooltip .mat-mdc-tooltip-surface { + max-width: 320px; + white-space: pre-line; +} + .cdk-overlay-pane .mat-mdc-option { padding: 0 18px; font-size: 13px;