From b2e70c2bb3d3eb36fb02ba926e3ce265a1dff576 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Tue, 28 Jul 2026 09:11:40 +0200 Subject: [PATCH] fix: institution visisbility button & refactor ID type (full OpenAlex link vs ID) into parent component --- .../uni-trend-chart.component.ts | 13 ++- .../uni-trend-parent.component.ts | 108 ++++++++++++------ .../author-selector.component.ts | 11 +- 3 files changed, 97 insertions(+), 35 deletions(-) diff --git a/webapp/src/app/modules/university-ranking/uni-trend-chart/uni-trend-chart.component.ts b/webapp/src/app/modules/university-ranking/uni-trend-chart/uni-trend-chart.component.ts index 2fc5b890..3893029d 100644 --- a/webapp/src/app/modules/university-ranking/uni-trend-chart/uni-trend-chart.component.ts +++ b/webapp/src/app/modules/university-ranking/uni-trend-chart/uni-trend-chart.component.ts @@ -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, diff --git a/webapp/src/app/modules/university-ranking/uni-trend-parent/uni-trend-parent.component.ts b/webapp/src/app/modules/university-ranking/uni-trend-parent/uni-trend-parent.component.ts index 423a39ef..a78965e4 100644 --- a/webapp/src/app/modules/university-ranking/uni-trend-parent/uni-trend-parent.component.ts +++ b/webapp/src/app/modules/university-ranking/uni-trend-parent/uni-trend-parent.component.ts @@ -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([]); readonly comparisonAuthors = signal([]); + readonly hasUserClearedInstitutions = signal(false); + readonly hasUserClearedAuthors = signal(false); readonly startYear = signal(2010); readonly endYear = signal(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(); } diff --git a/webapp/src/app/shared/ui/author-selector/author-selector.component.ts b/webapp/src/app/shared/ui/author-selector/author-selector.component.ts index 736b483f..d8fe5d0d 100644 --- a/webapp/src/app/shared/ui/author-selector/author-selector.component.ts +++ b/webapp/src/app/shared/ui/author-selector/author-selector.component.ts @@ -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, + ); } }