fix: institution visisbility button & refactor ID type (full OpenAlex link vs ID) into parent component
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
Kazgatari
2026-07-28 09:11:40 +02:00
parent ae8332dc3d
commit b2e70c2bb3
3 changed files with 97 additions and 35 deletions
@@ -77,6 +77,11 @@ export class UniTrendChartComponent {
];
const getFn = this.getEntityColor();
// Find index of first visible series for markLine zero baseline attachment
const firstVisibleIdx = trendData.series.findIndex(
(s) => (s as any).visible !== false,
);
// Build series: Line in top grid, growth volume bars and S-Curve in bottom grid
trendData.series.forEach((entity, entityIdx) => {
const rawColor = getFn
@@ -146,7 +151,7 @@ export class UniTrendChartComponent {
color: color,
},
markLine:
entityIdx === 0
entityIdx === firstVisibleIdx
? {
silent: true,
symbol: 'none',
@@ -421,7 +426,11 @@ export class UniTrendChartComponent {
return value > 0 ? `+${value}` : `${value}`;
},
},
axisLine: { show: false },
axisLine: {
show: true,
onZero: true,
lineStyle: { color: '#9ca3af', width: 1 },
},
axisTick: { show: false },
splitLine: {
show: true,
@@ -8,7 +8,9 @@ import {
untracked,
inject,
OnInit,
DestroyRef,
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import {
@@ -202,6 +204,8 @@ export class UniTrendParentComponent implements OnInit {
]);
readonly comparisonRegions = signal<CompareItem[]>([]);
readonly comparisonAuthors = signal<CompareItem[]>([]);
readonly hasUserClearedInstitutions = signal<boolean>(false);
readonly hasUserClearedAuthors = signal<boolean>(false);
readonly startYear = signal<number>(2010);
readonly endYear = signal<number>(2025);
readonly chartMode = signal<'normalized' | 'total' | 'cumulative'>(
@@ -583,14 +587,16 @@ export class UniTrendParentComponent implements OnInit {
}
isVisible(id: string): boolean {
return this.entityVisibilityMap().get(id) !== false;
const clean = this.cleanEntityId(id);
return this.entityVisibilityMap().get(clean) !== false;
}
toggleVisibility(id: string): void {
const clean = this.cleanEntityId(id);
this.entityVisibilityMap.update((map) => {
const newMap = new Map(map);
const current = newMap.get(id) !== false;
newMap.set(id, !current);
const current = newMap.get(clean) !== false;
newMap.set(clean, !current);
return newMap;
});
}
@@ -791,13 +797,26 @@ export class UniTrendParentComponent implements OnInit {
topics.forEach((topicName, idx) => {
const mappedName = this.getMappedTopic(topicName);
let matchKey = rawTopicKeys.find(
(rk) =>
rk.toLowerCase() === topicName.toLowerCase() ||
rk.toLowerCase() === mappedName.toLowerCase() ||
rk.toLowerCase().includes(topicName.toLowerCase()) ||
rk.toLowerCase().includes(mappedName.toLowerCase()),
);
const topicLower = topicName.toLowerCase().trim();
const mappedLower = mappedName.toLowerCase().trim();
let matchKey = rawTopicKeys.find((rk) => {
const rkLower = rk.toLowerCase().trim();
const rkClean = rkLower.includes('/')
? rkLower.split('/').pop()!
: rkLower.startsWith('news_topic_')
? rkLower.slice('news_topic_'.length)
: rkLower;
return (
rkLower === topicLower ||
rkLower === mappedLower ||
rkClean === topicLower ||
rkClean === mappedLower ||
rkLower.includes(topicLower) ||
rkLower.includes(mappedLower)
);
});
if (!matchKey && rawTopicKeys[idx]) {
matchKey = rawTopicKeys[idx];
@@ -912,7 +931,7 @@ export class UniTrendParentComponent implements OnInit {
this.availableYears.push(y);
}
this.router.events.subscribe((event) => {
this.router.events.pipe(takeUntilDestroyed()).subscribe((event) => {
if (event instanceof ResolveStart) {
this.isPageResolving.set(true);
} else if (event instanceof ResolveEnd) {
@@ -921,7 +940,7 @@ export class UniTrendParentComponent implements OnInit {
});
// Subscribe to route resolver data
this.route.data.subscribe((data) => {
this.route.data.pipe(takeUntilDestroyed()).subscribe((data) => {
if (data['trendData']) {
const resolved = data['trendData'];
const res = resolved.trendResponse ?? resolved;
@@ -1041,15 +1060,21 @@ export class UniTrendParentComponent implements OnInit {
);
}
// If comparison list is empty, initialize default institutions/authors dynamically
// If comparison list is empty, initialize default institutions/authors dynamically (unless explicitly cleared by user)
if (searchType === 'authors') {
const currentAuthors = untracked(() => this.comparisonAuthors());
if (currentAuthors.length === 0) {
if (
currentAuthors.length === 0 &&
!untracked(() => this.hasUserClearedAuthors())
) {
untracked(() => this.initializeDefaultAuthors());
}
} else {
const currentInsts = untracked(() => this.comparisonInstitutions());
if (currentInsts.length === 0) {
if (
currentInsts.length === 0 &&
!untracked(() => this.hasUserClearedInstitutions())
) {
untracked(() => this.initializeDefaultInstitutions());
}
}
@@ -1150,7 +1175,7 @@ export class UniTrendParentComponent implements OnInit {
});
// Handle initialization and synchronization of URL state
this.route.queryParams.subscribe((params) => {
this.route.queryParams.pipe(takeUntilDestroyed()).subscribe((params) => {
let hasInstsFromUrl = false;
if (params['search_type']) {
this.selectedSearchType.set(params['search_type'] as any);
@@ -1183,8 +1208,12 @@ export class UniTrendParentComponent implements OnInit {
}
}
// If URL didn't specify institutions and list is currently empty, initialize defaults
if (!hasInstsFromUrl && this.comparisonInstitutions().length === 0) {
// If URL didn't specify institutions and list is currently empty, initialize defaults (unless user explicitly cleared them)
if (
!hasInstsFromUrl &&
this.comparisonInstitutions().length === 0 &&
!this.hasUserClearedInstitutions()
) {
this.initializeDefaultInstitutions();
}
@@ -1798,15 +1827,14 @@ export class UniTrendParentComponent implements OnInit {
// Add comparison institution
addInstitution(id: string, name: string) {
const cleanId = id.includes('/') ? id.split('/').pop() || id : id;
const cleanId = this.cleanEntityId(id);
const current = this.comparisonInstitutions();
const exists = current.some((i: CompareItem) => {
const itemClean = i.id.includes('/')
? i.id.split('/').pop() || i.id
: i.id;
const itemClean = this.cleanEntityId(i.id);
return itemClean.toLowerCase() === cleanId.toLowerCase();
});
if (!exists) {
this.hasUserClearedInstitutions.set(false);
this.comparisonInstitutions.set([...current, { id: cleanId, name }]);
this.updateUrlParams();
}
@@ -1815,10 +1843,15 @@ export class UniTrendParentComponent implements OnInit {
}
removeInstitution(id: string) {
const cleanTarget = this.cleanEntityId(id);
const current = this.comparisonInstitutions();
this.comparisonInstitutions.set(
current.filter((i: CompareItem) => i.id !== id),
const updated = current.filter(
(i: CompareItem) => this.cleanEntityId(i.id) !== cleanTarget,
);
if (updated.length === 0) {
this.hasUserClearedInstitutions.set(true);
}
this.comparisonInstitutions.set(updated);
this.updateUrlParams();
}
@@ -1888,17 +1921,20 @@ export class UniTrendParentComponent implements OnInit {
const current = this.comparisonAuthors();
const updated = [...current];
(res.results || []).forEach((author: any) => {
const shortId =
author.id && author.id.includes('/')
? author.id.split('/').pop() || author.id
: author.id;
if (shortId && !updated.some((a) => a.id === shortId)) {
const shortId = this.cleanEntityId(author.id);
if (
shortId &&
!updated.some((a) => this.cleanEntityId(a.id) === shortId)
) {
updated.push({
id: shortId,
name: author.display_name || 'Unbekannt',
});
}
});
if (updated.length > 0) {
this.hasUserClearedAuthors.set(false);
}
this.comparisonAuthors.set(updated);
this.isSuggestionsLoading.set(false);
this.updateUrlParams();
@@ -1914,17 +1950,25 @@ export class UniTrendParentComponent implements OnInit {
}
addAuthor(id: string, name: string) {
const shortId = id.includes('/') ? id.split('/').pop() || id : id;
const shortId = this.cleanEntityId(id);
const current = this.comparisonAuthors();
if (!current.some((a) => a.id === shortId)) {
if (!current.some((a) => this.cleanEntityId(a.id) === shortId)) {
this.hasUserClearedAuthors.set(false);
this.comparisonAuthors.set([...current, { id: shortId, name }]);
this.updateUrlParams();
}
}
removeAuthor(id: string) {
const cleanTarget = this.cleanEntityId(id);
const current = this.comparisonAuthors();
this.comparisonAuthors.set(current.filter((a: CompareItem) => a.id !== id));
const updated = current.filter(
(a: CompareItem) => this.cleanEntityId(a.id) !== cleanTarget,
);
if (updated.length === 0) {
this.hasUserClearedAuthors.set(true);
}
this.comparisonAuthors.set(updated);
this.updateUrlParams();
}
@@ -109,8 +109,17 @@ export class AuthorSelectorComponent {
this.toggleVisibility.emit(id);
}
private cleanId(id: string | undefined): string {
if (!id) return '';
const lower = id.toLowerCase().trim();
return lower.includes('/') ? lower.split('/').pop()! : lower;
}
isAlreadyAdded(id: string | undefined): boolean {
if (!id) return false;
return this.comparisonAuthors().some((i) => i.id === id);
const cleanTarget = this.cleanId(id);
return this.comparisonAuthors().some(
(i) => this.cleanId(i.id) === cleanTarget,
);
}
}