topic-legend: select fields and subfields separately

This commit is contained in:
2026-06-26 14:16:56 +02:00
parent 512356e106
commit f2cf83f63b
5 changed files with 72 additions and 22 deletions
@@ -23,7 +23,8 @@ import {
getTopicLegendSubfieldId,
TopicLegendGroup,
TopicLegendSubfieldSelection,
toggleTopicLegendSelection,
toggleTopicLegendFieldSelection,
toggleTopicLegendSubfieldSelection,
} from '../../shared/utils/topic-legend';
interface InterestTag {
@@ -154,18 +155,25 @@ export class PersonInterestingComponent implements OnInit {
}
onLegendFieldToggle(group: TopicLegendGroup): void {
this.activeLegendFieldIds.set(
toggleTopicLegendSelection(this.activeLegendFieldIds(), group.id),
const selection = toggleTopicLegendFieldSelection(
this.activeLegendFieldIds(),
this.activeLegendSubfieldIds(),
group,
);
this.activeLegendFieldIds.set(selection.fieldIds);
this.activeLegendSubfieldIds.set(selection.subfieldIds);
}
onLegendSubfieldToggle(selection: TopicLegendSubfieldSelection): void {
this.activeLegendSubfieldIds.set(
toggleTopicLegendSelection(
this.activeLegendSubfieldIds(),
selection.item.id,
),
const nextSelection = toggleTopicLegendSubfieldSelection(
this.activeLegendFieldIds(),
this.activeLegendSubfieldIds(),
selection,
);
this.activeLegendFieldIds.set(nextSelection.fieldIds);
this.activeLegendSubfieldIds.set(nextSelection.subfieldIds);
}
isTagActive(tag: InterestTag): boolean {
@@ -21,7 +21,8 @@ import {
getTopicLegendSubfieldId,
TopicLegendGroup,
TopicLegendSubfieldSelection,
toggleTopicLegendSelection,
toggleTopicLegendFieldSelection,
toggleTopicLegendSubfieldSelection,
} from '../../../../shared/utils/topic-legend';
import { buildTopicHierarchyTooltip } from '../../../../shared/utils/topic-tooltip';
@@ -430,17 +431,25 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
}
onLegendFieldToggle(group: TopicLegendGroup): void {
this.activeLegendFieldIds = toggleTopicLegendSelection(
const selection = toggleTopicLegendFieldSelection(
this.activeLegendFieldIds,
group.id,
this.activeLegendSubfieldIds,
group,
);
this.activeLegendFieldIds = selection.fieldIds;
this.activeLegendSubfieldIds = selection.subfieldIds;
}
onLegendSubfieldToggle(selection: TopicLegendSubfieldSelection): void {
this.activeLegendSubfieldIds = toggleTopicLegendSelection(
const nextSelection = toggleTopicLegendSubfieldSelection(
this.activeLegendFieldIds,
this.activeLegendSubfieldIds,
selection.item.id,
selection,
);
this.activeLegendFieldIds = nextSelection.fieldIds;
this.activeLegendSubfieldIds = nextSelection.subfieldIds;
}
isTopicActiveByLegend(topic: TopicTimelineTopic): boolean {
@@ -47,7 +47,7 @@
<div
*ngFor="let group of visibleGroups; trackBy: trackByGroup"
class="topic-legend-group"
[class.topic-legend-group-active]="isGroupActive(group)"
[class.topic-legend-group-active]="isFieldActive(group)"
[style.--legend-color]="group.color">
<button
type="button"
@@ -21,7 +21,7 @@ export class TopicLegendComponent {
@Input() groups: TopicLegendGroup[] = [];
@Input() title = 'Farben nach Fachgebiet';
@Input() infoTooltip =
'Fachgebiete bestimmen die Farbe. Themenbereiche werden darunter gruppiert.';
'Fachgebiete bestimmen die Farbe. Themenbereiche werden darunter gruppiert. Fachgebiete oder Themenbereiche können angeklickt werden, um die passenden Themen zu markieren.';
@Input() visible = true;
@Input() expanded = false;
@Input() showTitle = true;
@@ -99,13 +99,6 @@ export class TopicLegendComponent {
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;
}
@@ -31,6 +31,11 @@ export interface TopicLegendSubfieldSelection {
item: TopicLegendItem;
}
export interface TopicLegendSelectionState {
fieldIds: Set<string>;
subfieldIds: Set<string>;
}
export function getTopicLegendFieldId(topic: TopicLegendTopic): string {
const fieldName = normalizeLegendValue(topic.field_name) ?? 'Ohne Fachgebiet';
@@ -60,6 +65,41 @@ export function toggleTopicLegendSelection(
return nextSelection;
}
export function toggleTopicLegendFieldSelection(
currentFieldIds: ReadonlySet<string>,
currentSubfieldIds: ReadonlySet<string>,
group: TopicLegendGroup,
): TopicLegendSelectionState {
const fieldIds = toggleTopicLegendSelection(currentFieldIds, group.id);
const subfieldIds = new Set(currentSubfieldIds);
if (fieldIds.has(group.id)) {
for (const item of group.items) {
subfieldIds.delete(item.id);
}
}
return { fieldIds, subfieldIds };
}
export function toggleTopicLegendSubfieldSelection(
currentFieldIds: ReadonlySet<string>,
currentSubfieldIds: ReadonlySet<string>,
selection: TopicLegendSubfieldSelection,
): TopicLegendSelectionState {
const fieldIds = new Set(currentFieldIds);
const subfieldIds = toggleTopicLegendSelection(
currentSubfieldIds,
selection.item.id,
);
if (subfieldIds.has(selection.item.id)) {
fieldIds.delete(selection.group.id);
}
return { fieldIds, subfieldIds };
}
export function buildTopicLegendGroups(
topics: readonly TopicLegendTopic[],
): TopicLegendGroup[] {