From 0fd028c6cb7eb072015f8e56bfe7f045ed69adc0 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Mon, 13 Jul 2026 12:14:42 +0200 Subject: [PATCH] added pie chart for authors and institutions --- .../uni-pie-chart.component.html | 3 + .../uni-pie-chart.component.scss | 17 ++ .../uni-pie-chart/uni-pie-chart.component.ts | 155 ++++++++++++++++++ .../uni-trend-parent.component.html | 29 +++- .../uni-trend-parent.component.ts | 59 ++++++- .../author-selector.component.html | 11 +- .../author-selector.component.ts | 6 + .../institution-selector.component.html | 31 +++- .../institution-selector.component.ts | 6 + .../location-selector.component.html | 22 ++- .../location-selector.component.ts | 6 + 11 files changed, 328 insertions(+), 17 deletions(-) create mode 100644 webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.html create mode 100644 webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.scss create mode 100644 webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.ts diff --git a/webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.html b/webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.html new file mode 100644 index 00000000..86b3f2a6 --- /dev/null +++ b/webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.html @@ -0,0 +1,3 @@ +
+
+
diff --git a/webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.scss b/webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.scss new file mode 100644 index 00000000..20a76242 --- /dev/null +++ b/webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.scss @@ -0,0 +1,17 @@ +.pie-chart-holder { + display: flex; + flex-direction: column; + background: white; + border: 1px solid #d7e4ff; + border-radius: 16px; + padding: 16px; + box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04); + box-sizing: border-box; + width: 100%; + height: 300px; +} + +.pie-chart-container { + width: 100%; + height: 100%; +} diff --git a/webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.ts b/webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.ts new file mode 100644 index 00000000..f8106798 --- /dev/null +++ b/webapp/src/app/modules/university-ranking/uni-pie-chart/uni-pie-chart.component.ts @@ -0,0 +1,155 @@ +import { + Component, + input, + computed, + ChangeDetectionStrategy, +} from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { EChartsOption } from 'echarts'; +import { NgxEchartsDirective } from 'ngx-echarts'; +import { TrendResponse } from '../../../api'; +import { topicHierarchyColor } from '../../../resolvers/utils/topic-colors'; + +@Component({ + selector: 'app-uni-pie-chart', + templateUrl: './uni-pie-chart.component.html', + styleUrl: './uni-pie-chart.component.scss', + imports: [NgxEchartsDirective, CommonModule], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class UniPieChartComponent { + readonly data = input(null); + readonly entityId = input(null); + readonly entityName = input(null); + readonly startYear = input(2010); + readonly endYear = input(2025); + + getTopicColor(topic: string): string { + return topicHierarchyColor({ name: topic }); + } + + readonly chartOptions = computed(() => { + const trendData = this.data(); + const entityIdVal = this.entityId(); + if (!trendData || !entityIdVal) { + return {}; + } + + // Find the series for the selected entity (resilient matching) + const series = trendData.series.find((s) => { + const sId = s.entity_id; + const targetId = entityIdVal; + return ( + sId === targetId || + sId.toUpperCase() === targetId.toUpperCase() || + sId.split('/').pop()?.toUpperCase() === targetId.toUpperCase() || + targetId.split('/').pop()?.toUpperCase() === sId.toUpperCase() + ); + }); + + if (!series || !series.topic_data) { + return { + title: { + text: 'Keine Daten vorhanden', + left: 'center', + top: 'center', + textStyle: { color: '#6b7280', fontSize: 13 }, + }, + }; + } + + const startYr = this.startYear(); + const endYr = this.endYear(); + + const pieDataList: any[] = []; + Object.entries(series.topic_data).forEach(([topicName, yearlyItems]) => { + const filtered = (yearlyItems || []).filter( + (y) => y.year >= startYr && y.year <= endYr, + ); + const totalRaw = filtered.reduce((sum, item) => sum + item.raw, 0); + + if (totalRaw > 0) { + pieDataList.push({ + value: totalRaw, + name: topicName, + itemStyle: { + color: this.getTopicColor(topicName), + }, + }); + } + }); + + if (pieDataList.length === 0) { + return { + title: { + text: `Keine Daten im Zeitraum ${startYr} - ${endYr}`, + left: 'center', + top: 'center', + textStyle: { color: '#6b7280', fontSize: 13 }, + }, + }; + } + + return { + title: { + text: `Verteilung: ${this.entityName()}`, + subtext: `Zeitraum: ${startYr} - ${endYr}`, + left: 'center', + top: 10, + textStyle: { + fontSize: 13, + fontWeight: 600, + color: '#1f2937', + }, + subtextStyle: { + fontSize: 10, + color: '#6b7280', + }, + }, + tooltip: { + trigger: 'item', + formatter: '{b}: {c} ({d}%)', + }, + legend: { + show: false, // Hide default legend to keep layout clean and readable in small containers + }, + series: [ + { + name: 'Themenverteilung', + type: 'pie', + radius: ['45%', '75%'], + avoidLabelOverlap: true, + top: 40, + bottom: 10, + itemStyle: { + borderRadius: 6, + borderColor: '#fff', + borderWidth: 2, + }, + label: { + show: true, + position: 'outside', + fontSize: 9, + formatter: '{b}: {d}%', + color: '#374151', + }, + labelLine: { + show: true, + length: 8, + length2: 5, + smooth: true, + }, + emphasis: { + label: { + show: true, + fontSize: 10, + fontWeight: 'bold', + formatter: '{b}\n{c} ({d}%)', + }, + }, + data: pieDataList, + }, + ], + }; + }); +} 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 629a11c9..bb8d5e1c 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 @@ -55,10 +55,12 @@ [locationSearchResults]="locationSearchResults()" [getEntityColor]="boundGetEntityColor" [isVisible]="boundIsVisible" + [selectedPieEntityId]="selectedPieEntity()?.id ?? null" (addLocation)="addLocation($event)" (removeLocation)="removeLocation($event.id, $event.type)" (searchChange)="onLocationSearchChange($event)" - (toggleVisibility)="toggleVisibility($event)"> + (toggleVisibility)="toggleVisibility($event)" + (selectPie)="onSelectPieEntity($event)"> } @@ -130,6 +132,23 @@ [endYear]="endYear()"> + + @if ( + selectedPieEntity() && + selectedSearchType() !== 'news' && + selectedSearchType() !== 'all' + ) { +
+ + +
+ } + @if (activeConfig().showInstitutionSelector) { + (toggleVisibility)="toggleVisibility($event)" + (selectPie)="onSelectPieEntity($event)"> } @@ -161,10 +182,12 @@ [searchResults]="authorSearchResults()" [getEntityColor]="boundGetEntityColor" [isVisible]="boundIsVisible" + [selectedPieEntityId]="selectedPieEntity()?.id ?? null" (addAuthor)="addAuthor($event.id, $event.name)" (removeAuthor)="removeAuthor($event)" (searchChange)="onAuthorSearchChange($event)" - (toggleVisibility)="toggleVisibility($event)"> + (toggleVisibility)="toggleVisibility($event)" + (selectPie)="onSelectPieEntity($event)"> } 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 e145ecd6..45bbc8bf 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 @@ -22,6 +22,7 @@ import { MatIconModule } from '@angular/material/icon'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { MatAutocompleteModule } from '@angular/material/autocomplete'; import { UniTrendChartComponent } from '../uni-trend-chart/uni-trend-chart.component'; +import { UniPieChartComponent } from '../uni-pie-chart/uni-pie-chart.component'; import { TrendResponse, TrendSeries, @@ -108,6 +109,7 @@ export const TREND_CONFIGS: Record = { CommonModule, FormsModule, UniTrendChartComponent, + UniPieChartComponent, MatCheckboxModule, MatButtonModule, MatIconModule, @@ -159,6 +161,9 @@ export class UniTrendParentComponent implements OnInit { 'normalized', ); readonly activeChartTopic = signal(''); + readonly selectedPieEntity = signal<{ id: string; name: string } | null>( + null, + ); // Config mapper for active strategy UI representation readonly activeConfig = computed( @@ -255,6 +260,10 @@ export class UniTrendParentComponent implements OnInit { return entityColors[idx % entityColors.length]; } + onSelectPieEntity(event: { id: string; name: string }) { + this.selectedPieEntity.set(event); + } + readonly boundGetEntityColor = (id: string) => this.getEntityColor(id); readonly boundIsVisible = (id: string) => this.isVisible(id); @@ -592,6 +601,43 @@ export class UniTrendParentComponent implements OnInit { this.activeChartTopic.set(params['active_chart_topic']); } }); + + // Effect: automatically select/sync selectedPieEntity with active trendResponse series list + effect(() => { + const data = this.trendResponse(); + const currentPie = untracked(() => this.selectedPieEntity()); + + if (!data || data.series.length === 0) { + this.selectedPieEntity.set(null); + return; + } + + if (currentPie) { + const stillExists = data.series.some((s) => { + const sId = s.entity_id; + const targetId = currentPie.id; + return ( + sId === targetId || + sId.toUpperCase() === targetId.toUpperCase() || + sId.split('/').pop()?.toUpperCase() === targetId.toUpperCase() || + targetId.split('/').pop()?.toUpperCase() === sId.toUpperCase() + ); + }); + if (stillExists) { + return; + } + } + + const firstSeries = data.series[0]; + if (firstSeries) { + this.selectedPieEntity.set({ + id: firstSeries.entity_id, + name: firstSeries.entity_name, + }); + } else { + this.selectedPieEntity.set(null); + } + }); } ngOnInit() { @@ -997,9 +1043,13 @@ export class UniTrendParentComponent implements OnInit { const current = this.comparisonAuthors(); const updated = [...current]; (res.results || []).forEach((author: any) => { - if (author.id && !updated.some((a) => a.id === author.id)) { + const shortId = + author.id && author.id.includes('/') + ? author.id.split('/').pop() || author.id + : author.id; + if (shortId && !updated.some((a) => a.id === shortId)) { updated.push({ - id: author.id, + id: shortId, name: author.display_name || 'Unbekannt', }); } @@ -1018,9 +1068,10 @@ export class UniTrendParentComponent implements OnInit { } addAuthor(id: string, name: string) { + const shortId = id.includes('/') ? id.split('/').pop() || id : id; const current = this.comparisonAuthors(); - if (!current.some((a) => a.id === id)) { - this.comparisonAuthors.set([...current, { id, name }]); + if (!current.some((a) => a.id === shortId)) { + this.comparisonAuthors.set([...current, { id: shortId, name }]); } } diff --git a/webapp/src/app/shared/ui/author-selector/author-selector.component.html b/webapp/src/app/shared/ui/author-selector/author-selector.component.html index 349f3c91..cd347469 100644 --- a/webapp/src/app/shared/ui/author-selector/author-selector.component.html +++ b/webapp/src/app/shared/ui/author-selector/author-selector.component.html @@ -45,8 +45,15 @@ ' 8%, #ffffff)' " [style.color]="getEntityColor()(auth.id)"> - - person {{ auth.name }} + + {{ + selectedPieEntityId() === auth.id ? 'pie_chart' : 'person' + }} + {{ auth.name }}