Skip to content

Commit

Permalink
SNRGY-2966 #Close
Browse files Browse the repository at this point in the history
  • Loading branch information
franzmueller committed Nov 15, 2023
1 parent d7ecb5c commit 7bf4723
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/app/widgets/charts/export/shared/charts-export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {Injectable} from '@angular/core';
import {forkJoin, Observable} from 'rxjs';
import {forkJoin, Observable, of} from 'rxjs';
import {ChartsModel} from '../../shared/charts.model';
import {ElementSizeService} from '../../../../core/services/element-size.service';
import {ErrorHandlerService} from '../../../../core/services/error-handler.service';
Expand All @@ -40,10 +40,8 @@ import {
QueriesRequestFilterModel,
QueriesRequestTimeModel,
} from '../../../shared/export-data.model';
import {map} from 'rxjs/operators';
import {catchError, map} from 'rxjs/operators';
import {environment} from '../../../../../environments/environment';
import { catchError } from 'rxjs/operators';
import { of } from 'rxjs';

const customColor = '#4484ce'; // /* cc */

Expand Down Expand Up @@ -152,7 +150,7 @@ export class ChartsExportService {
(newField as QueriesRequestElementInfluxModel).orderColumnIndex = 0;
newField.columns[0].name = vAxis.valuePath || vAxis.valueName || '';
if (filters.length > 0) {
filters.forEach(f => f.column = vAxis.valuePath || vAxis.valueName || '');
filters.forEach(f => f.column = vAxis.valuePath || vAxis.valueName || '');
newField.filters = filters;
}
timescaleElements.push(newField);
Expand Down Expand Up @@ -181,12 +179,12 @@ export class ChartsExportService {
let mapper: number[] = [];
res.forEach(r => {
switch (r.source) {
case 'influx':
mapper = influxResultMapper;
break;
case 'timescale':
mapper = timescaleResultMapper;
break;
case 'influx':
mapper = influxResultMapper;
break;
case 'timescale':
mapper = timescaleResultMapper;
break;
}
r.res.forEach((series, index) => {
series?.forEach(row => {
Expand All @@ -209,7 +207,7 @@ export class ChartsExportService {
});
return table.length === 0 ? null : table;
}), catchError(err => {
const error: ErrorModel = { error: err.message};
const error: ErrorModel = {error: err.message};
return of(error);
}));
}
Expand All @@ -231,9 +229,17 @@ export class ChartsExportService {
});
}

private setData(series: any[][], properties: WidgetPropertiesModels): { table: ChartDataTableModel; colors?: string[] } {
private setData(series: any[][], properties: WidgetPropertiesModels): {
table: ChartDataTableModel;
colors?: string[]
} {
const vAxes = properties.vAxes || [];
const indices: { index: number; conversions: { from: any; to: any }[]; conversionDefault?: number; type: string }[] = [];
const indices: {
index: number;
conversions: { from: any; to: any }[];
conversionDefault?: number;
type: string
}[] = [];
const header: string[] = ['time'];
if (vAxes) {
vAxes.forEach((vAxis: ChartsExportVAxesModel, index) => {
Expand All @@ -249,20 +255,20 @@ export class ChartsExportService {
});
}
const dataTable = new ChartDataTableModel([header]);

var series2: any = []
if(series[0].length > 2 && properties.chartType === 'ColumnChart') {
if (series[0].length > 2 && properties.chartType === 'ColumnChart') {
/* Grouped Column -> all values for on x tick value need to be in one list
series = [
["2023-07-18T00:00:00Z", 2.7930317029043543, 5, 3]
]
*/
var tmp: any = {}
series.forEach((item: any[]) => {
var date: string = item[0]
var date: string = item[0]
item.slice(1).forEach((element, index) => {
if(!!element) {
if(!tmp[date]) {
if (!!element) {
if (!tmp[date]) {
tmp[date] = []
}
tmp[date][index] = element
Expand Down Expand Up @@ -297,7 +303,7 @@ export class ChartsExportService {
});
dataTable.data.push(dataPoint);
});

if (properties.chartType === 'PieChart') {
if (properties.calculateIntervals !== true) {
const transposed: any[] = [['', '']];
Expand All @@ -317,7 +323,7 @@ export class ChartsExportService {
dataTable.data.push([r[1], val]);
}
});
return {table: dataTable, colors: res.colors.slice(1)};
return {table: dataTable, colors: res.colors.slice(1)};
}
} else if (properties.chartType === 'Timeline') {
let breakInterval = -1;
Expand Down Expand Up @@ -431,7 +437,10 @@ export class ChartsExportService {
return array;
}

private transformTableForTimeline(dat: any[][], vAxes: ChartsExportVAxesModel[], breakInterval: number = -1, breakValue: number = 0, breakUnit: string = ''): {table: any[][]; colors: string[]} {
private transformTableForTimeline(dat: any[][], vAxes: ChartsExportVAxesModel[], breakInterval: number = -1, breakValue: number = 0, breakUnit: string = ''): {
table: any[][];
colors: string[]
} {
const allSlices: any[][] = [];
const offset = 60 * 1000 * (new Date(0).getTimezoneOffset());
const colors: string[] = [customColor];
Expand Down

0 comments on commit 7bf4723

Please sign in to comment.