From 02b82fcaf8b643755aaf9117a17c7b4c82205738 Mon Sep 17 00:00:00 2001 From: Gaurav Kumar Date: Wed, 29 Oct 2025 16:07:59 +0530 Subject: [PATCH] Update polar-chart.component.ts --- .../polar-chart/polar-chart.component.ts | 123 +++++++++++++++--- 1 file changed, 103 insertions(+), 20 deletions(-) diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/polar-chart/polar-chart.component.ts b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/polar-chart/polar-chart.component.ts index 0c01a8a..85800f6 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/polar-chart/polar-chart.component.ts +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/gadgets/polar-chart/polar-chart.component.ts @@ -511,7 +511,12 @@ export class PolarChartComponent implements OnInit, OnChanges { console.warn('Polar chart API returned null data. Check if the API endpoint is working correctly.'); this.noDataAvailable = true; this.polarAreaChartLabels = []; - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; // Reset flag after fetching this.isFetchingData = false; return; @@ -524,32 +529,54 @@ export class PolarChartComponent implements OnInit, OnChanges { this.noDataAvailable = data.chartLabels.length === 0; this.polarAreaChartLabels = data.chartLabels; if (data.chartData && data.chartData.length > 0) { - this.polarAreaChartData = data.chartData[0].data.map(value => { + // Convert the data to the expected format for polar area charts + const chartValues = data.chartData[0].data.map(value => { // Convert to number if it's not already return isNaN(Number(value)) ? 0 : Number(value); }); + // Assign data in the correct format (array of objects with data property) + this.polarAreaChartData = [ + { + data: chartValues, + label: data.chartData[0].label || 'Dataset 1' + } + ]; } else { - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; } - // Trigger change detection - this.polarAreaChartData = [...this.polarAreaChartData]; console.log('Updated polar chart with data:', { labels: this.polarAreaChartLabels, data: this.polarAreaChartData }); } else if (data && data.labels && data.data) { // Handle the original expected format as fallback this.noDataAvailable = data.labels.length === 0; this.polarAreaChartLabels = data.labels; - this.polarAreaChartData = data.data.map(value => { + // Convert the data to the expected format for polar area charts + const chartValues = data.data.map(value => { // Convert to number if it's not already return isNaN(Number(value)) ? 0 : Number(value); }); - // Trigger change detection - this.polarAreaChartData = [...this.polarAreaChartData]; + // Assign data in the correct format (array of objects with data property) + this.polarAreaChartData = [ + { + data: chartValues, + label: 'Dataset 1' + } + ]; console.log('Updated polar chart with legacy data format:', { labels: this.polarAreaChartLabels, data: this.polarAreaChartData }); } else { console.warn('Polar chart received data does not have expected structure', data); this.noDataAvailable = true; this.polarAreaChartLabels = []; - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; } // Reset flag after fetching this.isFetchingData = false; @@ -558,7 +585,12 @@ export class PolarChartComponent implements OnInit, OnChanges { console.error('Error fetching polar chart data:', error); this.noDataAvailable = true; this.polarAreaChartLabels = []; - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; // Reset flag after fetching this.isFetchingData = false; // Keep default data in case of error @@ -568,7 +600,12 @@ export class PolarChartComponent implements OnInit, OnChanges { console.log('Missing required data for polar chart:', { table: this.table, xAxis: this.xAxis, yAxis: this.yAxis, connection: this.connection }); this.noDataAvailable = true; this.polarAreaChartLabels = []; - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; // Reset flag after fetching this.isFetchingData = false; } @@ -598,7 +635,12 @@ export class PolarChartComponent implements OnInit, OnChanges { console.warn('Invalid drilldown layer index:', layerIndex); this.noDataAvailable = true; this.polarAreaChartLabels = []; - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; return; } } @@ -610,7 +652,12 @@ export class PolarChartComponent implements OnInit, OnChanges { console.warn('Missing drilldown configuration for level:', this.currentDrilldownLevel); this.noDataAvailable = true; this.polarAreaChartLabels = []; - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; return; } @@ -708,7 +755,12 @@ export class PolarChartComponent implements OnInit, OnChanges { console.warn('Drilldown API returned null data. Check if the API endpoint is working correctly.'); this.noDataAvailable = true; this.polarAreaChartLabels = []; - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; return; } @@ -718,12 +770,25 @@ export class PolarChartComponent implements OnInit, OnChanges { this.noDataAvailable = data.chartLabels.length === 0; this.polarAreaChartLabels = data.chartLabels; if (data.chartData && data.chartData.length > 0) { - this.polarAreaChartData = data.chartData[0].data.map(value => { + // Convert the data to the expected format for polar area charts + const chartValues = data.chartData[0].data.map(value => { // Convert to number if it's not already return isNaN(Number(value)) ? 0 : Number(value); }); + // Assign data in the correct format (array of objects with data property) + this.polarAreaChartData = [ + { + data: chartValues, + label: data.chartData[0].label || 'Dataset 1' + } + ]; } else { - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; } // Trigger change detection this.polarAreaChartData = [...this.polarAreaChartData]; @@ -732,10 +797,18 @@ export class PolarChartComponent implements OnInit, OnChanges { // Handle the original expected format as fallback this.noDataAvailable = data.labels.length === 0; this.polarAreaChartLabels = data.labels; - this.polarAreaChartData = data.data.map(value => { + // Convert the data to the expected format for polar area charts + const chartValues = data.data.map(value => { // Convert to number if it's not already return isNaN(Number(value)) ? 0 : Number(value); }); + // Assign data in the correct format (array of objects with data property) + this.polarAreaChartData = [ + { + data: chartValues, + label: 'Dataset 1' + } + ]; // Trigger change detection this.polarAreaChartData = [...this.polarAreaChartData]; console.log('Updated polar chart with drilldown legacy data format:', { labels: this.polarAreaChartLabels, data: this.polarAreaChartData }); @@ -743,14 +816,24 @@ export class PolarChartComponent implements OnInit, OnChanges { console.warn('Drilldown received data does not have expected structure', data); this.noDataAvailable = true; this.polarAreaChartLabels = []; - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; } }, (error) => { console.error('Error fetching drilldown data:', error); this.noDataAvailable = true; this.polarAreaChartLabels = []; - this.polarAreaChartData = []; + this.polarAreaChartData = [ + { + data: [], + label: 'Dataset 1' + } + ]; // Keep current data in case of error } ); @@ -906,4 +989,4 @@ export class PolarChartComponent implements OnInit, OnChanges { // Clean up document click handler this.removeDocumentClickHandler(); } -} \ No newline at end of file +} \ No newline at end of file