feat(wordcloud): implement year slider, add colors, remove topic count slider
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-06-15 23:43:20 +02:00
parent 79105b83b9
commit a5fe9728e8
5 changed files with 74 additions and 203 deletions
@@ -59,7 +59,7 @@
</div>
<div
*ngIf="timelineViewMode !== 'wordcloud' && hasYearRange"
*ngIf="hasYearRange"
class="year-filter"
aria-label="Zeitraum eingrenzen">
<div class="year-filter-top">
@@ -110,13 +110,6 @@
<span>{{ maxYear }}</span>
</div>
</div>
<div
*ngIf="timelineViewMode === 'wordcloud'"
class="year-filter"
aria-label="Anzahl angezeigter Themen">
<ng-content select="[timeline-wordcloud-controls]"></ng-content>
</div>
</div>
<ng-container *ngIf="timelineViewMode === 'wordcloud'; else timelineViews">
@@ -38,7 +38,7 @@
.timeline-header {
display: grid;
grid-template-columns: minmax(260px, 1fr) auto minmax(260px, 1fr);
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
align-items: flex-start;
gap: 24px;
margin-bottom: 28px;
@@ -103,6 +103,7 @@
border: 1px solid #dbe5f6;
border-radius: 10px;
background: #fbfdff;
box-sizing: border-box;
}
.year-filter-top,
@@ -14,26 +14,6 @@
(topicSelect)="onTimelineTopicSelect($event)"
(yearSelect)="onTimelineYearSelect($event)"
(loadEarlierYears)="onTimelineLoadEarlierYears()">
<div timeline-wordcloud-controls class="word-cloud-slider-wrapper">
@if (loadingWordCloud) {
<span class="slider-label">Themen laden ...</span>
} @else if (wordCloudOptions && sliderMax > 5) {
<span class="slider-label">{{ topN }} Themen</span>
<div class="word-cloud-slider" [style.--range-value]="sliderPercent">
<div class="range-track"></div>
<input
type="range"
[min]="5"
[max]="sliderMax"
[value]="topN"
(input)="onTopNChange($event)"
aria-label="Anzahl der angezeigten Themen" />
</div>
} @else {
<span class="slider-label">Themen</span>
}
</div>
<div timeline-wordcloud-content class="word-cloud-view">
@if (loadingWordCloud) {
<div class="word-cloud-state">Forschungsthemen werden geladen ...</div>
@@ -5,91 +5,6 @@
box-sizing: border-box;
}
.word-cloud-slider-wrapper {
display: flex;
align-items: center;
justify-content: center;
gap: 0.75rem;
min-height: 86px;
}
.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-view {
min-height: 420px;
}
@@ -54,32 +54,10 @@ export class PersonOverviewComponent implements OnInit {
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<{
private rawTopicOccurrences: Array<{
name: string;
value: number;
topicId: string | undefined;
textStyle: { color: string; fontSize: number };
emphasis: {
textStyle: {
fontSize: number;
color: string;
shadowBlur: number;
shadowColor: string;
};
};
topicId: string;
year: number | undefined;
}> = [];
ngOnInit(): void {
@@ -123,6 +101,7 @@ export class PersonOverviewComponent implements OnInit {
onTimelineYearRangeChange(range: TimelineYearRange): void {
this.timelineStartYear = range.startYear;
this.timelineEndYear = range.endYear;
this.rebuildWordCloud();
this.updateTimelineQueryParams(
{
@@ -308,30 +287,20 @@ export class PersonOverviewComponent implements OnInit {
this.timelineEarlierYearsLoadFailed = false;
}
private readonly blueShades = [
'#0057ff',
'#1a6fff',
'#2952d9',
'#3d7cff',
'#1240cc',
'#5a90ff',
'#0044cc',
'#4d85ff',
'#0b4fe0',
'#2563eb',
private readonly timelineColors = [
'#7255d9',
'#2678e8',
'#39a96b',
'#f59e0b',
'#e0527c',
];
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 = [];
this.rawTopicOccurrences = [];
return;
}
@@ -344,64 +313,28 @@ export class PersonOverviewComponent implements OnInit {
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({
next: (page) => {
const counts = new Map<string, number>();
const nameToId = new Map<string, string>();
this.rawTopicOccurrences = [];
page.elements?.forEach((work) => {
const year = work.publication_year ?? undefined;
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);
}
this.rawTopicOccurrences.push({
name: topic.display_name,
topicId: topic.id,
year,
});
}
});
});
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) {
if (this.rawTopicOccurrences.length === 0) {
this.wordCloudEmpty = true;
return;
}
this.sliderMax = Math.min(50, this.allTopicData.length);
this.topN = Math.min(30, this.sliderMax);
setTimeout(() => {
this.rebuildWordCloud();
});
setTimeout(() => this.rebuildWordCloud());
},
error: (error) => {
console.error('Word cloud could not be loaded.', error);
@@ -412,8 +345,57 @@ export class PersonOverviewComponent implements OnInit {
}
private rebuildWordCloud(): void {
const data = this.allTopicData.slice(0, this.topN);
if (data.length === 0) return;
const start = this.timelineStartYear;
const end = this.timelineEndYear;
const counts = new Map<string, number>();
const nameToId = new Map<string, string>();
for (const occ of this.rawTopicOccurrences) {
if (start !== undefined && (occ.year === undefined || occ.year < start))
continue;
if (end !== undefined && (occ.year === undefined || occ.year > end))
continue;
counts.set(occ.name, (counts.get(occ.name) ?? 0) + 1);
if (!nameToId.has(occ.name)) nameToId.set(occ.name, occ.topicId);
}
if (counts.size === 0) {
this.wordCloudOptions = null;
this.wordCloudEmpty = true;
return;
}
this.wordCloudEmpty = false;
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));
const sorted = Array.from(counts.entries()).sort((a, b) => b[1] - a[1]);
const data = sorted.slice(0, 30).map(([name, value], i) => {
const fontSize = computeSize(value);
const color = this.timelineColors[i % this.timelineColors.length];
return {
name,
value,
topicId: nameToId.get(name),
textStyle: { color, fontSize },
emphasis: {
textStyle: {
fontSize: Math.round(fontSize * 1.1),
color,
shadowBlur: 16,
shadowColor: 'rgba(0, 87, 255, 0.35)',
},
},
};
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.wordCloudOptions = {
series: [