diff --git a/webapp/src/app/modules/person-network-collaborators/person-network-collaborators.component.html b/webapp/src/app/modules/person-network-collaborators/person-network-collaborators.component.html index dadd7299..174e3857 100644 --- a/webapp/src/app/modules/person-network-collaborators/person-network-collaborators.component.html +++ b/webapp/src/app/modules/person-network-collaborators/person-network-collaborators.component.html @@ -1,9 +1,4 @@ - +
@@ -16,7 +11,7 @@ - + @@ -43,7 +38,7 @@ [cdkDetailRowTpl]="tpl" >
ID HäufigkeitHäufigkeit {{ element.works.length }}
- +
diff --git a/webapp/src/app/modules/person-network-collaborators/person-network-collaborators.component.ts b/webapp/src/app/modules/person-network-collaborators/person-network-collaborators.component.ts index 7fc1e153..6138705f 100644 --- a/webapp/src/app/modules/person-network-collaborators/person-network-collaborators.component.ts +++ b/webapp/src/app/modules/person-network-collaborators/person-network-collaborators.component.ts @@ -6,12 +6,11 @@ import { ViewChild, } from '@angular/core'; import { CollaborationNetwork } from '../../api'; -import { Router, RouterModule } from '@angular/router'; +import { RouterModule } from '@angular/router'; import { MatTableDataSource, MatTableModule } from '@angular/material/table'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; -import { ScrollingModule } from '@angular/cdk/scrolling'; import { MatSort, MatSortModule } from '@angular/material/sort'; import { CdkDetailRowDirective } from '../../directives/cdk-detail-row.directive'; @@ -30,7 +29,6 @@ type Collaborator = { @Component({ selector: 'app-person-network-collaborators', imports: [ - ScrollingModule, MatTableModule, MatIconModule, MatSortModule, @@ -53,21 +51,47 @@ export class PersonNetworkCollaboratorsComponent implements AfterViewInit { @ViewChild(MatSort) sort!: MatSort; - constructor(private readonly router: Router) {} + constructor() { + effect(() => { + const collaborationNetwork = this.collaborationNetwork(); + this.dataSource = this.buildCollaboratorsDataSource(collaborationNetwork); + this.dataSource.sortingDataAccessor = (item, property) => { + if (property === 'count') { + return item.works.length; + } + return (item as Record)[property] as string | number; + }; + this.dataSource.filterPredicate = (data, filter) => { + const value = filter.trim().toLowerCase(); + return ( + data.id.toLowerCase().includes(value) || + data.name.toLowerCase().includes(value) + ); + }; + if (this.sort) { + this.dataSource.sort = this.sort; + this.setDefaultSort(); + } + const currentSearchTerm = this.searchTerm().trim().toLowerCase(); + this.dataSource.filter = currentSearchTerm; + }); + + effect(() => { + const searchTerm = this.searchTerm(); + const normalizedTerm = searchTerm.trim().toLowerCase(); + this.dataSource.filter = normalizedTerm; + }); + } ngAfterViewInit() { this.dataSource.sort = this.sort; } - onCollaborationNetworkChange = effect(() => { - const collaborationNetwork = this.collaborationNetwork(); - this.dataSource = this.buildCollaboratorsDataSource(collaborationNetwork); - }); - - onSearchTermChange = effect(() => { - const searchTerm = this.searchTerm(); - this.dataSource.filter = searchTerm.trim().toLowerCase(); - }); + private setDefaultSort(): void { + this.sort.active = 'name'; + this.sort.direction = 'asc'; + this.sort.sortChange.emit({ active: 'name', direction: 'asc' }); + } buildCollaboratorsDataSource( collaborationNetwork: CollaborationNetwork, diff --git a/webapp/src/app/modules/person-network-graph/person-network-graph.component.html b/webapp/src/app/modules/person-network-graph/person-network-graph.component.html index 650f7c3f..8a37053e 100644 --- a/webapp/src/app/modules/person-network-graph/person-network-graph.component.html +++ b/webapp/src/app/modules/person-network-graph/person-network-graph.component.html @@ -1 +1,16 @@ -

person-network-graph works!

+ + + Kollaborations Netzwerk von {{ authorDisplayName }} + + +
+
+
diff --git a/webapp/src/app/modules/person-network-graph/person-network-graph.component.scss b/webapp/src/app/modules/person-network-graph/person-network-graph.component.scss index e69de29b..199a7d8f 100644 --- a/webapp/src/app/modules/person-network-graph/person-network-graph.component.scss +++ b/webapp/src/app/modules/person-network-graph/person-network-graph.component.scss @@ -0,0 +1,25 @@ +:host { + display: flex; + width: 100%; +} + +mat-card { + display: flex; + flex-direction: column; + width: 100%; +} + +mat-card-content { + flex: 1 1 auto; + min-height: 0; +} + +.graph { + width: 100%; + height: 100%; + min-height: 400px; + overscroll-behavior: contain; + touch-action: none; + user-select: none; + cursor: grab; +} diff --git a/webapp/src/app/modules/person-network-graph/person-network-graph.component.spec.ts b/webapp/src/app/modules/person-network-graph/person-network-graph.component.spec.ts deleted file mode 100644 index 96d6e83c..00000000 --- a/webapp/src/app/modules/person-network-graph/person-network-graph.component.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { PersonNetworkGraphComponent } from './person-network-graph.component'; - -describe('PersonNetworkGraphComponent', () => { - let component: PersonNetworkGraphComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [PersonNetworkGraphComponent] - }) - .compileComponents(); - - fixture = TestBed.createComponent(PersonNetworkGraphComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/webapp/src/app/modules/person-network-graph/person-network-graph.component.ts b/webapp/src/app/modules/person-network-graph/person-network-graph.component.ts index b9567bec..c31f74d2 100644 --- a/webapp/src/app/modules/person-network-graph/person-network-graph.component.ts +++ b/webapp/src/app/modules/person-network-graph/person-network-graph.component.ts @@ -1,11 +1,136 @@ -import { Component } from '@angular/core'; +import { Component, effect, input } from '@angular/core'; +import { MatCardModule } from '@angular/material/card'; +import { CollaborationNetwork } from '../../api'; +import { NgxEchartsDirective } from 'ngx-echarts'; +import { EChartsCoreOption } from 'echarts/types/dist/core'; + +import * as echarts from 'echarts/core'; +import { GridComponent, TitleComponent } from 'echarts/components'; +import { CanvasRenderer } from 'echarts/renderers'; +import { GraphChart } from 'echarts/charts'; +echarts.use([GridComponent, CanvasRenderer, GraphChart, TitleComponent]); @Component({ selector: 'app-person-network-graph', - imports: [], + imports: [MatCardModule, NgxEchartsDirective], templateUrl: './person-network-graph.component.html', styleUrl: './person-network-graph.component.scss', }) export class PersonNetworkGraphComponent { + collaborationNetwork = input(); + authorDisplayName: string = ''; + + options!: EChartsCoreOption; + + constructor() { + effect(() => { + const network = this.collaborationNetwork(); + if (!network) { + return; + } + this.updateGraphOptions(network); + }); + } + + onGraphWheel(event: WheelEvent): void { + event.preventDefault(); + } + + private updateGraphOptions(collaborationNetwork: CollaborationNetwork): void { + if (!collaborationNetwork) { + return; + } + + const datas = [ + { + nodes: collaborationNetwork.nodes.map((node) => { + const category = (() => { + if (node.category === 'institution') { + return 'institution'; + } + if (node.category === 'work') { + return 'work'; + } + if (node.raw_id === collaborationNetwork.raw_person_id) { + return 'author'; + } + return 'collaborator'; + })(); + + if (node.category === 'work') { + return { + id: node.raw_id + '', + name: node.display_name, + category, + }; + } + + return { + id: node.raw_id + '', + name: node.display_name, + category, + label: { + show: true, + }, + }; + }), + links: collaborationNetwork.edges.map((edge) => { + return [edge.raw_source_id + '', edge.raw_target_id + '']; + }), + categories: [ + { + name: 'author', + }, + { + name: 'collaborator', + }, + { + name: 'institution', + }, + { + name: 'work', + }, + ], + }, + ]; + + this.authorDisplayName = + collaborationNetwork.nodes.find( + (node) => node.raw_id === collaborationNetwork.raw_person_id, + )?.display_name || 'Unknown Author'; + + this.options = { + series: datas.map((item) => { + return { + name: this.authorDisplayName, + type: 'graph', + layout: 'force', + symbolSize: 20, + animation: false, + data: item.nodes, + roam: true, + force: { + repulsion: 10000, + edgeLength: 125, + gravity: 0.2, + }, + links: item.links.map((e) => { + return { + source: e[0] + '', + target: e[1] + '', + }; + }), + categories: item.categories, + roamTrigger: 'global', // + 2 hours because of incomplete documentation https://github.com/apache/echarts/issues/17214 + emphasis: { + focus: 'adjacency', + lineStyle: { + width: 5, + }, + }, + }; + }), + }; + } } diff --git a/webapp/src/app/modules/person-network-publications/person-network-publications.component.html b/webapp/src/app/modules/person-network-publications/person-network-publications.component.html index 5b3cbdbd..a8c4c24b 100644 --- a/webapp/src/app/modules/person-network-publications/person-network-publications.component.html +++ b/webapp/src/app/modules/person-network-publications/person-network-publications.component.html @@ -1,9 +1,4 @@ - +
@@ -43,7 +38,7 @@ [cdkDetailRowTpl]="tpl" >
ID
- +
diff --git a/webapp/src/app/modules/person-network-publications/person-network-publications.component.ts b/webapp/src/app/modules/person-network-publications/person-network-publications.component.ts index 14d9a6a8..271906b9 100644 --- a/webapp/src/app/modules/person-network-publications/person-network-publications.component.ts +++ b/webapp/src/app/modules/person-network-publications/person-network-publications.component.ts @@ -6,13 +6,12 @@ import { ViewChild, } from '@angular/core'; import { CollaborationNetwork } from '../../api'; -import { Router, RouterModule } from '@angular/router'; +import { RouterModule } from '@angular/router'; import { MatTableDataSource, MatTableModule } from '@angular/material/table'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; -import { ScrollingModule } from '@angular/cdk/scrolling'; -import { MatSort } from '@angular/material/sort'; +import { MatSort, MatSortModule } from '@angular/material/sort'; import { CdkDetailRowDirective } from '../../directives/cdk-detail-row.directive'; type Collaborator = { @@ -32,9 +31,9 @@ type Work = { imports: [ MatTableModule, MatIconModule, + MatSortModule, RouterModule, CdkDetailRowDirective, - ScrollingModule, MatButtonModule, ], templateUrl: './person-network-publications.component.html', @@ -52,21 +51,41 @@ export class PersonNetworkPublicationsComponent implements AfterViewInit { @ViewChild(MatSort) sort!: MatSort; - constructor(private readonly router: Router) {} + constructor() { + effect(() => { + const collaborationNetwork = this.collaborationNetwork(); + if (!collaborationNetwork) { + return; + } + + this.dataSource = this.buildWorksDataSource(collaborationNetwork); + this.dataSource.sortingDataAccessor = (item, property) => { + if (property === 'contributors') { + return item.collaborators.length; + } + return (item as Record)[property] as string | number; + }; + if (this.sort) { + this.dataSource.sort = this.sort; + this.setDefaultSort(); + } + }); + + effect(() => { + const searchTerm = this.searchTerm(); + this.dataSource.filter = searchTerm.trim().toLowerCase(); + }); + } ngAfterViewInit() { this.dataSource.sort = this.sort; } - onCollaborationNetworkChange = effect(() => { - const collaborationNetwork = this.collaborationNetwork(); - this.dataSource = this.buildWorksDataSource(collaborationNetwork); - }); - - onSearchTermChange = effect(() => { - const searchTerm = this.searchTerm(); - this.dataSource.filter = searchTerm.trim().toLowerCase(); - }); + private setDefaultSort(): void { + this.sort.active = 'title'; + this.sort.direction = 'asc'; + this.sort.sortChange.emit({ active: 'title', direction: 'asc' }); + } buildWorksDataSource( collaborationNetwork: CollaborationNetwork, diff --git a/webapp/src/app/modules/person-network/person-network.component.html b/webapp/src/app/modules/person-network/person-network.component.html index a8d42a2e..47484f75 100644 --- a/webapp/src/app/modules/person-network/person-network.component.html +++ b/webapp/src/app/modules/person-network/person-network.component.html @@ -1,19 +1,5 @@
- - - Kollaborations Netzwerk von {{ authorDisplayName }} - - -
-
-
+
@@ -62,10 +48,9 @@ }} search diff --git a/webapp/src/app/modules/person-network/person-network.component.scss b/webapp/src/app/modules/person-network/person-network.component.scss index 71a45b8a..b68d8a98 100644 --- a/webapp/src/app/modules/person-network/person-network.component.scss +++ b/webapp/src/app/modules/person-network/person-network.component.scss @@ -3,19 +3,20 @@ flex-direction: row; padding: 40px; gap: 20px; - max-height: 1000px; + align-items: stretch; } -.graph { - width: 75vh; - height: 75vh; +.content > app-person-network-graph, +.right-card { + flex: 1 1 0; + min-width: 0; } .table { overflow: auto; width: 100%; - max-height: 1000px; - height: 1200px; + max-height: 70vh; + height: 100%; } .table table { @@ -55,24 +56,4 @@ .toggle-group .mat-button-toggle { text-transform: none; -} - -.element-row { - position: relative; -} - -.element-row:not(.expanded) { - cursor: pointer; -} - -.element-row:not(.expanded):hover { - background: #f5f5f5; -} - -.element-row.expanded { - border-bottom-color: transparent; -} - -.network-filter-form { - } \ No newline at end of file diff --git a/webapp/src/app/modules/person-network/person-network.component.ts b/webapp/src/app/modules/person-network/person-network.component.ts index 3055260f..73a9bfba 100644 --- a/webapp/src/app/modules/person-network/person-network.component.ts +++ b/webapp/src/app/modules/person-network/person-network.component.ts @@ -1,26 +1,14 @@ import { toSignal } from '@angular/core/rxjs-interop'; -import { - AfterViewInit, - Component, - computed, - effect, - OnInit, - signal, - ViewChild, - WritableSignal, -} from '@angular/core'; + +import { Component, computed, OnInit } from '@angular/core'; import { ActivatedRoute, Router, RouterModule } from '@angular/router'; -import type { EChartsCoreOption } from 'echarts/core'; import { MatCardModule } from '@angular/material/card'; import { MatButtonToggleModule } from '@angular/material/button-toggle'; import { MatRippleModule } from '@angular/material/core'; -import { NgxEchartsDirective, provideEchartsCore } from 'ngx-echarts'; +import { provideEchartsCore } from 'ngx-echarts'; import * as echarts from 'echarts/core'; -import { GridComponent, TitleComponent } from 'echarts/components'; -import { CanvasRenderer } from 'echarts/renderers'; -import { GraphChart } from 'echarts/charts'; -import { MatTableDataSource, MatTableModule } from '@angular/material/table'; +import { MatTableModule } from '@angular/material/table'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { ScrollingModule } from '@angular/cdk/scrolling'; @@ -33,13 +21,13 @@ import { } from '@angular/forms'; import { MatInputModule } from '@angular/material/input'; import { MatSliderModule } from '@angular/material/slider'; -import { MatSort, MatSortModule } from '@angular/material/sort'; +import { MatSortModule } from '@angular/material/sort'; import { LiveAnnouncer } from '@angular/cdk/a11y'; import { CollaborationNetwork } from '../../api'; import { PersonNetworkCollaboratorsComponent } from '../person-network-collaborators/person-network-collaborators.component'; import { PersonNetworkPublicationsComponent } from '../person-network-publications/person-network-publications.component'; import { debounceTime } from 'rxjs'; -echarts.use([GridComponent, CanvasRenderer, GraphChart, TitleComponent]); +import { PersonNetworkGraphComponent } from '../person-network-graph/person-network-graph.component'; type Collaborator = { id: string; @@ -56,7 +44,6 @@ type Works = { @Component({ selector: 'app-person-network', imports: [ - NgxEchartsDirective, MatCardModule, MatTableModule, MatButtonModule, @@ -74,19 +61,15 @@ type Works = { MatSliderModule, ReactiveFormsModule, FormsModule, + PersonNetworkGraphComponent, ], templateUrl: './person-network.component.html', styleUrl: './person-network.component.scss', providers: [provideEchartsCore({ echarts })], }) -export class PersonNetworkComponent implements OnInit, AfterViewInit { +export class PersonNetworkComponent implements OnInit { collaborationNetwork!: CollaborationNetwork; - displayedTable = signal<'collaborators' | 'publications'>('collaborators'); - searchTerm = signal(''); - - minimumCollaborations: WritableSignal = signal(5); - filterForm = new FormGroup({ searchTerm: new FormControl(''), startYear: new FormControl(2000), @@ -95,201 +78,77 @@ export class PersonNetworkComponent implements OnInit, AfterViewInit { displayedTable: new FormControl('collaborators'), }); + readonly formValue = toSignal(this.filterForm.valueChanges); + readonly debouncedFormValue = toSignal( + this.filterForm.valueChanges.pipe(debounceTime(300)), + ); + + displayedTable = computed(() => { + return this.formValue()?.displayedTable; + }); + + readonly searchTerm = computed(() => { + console.log('Search term computed:', this.debouncedFormValue()?.searchTerm); + return this.debouncedFormValue()?.searchTerm || ''; + }); + + readonly activatedRouteData = toSignal(this.activatedRoute.data); + formatYearLabel = (value: number) => `${value}`; - collaboratorsDataSource: MatTableDataSource = - new MatTableDataSource(); - worksDataSource: MatTableDataSource = new MatTableDataSource(); - - options!: EChartsCoreOption; - - displayedCollaboratorsColumns: string[] = ['id', 'name', 'actions']; - displayedWorksColumns: string[] = ['id', 'title']; - constructor( private readonly activatedRoute: ActivatedRoute, private readonly router: Router, private readonly _liveAnnouncer: LiveAnnouncer, ) {} - authorDisplayName: string = ''; - - @ViewChild(MatSort) collaboratorsSort!: MatSort; - @ViewChild(MatSort) worksSort!: MatSort; - - trackBy = (index: number, el: Collaborator) => el.id; - - ngAfterViewInit() { - this.collaboratorsDataSource.sort = this.collaboratorsSort; - this.worksDataSource.sort = this.worksSort; - } - ngOnInit(): void { this.activatedRoute.data.subscribe(({ collaborationNetwork }) => { this.collaborationNetwork = collaborationNetwork; - console.log('Collaboration Network:', this.collaborationNetwork); - - this.filterForm.valueChanges - .pipe(debounceTime(300)) - .subscribe((value) => { - this.router.navigate([], { - relativeTo: this.activatedRoute, - queryParams: { - table: value.displayedTable, - search_term: value.searchTerm, - start_year: value.startYear, - end_year: value.endYear, - }, - // replaceUrl: true, - }); - }); const currentParams = this.activatedRoute.snapshot.queryParams; - this.filterForm - .get('startYear')! - .setValue( - Number(currentParams['start_year']) || - this.collaborationNetwork.filter_information.min_possible_year, - ); - this.filterForm - .get('endYear')! - .setValue( - Number(currentParams['end_year']) || - this.collaborationNetwork.filter_information.max_possible_year, - ); + const initialStartYear = + Number(currentParams['start_year']) || + this.collaborationNetwork.filter_information.min_possible_year; + const initialEndYear = + Number(currentParams['end_year']) || + this.collaborationNetwork.filter_information.max_possible_year; - this.activatedRoute.queryParams.subscribe((params) => { - const table = params['table']; - if (table === 'collaborators' || table === 'publications') { - this.displayedTable.set(table); - } else { - this.displayedTable.set('collaborators'); - } - - const searchTerm = params['search_term'] || ''; - this.searchTerm.set(searchTerm); + this.filterForm.setValue({ + searchTerm: currentParams['search_term'] || '', + startYear: initialStartYear, + endYear: initialEndYear, + minimumCollaborations: + this.filterForm.get('minimumCollaborations')?.value ?? 1, + displayedTable: currentParams['table'] || 'collaborators', }); + }); - this.updateGraphOptions(); + this.filterForm.valueChanges.pipe(debounceTime(300)).subscribe((value) => { + const displayedTable = value.displayedTable; + const searchTerm = value.searchTerm; + const startYear = value.startYear; + const endYear = value.endYear; + + this.router.navigate([], { + relativeTo: this.activatedRoute, + queryParams: { + table: displayedTable, + search_term: searchTerm, + start_year: startYear, + end_year: endYear, + }, + }); }); } - private updateGraphOptions(): void { - const datas = [ - { - nodes: this.collaborationNetwork.nodes.map((node) => { - const category = (() => { - if (node.category === 'institution') { - return 'institution'; - } - if (node.category === 'work') { - return 'work'; - } - if (node.raw_id === this.collaborationNetwork.raw_person_id) { - return 'author'; - } - return 'collaborator'; - })(); - - if (category === 'work') { - return { - id: node.raw_id + '', - name: node.display_name, - category, - }; - } - return { - id: node.raw_id + '', - name: node.display_name, - category, - label: { show: true }, - }; - }), - links: this.collaborationNetwork.edges.map((edge) => { - return [edge.raw_source_id + '', edge.raw_target_id + '']; - }), - categories: [ - { - name: 'author', - label: { show: true }, - }, - { - name: 'collaborator', - }, - { - name: 'institution', - }, - { - name: 'work', - }, - ], - emphasis: { - label: { - show: true, - }, - }, - }, - ]; - - this.authorDisplayName = - this.collaborationNetwork.nodes.find( - (node) => node.raw_id === this.collaborationNetwork.raw_person_id, - )?.display_name || 'Unknown Author'; - - this.options = { - series: datas.map((item) => { - return { - name: this.authorDisplayName, - type: 'graph', - layout: 'force', - symbolSize: 25, - animation: false, - data: item.nodes, - roam: true, - legend: [ - { - data: item.categories.map((c) => c.name), - }, - ], - force: { - repulsion: 10000, - edgeLength: 100, - gravity: 0.1, - }, - links: item.links.map((e) => { - return { - source: e[0] + '', - target: e[1] + '', - }; - }), - categories: item.categories, - }; - }), - }; - } - - navigateToPerson(raw_person_id: string) { - this.router.navigate(['/person', raw_person_id]); - } - - onChartEvent(event: echarts.ECElementEvent, type: string) { - if (type !== 'chartClick') { - return; - } - const data = event.data as Collaborator; - const raw_person_id = data.id; - if (raw_person_id === this.collaborationNetwork.raw_person_id) { - return; - } - this.navigateToPerson(raw_person_id); - } - - changeSearchTerm(event: Event) { - const filterValue = (event.target as HTMLInputElement).value; - this.searchTerm.set(filterValue); - } + trackBy = (index: number, el: Collaborator) => el.id; onToggleChange(event: any) { - this.displayedTable.set(event.value); + const value = event.value; + if (!value) { + return; + } + this.filterForm.get('displayedTable')?.setValue(value); } }