Files
smartguide/webapp/src/app/modules/dashboard/topic-heatmap/topic-heatmap.component.ts
T
farajollahi fafd5018bd
LocationBasedServices/smartguide/pipeline/head This commit looks good
implement charts
2026-07-11 22:15:44 +02:00

213 lines
5.7 KiB
TypeScript

import { Component, Input, OnChanges } from '@angular/core';
import { EChartsOption } from 'echarts';
import { NgxEchartsDirective } from 'ngx-echarts';
import { TopicHeatmap } from '../dashboard-statistics.service';
@Component({
selector: 'app-topic-heatmap',
imports: [NgxEchartsDirective],
templateUrl: './topic-heatmap.component.html',
styleUrl: './topic-heatmap.component.scss',
})
export class TopicHeatmapComponent implements OnChanges {
@Input() heatmap?: TopicHeatmap;
@Input() loading = false;
options: EChartsOption = {};
private readonly colors = [
'#2563eb',
'#059669',
'#d97706',
'#dc2626',
'#7c3aed',
'#0284c7',
'#ea580c',
'#4f46e5',
'#0f766e',
'#be123c',
];
ngOnChanges(): void {
this.options = this.buildOptions();
}
private buildOptions(): EChartsOption {
const fields = this.heatmap?.fields ?? [];
const data = fields.map((field) => ({
id: field.id,
name: field.name,
value: field.total || this.totalCount(field.values),
label: {
show: true,
formatter: (params: any) =>
`${params.name}\n${this.formatCount(params.value)}`,
color: '#ffffff',
fontWeight: 700,
lineHeight: 18,
overflow: 'truncate' as const,
},
children: field.values
.filter((value) => value.count > 0)
.map((value) => ({
name: String(value.year),
value: value.count,
share: value.share,
})),
}));
return {
tooltip: {
formatter: (params: any) => {
const count = Number(params.value ?? 0);
const share =
typeof params.data?.share === 'number'
? `<br />Anteil im Jahr: <strong>${(params.data.share * 100).toFixed(1)}%</strong>`
: '';
return `${params.name}<br /><strong>${count}</strong> Publikationen${share}`;
},
},
series: [
{
name: 'Fields',
type: 'treemap',
data,
roam: false,
nodeClick: 'zoomToNode',
sort: 'desc',
drillDownIcon: '',
breadcrumb: {
show: true,
bottom: 0,
height: 24,
left: 8,
right: 8,
emptyItemWidth: 80,
itemStyle: {
color: '#f8fafc',
borderColor: '#cbd5e1',
borderWidth: 1,
textStyle: {
color: '#334155',
fontWeight: 600,
},
},
emphasis: {
itemStyle: {
color: '#e0f2fe',
borderColor: '#93c5fd',
textStyle: {
color: '#0f172a',
fontWeight: 700,
},
},
},
},
color: this.colors,
colorMappingBy: 'id',
label: {
show: true,
formatter: (params: any) =>
`${params.name}\n${this.formatCount(params.value)}`,
color: '#ffffff',
fontWeight: 600,
lineHeight: 18,
position: 'inside',
align: 'center',
verticalAlign: 'middle',
overflow: 'truncate',
},
upperLabel: {
show: true,
formatter: (params: any) =>
`${params.name} · ${this.formatCount(params.value)}`,
height: 30,
color: '#ffffff',
fontWeight: 700,
overflow: 'truncate',
},
levels: [
{
color: this.colors,
label: {
show: true,
position: 'inside',
align: 'center',
verticalAlign: 'middle',
},
upperLabel: { show: false },
itemStyle: {
borderColor: '#ffffff',
borderWidth: 3,
gapWidth: 3,
},
},
{
color: this.colors,
label: {
show: true,
position: 'inside',
align: 'center',
verticalAlign: 'middle',
},
upperLabel: { show: false },
itemStyle: {
borderColor: '#ffffff',
borderWidth: 3,
gapWidth: 3,
},
},
{
colorSaturation: [0.45, 0.78],
label: {
show: true,
formatter: (params: any) =>
`${params.name}\n${this.formatCount(params.value)}`,
position: 'inside',
align: 'center',
verticalAlign: 'middle',
color: '#ffffff',
fontWeight: 700,
lineHeight: 18,
overflow: 'truncate',
},
upperLabel: { show: false },
itemStyle: {
borderColor: '#ffffff',
borderWidth: 2,
gapWidth: 2,
},
},
],
leafDepth: 1,
top: 8,
right: 8,
bottom: 32,
left: 8,
animationDurationUpdate: 450,
emphasis: {
focus: 'self',
label: {
color: '#ffffff',
},
},
itemStyle: {
borderRadius: 4,
borderColor: '#ffffff',
borderWidth: 3,
gapWidth: 3,
},
},
],
};
}
private totalCount(values: Array<{ count: number }>): number {
return values.reduce((sum, value) => sum + value.count, 0);
}
private formatCount(value: unknown): string {
return Number(value ?? 0).toLocaleString('de-DE');
}
}