From 11ac6525c19289666e5485126ff666f33479a8b4 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sat, 25 Jul 2026 00:27:54 +0200 Subject: [PATCH] moved row with filters up above all visuals. Implemented treemap for fuzzy search. adapted resolver --- .../uni-trend-parent.component.html | 202 ++++++----- .../uni-trend-parent.component.ts | 334 ++++++++++++++++-- .../src/app/resolvers/uni-trend.resolver.ts | 73 ++-- 3 files changed, 463 insertions(+), 146 deletions(-) diff --git a/webapp/src/app/modules/university-ranking/uni-trend-parent/uni-trend-parent.component.html b/webapp/src/app/modules/university-ranking/uni-trend-parent/uni-trend-parent.component.html index ccc758ea..eba4f3a6 100644 --- a/webapp/src/app/modules/university-ranking/uni-trend-parent/uni-trend-parent.component.html +++ b/webapp/src/app/modules/university-ranking/uni-trend-parent/uni-trend-parent.component.html @@ -92,6 +92,87 @@ + +
+ + @if (activeConfig().showLocationSelector) { + + + } + + + @if (activeConfig().showAuthorSelector) { + + + } + + + @if (activeConfig().showInstitutionSelector) { + + + } + + + @if (activeConfig().showAuthorSelector) { + + + } +
+
@if (isPageResolving() || (isTrendLoading() && !rawTrendResponse())) { @@ -109,11 +190,11 @@ @if (selectedSearchType() === 'news') { + (chipClick)="toggleVisibility('news_topic_' + topic)"> } @else if (selectedTrendTopics().length > 1) { } - -
- - @if (activeConfig().showLocationSelector) { - - - } - - - @if (activeConfig().showAuthorSelector) { - - - } - - - @if (activeConfig().showInstitutionSelector) { - - - } - - - @if (activeConfig().showAuthorSelector) { - - - } -
+ + @if (isFuzzy() && activeTreemapData()) { +
+
+

+ account_tree + Themen-Hierarchie & Verteilung (Treemap) + @if (selectedPieEntity()?.name || primaryInstitutionName()) { + + · + {{ selectedPieEntity()?.name || primaryInstitutionName() }} + + } +

+ + +
+
+ } } @else {
trending_up 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 9fd2a328..eb689866 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 @@ -56,6 +56,16 @@ import { AuthorSelectorComponent } from '../../../shared/ui/author-selector/auth import { AuthorInstitutionSelectorComponent } from '../../../shared/ui/author-institution-selector/author-institution-selector.component'; import { SearchResultsStateService } from '../../keywords-search/search-results/search-results-state.service'; import { LoadingComponent } from '../../../shared/ui/loading/loading.component'; +import { TopicTreemapComponent } from '../../../shared/ui/topic-treemap/topic-treemap.component'; +import { + TopicTreemapData, + TopicTreemapField, + TopicTreemapSubfield, + TopicTreemapTopic, + TopicTreemapValue, + TopicTreemapTopicSelect, +} from '../../../shared/ui/topic-treemap/topic-treemap.models'; +import { TopicsService } from '../../../api/api/topics.service'; export interface CompareItem { id: string; @@ -136,6 +146,7 @@ export const TREND_CONFIGS: Record = { AuthorSelectorComponent, AuthorInstitutionSelectorComponent, LoadingComponent, + TopicTreemapComponent, ], templateUrl: './uni-trend-parent.component.html', styleUrl: './uni-trend-parent.component.scss', @@ -143,6 +154,7 @@ export const TREND_CONFIGS: Record = { }) export class UniTrendParentComponent implements OnInit { private readonly apiService = inject(UniversityRankingsService); + private readonly topicsService = inject(TopicsService); private readonly institutionsApiService = inject(InstitutionsService); private readonly personsApiService = inject(PersonsService); private readonly organizationService = inject(OrganizationService, { @@ -230,6 +242,12 @@ export class UniTrendParentComponent implements OnInit { readonly isTopTopicsLoading = signal(false); readonly topTopicsError = signal(false); + // Topic Treemap signals + readonly isFuzzy = computed(() => this.state?.fuzzySearch() ?? true); + readonly topicTreemap = signal(null); + readonly isTreemapLoading = signal(false); + readonly selectedTopicTreemapNode = signal(undefined); + getMappedTopic(topicOrKeyword: string): string { const kws = this.keywords(); const topics = this.state?.topicsList() ?? kws; @@ -299,6 +317,197 @@ export class UniTrendParentComponent implements OnInit { }); }); + cleanEntityId(id: string | null | undefined): string { + if (!id) return ''; + const lower = id.toLowerCase().trim(); + return lower.includes('/') ? lower.split('/').pop()! : lower; + } + + // Dynamic Treemap Data for Selected Entity (Institution or Author or Region/Country) + readonly activeTreemapData = computed(() => { + const data = this.trendResponse(); + const searchType = this.selectedSearchType(); + const isFuzzy = this.isFuzzy(); + if (!data || !data.series || !isFuzzy) return null; + + const startYr = this.startYear(); + const endYr = this.endYear(); + + const activePie = this.selectedPieEntity(); + let targetEntityId: string | undefined = activePie?.id || undefined; + let targetEntityName = activePie?.name || 'Ausgewählte Entität'; + + if (!targetEntityId) { + if (searchType === 'authors') { + const firstAuthor = this.comparisonAuthors()[0]; + targetEntityId = firstAuthor?.id || undefined; + targetEntityName = firstAuthor?.name || 'Autor'; + } else { + targetEntityId = this.primaryInstitution() || undefined; + targetEntityName = this.primaryInstitutionName(); + } + } + + const cleanTargetId = targetEntityId + ? this.cleanEntityId(targetEntityId) + : ''; + + let matchingSeries: TrendSeries[] = []; + if (searchType === 'news') { + matchingSeries = data.series; + } else { + matchingSeries = data.series.filter( + (s) => this.cleanEntityId(s.entity_id) === cleanTargetId, + ); + if (matchingSeries.length === 0 && data.series.length > 0) { + matchingSeries = data.series; + } + } + + if (matchingSeries.length === 0) return null; + + const keywordEntries = this.state?.selectedKeywordEntries() ?? []; + const fieldsMap = new Map< + string, + { + id: string; + name: string; + subfieldsMap: Map< + string, + { + id: string; + name: string; + topicsMap: Map< + string, + { + id: string; + name: string; + total: number; + values: TopicTreemapValue[]; + } + >; + } + >; + } + >(); + + matchingSeries.forEach((s) => { + Object.entries(s.topic_data || {}).forEach( + ([topicName, yearlyDataList]) => { + const totalCount = yearlyDataList + .filter((y) => y.year >= startYr && y.year <= endYr) + .reduce((sum, item) => sum + (item.raw || 0), 0); + + if (totalCount <= 0) return; + + const mappedName = this.getMappedTopic(topicName); + const targetLower = topicName.toLowerCase().trim(); + const mappedLower = mappedName.toLowerCase().trim(); + + const match = keywordEntries.find( + (e) => + e.topic_mapping?.topic?.display_name?.toLowerCase().trim() === + mappedLower || + e.topic_mapping?.topic?.display_name?.toLowerCase().trim() === + targetLower || + e.llm_keyword?.keyword?.toLowerCase().trim() === targetLower, + ); + + const fieldName = + match?.topic_mapping?.topic?.field?.display_name || + 'Information & Communication Technology'; + const fieldId = match?.topic_mapping?.topic?.field?.id + ? String(match.topic_mapping.topic.field.id) + : 'field_ict'; + + const subfieldName = + match?.topic_mapping?.topic?.subfield?.display_name || fieldName; + const subfieldId = match?.topic_mapping?.topic?.subfield?.id + ? String(match.topic_mapping.topic.subfield.id) + : `subfield_${fieldId}`; + + const topicId = match?.topic_mapping?.topic?.id + ? String(match.topic_mapping.topic.id) + : topicName; + + if (!fieldsMap.has(fieldId)) { + fieldsMap.set(fieldId, { + id: fieldId, + name: fieldName, + subfieldsMap: new Map(), + }); + } + const fieldEntry = fieldsMap.get(fieldId)!; + + if (!fieldEntry.subfieldsMap.has(subfieldId)) { + fieldEntry.subfieldsMap.set(subfieldId, { + id: subfieldId, + name: subfieldName, + topicsMap: new Map(), + }); + } + const subfieldEntry = fieldEntry.subfieldsMap.get(subfieldId)!; + + if (!subfieldEntry.topicsMap.has(topicId)) { + const yearlyValues: TopicTreemapValue[] = yearlyDataList + .filter((y) => y.year >= startYr && y.year <= endYr) + .map((y) => ({ + year: y.year, + count: y.raw || 0, + share: y.normalized || 0, + })); + + subfieldEntry.topicsMap.set(topicId, { + id: topicId, + name: topicName, + total: totalCount, + values: yearlyValues, + }); + } + }, + ); + }); + + const years = Array.from( + { length: endYr - startYr + 1 }, + (_, i) => startYr + i, + ); + const fields: TopicTreemapField[] = Array.from(fieldsMap.values()).map( + (f) => { + const subfields: TopicTreemapSubfield[] = Array.from( + f.subfieldsMap.values(), + ).map((sf) => { + const topics: TopicTreemapTopic[] = Array.from(sf.topicsMap.values()); + const sfTotal = topics.reduce((sum, t) => sum + t.total, 0); + return { + id: sf.id, + name: sf.name, + total: sfTotal, + values: [], + topics, + }; + }); + const fTotal = subfields.reduce((sum, sf) => sum + sf.total, 0); + return { + id: f.id, + name: f.name, + total: fTotal, + values: [], + subfields, + }; + }, + ); + + if (fields.length === 0) return null; + + return { + institution_id: cleanTargetId, + organization_name: targetEntityName, + years, + fields, + }; + }); + // Autocomplete UI state readonly searchQuery = signal(''); readonly searchResults = signal([]); @@ -316,6 +525,26 @@ export class UniTrendParentComponent implements OnInit { readonly entityVisibilityMap = signal>(new Map()); + isTopicEmpty(topic: string): boolean { + const res = this.rawTrendResponse(); + if (!res || !res.series || res.series.length === 0) return false; + const startYr = this.startYear(); + const endYr = this.endYear(); + const mapped = this.getMappedTopic(topic).toLowerCase().trim(); + + return !res.series.some((s) => { + const yearlyList = + s.topic_data?.[topic] || + s.topic_data?.[mapped] || + Object.values(s.topic_data || {})[0]; + if (!yearlyList) return false; + const total = yearlyList + .filter((y) => y.year >= startYr && y.year <= endYr) + .reduce((sum, item) => sum + (item.raw || 0), 0); + return total > 0; + }); + } + isVisible(id: string): boolean { return this.entityVisibilityMap().get(id) !== false; } @@ -621,20 +850,50 @@ export class UniTrendParentComponent implements OnInit { if (resolved.topics && resolved.topics.length > 0) { this.selectedTrendTopics.set(resolved.topics); this.fetchedTopics.set([...resolved.topics]); - if ( - !this.activeChartTopic() || - !resolved.topics.includes(this.activeChartTopic()) - ) { - this.activeChartTopic.set(resolved.topics[0]); - } + const firstNonEmpty = resolved.topics.find( + (t: string) => !this.isTopicEmpty(t), + ); + const targetTopic = firstNonEmpty || resolved.topics[0]; + this.activeChartTopic.set(targetTopic); } else { this.fetchedTopics.set([...this.selectedTrendTopics()]); } - this.fetchedInstitutions.set([...this.comparisonInstitutions()]); - this.fetchedCountries.set([...this.comparisonCountries()]); - this.fetchedRegions.set([...this.comparisonRegions()]); - this.fetchedAuthors.set([...this.comparisonAuthors()]); + if (resolved.institutions && resolved.institutions.length > 0) { + this.comparisonInstitutions.set(resolved.institutions); + this.fetchedInstitutions.set([...resolved.institutions]); + } else { + this.fetchedInstitutions.set([...this.comparisonInstitutions()]); + } + + if (resolved.countries && resolved.countries.length > 0) { + this.comparisonCountries.set(resolved.countries); + this.fetchedCountries.set([...resolved.countries]); + } else { + this.fetchedCountries.set([...this.comparisonCountries()]); + } + + if (resolved.regions && resolved.regions.length > 0) { + this.comparisonRegions.set(resolved.regions); + this.fetchedRegions.set([...resolved.regions]); + } else { + this.fetchedRegions.set([...this.comparisonRegions()]); + } + + if (resolved.authors && resolved.authors.length > 0) { + this.comparisonAuthors.set(resolved.authors); + this.fetchedAuthors.set([...resolved.authors]); + } else { + this.fetchedAuthors.set([...this.comparisonAuthors()]); + } + + if (resolved.treemapData) { + this.topicTreemap.set(resolved.treemapData); + } + + if (resolved.treemapNode !== undefined) { + this.selectedTopicTreemapNode.set(resolved.treemapNode || undefined); + } this.isTrendLoading.set(false); } @@ -1335,6 +1594,7 @@ export class UniTrendParentComponent implements OnInit { end_year: this.endYear(), chart_mode: this.chartMode(), active_chart_topic: this.activeChartTopic(), + treemapNode: this.selectedTopicTreemapNode() ?? null, }; this.router.navigate([], { @@ -1344,6 +1604,34 @@ export class UniTrendParentComponent implements OnInit { }); } + fetchTreemapData() { + const fuzzy = this.state?.fuzzySearch() ?? true; + const topics = this.selectedTrendTopics(); + if (!fuzzy || topics.length === 0) { + this.topicTreemap.set(null); + return; + } + this.isTreemapLoading.set(true); + this.topicsService.countTopicHierarchy(topics).subscribe({ + next: (res: any) => { + this.topicTreemap.set(res); + this.isTreemapLoading.set(false); + }, + error: () => { + this.isTreemapLoading.set(false); + }, + }); + } + + onTopicTreemapNodeChange(nodeId: string | undefined): void { + this.selectedTopicTreemapNode.set(nodeId); + this.updateUrlParams(); + } + + onTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void { + // Topic selected inside treemap component + } + // Checkbox topic toggling onTrendTopicToggle(topic: string, event: Event) { const isChecked = (event.target as HTMLInputElement).checked; @@ -1541,32 +1829,6 @@ export class UniTrendParentComponent implements OnInit { } } - isTopicEmpty(topic: string): boolean { - const data = this.trendResponse(); - if (!data || !data.series || data.series.length === 0) { - return false; - } - const mapped = this.getMappedTopic(topic); - const startYr = this.startYear(); - const endYr = this.endYear(); - - let totalRaw = 0; - data.series.forEach((s) => { - if (s.visible !== false && s.topic_data) { - const items = s.topic_data[topic] || s.topic_data[mapped]; - if (items) { - items.forEach((y) => { - if (y.year >= startYr && y.year <= endYr) { - totalRaw += y.raw || 0; - } - }); - } - } - }); - - return totalRaw === 0; - } - // Topic tab toggle (data reuses instantly) updateActiveChartTopic(topic: string) { if (this.isTopicEmpty(topic)) { diff --git a/webapp/src/app/resolvers/uni-trend.resolver.ts b/webapp/src/app/resolvers/uni-trend.resolver.ts index 0382efef..b61b49fa 100644 --- a/webapp/src/app/resolvers/uni-trend.resolver.ts +++ b/webapp/src/app/resolvers/uni-trend.resolver.ts @@ -4,12 +4,22 @@ import { catchError, of, Observable, map } from 'rxjs'; import { TrendResponse, UniversityRankingsService } from '../api'; import { SearchResultsStateService } from '../modules/keywords-search/search-results/search-results-state.service'; +export interface CompareItem { + id: string; + name: string; +} + export interface UniTrendResolvedData { trendResponse: TrendResponse | null; searchType: string; topics: string[]; keywords: string[]; fuzzy: boolean; + institutions: CompareItem[]; + countries: CompareItem[]; + regions: CompareItem[]; + authors: CompareItem[]; + treemapNode?: string | null; } export const uniTrendResolver: ResolveFn = ( @@ -21,6 +31,7 @@ export const uniTrendResolver: ResolveFn = ( const searchType = params.get('search_type') || 'publications'; const fuzzy = params.get('fuzzy') !== 'false'; + const treemapNode = params.get('treemapNode'); // Extract keywords & topics let keywords = params.getAll('keyword'); @@ -61,32 +72,42 @@ export const uniTrendResolver: ResolveFn = ( keywords = topics; } - // Parse institutions + // Parse comparison items const instParams = params.getAll('institutions'); - let institutions = instParams.map((i) => { + const parsedInstitutions: CompareItem[] = instParams.map((i) => { const parts = i.split('|'); const cleanId = parts[0].includes('/') ? parts[0].split('/').pop() || parts[0] : parts[0]; - return cleanId; + return { id: cleanId, name: parts[1] || cleanId }; }); - if (institutions.length === 0) { - institutions = ['I62318514']; - } - // Parse countries const countryParams = params.getAll('countries'); - let countries = countryParams.map((c) => c.split('|')[0]); - if (countries.length === 0) { - countries = ['DE']; - } + const parsedCountries: CompareItem[] = countryParams.map((c) => { + const parts = c.split('|'); + return { id: parts[0], name: parts[1] || parts[0] }; + }); - // Parse regions & authors const regionParams = params.getAll('regions'); - const regions = regionParams.map((r) => r.split('|')[0]); + const parsedRegions: CompareItem[] = regionParams.map((r) => { + const parts = r.split('|'); + return { id: parts[0], name: parts[1] || parts[0] }; + }); const authorParams = params.getAll('authors'); - const authors = authorParams.map((a) => a.split('|')[0]); + const parsedAuthors: CompareItem[] = authorParams.map((a) => { + const parts = a.split('|'); + return { id: parts[0], name: parts[1] || parts[0] }; + }); + + const instIds = + parsedInstitutions.length > 0 + ? parsedInstitutions.map((i) => i.id) + : ['I62318514']; + const countryIds = + parsedCountries.length > 0 ? parsedCountries.map((c) => c.id) : ['DE']; + const regionIds = parsedRegions.map((r) => r.id); + const authorIds = parsedAuthors.map((a) => a.id); const apiService = inject(UniversityRankingsService); @@ -95,29 +116,25 @@ export const uniTrendResolver: ResolveFn = ( topics, keywords, fuzzy, - institutions, - countries, - regions, - authors, + instIds, + countryIds, + regionIds, + authorIds, searchType as any, ) .pipe( + catchError(() => of(null)), map((trendResponse) => ({ trendResponse, searchType, topics, keywords, fuzzy, + institutions: parsedInstitutions, + countries: parsedCountries, + regions: parsedRegions, + authors: parsedAuthors, + treemapNode, })), - catchError((err) => { - console.error('uniTrendResolver failed to load trend data:', err); - return of({ - trendResponse: null, - searchType, - topics, - keywords, - fuzzy, - }); - }), ); };