Skip to content

Commit aa29d97

Browse files
authored
Merge pull request #330 from iteratec/bugfix/timeseriesLegendFix
Bugfix: Fixed zoom in time series chart. Bugfix: Fixed legend time series chart.
2 parents 79a597d + ca1a14a commit aa29d97

File tree

4 files changed

+562
-365
lines changed

4 files changed

+562
-365
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ osm-time-series-line-chart {
44
#time-series-line-chart-container {
55
position: relative;
66
width: 100%;
7+
8+
rect.overlay {
9+
cursor: default !important
10+
}
711
}
812

913
#marker-tooltip {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export class TimeSeriesLineChartComponent implements AfterContentInit, OnChanges
7070

7171
this.spinnerService.hideSpinner("time-series-line-chart-spinner");
7272

73-
this.lineChartService.setLegendData(this.timeSeriesResults);
7473
this.lineChartService.drawLineChart(this.timeSeriesResults);
7574
}
7675

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { Injectable } from '@angular/core';
2+
import {TimeSeries} from "../models/time-series.model";
3+
import {
4+
scaleLinear as d3ScaleLinear,
5+
ScaleLinear as D3ScaleLinear,
6+
scaleTime as d3ScaleTime,
7+
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";
11+
12+
@Injectable({
13+
providedIn: 'root'
14+
})
15+
export class LineChartScaleService {
16+
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+
};
26+
27+
public getMinDate(data: TimeSeries[]): Date {
28+
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+
});
41+
}
42+
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+
});
50+
}
51+
52+
/**
53+
* Determine the xScale for the given data
54+
*/
55+
public getXScale(data: TimeSeries[], width: number): D3ScaleTime<number, number> {
56+
return d3ScaleTime() // Define a scale for the X-Axis
57+
.range([0, width]) // Display the X-Axis over the complete width
58+
.domain([this.getMinDate(data), this.getMaxDate(data)]);
59+
}
60+
61+
/**
62+
* Determine the yScale for the given data
63+
*/
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();
69+
}
70+
71+
/**
72+
* Determine the yScale for the given data in time range
73+
*/
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();
79+
}
80+
}

0 commit comments

Comments
 (0)