From 50c3ce7497e0a7e67ea4823aa8ecf35517f4f27f Mon Sep 17 00:00:00 2001 From: Desy Ayurianti Date: Wed, 6 Nov 2024 09:28:54 +0700 Subject: [PATCH] fix: clean code --- .../pages/dashboard/page/graph/graph.component.html | 4 ++-- .../app/pages/dashboard/page/graph/graph.component.ts | 11 +++-------- .../page/historygraph/historygraph.component.html | 1 - .../page/historygraph/historygraph.component.ts | 1 - 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.html b/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.html index 31fe216..a1ef947 100644 --- a/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.html +++ b/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.html @@ -20,7 +20,7 @@
Sensor NPK 1
- @@ -39,7 +39,7 @@
Sensor NPK 2
- diff --git a/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.ts b/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.ts index 5cc5a37..3929da9 100644 --- a/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.ts +++ b/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.ts @@ -82,15 +82,12 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang this.updateCharts(); } - ngOnChanges(changes: SimpleChanges): void { - if (changes['interval'] && !changes['interval'].firstChange) { - this.selectedInterval = changes['interval'].currentValue; - this.updateCharts(); + if (changes['interval'] && changes['interval'].previousValue !== changes['interval'].currentValue) { + this.selectedInterval = changes['interval'].currentValue; } } - ngAfterViewInit(): void { this.onResize(); } @@ -157,7 +154,6 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang fetchNPK2Data(savedTimeRange: string): void { const startEnd = this.getDate(); - const timeRange = this.interval; this.sensorService.getSensorData('npk2', this.selectedNPK2, startEnd, savedTimeRange).subscribe({ next: (response) => { console.log(savedTimeRange); @@ -177,7 +173,7 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang } updateCharts(): void { - const interval = this.selectedInterval; + const interval = this.selectedInterval; Object.keys(this.charts).forEach(key => { if (this.charts[key]) { @@ -191,7 +187,6 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang this.fetchNPK2Data(interval); } - createChart(canvas: HTMLCanvasElement, response: ApiResponse, sensor: string, selectedOption: string): void { const ctx = canvas.getContext('2d'); diff --git a/agrilink_vocpro/src/app/pages/dashboard/page/historygraph/historygraph.component.html b/agrilink_vocpro/src/app/pages/dashboard/page/historygraph/historygraph.component.html index 05ad280..d6cec24 100644 --- a/agrilink_vocpro/src/app/pages/dashboard/page/historygraph/historygraph.component.html +++ b/agrilink_vocpro/src/app/pages/dashboard/page/historygraph/historygraph.component.html @@ -11,7 +11,6 @@
-
diff --git a/agrilink_vocpro/src/app/pages/dashboard/page/historygraph/historygraph.component.ts b/agrilink_vocpro/src/app/pages/dashboard/page/historygraph/historygraph.component.ts index ba07afd..0f2846b 100644 --- a/agrilink_vocpro/src/app/pages/dashboard/page/historygraph/historygraph.component.ts +++ b/agrilink_vocpro/src/app/pages/dashboard/page/historygraph/historygraph.component.ts @@ -42,7 +42,6 @@ export class HistorygraphComponent implements OnInit, OnDestroy { } }, 300); } - ngOnDestroy(): void { if (this.intervalId) {