Files
psp_panel/src/components/dashboard/revenuestreamwidget.ts
T

110 lines
3.2 KiB
TypeScript
Raw Normal View History

2025-01-03 01:13:17 +03:00
import { Component } from '@angular/core';
import { ChartModule } from 'primeng/chart';
import { debounceTime, Subscription } from 'rxjs';
2025-01-03 12:53:23 +03:00
import { LayoutService } from '@/src/service/layout.service';
2025-01-03 01:13:17 +03:00
@Component({
standalone:true,
2025-01-03 11:53:59 +03:00
selector: 'app-revenue-stream-widget',
2025-01-03 01:13:17 +03:00
imports: [
ChartModule,
],
2025-01-06 12:25:17 +03:00
template: `<div class="card !mb-8">
2025-01-03 01:13:17 +03:00
<div class="font-semibold text-xl mb-4">Revenue Stream</div>
<p-chart type="bar" [data]="chartData" [options]="chartOptions" class="h-80" />
</div>`,
})
export class RevenueStreamWidget {
chartData: any;
chartOptions: any;
subscription!: Subscription;
constructor(public layoutService: LayoutService) {
this.subscription = this.layoutService.configUpdate$
.pipe(debounceTime(25))
2025-01-03 11:41:08 +03:00
.subscribe(() => {
2025-01-03 01:13:17 +03:00
this.initChart();
});
}
ngOnInit() {
this.initChart();
}
initChart() {
const documentStyle = getComputedStyle(document.documentElement);
2025-01-06 12:25:17 +03:00
const borderColor = documentStyle.getPropertyValue('--surface-border');
const textMutedColor = documentStyle.getPropertyValue('--text-color-secondary');
2025-01-03 01:13:17 +03:00
this.chartData = {
2025-01-06 12:25:17 +03:00
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
2025-01-03 01:13:17 +03:00
datasets: [
{
2025-01-06 12:25:17 +03:00
type: 'bar',
label: 'Subscriptions',
backgroundColor: documentStyle.getPropertyValue('--p-primary-400'),
data: [4000, 10000, 15000, 4000],
barThickness: 32
2025-01-03 01:13:17 +03:00
},
{
2025-01-06 12:25:17 +03:00
type: 'bar',
label: 'Advertising',
backgroundColor: documentStyle.getPropertyValue('--p-primary-300'),
data: [2100, 8400, 2400, 7500],
barThickness: 32
},
{
type: 'bar',
label: 'Affiliate',
backgroundColor: documentStyle.getPropertyValue('--p-primary-200'),
data: [4100, 5200, 3400, 7400],
borderRadius: {
topLeft: 8,
2025-01-06 14:28:01 +03:00
topRight: 8,
bottomLeft: 0,
bottomRight: 0
2025-01-06 12:25:17 +03:00
},
2025-01-06 14:28:01 +03:00
borderSkipped: false,
2025-01-06 12:25:17 +03:00
barThickness: 32
2025-01-03 01:13:17 +03:00
}
]
};
this.chartOptions = {
2025-01-06 12:25:17 +03:00
maintainAspectRatio: false,
aspectRatio: 0.8,
scales: {
x: {
stacked: true,
ticks: {
color: textMutedColor
},
grid: {
color: 'transparent',
borderColor: 'transparent'
2025-01-03 01:13:17 +03:00
}
},
2025-01-06 12:25:17 +03:00
y: {
stacked: true,
ticks: {
color: textMutedColor
2025-01-03 01:13:17 +03:00
},
2025-01-06 12:25:17 +03:00
grid: {
color: borderColor,
borderColor: 'transparent',
drawTicks: false
2025-01-03 01:13:17 +03:00
}
}
2025-01-06 12:25:17 +03:00
}
};
2025-01-03 01:13:17 +03:00
}
ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
}
}