topic-legend: highlight selected fields and topic
This commit is contained in:
@@ -11,10 +11,15 @@
|
||||
<app-topic-legend
|
||||
[groups]="legendGroups()"
|
||||
[expanded]="legendExpanded()"
|
||||
[selectable]="true"
|
||||
[activeFieldIds]="activeLegendFieldIds()"
|
||||
[activeSubfieldIds]="activeLegendSubfieldIds()"
|
||||
[showTitle]="false"
|
||||
[showVisibilityToggle]="false"
|
||||
[collapsedGroupLimit]="3"
|
||||
variant="compact"
|
||||
(fieldToggle)="onLegendFieldToggle($event)"
|
||||
(subfieldToggle)="onLegendSubfieldToggle($event)"
|
||||
(expandedChange)="onLegendExpandedChange($event)">
|
||||
</app-topic-legend>
|
||||
<div class="interest-tags">
|
||||
@@ -29,6 +34,7 @@
|
||||
[domainName]="tag.domainName"
|
||||
[color]="tag.color"
|
||||
[disabled]="!tag.id"
|
||||
[active]="isTagActive(tag)"
|
||||
countIcon="article"
|
||||
descriptionTooltipTarget="button"
|
||||
(chipClick)="onTagClick(tag)">
|
||||
|
||||
@@ -17,7 +17,14 @@ import { TopicCount } from '../../api';
|
||||
import { TopicChipComponent } from '../../shared/ui/topic-chip/topic-chip.component';
|
||||
import { TopicLegendComponent } from '../../shared/ui/topic-legend/topic-legend.component';
|
||||
import { topicHierarchyColor } from '../../shared/utils/topic-colors';
|
||||
import { buildTopicLegendGroups } from '../../shared/utils/topic-legend';
|
||||
import {
|
||||
buildTopicLegendGroups,
|
||||
getTopicLegendFieldId,
|
||||
getTopicLegendSubfieldId,
|
||||
TopicLegendGroup,
|
||||
TopicLegendSubfieldSelection,
|
||||
toggleTopicLegendSelection,
|
||||
} from '../../shared/utils/topic-legend';
|
||||
|
||||
interface InterestTag {
|
||||
id: string;
|
||||
@@ -59,6 +66,8 @@ export class PersonInterestingComponent implements OnInit {
|
||||
|
||||
readonly topics = input<TopicCount[] | null>(null);
|
||||
readonly legendExpanded = signal(false);
|
||||
readonly activeLegendFieldIds = signal<ReadonlySet<string>>(new Set());
|
||||
readonly activeLegendSubfieldIds = signal<ReadonlySet<string>>(new Set());
|
||||
|
||||
readonly tagClick = output<{ id: string; name: string }>();
|
||||
|
||||
@@ -144,6 +153,38 @@ export class PersonInterestingComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onLegendFieldToggle(group: TopicLegendGroup): void {
|
||||
this.activeLegendFieldIds.set(
|
||||
toggleTopicLegendSelection(this.activeLegendFieldIds(), group.id),
|
||||
);
|
||||
}
|
||||
|
||||
onLegendSubfieldToggle(selection: TopicLegendSubfieldSelection): void {
|
||||
this.activeLegendSubfieldIds.set(
|
||||
toggleTopicLegendSelection(
|
||||
this.activeLegendSubfieldIds(),
|
||||
selection.item.id,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
isTagActive(tag: InterestTag): boolean {
|
||||
const fieldLegendId = getTopicLegendFieldId({
|
||||
field_id: tag.fieldId,
|
||||
field_name: tag.fieldName,
|
||||
});
|
||||
const subfieldLegendId = getTopicLegendSubfieldId({
|
||||
subfield_id: tag.subfieldId,
|
||||
subfield_name: tag.subfieldName,
|
||||
});
|
||||
|
||||
return (
|
||||
this.activeLegendFieldIds().has(fieldLegendId) ||
|
||||
(subfieldLegendId.length > 0 &&
|
||||
this.activeLegendSubfieldIds().has(subfieldLegendId))
|
||||
);
|
||||
}
|
||||
|
||||
private parseBooleanQueryParam(
|
||||
value: string | null,
|
||||
fallback: boolean,
|
||||
|
||||
+8
@@ -12,6 +12,11 @@
|
||||
[visible]="subfieldLegendVisible"
|
||||
[expanded]="subfieldLegendExpanded"
|
||||
[collapsedGroupLimit]="3"
|
||||
[selectable]="true"
|
||||
[activeFieldIds]="activeLegendFieldIds"
|
||||
[activeSubfieldIds]="activeLegendSubfieldIds"
|
||||
(fieldToggle)="onLegendFieldToggle($event)"
|
||||
(subfieldToggle)="onLegendSubfieldToggle($event)"
|
||||
(visibleChange)="onSubfieldLegendVisibleChange($event)"
|
||||
(expandedChange)="onSubfieldLegendExpandedChange($event)">
|
||||
</app-topic-legend>
|
||||
@@ -254,6 +259,7 @@
|
||||
[countTooltip]="getYearTopicCountTooltip(topic, item)"
|
||||
[color]="getTopicColor(topic)"
|
||||
[disabled]="!topic.id"
|
||||
[active]="isTopicActiveByLegend(topic)"
|
||||
(chipClick)="selectTopic(topic, [item.year])">
|
||||
</app-topic-chip>
|
||||
</ng-container>
|
||||
@@ -354,6 +360,7 @@
|
||||
[countTooltip]="getPhaseTopicCountTooltip(topic, phase)"
|
||||
[color]="getTopicColor(topic)"
|
||||
[disabled]="!topic.id"
|
||||
[active]="isTopicActiveByLegend(topic)"
|
||||
(chipClick)="selectTopic(topic, getPhaseYears(phase))">
|
||||
</app-topic-chip>
|
||||
</ng-container>
|
||||
@@ -431,6 +438,7 @@
|
||||
[countTooltip]="getYearTopicCountTooltip(topic, year)"
|
||||
[color]="getTopicColor(topic)"
|
||||
[disabled]="!topic.id"
|
||||
[active]="isTopicActiveByLegend(topic)"
|
||||
(chipClick)="selectTopic(topic, [year.year])">
|
||||
</app-topic-chip>
|
||||
</ng-container>
|
||||
|
||||
+31
-1
@@ -17,7 +17,11 @@ import { TopicLegendComponent } from '../../../../shared/ui/topic-legend/topic-l
|
||||
import { topicHierarchyColor } from '../../../../shared/utils/topic-colors';
|
||||
import {
|
||||
buildTopicLegendGroups,
|
||||
getTopicLegendFieldId,
|
||||
getTopicLegendSubfieldId,
|
||||
TopicLegendGroup,
|
||||
TopicLegendSubfieldSelection,
|
||||
toggleTopicLegendSelection,
|
||||
} from '../../../../shared/utils/topic-legend';
|
||||
import { buildTopicHierarchyTooltip } from '../../../../shared/utils/topic-tooltip';
|
||||
|
||||
@@ -130,6 +134,8 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
|
||||
private readonly displayedPhaseTopicLimit = 4;
|
||||
private readonly scrollRestoreThreshold = 24;
|
||||
private readonly expandedPhaseIds = new Set<string>();
|
||||
activeLegendFieldIds: ReadonlySet<string> = new Set();
|
||||
activeLegendSubfieldIds: ReadonlySet<string> = new Set();
|
||||
|
||||
private pendingTimelineScrollAnchor: TimelineScrollAnchor | undefined;
|
||||
|
||||
@@ -423,6 +429,31 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
|
||||
this.subfieldLegendVisibleChange.emit(this.subfieldLegendVisible);
|
||||
}
|
||||
|
||||
onLegendFieldToggle(group: TopicLegendGroup): void {
|
||||
this.activeLegendFieldIds = toggleTopicLegendSelection(
|
||||
this.activeLegendFieldIds,
|
||||
group.id,
|
||||
);
|
||||
}
|
||||
|
||||
onLegendSubfieldToggle(selection: TopicLegendSubfieldSelection): void {
|
||||
this.activeLegendSubfieldIds = toggleTopicLegendSelection(
|
||||
this.activeLegendSubfieldIds,
|
||||
selection.item.id,
|
||||
);
|
||||
}
|
||||
|
||||
isTopicActiveByLegend(topic: TopicTimelineTopic): boolean {
|
||||
const fieldLegendId = getTopicLegendFieldId(topic);
|
||||
const subfieldLegendId = getTopicLegendSubfieldId(topic);
|
||||
|
||||
return (
|
||||
this.activeLegendFieldIds.has(fieldLegendId) ||
|
||||
(subfieldLegendId.length > 0 &&
|
||||
this.activeLegendSubfieldIds.has(subfieldLegendId))
|
||||
);
|
||||
}
|
||||
|
||||
trackByYear(_: number, item: TopicTimelineElement): number {
|
||||
return item.year;
|
||||
}
|
||||
@@ -558,7 +589,6 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
|
||||
|
||||
return `im Zeitraum ${this.getPhaseYearLabel(phase)}`;
|
||||
}
|
||||
|
||||
private get earlierYearsColumnCount(): number {
|
||||
return this.showEarlierYearsControl ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -61,13 +61,38 @@
|
||||
|
||||
:host(.topic-chip--active.topic-chip--normal) .topic-chip__button {
|
||||
border-color: var(--topic-color);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--topic-color) 26%, transparent);
|
||||
background: color-mix(in srgb, var(--topic-color) 27%, #ffffff);
|
||||
color: color-mix(in srgb, var(--topic-color) 40%, #07163d);
|
||||
box-shadow:
|
||||
inset 0 0 0 1px var(--topic-color),
|
||||
0 0 0 2px #ffffff,
|
||||
0 0 0 4px color-mix(in srgb, var(--topic-color) 48%, transparent),
|
||||
0 5px 12px rgba(15, 23, 42, 0.16);
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
box-shadow:
|
||||
inset 0 0 0 1px var(--topic-color),
|
||||
0 0 0 2px #ffffff,
|
||||
0 0 0 4px color-mix(in srgb, var(--topic-color) 56%, transparent),
|
||||
0 7px 14px rgba(15, 23, 42, 0.18);
|
||||
}
|
||||
}
|
||||
|
||||
:host(.topic-chip--active.topic-chip--mini) .topic-chip__button {
|
||||
background: color-mix(in srgb, var(--topic-color) 24%, #ffffff);
|
||||
color: var(--topic-text);
|
||||
box-shadow: 0 0 0 1.5px var(--topic-color);
|
||||
background: color-mix(in srgb, var(--topic-color) 32%, #ffffff);
|
||||
color: color-mix(in srgb, var(--topic-color) 42%, #07163d);
|
||||
box-shadow:
|
||||
0 0 0 1px #ffffff,
|
||||
0 0 0 3px color-mix(in srgb, var(--topic-color) 72%, transparent);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
:host(.topic-chip--active.topic-chip--normal) .topic-chip__count {
|
||||
background: #ffffff;
|
||||
color: color-mix(in srgb, var(--topic-color) 46%, #07163d);
|
||||
box-shadow:
|
||||
inset 0 0 0 1px color-mix(in srgb, var(--topic-color) 72%, transparent),
|
||||
0 1px 4px rgba(15, 23, 42, 0.18);
|
||||
}
|
||||
|
||||
.topic-chip__label {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
class="topic-legend"
|
||||
[class.topic-legend-compact]="variant === 'compact'"
|
||||
[class.topic-legend-expanded]="expanded"
|
||||
[class.topic-legend-selectable]="selectable"
|
||||
aria-label="Aktuell sichtbare Themenbereiche">
|
||||
<div *ngIf="hasHeader" class="topic-legend-header">
|
||||
<div *ngIf="showTitle" class="topic-legend-title">
|
||||
@@ -45,30 +46,40 @@
|
||||
<div class="topic-legend-content">
|
||||
<div
|
||||
*ngFor="let group of visibleGroups; trackBy: trackByGroup"
|
||||
class="topic-legend-group">
|
||||
<span
|
||||
class="topic-legend-group"
|
||||
[class.topic-legend-group-active]="isGroupActive(group)"
|
||||
[style.--legend-color]="group.color">
|
||||
<button
|
||||
type="button"
|
||||
class="topic-legend-field"
|
||||
[class.topic-legend-entry-active]="isFieldActive(group)"
|
||||
[attr.aria-pressed]="selectable ? isFieldActive(group) : null"
|
||||
[matTooltip]="group.tooltip"
|
||||
[matTooltipDisabled]="!group.tooltip"
|
||||
matTooltipClass="topic-chip-tooltip"
|
||||
matTooltipPosition="above">
|
||||
matTooltipPosition="above"
|
||||
(click)="toggleField(group)">
|
||||
<span
|
||||
class="topic-legend-dot"
|
||||
[style.background]="group.color"
|
||||
aria-hidden="true"></span>
|
||||
<span>{{ group.name }}</span>
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<span class="topic-legend-items">
|
||||
<span
|
||||
<button
|
||||
*ngFor="let item of group.items; trackBy: trackByItem"
|
||||
type="button"
|
||||
class="topic-legend-item"
|
||||
[class.topic-legend-entry-active]="isSubfieldActive(item)"
|
||||
[attr.aria-pressed]="selectable ? isSubfieldActive(item) : null"
|
||||
[matTooltip]="item.tooltip"
|
||||
[matTooltipDisabled]="!item.tooltip"
|
||||
matTooltipClass="topic-chip-tooltip"
|
||||
matTooltipPosition="above">
|
||||
matTooltipPosition="above"
|
||||
(click)="toggleSubfield(group, item)">
|
||||
{{ item.name }}
|
||||
</span>
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -110,11 +110,39 @@
|
||||
background: #fbfdff;
|
||||
}
|
||||
|
||||
.topic-legend-group-active {
|
||||
border-color: var(--legend-color, var(--topic-legend-accent));
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--legend-color, var(--topic-legend-accent)) 10%,
|
||||
#fbfdff
|
||||
);
|
||||
box-shadow:
|
||||
inset 0 0 0 1px
|
||||
color-mix(
|
||||
in srgb,
|
||||
var(--legend-color, var(--topic-legend-accent)) 55%,
|
||||
transparent
|
||||
),
|
||||
0 0 0 2px
|
||||
color-mix(
|
||||
in srgb,
|
||||
var(--legend-color, var(--topic-legend-accent)) 22%,
|
||||
transparent
|
||||
);
|
||||
}
|
||||
|
||||
.topic-legend-field {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
gap: 5px;
|
||||
padding: 2px 4px;
|
||||
appearance: none;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
background: transparent;
|
||||
color: #07163d;
|
||||
font-family: inherit;
|
||||
font-size: 11px;
|
||||
font-weight: 800;
|
||||
line-height: 1.2;
|
||||
@@ -143,13 +171,87 @@
|
||||
}
|
||||
|
||||
.topic-legend-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 4px;
|
||||
appearance: none;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
background: transparent;
|
||||
color: #53617e;
|
||||
font-family: inherit;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.topic-legend-selectable {
|
||||
.topic-legend-field,
|
||||
.topic-legend-item {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.topic-legend-field:hover,
|
||||
.topic-legend-item:hover {
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--legend-color, var(--topic-legend-accent)) 8%,
|
||||
#ffffff
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
.topic-legend-field:focus-visible,
|
||||
.topic-legend-item:focus-visible {
|
||||
outline: 2px solid var(--topic-legend-accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.topic-legend-entry-active {
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--legend-color, var(--topic-legend-accent)) 24%,
|
||||
#ffffff
|
||||
);
|
||||
box-shadow:
|
||||
inset 0 0 0 1px
|
||||
color-mix(
|
||||
in srgb,
|
||||
var(--legend-color, var(--topic-legend-accent)) 75%,
|
||||
transparent
|
||||
),
|
||||
0 1px 3px rgba(15, 23, 42, 0.12);
|
||||
}
|
||||
|
||||
.topic-legend-field.topic-legend-entry-active {
|
||||
color: color-mix(
|
||||
in srgb,
|
||||
var(--legend-color, var(--topic-legend-accent)) 34%,
|
||||
#07163d
|
||||
);
|
||||
}
|
||||
|
||||
.topic-legend-field.topic-legend-entry-active .topic-legend-dot {
|
||||
box-shadow:
|
||||
0 0 0 2px #ffffff,
|
||||
0 0 0 4px
|
||||
color-mix(
|
||||
in srgb,
|
||||
var(--legend-color, var(--topic-legend-accent)) 82%,
|
||||
transparent
|
||||
);
|
||||
}
|
||||
|
||||
.topic-legend-item.topic-legend-entry-active {
|
||||
color: color-mix(
|
||||
in srgb,
|
||||
var(--legend-color, var(--topic-legend-accent)) 34%,
|
||||
#07163d
|
||||
);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.topic-legend-more-toggle {
|
||||
flex: 0 0 auto;
|
||||
padding: 0;
|
||||
|
||||
@@ -2,7 +2,11 @@ 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';
|
||||
import {
|
||||
TopicLegendGroup,
|
||||
TopicLegendItem,
|
||||
TopicLegendSubfieldSelection,
|
||||
} from '../../utils/topic-legend';
|
||||
|
||||
export type TopicLegendVariant = 'default' | 'compact';
|
||||
|
||||
@@ -24,9 +28,14 @@ export class TopicLegendComponent {
|
||||
@Input() showVisibilityToggle = true;
|
||||
@Input() collapsedGroupLimit = 3;
|
||||
@Input() variant: TopicLegendVariant = 'default';
|
||||
@Input() selectable = false;
|
||||
@Input() activeFieldIds: ReadonlySet<string> | readonly string[] = [];
|
||||
@Input() activeSubfieldIds: ReadonlySet<string> | readonly string[] = [];
|
||||
|
||||
@Output() visibleChange = new EventEmitter<boolean>();
|
||||
@Output() expandedChange = new EventEmitter<boolean>();
|
||||
@Output() fieldToggle = new EventEmitter<TopicLegendGroup>();
|
||||
@Output() subfieldToggle = new EventEmitter<TopicLegendSubfieldSelection>();
|
||||
|
||||
get hasGroups(): boolean {
|
||||
return this.groups.length > 0;
|
||||
@@ -66,6 +75,37 @@ export class TopicLegendComponent {
|
||||
this.expandedChange.emit(!this.expanded);
|
||||
}
|
||||
|
||||
toggleField(group: TopicLegendGroup): void {
|
||||
if (!this.selectable) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.fieldToggle.emit(group);
|
||||
}
|
||||
|
||||
toggleSubfield(group: TopicLegendGroup, item: TopicLegendItem): void {
|
||||
if (!this.selectable) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.subfieldToggle.emit({ group, item });
|
||||
}
|
||||
|
||||
isFieldActive(group: TopicLegendGroup): boolean {
|
||||
return this.isActiveLegendId(this.activeFieldIds, group.id);
|
||||
}
|
||||
|
||||
isSubfieldActive(item: TopicLegendItem): boolean {
|
||||
return this.isActiveLegendId(this.activeSubfieldIds, item.id);
|
||||
}
|
||||
|
||||
isGroupActive(group: TopicLegendGroup): boolean {
|
||||
return (
|
||||
this.isFieldActive(group) ||
|
||||
group.items.some((item) => this.isSubfieldActive(item))
|
||||
);
|
||||
}
|
||||
|
||||
trackByGroup(_: number, group: TopicLegendGroup): string {
|
||||
return group.id;
|
||||
}
|
||||
@@ -73,4 +113,15 @@ export class TopicLegendComponent {
|
||||
trackByItem(_: number, item: TopicLegendItem): string {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
private isActiveLegendId(
|
||||
activeIds: ReadonlySet<string> | readonly string[],
|
||||
id: string,
|
||||
): boolean {
|
||||
if ('has' in activeIds) {
|
||||
return activeIds.has(id);
|
||||
}
|
||||
|
||||
return activeIds.includes(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,40 @@ export interface TopicLegendGroup {
|
||||
items: TopicLegendItem[];
|
||||
}
|
||||
|
||||
export interface TopicLegendSubfieldSelection {
|
||||
group: TopicLegendGroup;
|
||||
item: TopicLegendItem;
|
||||
}
|
||||
|
||||
export function getTopicLegendFieldId(topic: TopicLegendTopic): string {
|
||||
const fieldName = normalizeLegendValue(topic.field_name) ?? 'Ohne Fachgebiet';
|
||||
|
||||
return topic.field_id ?? normalizeLegendKey(fieldName);
|
||||
}
|
||||
|
||||
export function getTopicLegendSubfieldId(topic: TopicLegendTopic): string {
|
||||
const subfieldName = normalizeLegendValue(topic.subfield_name);
|
||||
|
||||
return (
|
||||
topic.subfield_id ?? (subfieldName ? normalizeLegendKey(subfieldName) : '')
|
||||
);
|
||||
}
|
||||
|
||||
export function toggleTopicLegendSelection(
|
||||
currentSelection: ReadonlySet<string>,
|
||||
id: string,
|
||||
): Set<string> {
|
||||
const nextSelection = new Set(currentSelection);
|
||||
|
||||
if (nextSelection.has(id)) {
|
||||
nextSelection.delete(id);
|
||||
return nextSelection;
|
||||
}
|
||||
|
||||
nextSelection.add(id);
|
||||
return nextSelection;
|
||||
}
|
||||
|
||||
export function buildTopicLegendGroups(
|
||||
topics: readonly TopicLegendTopic[],
|
||||
): TopicLegendGroup[] {
|
||||
@@ -47,8 +81,8 @@ export function buildTopicLegendGroups(
|
||||
normalizeLegendValue(topic.domain_description) ?? '';
|
||||
const subfieldDescription =
|
||||
normalizeLegendValue(topic.subfield_description) ?? '';
|
||||
const fieldKey = topic.field_id ?? normalizeLegendKey(fieldName);
|
||||
const subfieldKey = topic.subfield_id ?? normalizeLegendKey(subfieldName);
|
||||
const fieldKey = getTopicLegendFieldId(topic);
|
||||
const subfieldKey = getTopicLegendSubfieldId(topic);
|
||||
|
||||
if (!groups.has(fieldKey)) {
|
||||
groups.set(fieldKey, {
|
||||
|
||||
Reference in New Issue
Block a user