feat(ui): show topic hierarchy in tooltips
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+15
-4
@@ -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"
|
||||
|
||||
+13
-2
@@ -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(
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
[attr.aria-pressed]="active ? 'true' : null"
|
||||
[matTooltip]="buttonTooltip"
|
||||
[matTooltipDisabled]="!buttonTooltip"
|
||||
matTooltipClass="topic-chip-tooltip"
|
||||
(click)="handleClick()">
|
||||
<span
|
||||
class="topic-chip__label"
|
||||
[matTooltip]="labelTooltip"
|
||||
[matTooltipDisabled]="!labelTooltip">
|
||||
[matTooltipDisabled]="!labelTooltip"
|
||||
matTooltipClass="topic-chip-tooltip">
|
||||
{{ label }}
|
||||
</span>
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user