Skip to content

Commit 1936d9e

Browse files
devversionmmalerba
authored andcommitted
chore(dashboard): fix invalid curve for payload chart (#5609)
The dashboard payload size chart showed invalid curves for the Material and CDK package size. This happened because there were multiple different values for the same day (multiple PRs merged into master at the same day). Removing the duplicate values and only taking the last result of the day ensures that the curve is always correct and also makes the chart way better in performance.
1 parent be0c7a2 commit 1936d9e

File tree

8 files changed

+84
-21
lines changed

8 files changed

+84
-21
lines changed

tools/dashboard/package.json

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,33 @@
1010
},
1111
"private": true,
1212
"dependencies": {
13-
"@angular/animations": "^4.2.2",
13+
"@angular/animations": "^4.2.6",
1414
"@angular/cdk": "github:angular/cdk-builds",
15-
"@angular/common": "^4.2.2",
16-
"@angular/compiler": "^4.2.2",
17-
"@angular/core": "^4.2.2",
18-
"@angular/forms": "^4.2.2",
19-
"@angular/http": "^4.2.2",
15+
"@angular/common": "^4.2.6",
16+
"@angular/compiler": "^4.2.6",
17+
"@angular/core": "^4.2.6",
18+
"@angular/forms": "^4.2.6",
19+
"@angular/http": "^4.2.6",
2020
"@angular/material": "github:angular/material2-builds",
21-
"@angular/platform-browser": "^4.2.2",
22-
"@angular/platform-browser-dynamic": "^4.2.2",
23-
"@angular/router": "^4.2.2",
24-
"@swimlane/ngx-charts": "^5.3.1",
21+
"@angular/platform-browser": "^4.2.6",
22+
"@angular/platform-browser-dynamic": "^4.2.6",
23+
"@angular/router": "^4.2.6",
24+
"@swimlane/ngx-charts": "^6.0.0",
2525
"angularfire2": "^4.0.0-rc.1",
2626
"core-js": "^2.4.1",
2727
"d3": "^4.9.1",
28-
"firebase": "^4.1.2",
29-
"rxjs": "^5.1.0",
28+
"firebase": "^4.1.3",
29+
"rxjs": "^5.4.2",
3030
"zone.js": "^0.8.12"
3131
},
3232
"devDependencies": {
33-
"@angular/cli": "1.1.1",
34-
"@angular/compiler-cli": "^4.2.2",
35-
"@angular/language-service": "^4.2.2",
33+
"@angular/cli": "^1.2.0",
34+
"@angular/compiler-cli": "^4.2.6",
35+
"@angular/language-service": "^4.2.6",
3636
"@types/jasmine": "2.5.45",
3737
"@types/node": "~6.0.60",
3838
"firebase-tools": "^3.9.1",
3939
"ts-node": "~3.0.4",
40-
"tslint": "~5.3.2",
41-
"typescript": "~2.3.3"
40+
"typescript": "^2.4.1"
4241
}
4342
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
.dashboard-content {
2-
margin: 16px;
2+
padding: 16px;
3+
}
4+
5+
.payload-size-card {
6+
width: 100%;
7+
max-width: 700px;
38
}

tools/dashboard/src/app/dashboard-app.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
</md-toolbar>
44

55
<div class="dashboard-content">
6-
<payload-chart [data]="payloads | async" *ngIf="payloads | async"></payload-chart>
6+
<md-card class="payload-size-card">
7+
<md-card-title>Payload Size Chart</md-card-title>
8+
<md-card-content>
9+
<payload-chart [data]="payloads | async"></payload-chart>
10+
</md-card-content>
11+
</md-card>
712
</div>

tools/dashboard/src/app/dashboard-module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import {AngularFireDatabaseModule} from 'angularfire2/database';
44
import {NgModule} from '@angular/core';
55
import {DashboardApp} from './dashboard-app';
66
import {environment} from '../environments/environment';
7-
import {MdToolbarModule} from '@angular/material';
7+
import {MdCardModule, MdProgressSpinnerModule, MdToolbarModule} from '@angular/material';
88
import {NgxChartsModule} from '@swimlane/ngx-charts';
99
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
1010
import {PayloadChart} from './payload-chart/payload-chart';
1111

1212
@NgModule({
1313
exports: [
14-
MdToolbarModule
14+
MdCardModule,
15+
MdToolbarModule,
16+
MdProgressSpinnerModule
1517
]
1618
})
1719
export class DashboardMaterialModule {}

tools/dashboard/src/app/payload-chart/payload-chart.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<ngx-charts-line-chart
2+
*ngIf="chartData.length"
23
[scheme]="colorScheme"
34
[results]="chartData"
45
[gradient]="false"
@@ -12,3 +13,6 @@
1213
[yAxisLabel]="yAxisLabel"
1314
[autoScale]="true">
1415
</ngx-charts-line-chart>
16+
17+
<md-progress-spinner *ngIf="!chartData.length" class="payload-chart-loading" mode="indeterminate">
18+
</md-progress-spinner>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$payload-chart-loading-size: 50px;
2+
3+
:host {
4+
display: block;
5+
position: relative;
6+
7+
height: 400px;
8+
width: 100%;
9+
max-width: 700px;
10+
}
11+
12+
.payload-chart-loading {
13+
position: absolute;
14+
15+
top: calc(50% - #{$payload-chart-loading-size});
16+
left: calc(50% - #{$payload-chart-loading-size});
17+
18+
height: $payload-chart-loading-size;
19+
width: $payload-chart-loading-size;
20+
}

tools/dashboard/src/app/payload-chart/payload-chart.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {NgxChartItem, NgxChartResult} from './ngx-definitions';
55
@Component({
66
selector: 'payload-chart',
77
templateUrl: './payload-chart.html',
8+
styleUrls: ['./payload-chart.scss'],
89
changeDetection: ChangeDetectionStrategy.OnPush
910
})
1011
export class PayloadChart {
@@ -29,6 +30,26 @@ export class PayloadChart {
2930
this.chartData = this.createChartResults(value);
3031
}
3132

33+
/** Remove duplicate payload results for similar days. */
34+
private filterDuplicateDays(data: PayloadResult[]) {
35+
const filteredData = new Map<string, PayloadResult>();
36+
37+
data.forEach(result => {
38+
// Parse the timestamp from the payload results as a date.
39+
const date = new Date(result.timestamp);
40+
41+
// Ignore hours, minutes, seconds and milliseconds from the date to allow comparisons
42+
// only of the day.
43+
date.setHours(0, 0, 0, 0);
44+
45+
// Store the ISO string of the date in a Map to overwrite the previous payload result for
46+
// the same day.
47+
filteredData.set(date.toISOString(), result);
48+
});
49+
50+
return Array.from(filteredData.values());
51+
}
52+
3253
/** Creates a list of ngx-chart results of the Payload results. */
3354
private createChartResults(data: PayloadResult[]) {
3455
if (!data) {
@@ -39,6 +60,11 @@ export class PayloadChart {
3960
// manually sort the results by their timestamp.
4061
data = data.sort((a, b) => a.timestamp < b.timestamp ? -1 : 1);
4162

63+
// It can happen that there will be multiple payload results for the same day. This happens
64+
// when multiple Pull Requests are merged in the same day. For the charts we only want to
65+
// have the last payload result of a day (for performance and value correctness)
66+
data = this.filterDuplicateDays(data);
67+
4268
const materialChartItems: NgxChartItem[] = [];
4369
const cdkChartItems: NgxChartItem[] = [];
4470

tools/dashboard/src/theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ $dashboard-light-theme: mat-light-theme($dashboard-primary, $dashboard-accent);
88

99
// Only include the theme of the components that are used.
1010
@include mat-toolbar-theme($dashboard-light-theme);
11+
@include mat-progress-spinner-theme($dashboard-light-theme);
12+
@include mat-card-theme($dashboard-light-theme);

0 commit comments

Comments
 (0)