add silder for relevant years

This commit is contained in:
Steven Tischer
2026-07-12 14:19:37 +02:00
parent afe3038dce
commit d16b1544b9
3 changed files with 123 additions and 23 deletions
@@ -28,23 +28,46 @@
</mat-card-content>
</mat-card>
<mat-card class="weights-card">
<mat-card-content>
<app-weights-sliders
[options]="weightOptions"
[initialWeights]="defaultWeights"
title="Personen-Gewichtung"
description="Werte zwischen 0 und 1. Summe wird normalisiert zu 1."
resetLabel="Ausgewogen"
applyLabel="Neu gewichten"
normalizedTitle="Normalisiert"
queryParamPrefix="personW_"
[persistInQueryParams]="true"
[showApplyButton]="true"
[showResetButton]="true"
[showNormalizedPreview]="true"
(weightsChange)="onWeightsChange($event)"
(applyWeights)="onApplyWeights($event)" />
</mat-card-content>
</mat-card>
<div class="controls-column">
<mat-card class="weights-card">
<mat-card-content>
<app-weights-sliders
[options]="weightOptions"
[initialWeights]="defaultWeights"
title="Personen-Gewichtung"
description="Werte zwischen 0 und 1. Summe wird normalisiert zu 1."
resetLabel="Ausgewogen"
applyLabel="Neu gewichten"
normalizedTitle="Normalisiert"
queryParamPrefix="personW_"
[persistInQueryParams]="true"
[showApplyButton]="true"
[showResetButton]="true"
[showNormalizedPreview]="true"
(weightsChange)="onWeightsChange($event)"
(applyWeights)="onApplyWeights($event)" />
</mat-card-content>
</mat-card>
<mat-card class="timespan-card">
<mat-card-content>
<div class="timespan-header">
<mat-icon>date_range</mat-icon>
<span>Zeitraum: {{ timespanFrom() }} – {{ timespanTo() }}</span>
</div>
<mat-slider [min]="minYear" [max]="maxYear" [step]="1" discrete>
<input
matSliderStartThumb
[value]="timespanFrom()"
(valueChange)="timespanFrom.set($event)"
(dragEnd)="onTimespanChange()" />
<input
matSliderEndThumb
[value]="timespanTo()"
(valueChange)="timespanTo.set($event)"
(dragEnd)="onTimespanChange()" />
</mat-slider>
</mat-card-content>
</mat-card>
</div>
</div>
@@ -7,12 +7,21 @@
grid-template-areas: 'summary results';
gap: 0.75rem;
align-items: start;
width: 100%;
}
.search-summary-card {
.search-summary-card,
.controls-column {
grid-area: summary;
}
.controls-column {
display: flex;
flex-direction: column;
gap: 0.75rem;
min-width: 0;
}
.results-card {
grid-area: results;
}
@@ -65,3 +74,18 @@
.results-hint {
padding: 0.5rem 0.25rem;
}
/* ============================================================
TIMESPAN
============================================================ */
.timespan-header {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.25rem;
font-weight: 500;
}
.timespan-card mat-slider {
width: 100%;
}
@@ -1,9 +1,10 @@
import { Component, inject, signal } from '@angular/core';
import { Component, OnInit, inject, signal } from '@angular/core';
import { DecimalPipe } from '@angular/common';
import { RouterLink } from '@angular/router';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';
import { MatSliderModule } from '@angular/material/slider';
import {
WeightMap,
@@ -28,15 +29,18 @@ import { SearchResultsStateService } from '../search-results-state.service';
RouterLink,
MatCardModule,
MatIconModule,
MatSliderModule,
WeightsSlidersComponent,
],
templateUrl: './persons-results.component.html',
styleUrl: './persons-results.component.scss',
})
export class KeywordsToPersonsResultsComponent {
export class KeywordsToPersonsResultsComponent implements OnInit {
// injects the state set by the parent route — no duplicate parsing here
private readonly state = inject(SearchResultsStateService);
private readonly rankingService = inject(RankingService);
private readonly route = inject(ActivatedRoute);
private readonly router = inject(Router);
// for now only works and citations are used as metrics/weights
readonly defaultWeights: WeightMap = {
@@ -96,11 +100,47 @@ export class KeywordsToPersonsResultsComponent {
valid: true,
});
// publication-year timespan filter (range slider)
readonly minYear = 1900;
readonly maxYear = 2026;
readonly timespanFrom = signal(this.minYear);
readonly timespanTo = signal(this.maxYear);
readonly authors = signal<RankedAuthor[]>([]);
readonly loading = signal(false);
private hasLoadedInitial = false;
ngOnInit(): void {
// restore the timespan from the URL so the range is shareable/bookmarkable
this.timespanFrom.set(this.readYearParam('tFrom', this.minYear));
this.timespanTo.set(this.readYearParam('tTo', this.maxYear));
}
// reads a year query param, clamped to the valid range; falls back on invalid input
private readYearParam(name: string, fallback: number): number {
const rawValue = this.route.snapshot.queryParamMap.get(name);
if (rawValue === null) {
return fallback;
}
const year = Number(rawValue);
if (!Number.isFinite(year)) {
return fallback;
}
return Math.min(this.maxYear, Math.max(this.minYear, Math.round(year)));
}
private writeTimespanToUrl(): void {
this.router.navigate([], {
relativeTo: this.route,
queryParams: { tFrom: this.timespanFrom(), tTo: this.timespanTo() },
queryParamsHandling: 'merge',
replaceUrl: true,
});
}
onWeightsChange(value: WeightsSlidersValue): void {
this.currentWeights.set(value);
@@ -116,6 +156,15 @@ export class KeywordsToPersonsResultsComponent {
this.loadAuthors();
}
// called when a timespan thumb is released — persist to the URL and reload
onTimespanChange(): void {
if (this.timespanFrom() > this.timespanTo()) {
return;
}
this.writeTimespanToUrl();
this.loadAuthors();
}
// the backend returns the full OpenAlex url; the profile route needs only the id
authorProfileId(author: RankedAuthor): string {
const parts = author.author_id.split('/');
@@ -138,6 +187,10 @@ export class KeywordsToPersonsResultsComponent {
works: rawWeights['works'],
citation: rawWeights['citations'],
},
timespan: {
from: this.timespanFrom(),
to: this.timespanTo(),
},
};
this.loading.set(true);