Skip to content

Commit 238f038

Browse files
authored
Merge pull request #335 from iteratec/feature/timeSeriesChartDetails
Optimization of the new time series chart (collected tasks)
2 parents aa29d97 + 4caa8d3 commit 238f038

File tree

16 files changed

+1051
-873
lines changed

16 files changed

+1051
-873
lines changed

frontend/src/app/enums/color-scheme.enum.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export enum COLOR_SCHEME {
1313
DARK_BLUE = '#751ec3', // dark blue
1414
RED = '#ff0000', // red
1515
BLACK = '#0d233a', // black
16-
YELLOW = '#ffdb00', // yellow
16+
YELLOW = '#ffdb00', // yellow
1717
HIGHCHARTS_YELLOW = '#ffdc08', // highcharts yellow
1818
HIGHCHARTS_PURPLE = '#492970', // highcharts purple
1919
HIGHCHARTS_LIGHT_BLUE = '#77a1e5', // highcharts light blue
2020
HIGHCHARTS_ORANGE = '#f28f43', // highcharts orange
2121
HIGHCHARTS_RED = '#910000', // highcharts red
2222
HIGHCHARTS_BLACK = '#0d233a', // highcharts black
2323
HIGHCHARTS_BLUE = '#2f7ed8', // highcharts blue
24-
HIGHCHARTS_GREEN = '#8bbc21' // highcharts green
24+
HIGHCHARTS_GREEN = '#8bbc21' // highcharts green
2525
}
2626

2727
export function getColorScheme(): string[] {

frontend/src/app/modules/shared/components/spinner/spinner.component.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@
3232
background: white;
3333
opacity: 0.5;
3434
z-index: 10;
35+
top: 0;
36+
left: 0;
3537
}

frontend/src/app/modules/time-series/components/time-series-line-chart/time-series-line-chart.component.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ osm-time-series-line-chart {
5252
font-size: 14px;
5353
fill: $color-text-light;
5454
}
55+
56+
.unit {
57+
text-anchor: middle;
58+
}
5559
}
5660

5761
.marker-line {
@@ -63,7 +67,6 @@ osm-time-series-line-chart {
6367
stroke-width: 2px;
6468
fill: white;
6569
}
66-
6770
}
6871
}
6972

frontend/src/app/modules/time-series/components/time-series-line-chart/time-series-line-chart.component.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import {
88
SimpleChanges,
99
ViewChild,
1010
ViewEncapsulation
11-
} from "@angular/core";
11+
} from '@angular/core';
1212

1313
import {EventResultData} from '../../models/event-result-data.model';
1414
import {LineChartService} from '../../services/line-chart.service';
15-
import {NgxSmartModalService} from "ngx-smart-modal";
16-
import {SpinnerService} from "../../../shared/services/spinner.service";
15+
import {NgxSmartModalService} from 'ngx-smart-modal';
16+
import {SpinnerService} from '../../../shared/services/spinner.service';
1717

1818

1919
@Component({
@@ -27,7 +27,7 @@ export class TimeSeriesLineChartComponent implements AfterContentInit, OnChanges
2727
@Input()
2828
timeSeriesResults: EventResultData;
2929

30-
@ViewChild("svg")
30+
@ViewChild('svg')
3131
svgElement: ElementRef;
3232

3333
public ngxSmartModalService;
@@ -63,17 +63,16 @@ export class TimeSeriesLineChartComponent implements AfterContentInit, OnChanges
6363
}
6464

6565
redraw() {
66-
if(this.timeSeriesResults == null) {
67-
this.spinnerService.showSpinner("time-series-line-chart-spinner");
66+
if (this.timeSeriesResults == null) {
67+
this.spinnerService.showSpinner('time-series-line-chart-spinner');
6868
return;
6969
}
70-
71-
this.spinnerService.hideSpinner("time-series-line-chart-spinner");
70+
this.spinnerService.hideSpinner('time-series-line-chart-spinner');
7271

7372
this.lineChartService.drawLineChart(this.timeSeriesResults);
7473
}
7574

7675
handlePointSelectionError() {
77-
this.ngxSmartModalService.open("pointSelectionErrorModal");
76+
this.ngxSmartModalService.open('pointSelectionErrorModal');
7877
}
7978
}

frontend/src/app/modules/time-series/models/event-result-data.model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ import {EventResultSeriesDTO} from './event-result-series.model';
22
import {SummaryLabel} from "./summary-label.model";
33

44
export interface EventResultDataDTO {
5+
measurandGroups: any;
56
series: EventResultSeriesDTO[];
67
summaryLabels: SummaryLabel[];
8+
numberOfTimeSeries: number;
79
}
810

911
export class EventResultData implements EventResultDataDTO {
12+
measurandGroups: any;
1013
series: EventResultSeriesDTO[];
1114
summaryLabels: SummaryLabel[];
15+
numberOfTimeSeries: number;
1216

1317
constructor() {
18+
this.measurandGroups = {};
1419
this.series = [];
1520
this.summaryLabels = [];
21+
this.numberOfTimeSeries = 0;
1622
}
1723
}

frontend/src/app/modules/time-series/models/time-series-point.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {WptInfo} from "./wpt-info.model";
66
export class TimeSeriesPoint {
77
date: Date;
88
value: number;
9+
agent: string;
910
tooltipText: string;
1011
wptInfo: WptInfo;
1112

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,95 @@
1-
import { Injectable } from '@angular/core';
2-
import {TimeSeries} from "../models/time-series.model";
1+
import {Injectable} from '@angular/core';
2+
import {TimeSeries} from '../models/time-series.model';
33
import {
44
scaleLinear as d3ScaleLinear,
55
ScaleLinear as D3ScaleLinear,
66
scaleTime as d3ScaleTime,
77
ScaleTime as D3ScaleTime
8-
} from "d3-scale";
9-
import {TimeSeriesPoint} from "../models/time-series-point.model";
10-
import {max as d3Max, min as d3Min} from "d3-array";
8+
} from 'd3-scale';
9+
import {TimeSeriesPoint} from '../models/time-series-point.model';
10+
import {max as d3Max, min as d3Min} from 'd3-array';
1111

1212
@Injectable({
1313
providedIn: 'root'
1414
})
1515
export class LineChartScaleService {
1616

17-
constructor() { }
18-
19-
private getDate(data: TimeSeries[], f: Function): Date {
20-
return f(data, (dataItem: TimeSeries) => {
21-
return f(dataItem.values, (point: TimeSeriesPoint) => {
22-
return point.date;
23-
});
24-
});
25-
};
17+
constructor() {
18+
}
2619

27-
public getMinDate(data: TimeSeries[]): Date {
20+
public getMinDate(data: TimeSeries[][]): Date {
2821
return this.getDate(data, d3Min);
29-
};
30-
31-
public getMaxDate(data: TimeSeries[]): Date {
32-
return this.getDate(data, d3Max);
33-
};
34-
35-
private getMaxValue(data: TimeSeries[]): number {
36-
return d3Max(data, (dataItem: TimeSeries) => {
37-
return d3Max(dataItem.values, (point: TimeSeriesPoint) => {
38-
return point.value;
39-
});
40-
});
4122
}
4223

43-
private getMaxValueInTime(data: TimeSeries[], minDate: Date, maxDate: Date): number {
44-
return d3Max(data, (dataSeries: TimeSeries) => {
45-
const valuesInRange = dataSeries.values.filter(value => value.date <= maxDate && value.date >= minDate);
46-
return d3Max(valuesInRange, (point: TimeSeriesPoint) => {
47-
return point.value;
48-
});
49-
});
24+
public getMaxDate(data: TimeSeries[][]): Date {
25+
return this.getDate(data, d3Max);
5026
}
5127

5228
/**
5329
* Determine the xScale for the given data
5430
*/
55-
public getXScale(data: TimeSeries[], width: number): D3ScaleTime<number, number> {
31+
public getXScale(data: TimeSeries[][], width: number): D3ScaleTime<number, number> {
5632
return d3ScaleTime() // Define a scale for the X-Axis
5733
.range([0, width]) // Display the X-Axis over the complete width
5834
.domain([this.getMinDate(data), this.getMaxDate(data)]);
5935
}
6036

6137
/**
62-
* Determine the yScale for the given data
38+
* Determine the yScales for the given data
6339
*/
64-
public getYScale(data: TimeSeries[], height: number): D3ScaleLinear<number, number> {
65-
return d3ScaleLinear() // Linear scale for the numbers on the Y-Axis
66-
.range([height, 0]) // Display the Y-Axis over the complete height - origin is top left corner, so height comes first
67-
.domain([0, this.getMaxValue(data)])
68-
.nice();
40+
public getYScales(dataList: TimeSeries[][], height: number): D3ScaleLinear<number, number>[] {
41+
const yScales: D3ScaleLinear<number, number>[] = [];
42+
dataList.forEach((data: TimeSeries[]) => {
43+
const yScale: D3ScaleLinear<number, number> = d3ScaleLinear() // Linear scale for the numbers on the Y-Axis
44+
.range([height, 0]) // Display the Y-Axis over the complete height - origin is top left corner, so height comes first
45+
.domain([0, this.getMaxValue(data)])
46+
.nice();
47+
yScales.push(yScale);
48+
});
49+
50+
return yScales;
6951
}
7052

7153
/**
72-
* Determine the yScale for the given data in time range
54+
* Determine the yScales for the given data in time range
7355
*/
74-
public getYScaleInRange(data: TimeSeries[], minDate: Date, maxDate: Date, height: number): D3ScaleLinear<number, number> {
75-
return d3ScaleLinear() // Linear scale for the numbers on the Y-Axis
76-
.range([height, 0]) // Display the Y-Axis over the complete height - origin is top left corner, so height comes first
77-
.domain([0, this.getMaxValueInTime(data, minDate, maxDate)])
78-
.nice();
56+
public getYScalesInTimeRange(dataList: TimeSeries[][], minDate: Date, maxDate: Date, height: number): D3ScaleLinear<number, number>[] {
57+
const yScales: D3ScaleLinear<number, number>[] = [];
58+
dataList.forEach((data: TimeSeries[]) => {
59+
const yScale: D3ScaleLinear<number, number> = d3ScaleLinear() // Linear scale for the numbers on the Y-Axis
60+
.range([height, 0]) // Display the Y-Axis over the complete height - origin is top left corner, so height comes first
61+
.domain([0, this.getMaxValueInTime(data, minDate, maxDate)])
62+
.nice();
63+
yScales.push(yScale);
64+
});
65+
66+
return yScales;
67+
}
68+
69+
private getDate(dataList: TimeSeries[][], f: Function): Date {
70+
return f(dataList, (data: TimeSeries[]) => {
71+
return f(data, (dataItem: TimeSeries) => {
72+
return f(dataItem.values, (point: TimeSeriesPoint) => {
73+
return point.date;
74+
});
75+
});
76+
});
77+
}
78+
79+
private getMaxValue(data: TimeSeries[]): number {
80+
return d3Max(data, (dataItem: TimeSeries) => {
81+
return d3Max(dataItem.values, (point: TimeSeriesPoint) => {
82+
return point.value;
83+
});
84+
});
85+
}
86+
87+
private getMaxValueInTime(data: TimeSeries[], minDate: Date, maxDate: Date): number {
88+
return d3Max(data, (dataSeries: TimeSeries) => {
89+
const valuesInRange = dataSeries.values.filter(value => value.date <= maxDate && value.date >= minDate);
90+
return d3Max(valuesInRange, (point: TimeSeriesPoint) => {
91+
return point.value;
92+
});
93+
});
7994
}
8095
}

0 commit comments

Comments
 (0)