diff --git a/webapp/.npmrc b/webapp/.npmrc new file mode 100644 index 00000000..521a9f7c --- /dev/null +++ b/webapp/.npmrc @@ -0,0 +1 @@ +legacy-peer-deps=true diff --git a/webapp/package-lock.json b/webapp/package-lock.json index b22aea70..9927c8ec 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -19,6 +19,7 @@ "@angular/platform-browser-dynamic": "^21.2.14", "@angular/router": "^21.2.14", "echarts": "^6.1.0", + "echarts-wordcloud": "^2.1.0", "ngx-echarts": "^21.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", @@ -325,38 +326,6 @@ "url": "https://github.com/sponsors/epoberezkin" } }, - "node_modules/@angular-devkit/architect/node_modules/chokidar": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-5.0.0.tgz", - "integrity": "sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==", - "dev": true, - "optional": true, - "peer": true, - "dependencies": { - "readdirp": "^5.0.0" - }, - "engines": { - "node": ">= 20.19.0" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@angular-devkit/architect/node_modules/readdirp": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.0.0.tgz", - "integrity": "sha512-9u/XQ1pvrQtYyMpZe7DXKv2p5CNvyVwzUB6uhLAnQwHMSgKMBR62lc7AHljaeteeHXn11XTAaLLUVZYVZyuRBQ==", - "dev": true, - "optional": true, - "peer": true, - "engines": { - "node": ">= 20.19.0" - }, - "funding": { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/@angular-devkit/architect/node_modules/source-map": { "version": "0.7.6", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.6.tgz", @@ -431,38 +400,6 @@ "url": "https://github.com/sponsors/epoberezkin" } }, - "node_modules/@angular-devkit/schematics/node_modules/chokidar": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-5.0.0.tgz", - "integrity": "sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==", - "dev": true, - "optional": true, - "peer": true, - "dependencies": { - "readdirp": "^5.0.0" - }, - "engines": { - "node": ">= 20.19.0" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@angular-devkit/schematics/node_modules/readdirp": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.0.0.tgz", - "integrity": "sha512-9u/XQ1pvrQtYyMpZe7DXKv2p5CNvyVwzUB6uhLAnQwHMSgKMBR62lc7AHljaeteeHXn11XTAaLLUVZYVZyuRBQ==", - "dev": true, - "optional": true, - "peer": true, - "engines": { - "node": ">= 20.19.0" - }, - "funding": { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/@angular-devkit/schematics/node_modules/source-map": { "version": "0.7.6", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.6.tgz", @@ -701,38 +638,6 @@ "url": "https://github.com/sponsors/epoberezkin" } }, - "node_modules/@angular/cli/node_modules/chokidar": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-5.0.0.tgz", - "integrity": "sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==", - "dev": true, - "optional": true, - "peer": true, - "dependencies": { - "readdirp": "^5.0.0" - }, - "engines": { - "node": ">= 20.19.0" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@angular/cli/node_modules/readdirp": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.0.0.tgz", - "integrity": "sha512-9u/XQ1pvrQtYyMpZe7DXKv2p5CNvyVwzUB6uhLAnQwHMSgKMBR62lc7AHljaeteeHXn11XTAaLLUVZYVZyuRBQ==", - "dev": true, - "optional": true, - "peer": true, - "engines": { - "node": ">= 20.19.0" - }, - "funding": { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/@angular/cli/node_modules/source-map": { "version": "0.7.6", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.6.tgz", @@ -1264,43 +1169,6 @@ "node": ">=0.1.90" } }, - "node_modules/@emnapi/core": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz", - "integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "@emnapi/wasi-threads": "1.2.1", - "tslib": "^2.4.0" - } - }, - "node_modules/@emnapi/runtime": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz", - "integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, - "node_modules/@emnapi/wasi-threads": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz", - "integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, "node_modules/@esbuild/aix-ppc64": { "version": "0.27.3", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.3.tgz", @@ -2639,6 +2507,9 @@ "arm64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -2656,6 +2527,9 @@ "arm64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -2673,6 +2547,9 @@ "ppc64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -2690,6 +2567,9 @@ "riscv64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -2707,6 +2587,9 @@ "s390x" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -2724,6 +2607,9 @@ "x64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -2741,6 +2627,9 @@ "x64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -3706,6 +3595,9 @@ "arm" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3727,6 +3619,9 @@ "arm" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -3748,6 +3643,9 @@ "arm64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3769,6 +3667,9 @@ "arm64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -3790,6 +3691,9 @@ "x64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3811,6 +3715,9 @@ "x64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -3988,6 +3895,9 @@ "arm64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4005,6 +3915,9 @@ "arm64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4022,6 +3935,9 @@ "x64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4039,6 +3955,9 @@ "x64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4215,6 +4134,9 @@ "arm" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4229,6 +4151,9 @@ "arm" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4243,6 +4168,9 @@ "arm64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4257,6 +4185,9 @@ "arm64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4271,6 +4202,9 @@ "loong64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4285,6 +4219,9 @@ "loong64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4299,6 +4236,9 @@ "ppc64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4313,6 +4253,9 @@ "ppc64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4327,6 +4270,9 @@ "riscv64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4341,6 +4287,9 @@ "riscv64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4355,6 +4304,9 @@ "s390x" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4369,6 +4321,9 @@ "x64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4383,6 +4338,9 @@ "x64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4535,38 +4493,6 @@ "url": "https://github.com/sponsors/epoberezkin" } }, - "node_modules/@schematics/angular/node_modules/chokidar": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-5.0.0.tgz", - "integrity": "sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==", - "dev": true, - "optional": true, - "peer": true, - "dependencies": { - "readdirp": "^5.0.0" - }, - "engines": { - "node": ">= 20.19.0" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@schematics/angular/node_modules/readdirp": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.0.0.tgz", - "integrity": "sha512-9u/XQ1pvrQtYyMpZe7DXKv2p5CNvyVwzUB6uhLAnQwHMSgKMBR62lc7AHljaeteeHXn11XTAaLLUVZYVZyuRBQ==", - "dev": true, - "optional": true, - "peer": true, - "engines": { - "node": ">= 20.19.0" - }, - "funding": { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/@schematics/angular/node_modules/source-map": { "version": "0.7.6", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.6.tgz", @@ -6252,6 +6178,15 @@ "zrender": "6.1.0" } }, + "node_modules/echarts-wordcloud": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/echarts-wordcloud/-/echarts-wordcloud-2.1.0.tgz", + "integrity": "sha512-Kt1JmbcROgb+3IMI48KZECK2AP5lG6bSsOEs+AsuwaWJxQom31RTNd6NFYI01E/YaI1PFZeueaupjlmzSQasjQ==", + "license": "ISC", + "peerDependencies": { + "echarts": "^5.0.1" + } + }, "node_modules/echarts/node_modules/tslib": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", @@ -10635,9 +10570,9 @@ } }, "node_modules/tmp": { - "version": "0.2.5", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.5.tgz", - "integrity": "sha512-voyz6MApa1rQGUxT3E+BK7/ROe8itEx7vD8/HEvt4xwXucvQ5G5oeEiHkmHZJuBO21RpOf+YYm9MOivj709jow==", + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.7.tgz", + "integrity": "sha512-e0votIpp4Uo2AJYSzVHV6xCcawuiez3DzqDAbrTc3YxBkplN6e+dM13ZeIcZnDg/QpSuU2zfZ3rzwY8ukEnaXw==", "dev": true, "license": "MIT", "engines": { diff --git a/webapp/package.json b/webapp/package.json index 3c83c9ca..7c6bbb36 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -22,6 +22,7 @@ "@angular/platform-browser-dynamic": "^21.2.14", "@angular/router": "^21.2.14", "echarts": "^6.1.0", + "echarts-wordcloud": "^2.1.0", "ngx-echarts": "^21.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", diff --git a/webapp/src/app/app.config.ts b/webapp/src/app/app.config.ts index 07ccef98..b7c9aad4 100644 --- a/webapp/src/app/app.config.ts +++ b/webapp/src/app/app.config.ts @@ -10,6 +10,7 @@ import { authenticationInterceptor } from './shared/interceptors/authentication. import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field'; import { MatPaginatorIntl } from '@angular/material/paginator'; import { PaginatorIntl } from './shared/utils/paginatorIntl'; +import { provideEchartsCore } from 'ngx-echarts'; registerLocaleData(locale); @@ -26,5 +27,6 @@ export const appConfig: ApplicationConfig = { provideHttpClient(withInterceptors([authenticationInterceptor])), // provideApi('/inse-service'), provideAnimationsAsync(), + provideEchartsCore({ echarts: () => import('echarts') }), ], }; diff --git a/webapp/src/app/modules/person-overview/person-overview.component.html b/webapp/src/app/modules/person-overview/person-overview.component.html index e7340843..e5b2489c 100644 --- a/webapp/src/app/modules/person-overview/person-overview.component.html +++ b/webapp/src/app/modules/person-overview/person-overview.component.html @@ -15,4 +15,38 @@ (yearSelect)="onTimelineYearSelect($event)" (loadEarlierYears)="onTimelineLoadEarlierYears()" > + + @if (!loadingWordCloud) { +
+
+

Forschungsthemen

+ @if (wordCloudOptions && sliderMax > 5) { +
+ {{ topN }} Themen +
+
+ +
+
+ } +
+ @if (wordCloudOptions) { +
+ } @else if (wordCloudEmpty) { +

Keine Forschungsthemen gefunden.

+ } +
+ } \ No newline at end of file diff --git a/webapp/src/app/modules/person-overview/person-overview.component.scss b/webapp/src/app/modules/person-overview/person-overview.component.scss index 52461a52..d3eeaeb2 100644 --- a/webapp/src/app/modules/person-overview/person-overview.component.scss +++ b/webapp/src/app/modules/person-overview/person-overview.component.scss @@ -1,4 +1,125 @@ .person-overview { width: 100%; display: block; -} \ No newline at end of file + padding: 1.5rem 1.5rem 0; + box-sizing: border-box; +} + +.word-cloud-card { + margin-top: 1.5rem; + padding: 24px 28px; + border: 1px solid #d7e4ff; + border-radius: 16px; + background: #ffffff; + box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04); + box-sizing: border-box; +} + +.word-cloud-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 1.5rem; + margin-bottom: 0.75rem; +} + +.word-cloud-title { + margin: 0; + font-family: "Montserrat", "Open Sans", Arial, sans-serif; + font-size: 20px; + font-weight: 700; + color: var(--sg-text); +} + +.word-cloud-slider-wrapper { + display: flex; + align-items: center; + gap: 0.75rem; + flex-shrink: 0; +} + +.slider-label { + font-size: 13px; + color: var(--sg-text-muted); + white-space: nowrap; + min-width: 4.5rem; + text-align: right; +} + +.word-cloud-slider { + --accent: #0057ff; + --range-value: 50%; + + position: relative; + width: 160px; + height: 22px; + + .range-track { + position: absolute; + top: 50%; + left: 0; + right: 0; + height: 5px; + transform: translateY(-50%); + border-radius: 999px; + background: linear-gradient( + to right, + var(--accent) 0%, + var(--accent) var(--range-value), + #d8e2f4 var(--range-value), + #d8e2f4 100% + ); + } + + input[type='range'] { + position: absolute; + inset: 0; + width: 100%; + height: 22px; + margin: 0; + appearance: none; + background: transparent; + + &::-webkit-slider-runnable-track, + &::-moz-range-track { + height: 5px; + background: transparent; + border: none; + } + + &::-webkit-slider-thumb { + appearance: none; + width: 15px; + height: 15px; + margin-top: -5px; + border: 2px solid #ffffff; + border-radius: 50%; + background: var(--accent); + box-shadow: 0 0 0 1px #9ab7ff, 0 2px 6px rgba(0, 87, 255, 0.22); + cursor: pointer; + } + + &::-moz-range-thumb { + width: 15px; + height: 15px; + border: 2px solid #ffffff; + border-radius: 50%; + background: var(--accent); + box-shadow: 0 0 0 1px #9ab7ff, 0 2px 6px rgba(0, 87, 255, 0.22); + cursor: pointer; + } + } +} + +.word-cloud-chart { + width: 100%; + height: 400px; + cursor: pointer; +} + +.word-cloud-empty { + margin: 2rem 0 0.5rem; + text-align: center; + color: var(--sg-text-muted); + font-size: 14px; +} diff --git a/webapp/src/app/modules/person-overview/person-overview.component.ts b/webapp/src/app/modules/person-overview/person-overview.component.ts index c94bd967..48a20769 100644 --- a/webapp/src/app/modules/person-overview/person-overview.component.ts +++ b/webapp/src/app/modules/person-overview/person-overview.component.ts @@ -3,9 +3,11 @@ import { Component, DestroyRef, OnInit, inject } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ActivatedRoute, ParamMap, Router } from '@angular/router'; import { combineLatest, distinctUntilChanged, map } from 'rxjs'; +import { NgxEchartsDirective } from 'ngx-echarts'; +import type { EChartsOption } from 'echarts'; +import 'echarts-wordcloud'; -import { TopicCount, TopicsByYear } from '../../api'; -import { WorksService } from '../../api'; +import { TopicCount, TopicsByYear, WorksService } from '../../api'; import { ResearchTimelineComponent, TimelineViewMode, @@ -18,7 +20,7 @@ import { @Component({ selector: 'app-person-overview', standalone: true, - imports: [CommonModule, ResearchTimelineComponent], + imports: [CommonModule, ResearchTimelineComponent, NgxEchartsDirective], templateUrl: './person-overview.component.html', styleUrl: './person-overview.component.scss', }) @@ -48,6 +50,31 @@ export class PersonOverviewComponent implements OnInit { timelineStartYear: number | undefined; timelineEndYear: number | undefined; + wordCloudOptions: EChartsOption | null = null; + loadingWordCloud = false; + wordCloudEmpty = false; + + topN = 30; + sliderMax = 50; + + get sliderPercent(): string { + if (this.sliderMax <= 5) return '100%'; + return `${(((this.topN - 5) / (this.sliderMax - 5)) * 100).toFixed(1)}%`; + } + + onTopNChange(event: Event): void { + this.topN = Number((event.target as HTMLInputElement).value); + this.rebuildWordCloud(); + } + + private allTopicData: Array<{ + name: string; + value: number; + topicId: string | undefined; + textStyle: { color: string; fontSize: number }; + emphasis: { textStyle: { fontSize: number; color: string; shadowBlur: number; shadowColor: string } }; + }> = []; + ngOnInit(): void { combineLatest(this.route.pathFromRoot.map((route) => route.paramMap)) .pipe( @@ -57,6 +84,7 @@ export class PersonOverviewComponent implements OnInit { ) .subscribe((authorId) => { this.loadTopicTimeline(authorId); + this.loadWordCloud(authorId); }); this.route.queryParamMap @@ -141,6 +169,21 @@ export class PersonOverviewComponent implements OnInit { this.loadCompleteTopicTimeline(this.currentAuthorId); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + onWordClick(event: any): void { + const topicId = event?.data?.topicId; + const topicName = event?.data?.name; + if (!topicId) return; + void this.router.navigate(['../publications'], { + relativeTo: this.route, + queryParams: { + publicationPage: 1, + publicationTopicId: topicId, + publicationTopicName: topicName, + }, + }); + } + private findAuthorId(paramMaps: readonly ParamMap[]): string { return ( paramMaps @@ -255,6 +298,116 @@ export class PersonOverviewComponent implements OnInit { this.timelineEarlierYearsLoadFailed = false; } + private readonly blueShades = [ + '#0057ff', '#1a6fff', '#2952d9', '#3d7cff', + '#1240cc', '#5a90ff', '#0044cc', '#4d85ff', + '#0b4fe0', '#2563eb', + ]; + + private topicColor(name: string): string { + const hash = name.split('').reduce((acc, c) => acc + c.charCodeAt(0), 0); + return this.blueShades[hash % this.blueShades.length]; + } + + private loadWordCloud(authorId: string): void { + if (!authorId || authorId === '0') { + this.wordCloudOptions = null; + this.wordCloudEmpty = false; + this.loadingWordCloud = false; + this.allTopicData = []; + return; + } + + this.loadingWordCloud = true; + this.wordCloudEmpty = false; + this.wordCloudOptions = null; + + this.worksService + .getAuthorWorks(authorId, 1, 100) + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe({ + next: (page) => { + const counts = new Map(); + const nameToId = new Map(); + + page.elements?.forEach(work => { + work.topics?.forEach(topic => { + if (topic.display_name && topic.id) { + counts.set(topic.display_name, (counts.get(topic.display_name) ?? 0) + 1); + if (!nameToId.has(topic.display_name)) { + nameToId.set(topic.display_name, topic.id); + } + } + }); + }); + + const allValues = Array.from(counts.values()); + const minVal = Math.min(...allValues); + const maxVal = Math.max(...allValues); + const computeSize = (v: number): number => + maxVal === minVal + ? 22 + : Math.round(12 + ((v - minVal) / (maxVal - minVal)) * (32 - 12)); + + this.allTopicData = Array.from(counts.entries()) + .sort((a, b) => b[1] - a[1]) + .map(([name, value]) => { + const fontSize = computeSize(value); + return { + name, + value, + topicId: nameToId.get(name), + textStyle: { color: this.topicColor(name), fontSize }, + emphasis: { + textStyle: { + fontSize: Math.round(fontSize * 1.1), + color: '#101a3d', + shadowBlur: 16, + shadowColor: 'rgba(0, 87, 255, 0.35)', + }, + }, + }; + }); + + this.loadingWordCloud = false; + + if (this.allTopicData.length === 0) { + this.wordCloudEmpty = true; + return; + } + + this.sliderMax = Math.min(50, this.allTopicData.length); + this.topN = Math.min(30, this.sliderMax); + + setTimeout(() => { this.rebuildWordCloud(); }); + }, + error: (error) => { + console.error('Word cloud could not be loaded.', error); + this.loadingWordCloud = false; + this.wordCloudEmpty = true; + }, + }); + } + + private rebuildWordCloud(): void { + const data = this.allTopicData.slice(0, this.topN); + if (data.length === 0) return; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + this.wordCloudOptions = { + series: [{ + type: 'wordCloud', + rotationRange: [0, 0], + rotationStep: 0, + gridSize: 4, + width: '100%', + height: '100%', + drawOutOfBound: false, + textStyle: { fontFamily: 'Open Sans, sans-serif', fontWeight: 'bold' }, + data, + }], + } as any; + } + private mapTimelineElements( elements: TopicsByYear[] | undefined, ): TopicTimelineElement[] {