From 944e51b756fa31a1370b3533af237c7ab6ab232b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87etin?= <69278826+cetincakiroglu@users.noreply.github.com> Date: Fri, 21 Jan 2022 09:41:16 +0300 Subject: [PATCH] fix dashboard chart darkmode --- .../dashboard/dashboard.component.html | 2 +- .../dashboard/dashboard.component.ts | 86 ++++++++++++++++++- 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/app/components/dashboard/dashboard.component.html b/src/app/components/dashboard/dashboard.component.html index 67a1b9b..357f1c4 100755 --- a/src/app/components/dashboard/dashboard.component.html +++ b/src/app/components/dashboard/dashboard.component.html @@ -174,7 +174,7 @@
Sales Overview
- +
diff --git a/src/app/components/dashboard/dashboard.component.ts b/src/app/components/dashboard/dashboard.component.ts index a25750a..595c62b 100755 --- a/src/app/components/dashboard/dashboard.component.ts +++ b/src/app/components/dashboard/dashboard.component.ts @@ -2,6 +2,9 @@ import { Component, OnInit } from '@angular/core'; import { MenuItem } from 'primeng/api'; import { Product } from '../../api/product'; import { ProductService } from '../../service/productservice'; +import { Subscription } from 'rxjs'; +import { ConfigService } from '../../service/app.config.service'; +import { AppConfig } from '../../api/appconfig'; @Component({ templateUrl: './dashboard.component.html', @@ -12,11 +15,22 @@ export class DashboardComponent implements OnInit { products: Product[]; - chartData:any; + chartData: any; - constructor(private productService: ProductService) {} + chartOptions: any; + + subscription: Subscription; + + config: AppConfig; + + constructor(private productService: ProductService, public configService: ConfigService) {} ngOnInit() { + this.config = this.configService.config; + this.subscription = this.configService.configUpdate$.subscribe(config => { + this.config = config; + this.updateChartOptions(); + }); this.productService.getProductsSmall().then(data => this.products = data); this.items = [ @@ -46,4 +60,72 @@ export class DashboardComponent implements OnInit { ] }; } + + updateChartOptions() { + if (this.config.dark) + this.applyDarkTheme(); + else + this.applyLightTheme(); + + } + + applyDarkTheme() { + this.chartOptions = { + plugins: { + legend: { + labels: { + color: '#ebedef' + } + } + }, + scales: { + x: { + ticks: { + color: '#ebedef' + }, + grid: { + color: 'rgba(160, 167, 181, .3)', + } + }, + y: { + ticks: { + color: '#ebedef' + }, + grid: { + color: 'rgba(160, 167, 181, .3)', + } + }, + } + }; + } + + applyLightTheme() { + this.chartOptions = { + plugins: { + legend: { + labels: { + color: '#495057' + } + } + }, + scales: { + x: { + ticks: { + color: '#495057' + }, + grid: { + color: '#ebedef', + } + }, + y: { + ticks: { + color: '#495057' + }, + grid: { + color: '#ebedef', + } + }, + } + }; + } }