fix treemap
LocationBasedServices/smartguide/pipeline/head There was a failure building this commit

This commit is contained in:
2026-07-14 13:09:45 +02:00
parent a0ef884ca3
commit dfdc35ad81
12 changed files with 777 additions and 268 deletions
@@ -32,7 +32,7 @@ export interface TopAuthor {
export interface TopAuthorStatistics {
institution_id: string;
works: TopAuthor[];
projects: TopAuthor[];
eu_projects: TopAuthor[];
patents: TopAuthor[];
news: TopAuthor[];
}
@@ -48,6 +48,22 @@ export interface TopicHeatmapField {
name: string;
total: number;
values: TopicHeatmapValue[];
subfields: TopicHeatmapSubfield[];
}
export interface TopicHeatmapSubfield {
id: string;
name: string;
total: number;
values: TopicHeatmapValue[];
topics: TopicHeatmapTopic[];
}
export interface TopicHeatmapTopic {
id: string;
name: string;
total: number;
values: TopicHeatmapValue[];
}
export interface TopicHeatmap {
@@ -57,6 +73,17 @@ export interface TopicHeatmap {
fields: TopicHeatmapField[];
}
export interface TopicWordCloudWord {
id: string;
name: string;
count: number;
}
export interface TopicWordCloud {
topic_id: string;
words: TopicWordCloudWord[];
}
@Injectable({ providedIn: 'root' })
export class DashboardStatisticsService {
private readonly httpClient = inject(HttpClient);
@@ -122,4 +149,18 @@ export class DashboardStatisticsService {
{ params },
);
}
getTopicWordCloud(
topicId: string,
fromYear?: number,
toYear?: number,
): Observable<TopicWordCloud> {
const params: Record<string, string | number> = { topicId };
if (fromYear !== undefined) params['from_year'] = fromYear;
if (toYear !== undefined) params['to_year'] = toYear;
return this.httpClient.get<TopicWordCloud>(
`${this.apiConfiguration?.basePath ?? ''}/api/dashboard/topic-wordcloud`,
{ params },
);
}
}
@@ -105,6 +105,11 @@ export class DashboardComponent implements OnInit {
icon: 'menu_book',
entries: this.topAuthors?.works ?? [],
},
{
title: 'EU-Projekte',
icon: 'public',
entries: this.topAuthors?.eu_projects ?? [],
},
{
title: 'Patente',
icon: 'description',
@@ -1,5 +1,9 @@
@if (heatmap?.fields?.length) {
<div echarts [options]="options" class="topic-treemap-chart"></div>
<div
echarts
[options]="options"
class="topic-treemap-chart"
(chartClick)="onChartClick($event)"></div>
} @else {
<p class="topic-treemap-empty">
{{ loading ? 'Wird geladen ...' : 'Keine Field-Daten vorhanden.' }}
@@ -1,8 +1,13 @@
import { Component, Input, OnChanges } from '@angular/core';
import { Component, Input, OnChanges, inject } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { EChartsOption } from 'echarts';
import { NgxEchartsDirective } from 'ngx-echarts';
import { TopicHeatmap } from '../dashboard-statistics.service';
import {
TopicWordCloudDialogComponent,
TopicWordCloudDialogData,
} from '../topic-wordcloud-dialog/topic-wordcloud-dialog.component';
@Component({
selector: 'app-topic-heatmap',
@@ -11,6 +16,7 @@ import { TopicHeatmap } from '../dashboard-statistics.service';
styleUrl: './topic-heatmap.component.scss',
})
export class TopicHeatmapComponent implements OnChanges {
private readonly dialog = inject(MatDialog);
@Input() heatmap?: TopicHeatmap;
@Input() loading = false;
@@ -32,6 +38,26 @@ export class TopicHeatmapComponent implements OnChanges {
this.options = this.buildOptions();
}
onChartClick(event: any): void {
const data = event?.data;
if (!data?.id || !data?.subfieldName || data?.children?.length) return;
this.dialog.open<TopicWordCloudDialogComponent, TopicWordCloudDialogData>(
TopicWordCloudDialogComponent,
{
width: '85vw',
maxWidth: '92vw',
data: {
topicId: data.id,
topicName: data.name,
fieldName: data.fieldName,
subfieldName: data.subfieldName,
fromYear: this.heatmap?.years.at(0),
toYear: this.heatmap?.years.at(-1),
},
},
);
}
private buildOptions(): EChartsOption {
const fields = this.heatmap?.fields ?? [];
const data = fields.map((field) => ({
@@ -47,12 +73,22 @@ export class TopicHeatmapComponent implements OnChanges {
lineHeight: 18,
overflow: 'truncate' as const,
},
children: field.values
.filter((value) => value.count > 0)
.map((value) => ({
name: String(value.year),
value: value.count,
share: value.share,
children: (field.subfields ?? [])
.filter((subfield) => subfield.total > 0)
.map((subfield) => ({
id: subfield.id,
name: subfield.name,
value: subfield.total,
fieldName: field.name,
children: (subfield.topics ?? [])
.filter((topic) => topic.total > 0)
.map((topic) => ({
id: topic.id,
name: topic.name,
value: topic.total,
fieldName: field.name,
subfieldName: subfield.name,
})),
})),
}));
@@ -60,11 +96,13 @@ export class TopicHeatmapComponent implements OnChanges {
tooltip: {
formatter: (params: any) => {
const count = Number(params.value ?? 0);
const share =
typeof params.data?.share === 'number'
? `<br />Anteil im Jahr: <strong>${(params.data.share * 100).toFixed(1)}%</strong>`
: '';
return `${params.name}<br /><strong>${count}</strong> Publikationen${share}`;
const field = params.data?.fieldName
? `<br />Field: ${params.data.fieldName}`
: '';
const subfield = params.data?.subfieldName
? `<br />Subfield: ${params.data.subfieldName}`
: '';
return `${params.name}${field}${subfield}<br /><strong>${count}</strong> Publikationen`;
},
},
series: [
@@ -0,0 +1,37 @@
<div class="dialog-title" mat-dialog-title>
<div>
<h2>{{ data.topicName }}</h2>
<p>
{{ data.fieldName }}
@if (data.subfieldName) {
<span>· {{ data.subfieldName }}</span>
}
</p>
</div>
<button mat-icon-button type="button" aria-label="Dialog schließen" mat-dialog-close>
<mat-icon>close</mat-icon>
</button>
</div>
<mat-dialog-content>
@if (loading) {
<div class="word-cloud-state">Verwandte Themen werden geladen ...</div>
} @else if (loadFailed) {
<div class="word-cloud-state error">Wordcloud konnte nicht geladen werden.</div>
} @else if (words.length) {
<div class="word-cloud-chart" aria-label="Wordcloud verwandter Themen">
@for (word of words; track word.id) {
<span
class="word-cloud-word"
[style.color]="word.color"
[style.fontSize.px]="word.fontSize"
[style.fontWeight]="word.fontWeight"
[title]="word.count + ' Publikationen'">
{{ word.name }}
</span>
}
</div>
} @else {
<div class="word-cloud-state">Keine verwandten Themen gefunden.</div>
}
</mat-dialog-content>
@@ -0,0 +1,49 @@
.dialog-title {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
h2 {
margin: 0;
}
p {
margin: 4px 0 0;
color: #64748b;
font-size: 0.875rem;
}
}
mat-dialog-content {
min-height: 330px;
}
.word-cloud-chart {
min-height: 300px;
display: flex;
flex-wrap: wrap;
align-content: center;
align-items: baseline;
justify-content: center;
gap: 12px 18px;
padding: 24px;
border-radius: 12px;
background: linear-gradient(145deg, #f8fafc, #ffffff);
}
.word-cloud-word {
line-height: 1.1;
text-align: center;
}
.word-cloud-state {
min-height: 300px;
display: grid;
place-items: center;
color: #64748b;
&.error {
color: #b91c1c;
}
}
@@ -0,0 +1,102 @@
import { CommonModule } from '@angular/common';
import { Component, DestroyRef, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import {
MAT_DIALOG_DATA,
MatDialogModule,
} from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatButtonModule } from '@angular/material/button';
import {
DashboardStatisticsService,
TopicWordCloudWord,
} from '../dashboard-statistics.service';
export interface TopicWordCloudDialogData {
topicId: string;
topicName: string;
fieldName?: string;
subfieldName?: string;
fromYear?: number;
toYear?: number;
}
interface DisplayWord extends TopicWordCloudWord {
color: string;
fontSize: number;
fontWeight: number;
}
@Component({
selector: 'app-topic-wordcloud-dialog',
standalone: true,
imports: [CommonModule, MatButtonModule, MatDialogModule, MatIconModule],
templateUrl: './topic-wordcloud-dialog.component.html',
styleUrl: './topic-wordcloud-dialog.component.scss',
})
export class TopicWordCloudDialogComponent {
readonly data = inject<TopicWordCloudDialogData>(MAT_DIALOG_DATA);
private readonly statisticsService = inject(DashboardStatisticsService);
private readonly destroyRef = inject(DestroyRef);
words: DisplayWord[] = [];
loading = true;
loadFailed = false;
private readonly colors = [
'#2563eb',
'#059669',
'#d97706',
'#dc2626',
'#7c3aed',
'#0284c7',
'#ea580c',
'#4f46e5',
'#0f766e',
'#be123c',
];
constructor() {
this.statisticsService
.getTopicWordCloud(
this.data.topicId,
this.data.fromYear,
this.data.toYear,
)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({
next: (response) => {
this.words = this.buildWords(response.words);
this.loading = false;
},
error: () => {
this.loading = false;
this.loadFailed = true;
},
});
}
private buildWords(words: TopicWordCloudWord[]): DisplayWord[] {
if (!words.length) return [];
const values = words.map((word) => word.count);
const minimum = Math.min(...values);
const maximum = Math.max(...values);
const scaled = words.map((word, index) => {
const intensity =
maximum === minimum ? 1 : (word.count - minimum) / (maximum - minimum);
return {
...word,
color: this.colors[index % this.colors.length],
fontSize: Math.round(14 + intensity * 24),
fontWeight: intensity > 0.66 ? 800 : intensity > 0.33 ? 600 : 400,
};
});
const centred: DisplayWord[] = [];
scaled.forEach((word, index) => {
if (index % 2 === 0) centred.push(word);
else centred.unshift(word);
});
return centred;
}
}