Skip to content

Commit fea6a64

Browse files
shu-mutouSebastian Florek
andauthored
Hide area under zero in graph (#5000)
* Hide area under zero in graph Set yScaleMax not to show area under zero. * Update graph Co-authored-by: Sebastian Florek <[email protected]>
1 parent 8e4748d commit fea6a64

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/app/frontend/common/components/graph/component.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class GraphComponent implements OnInit, OnChanges {
3434
customColors = {};
3535
yAxisLabel = '';
3636
yAxisTickFormatting = (value: number) => `${value} ${this.yAxisSuffix_}`;
37+
yScaleMax = 0;
3738

3839
private suffixMap_: Map<number, string> = new Map<number, string>();
3940
private yAxisSuffix_ = '';
@@ -62,6 +63,7 @@ export class GraphComponent implements OnInit, OnChanges {
6263
let series: FormattedValue[];
6364
let highestSuffixPower = 0;
6465
let highestSuffix = '';
66+
let maxValue = 0;
6567

6668
switch (this.graphType) {
6769
case GraphType.Memory:
@@ -99,17 +101,35 @@ export class GraphComponent implements OnInit, OnChanges {
99101
} as DataPoint);
100102
});
101103

102-
return [
104+
const result = [
103105
{
104106
name: this.id,
105107
series: points.reduce(this._average.bind(this), []).map(point => {
108+
if (maxValue < point.y) {
109+
maxValue = point.y;
110+
}
111+
106112
return {
107113
value: point.y,
108114
name: timeFormat('%H:%M')(new Date(1000 * point.x)),
109115
};
110116
}),
111117
},
112118
];
119+
120+
// This way if max value is very small i.e. 0.0001 graph will be scaled to the more significant
121+
// value.
122+
switch (this.graphType) {
123+
case GraphType.CPU:
124+
this.yScaleMax = maxValue + 0.01;
125+
break;
126+
case GraphType.Memory:
127+
this.yScaleMax = maxValue + 10;
128+
break;
129+
default:
130+
}
131+
132+
return result;
113133
}
114134

115135
// Calculate the average usage based on minute intervals. If there are more data points within

src/app/frontend/common/components/graph/template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
[showYAxisLabel]="true"
2121
[yAxisLabel]="yAxisLabel"
2222
[yAxisTickFormatting]="yAxisTickFormatting"
23+
[yScaleMax]="yScaleMax"
2324
[results]="series"
2425
[showGridLines]="true"
2526
[curve]="curve"

0 commit comments

Comments
 (0)