diff --git a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.html b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.html
index fe7d4515..e72920fa 100644
--- a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.html
+++ b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.html
@@ -6,6 +6,26 @@
Entwicklung der Forschungsthemen im Zeitverlauf
(basierend auf Publikationen)
+
+
+
+
+ {{ earlierYearsLabel }}
+
+
+
+
+ Frühere Jahre konnten nicht geladen werden.
+
@@ -81,8 +101,9 @@
-
- Forschungstimeline wird geladen ...
+
+
+ Forschungstimeline wird geladen ...
@@ -92,11 +113,28 @@
0; else emptyTimeline">
-
+
+
+
+ ‹
+
+
+
+
+
+
+
+
+
+ {{ earlierYearsLabel }}
+
+
+
+
+
+ Laden fehlgeschlagen.
+
+
+
-
\ No newline at end of file
+
diff --git a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.scss b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.scss
index 1bac000d..1739f559 100644
--- a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.scss
+++ b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.scss
@@ -637,6 +637,23 @@
background: #52627f;
}
+.load-more-content {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 7px;
+}
+
+.timeline-title .reset-range-button {
+ display: inline-flex;
+ margin-top: 8px;
+}
+
+.timeline-title > .no-topics {
+ display: block;
+ margin-top: 6px;
+}
+
.timeline-state {
display: flex;
min-height: 140px;
@@ -648,6 +665,11 @@
text-align: center;
}
+.timeline-state-loading {
+ flex-direction: column;
+ gap: 10px;
+}
+
.timeline-state-error {
color: #b42318;
}
diff --git a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts
index 41193edc..510b5756 100644
--- a/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts
+++ b/webapp/src/app/modules/person-overview/components/research-timeline/research-timeline.component.ts
@@ -1,11 +1,15 @@
import { CommonModule } from '@angular/common';
+import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import {
+ AfterViewChecked,
Component,
+ ElementRef,
EventEmitter,
Input,
OnChanges,
Output,
SimpleChanges,
+ ViewChild,
} from '@angular/core';
export interface TopicTimelineTopic {
@@ -53,17 +57,28 @@ interface WorkingResearchTimelinePhase {
years: TopicTimelineElement[];
}
+interface TimelineScrollAnchor {
+ year: number;
+ offsetLeft: number;
+ scrollLeft: number;
+}
+
@Component({
selector: 'app-research-timeline',
standalone: true,
- imports: [CommonModule],
+ imports: [CommonModule, MatProgressSpinnerModule],
templateUrl: './research-timeline.component.html',
styleUrl: './research-timeline.component.scss',
})
-export class ResearchTimelineComponent implements OnChanges {
+export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
+ @ViewChild('timelineWrapper')
+ private timelineWrapper?: ElementRef;
@Input() elements: TopicTimelineElement[] = [];
@Input() loading = false;
@Input() loadFailed = false;
+ @Input() canLoadEarlierYears = false;
+ @Input() loadingEarlierYears = false;
+ @Input() earlierYearsLoadFailed = false;
@Input() viewMode: TimelineViewMode = 'years';
@Input() startYear: number | undefined;
@Input() endYear: number | undefined;
@@ -72,6 +87,7 @@ export class ResearchTimelineComponent implements OnChanges {
@Output() yearRangeChange = new EventEmitter();
@Output() topicSelect = new EventEmitter();
@Output() yearSelect = new EventEmitter();
+ @Output() loadEarlierYears = new EventEmitter();
timelineViewMode: TimelineViewMode = 'years';
@@ -84,9 +100,16 @@ export class ResearchTimelineComponent implements OnChanges {
private readonly columnWidth = 240;
private readonly displayedTopicLimit = 3;
private readonly displayedPhaseTopicLimit = 4;
+ private readonly scrollRestoreThreshold = 24;
private readonly expandedPhaseIds = new Set();
+ private pendingTimelineScrollAnchor: TimelineScrollAnchor | undefined;
+
ngOnChanges(changes: SimpleChanges): void {
+ if (changes['elements']) {
+ this.captureTimelineScrollAnchor();
+ }
+
if (changes['viewMode']) {
this.timelineViewMode = this.isTimelineViewMode(this.viewMode)
? this.viewMode
@@ -102,6 +125,22 @@ export class ResearchTimelineComponent implements OnChanges {
}
}
+ ngAfterViewChecked(): void {
+ if (!this.pendingTimelineScrollAnchor) {
+ return;
+ }
+
+ const scrollAnchor = this.pendingTimelineScrollAnchor;
+ this.pendingTimelineScrollAnchor = undefined;
+
+ if (typeof requestAnimationFrame === 'function') {
+ requestAnimationFrame(() => this.restoreTimelineScrollAnchor(scrollAnchor));
+ return;
+ }
+
+ setTimeout(() => this.restoreTimelineScrollAnchor(scrollAnchor));
+ }
+
get timelineItems(): TopicTimelineElement[] {
return this.sortedElements.filter((item) => {
return item.year >= this.selectedStartYear && item.year <= this.selectedEndYear;
@@ -120,6 +159,22 @@ export class ResearchTimelineComponent implements OnChanges {
return this.selectedStartYear !== this.minYear || this.selectedEndYear !== this.maxYear;
}
+ get showEarlierYearsControl(): boolean {
+ return this.canLoadEarlierYears || this.loadingEarlierYears;
+ }
+
+ get earlierYearsLabel(): string {
+ if (this.loadingEarlierYears) {
+ return 'Frühere Jahre werden geladen ...';
+ }
+
+ if (this.earlierYearsLoadFailed) {
+ return 'Frühere Jahre erneut laden';
+ }
+
+ return 'Frühere Jahre anzeigen';
+ }
+
get rangeStartPercent(): string {
return `${this.calculateRangePercent(this.selectedStartYear)}%`;
}
@@ -129,15 +184,31 @@ export class ResearchTimelineComponent implements OnChanges {
}
get gridTemplateColumns(): string {
- const count = Math.max(this.timelineItems.length, 1);
+ const count = Math.max(
+ this.timelineItems.length + this.earlierYearsColumnCount,
+ 1,
+ );
+
return `repeat(${count}, minmax(${this.columnWidth}px, 1fr))`;
}
get timelineMinWidth(): number {
- const count = Math.max(this.timelineItems.length, 1);
+ const count = Math.max(
+ this.timelineItems.length + this.earlierYearsColumnCount,
+ 1,
+ );
+
return Math.max(count * this.columnWidth, 1000);
}
+ requestEarlierYears(): void {
+ if (!this.canLoadEarlierYears || this.loadingEarlierYears) {
+ return;
+ }
+
+ this.loadEarlierYears.emit();
+ }
+
setTimelineViewMode(mode: TimelineViewMode): void {
if (this.timelineViewMode === mode) {
return;
@@ -266,6 +337,104 @@ export class ResearchTimelineComponent implements OnChanges {
return phase.id;
}
+
+ private captureTimelineScrollAnchor(): void {
+ if (this.timelineViewMode !== 'years') {
+ return;
+ }
+
+ const wrapper = this.timelineWrapper?.nativeElement;
+
+ if (!wrapper || wrapper.scrollLeft <= this.scrollRestoreThreshold) {
+ return;
+ }
+
+ const scrollAnchor = this.findVisibleTimelineAnchor(wrapper);
+
+ if (!scrollAnchor) {
+ return;
+ }
+
+ this.pendingTimelineScrollAnchor = scrollAnchor;
+ }
+
+ private restoreTimelineScrollAnchor(scrollAnchor: TimelineScrollAnchor): void {
+ if (this.timelineViewMode !== 'years') {
+ return;
+ }
+
+ const wrapper = this.timelineWrapper?.nativeElement;
+
+ if (!wrapper) {
+ return;
+ }
+
+ const anchorElement = wrapper.querySelector(
+ `.timeline-content .timeline-item[data-timeline-year="${scrollAnchor.year}"]`,
+ );
+
+ if (!anchorElement) {
+ wrapper.scrollLeft = scrollAnchor.scrollLeft;
+ return;
+ }
+
+ const wrapperRect = wrapper.getBoundingClientRect();
+ const anchorRect = anchorElement.getBoundingClientRect();
+ const nextOffsetLeft = anchorRect.left - wrapperRect.left;
+
+ wrapper.scrollLeft += nextOffsetLeft - scrollAnchor.offsetLeft;
+ }
+
+ private findVisibleTimelineAnchor(
+ wrapper: HTMLDivElement,
+ ): TimelineScrollAnchor | undefined {
+ const wrapperRect = wrapper.getBoundingClientRect();
+ const yearElements = Array.from(
+ wrapper.querySelectorAll(
+ '.timeline-content .timeline-item[data-timeline-year]',
+ ),
+ );
+
+ let bestAnchor: TimelineScrollAnchor | undefined;
+ let bestDistance = Number.POSITIVE_INFINITY;
+
+ for (const element of yearElements) {
+ const year = Number(element.dataset['timelineYear']);
+
+ if (!Number.isFinite(year)) {
+ continue;
+ }
+
+ const elementRect = element.getBoundingClientRect();
+ const isVisible =
+ elementRect.right > wrapperRect.left && elementRect.left < wrapperRect.right;
+
+ if (!isVisible) {
+ continue;
+ }
+
+ const offsetLeft = elementRect.left - wrapperRect.left;
+ const distanceFromLeftEdge = Math.abs(offsetLeft);
+
+ if (distanceFromLeftEdge >= bestDistance) {
+ continue;
+ }
+
+ bestDistance = distanceFromLeftEdge;
+ bestAnchor = {
+ year,
+ offsetLeft,
+ scrollLeft: wrapper.scrollLeft,
+ };
+ }
+
+ return bestAnchor;
+ }
+
+ private get earlierYearsColumnCount(): number {
+ return this.showEarlierYearsControl ? 1 : 0;
+ }
+
private get sortedElements(): TopicTimelineElement[] {
return [...(this.elements ?? [])].sort((left, right) => left.year - right.year);
}
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 67f93c9d..e7340843 100644
--- a/webapp/src/app/modules/person-overview/person-overview.component.html
+++ b/webapp/src/app/modules/person-overview/person-overview.component.html
@@ -3,6 +3,9 @@
[elements]="topicTimelineElements"
[loading]="loadingTimeline"
[loadFailed]="timelineLoadFailed"
+ [canLoadEarlierYears]="timelineCanLoadEarlierYears"
+ [loadingEarlierYears]="timelineLoadingEarlierYears"
+ [earlierYearsLoadFailed]="timelineEarlierYearsLoadFailed"
[viewMode]="timelineViewMode"
[startYear]="timelineStartYear"
[endYear]="timelineEndYear"
@@ -10,5 +13,6 @@
(yearRangeChange)="onTimelineYearRangeChange($event)"
(topicSelect)="onTimelineTopicSelect($event)"
(yearSelect)="onTimelineYearSelect($event)"
+ (loadEarlierYears)="onTimelineLoadEarlierYears()"
>
-
+
\ No newline at end of file
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 a6f20d55..36bc99fb 100644
--- a/webapp/src/app/modules/person-overview/person-overview.component.ts
+++ b/webapp/src/app/modules/person-overview/person-overview.component.ts
@@ -4,7 +4,7 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { combineLatest, distinctUntilChanged, map } from 'rxjs';
-import { TopicCount,TopicsByYear } from '../../api';
+import { TopicCount, TopicsByYear } from '../../api';
import { WorksService } from '../../api';
import {
ResearchTimelineComponent,
@@ -26,15 +26,23 @@ export class PersonOverviewComponent implements OnInit {
private static readonly timelineViewQueryParam = 'timeline_view';
private static readonly timelineStartYearQueryParam = 'timeline_start_year';
private static readonly timelineEndYearQueryParam = 'timeline_end_year';
+ private static readonly timelineTopicCountLimit = 4;
+ private static readonly initialTimelineTargetPublications = 300;
private readonly route = inject(ActivatedRoute);
private readonly router = inject(Router);
private readonly worksService = inject(WorksService);
private readonly destroyRef = inject(DestroyRef);
+ private currentAuthorId = '';
+ private timelineLoadId = 0;
+
topicTimelineElements: TopicTimelineElement[] = [];
loadingTimeline = false;
timelineLoadFailed = false;
+ timelineCanLoadEarlierYears = false;
+ timelineLoadingEarlierYears = false;
+ timelineEarlierYearsLoadFailed = false;
timelineViewMode: TimelineViewMode = 'years';
timelineStartYear: number | undefined;
@@ -120,6 +128,19 @@ export class PersonOverviewComponent implements OnInit {
});
}
+ onTimelineLoadEarlierYears(): void {
+ if (
+ !this.currentAuthorId ||
+ this.currentAuthorId === '0' ||
+ this.timelineLoadingEarlierYears ||
+ !this.timelineCanLoadEarlierYears
+ ) {
+ return;
+ }
+
+ this.loadCompleteTopicTimeline(this.currentAuthorId);
+ }
+
private findAuthorId(paramMaps: readonly ParamMap[]): string {
return (
paramMaps
@@ -129,36 +150,112 @@ export class PersonOverviewComponent implements OnInit {
}
private loadTopicTimeline(authorId: string): void {
+ const loadId = ++this.timelineLoadId;
+ this.currentAuthorId = authorId;
+
if (!authorId || authorId === '0') {
- this.topicTimelineElements = [];
- this.loadingTimeline = false;
- this.timelineLoadFailed = false;
+ this.resetTimelineState();
return;
}
+ this.topicTimelineElements = [];
this.loadingTimeline = true;
this.timelineLoadFailed = false;
-
- const topicCountLimit = 4;
+ this.timelineCanLoadEarlierYears = false;
+ this.timelineLoadingEarlierYears = false;
+ this.timelineEarlierYearsLoadFailed = false;
this.worksService
- .getTopicsByTimeByAuthor(authorId, topicCountLimit)
+ .getTopicsByTimeByAuthor(
+ authorId,
+ PersonOverviewComponent.timelineTopicCountLimit,
+ PersonOverviewComponent.initialTimelineTargetPublications,
+ false,
+ )
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({
next: (response) => {
- this.topicTimelineElements = this.mapTimelineElements(response.elements);
+ if (!this.isCurrentTimelineLoad(loadId, authorId)) {
+ return;
+ }
+
+ const timelineElements = this.mapTimelineElements(response.elements);
+
+ this.topicTimelineElements = timelineElements;
this.loadingTimeline = false;
this.timelineLoadFailed = false;
+ this.timelineCanLoadEarlierYears =
+ this.getTimelinePublicationCount(timelineElements) >=
+ PersonOverviewComponent.initialTimelineTargetPublications;
},
error: (error) => {
+ if (!this.isCurrentTimelineLoad(loadId, authorId)) {
+ return;
+ }
+
console.error('Topic timeline could not be loaded.', error);
this.topicTimelineElements = [];
this.loadingTimeline = false;
this.timelineLoadFailed = true;
+ this.timelineCanLoadEarlierYears = false;
+ this.timelineLoadingEarlierYears = false;
+ this.timelineEarlierYearsLoadFailed = false;
},
});
}
+ private loadCompleteTopicTimeline(authorId: string): void {
+ const loadId = this.timelineLoadId;
+
+ this.timelineLoadingEarlierYears = true;
+ this.timelineEarlierYearsLoadFailed = false;
+
+ this.worksService
+ .getTopicsByTimeByAuthor(
+ authorId,
+ PersonOverviewComponent.timelineTopicCountLimit,
+ undefined,
+ true,
+ )
+ .pipe(takeUntilDestroyed(this.destroyRef))
+ .subscribe({
+ next: (response) => {
+ if (!this.isCurrentTimelineLoad(loadId, authorId)) {
+ return;
+ }
+
+ const completeTimelineElements = this.mapTimelineElements(response.elements);
+
+ this.topicTimelineElements = this.mergeTimelineElements(
+ this.topicTimelineElements,
+ completeTimelineElements,
+ );
+ this.timelineCanLoadEarlierYears = false;
+ this.timelineLoadingEarlierYears = false;
+ this.timelineEarlierYearsLoadFailed = false;
+ },
+ error: (error) => {
+ if (!this.isCurrentTimelineLoad(loadId, authorId)) {
+ return;
+ }
+
+ console.error('Complete topic timeline could not be loaded.', error);
+ this.timelineCanLoadEarlierYears = true;
+ this.timelineLoadingEarlierYears = false;
+ this.timelineEarlierYearsLoadFailed = true;
+ },
+ });
+ }
+
+ private resetTimelineState(): void {
+ this.topicTimelineElements = [];
+ this.loadingTimeline = false;
+ this.timelineLoadFailed = false;
+ this.timelineCanLoadEarlierYears = false;
+ this.timelineLoadingEarlierYears = false;
+ this.timelineEarlierYearsLoadFailed = false;
+ }
+
private mapTimelineElements(
elements: TopicsByYear[] | undefined,
): TopicTimelineElement[] {
@@ -178,6 +275,31 @@ export class PersonOverviewComponent implements OnInit {
}));
}
+ private mergeTimelineElements(
+ currentElements: TopicTimelineElement[],
+ completeElements: TopicTimelineElement[],
+ ): TopicTimelineElement[] {
+ const elementsByYear = new Map();
+
+ for (const element of currentElements) {
+ elementsByYear.set(element.year, element);
+ }
+
+ for (const element of completeElements) {
+ elementsByYear.set(element.year, element);
+ }
+
+ return [...elementsByYear.values()].sort((left, right) => left.year - right.year);
+ }
+
+ private getTimelinePublicationCount(elements: TopicTimelineElement[]): number {
+ return elements.reduce((total, element) => total + element.publication_count, 0);
+ }
+
+ private isCurrentTimelineLoad(loadId: number, authorId: string): boolean {
+ return loadId === this.timelineLoadId && authorId === this.currentAuthorId;
+ }
+
private parseTimelineViewMode(value: string | null): TimelineViewMode {
return value === 'compact' ? 'compact' : 'years';
}
@@ -207,4 +329,4 @@ export class PersonOverviewComponent implements OnInit {
replaceUrl,
});
}
-}
+}
\ No newline at end of file