From f426761c7f1107efc261531b686b9976b3a047db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87etin?= <69278826+cetincakiroglu@users.noreply.github.com> Date: Fri, 3 Jan 2025 00:57:49 +0300 Subject: [PATCH] Add Chartdoc --- src/views/uikit/chartdoc.ts | 311 ++++++++++++++++++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 src/views/uikit/chartdoc.ts diff --git a/src/views/uikit/chartdoc.ts b/src/views/uikit/chartdoc.ts new file mode 100644 index 0000000..fcc781c --- /dev/null +++ b/src/views/uikit/chartdoc.ts @@ -0,0 +1,311 @@ +import { Component } from '@angular/core'; +import { ChartModule } from 'primeng/chart'; +import { CommonModule } from '@angular/common'; +import { debounceTime, Subscription } from 'rxjs'; +import { LayoutService } from '@/src/app/layout/service/app.layout.service'; + +@Component({ + standalone:true, + imports: [ + CommonModule, + ChartModule + ], + template: `
+
+
+
Linear Chart
+ +
+ +
+
Pie Chart
+ +
+ +
+
Polar Area Chart
+ +
+
+
+
+
Bar Chart
+ +
+ +
+
Doughnut Chart
+ +
+ +
+
Radar Chart
+ +
+
+
+ `, +}) +export class ChartDoc { + + lineData: any; + + barData: any; + + pieData: any; + + polarData: any; + + radarData: any; + + lineOptions: any; + + barOptions: any; + + pieOptions: any; + + polarOptions: any; + + radarOptions: any; + + subscription: Subscription; + constructor(private layoutService: LayoutService) { + this.subscription = this.layoutService.configUpdate$ + .pipe(debounceTime(25)) + .subscribe((config) => { + this.initCharts(); + }); + } + + ngOnInit() { + this.initCharts(); + } + + initCharts() { + const documentStyle = getComputedStyle(document.documentElement); + const textColor = documentStyle.getPropertyValue('--text-color'); + const textColorSecondary = documentStyle.getPropertyValue('--text-color-secondary'); + const surfaceBorder = documentStyle.getPropertyValue('--surface-border'); + + this.barData = { + labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], + datasets: [ + { + label: 'My First dataset', + backgroundColor: documentStyle.getPropertyValue('--primary-500'), + borderColor: documentStyle.getPropertyValue('--primary-500'), + data: [65, 59, 80, 81, 56, 55, 40] + }, + { + label: 'My Second dataset', + backgroundColor: documentStyle.getPropertyValue('--primary-200'), + borderColor: documentStyle.getPropertyValue('--primary-200'), + data: [28, 48, 40, 19, 86, 27, 90] + } + ] + }; + + this.barOptions = { + plugins: { + legend: { + labels: { + fontColor: textColor + } + } + }, + scales: { + x: { + ticks: { + color: textColorSecondary, + font: { + weight: 500 + } + }, + grid: { + display: false, + drawBorder: false + } + }, + y: { + ticks: { + color: textColorSecondary + }, + grid: { + color: surfaceBorder, + drawBorder: false + } + }, + } + }; + + this.pieData = { + labels: ['A', 'B', 'C'], + datasets: [ + { + data: [540, 325, 702], + backgroundColor: [ + documentStyle.getPropertyValue('--indigo-500'), + documentStyle.getPropertyValue('--purple-500'), + documentStyle.getPropertyValue('--teal-500') + ], + hoverBackgroundColor: [ + documentStyle.getPropertyValue('--indigo-400'), + documentStyle.getPropertyValue('--purple-400'), + documentStyle.getPropertyValue('--teal-400') + ] + }] + }; + + this.pieOptions = { + plugins: { + legend: { + labels: { + usePointStyle: true, + color: textColor + } + } + } + }; + + this.lineData = { + labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], + datasets: [ + { + label: 'First Dataset', + data: [65, 59, 80, 81, 56, 55, 40], + fill: false, + backgroundColor: documentStyle.getPropertyValue('--primary-500'), + borderColor: documentStyle.getPropertyValue('--primary-500'), + tension: .4 + }, + { + label: 'Second Dataset', + data: [28, 48, 40, 19, 86, 27, 90], + fill: false, + backgroundColor: documentStyle.getPropertyValue('--primary-200'), + borderColor: documentStyle.getPropertyValue('--primary-200'), + tension: .4 + } + ] + }; + + this.lineOptions = { + plugins: { + legend: { + labels: { + fontColor: textColor + } + } + }, + scales: { + x: { + ticks: { + color: textColorSecondary + }, + grid: { + color: surfaceBorder, + drawBorder: false + } + }, + y: { + ticks: { + color: textColorSecondary + }, + grid: { + color: surfaceBorder, + drawBorder: false + } + }, + } + }; + + this.polarData = { + datasets: [{ + data: [ + 11, + 16, + 7, + 3 + ], + backgroundColor: [ + documentStyle.getPropertyValue('--indigo-500'), + documentStyle.getPropertyValue('--purple-500'), + documentStyle.getPropertyValue('--teal-500'), + documentStyle.getPropertyValue('--orange-500') + ], + label: 'My dataset' + }], + labels: [ + 'Indigo', + 'Purple', + 'Teal', + 'Orange' + ] + }; + + this.polarOptions = { + plugins: { + legend: { + labels: { + color: textColor + } + } + }, + scales: { + r: { + grid: { + color: surfaceBorder + } + } + } + }; + + this.radarData = { + labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'], + datasets: [ + { + label: 'My First dataset', + borderColor: documentStyle.getPropertyValue('--indigo-400'), + pointBackgroundColor: documentStyle.getPropertyValue('--indigo-400'), + pointBorderColor: documentStyle.getPropertyValue('--indigo-400'), + pointHoverBackgroundColor: textColor, + pointHoverBorderColor: documentStyle.getPropertyValue('--indigo-400'), + data: [65, 59, 90, 81, 56, 55, 40] + }, + { + label: 'My Second dataset', + borderColor: documentStyle.getPropertyValue('--purple-400'), + pointBackgroundColor: documentStyle.getPropertyValue('--purple-400'), + pointBorderColor: documentStyle.getPropertyValue('--purple-400'), + pointHoverBackgroundColor: textColor, + pointHoverBorderColor: documentStyle.getPropertyValue('--purple-400'), + data: [28, 48, 40, 19, 96, 27, 100] + } + ] + }; + + this.radarOptions = { + plugins: { + legend: { + labels: { + fontColor: textColor + } + } + }, + scales: { + r: { + grid: { + color: textColorSecondary + } + } + } + }; + } + + ngOnDestroy() { + if (this.subscription) { + this.subscription.unsubscribe(); + } + } + +}