Skip to content
This repository was archived by the owner on Mar 25, 2023. It is now read-only.

Commit 0bfe8a0

Browse files
author
Darya Baklanova
authored
feat(pulse): store parameters for pulse
store parameters for pulse in the LocalStorage
1 parent 07cfcc3 commit 0bfe8a0

File tree

7 files changed

+161
-58
lines changed

7 files changed

+161
-58
lines changed

src/app/pulse/charts/aggregation-selector.component.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import {
33
Component,
44
EventEmitter,
55
Input,
6-
OnChanges,
76
Output,
8-
SimpleChanges,
97
ViewChild,
108
ViewEncapsulation
119
} from '@angular/core';
@@ -17,24 +15,24 @@ import * as debounce from 'lodash/debounce';
1715
selector: 'cs-aggregation-selector',
1816
templateUrl: 'aggregation-selector.component.html',
1917
styles: [
18+
`
19+
.aggregation-select {
20+
margin: 30px 10px 20px;
21+
}
22+
23+
.shift-input {
24+
width: 55px;
25+
}
26+
27+
.shift-select {
28+
width: 100px;
29+
}
2030
`
21-
.aggregation-select {
22-
margin: 30px 10px 20px;
23-
}
24-
25-
.shift-input {
26-
width: 55px;
27-
}
28-
29-
.shift-select {
30-
width: 100px;
31-
}
32-
`
3331
],
3432
encapsulation: ViewEncapsulation.None,
3533
changeDetection: ChangeDetectionStrategy.OnPush
3634
})
37-
export class AggregationSelectorComponent implements OnChanges {
35+
export class AggregationSelectorComponent {
3836
@Input() permittedIntervals: any;
3937
@Output() scaleChange = new EventEmitter();
4038
@Output() aggregationsChange = new EventEmitter<MdOptionSelectionChange>();
@@ -52,17 +50,6 @@ export class AggregationSelectorComponent implements OnChanges {
5250
this.emitShiftChange = debounce(this.emitShiftChange, 300);
5351
}
5452

55-
public ngOnChanges(changes: SimpleChanges) {
56-
if ('permittedIntervals' in changes) {
57-
if (this.permittedIntervals) {
58-
setTimeout(() => {
59-
this.selectedShift = this.permittedIntervals.shifts[0];
60-
this.shiftChange.emit(this.selectedShift);
61-
});
62-
}
63-
}
64-
}
65-
6653
@Input()
6754
public get scale() {
6855
return this.selectedScale;

src/app/pulse/charts/pulse-chart.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,44 @@ export const defaultChartOptions = {
2626
maintainAspectRatio: false,
2727
layout: {
2828
padding: {
29-
left: 20,
30-
right: 10
29+
left: 80,
30+
right: 40
3131
}
3232
},
3333
tooltips: {
3434
intersect: false,
3535
mode: 'x'
3636
},
3737
scales: {
38-
xAxes: [{
39-
type: 'time',
40-
position: 'bottom',
41-
time: {
42-
tooltipFormat: 'llll',
43-
displayFormats: {
44-
second: 'LTS',
45-
minute: 'LT',
46-
hour: 'LT'
38+
xAxes: [
39+
{
40+
type: 'time',
41+
position: 'bottom',
42+
time: {
43+
tooltipFormat: 'llll',
44+
displayFormats: {
45+
second: 'LTS',
46+
minute: 'LT',
47+
hour: 'LT'
48+
}
4749
}
4850
}
49-
}],
50-
yAxes: [{
51-
ticks: { suggestedMin: 0 }
52-
}]
51+
],
52+
yAxes: [
53+
{
54+
ticks: {
55+
autoSkip: false,
56+
padding: 40,
57+
mirror: true,
58+
suggestedMin: 0,
59+
userCallback(val) {
60+
if (val % 1 === 0) {
61+
return val;
62+
}
63+
}
64+
}
65+
}
66+
]
5367
}
5468
};
5569

@@ -65,7 +79,7 @@ export const defaultChartConfig = {
6579
export function getChart(config: Array<any>) {
6680
return config.map(_ => {
6781
const options = Object.assign({}, defaultChartOptions, _.options);
68-
return Object.assign({}, defaultChartConfig, { ..._, options })
82+
return Object.assign({}, defaultChartConfig, { ..._, options });
6983
});
7084
}
7185

@@ -81,7 +95,8 @@ export abstract class PulseChartComponent {
8195
public loading = false;
8296
public error = false;
8397

84-
constructor(protected pulse: PulseService, protected cd: ChangeDetectorRef) {}
98+
constructor(protected pulse: PulseService, protected cd: ChangeDetectorRef) {
99+
}
85100

86101
protected setLoading(loading = true) {
87102
this.loading = loading;

src/app/pulse/charts/pulse-cpu-ram-chart/pulse-cpu-ram-chart.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export class PulseCpuRamChartComponent extends PulseChartComponent
1919
...defaultChartOptions.scales,
2020
yAxes: [{
2121
ticks: {
22+
padding: 40,
23+
mirror: true,
2224
suggestedMin: 0,
2325
suggestedMax: 100,
2426
userCallback(val) {
@@ -37,6 +39,8 @@ export class PulseCpuRamChartComponent extends PulseChartComponent
3739
...defaultChartOptions.scales,
3840
yAxes: [{
3941
ticks: {
42+
padding: 40,
43+
mirror: true,
4044
suggestedMin: 0,
4145
userCallback(val) {
4246
return humanReadableSize(val * 1024);

src/app/pulse/charts/pulse-disk-chart/pulse-disk-chart.component.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ export class PulseDiskChartComponent extends PulseChartComponent implements OnIn
4545
yAxes: [
4646
{
4747
ticks: {
48+
padding: 40,
49+
mirror: true,
4850
suggestedMin: 0,
4951
userCallback(val) {
50-
return `${humanReadableSize(val, true)}/s`;
52+
return !!humanReadableSize(val, true)
53+
? `${humanReadableSize(val, true)}/s`
54+
: null;
5155
}
5256
}
5357
}
@@ -133,10 +137,12 @@ export class PulseDiskChartComponent extends PulseChartComponent implements OnIn
133137
sets.iops.push(readIops, writeIops);
134138

135139

136-
this.charts[2].labels = res.map(_ => new Date(_.time)); // TODO
137140
const errors = {
138-
data: res.map(_ => +_.ioErrors),
139-
label: `${this.translations['PULSE.LABELS.DISK_IO_ERRORS']} ${aggregation}`
141+
data: res.map(_ => ({
142+
x: new Date(_.time),
143+
y: +_.ioErrors
144+
})),
145+
label: `${this.translations['DISK_IO_ERRORS']} ${aggregation}`
140146
};
141147
sets.errors.push(errors);
142148
});

src/app/pulse/charts/pulse-network-chart/pulse-network-chart.component.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ export class PulseNetworkChartComponent extends PulseChartComponent implements O
4545
yAxes: [
4646
{
4747
ticks: {
48+
mirror: true,
49+
padding: 40,
4850
suggestedMin: 0,
4951
userCallback(val) {
50-
return `${humanReadableSizeInBits(val)}/s`;
52+
return !!humanReadableSizeInBits(val)
53+
? `${humanReadableSizeInBits(val)}/s`
54+
: null;
5155
}
5256
}
5357
}
@@ -132,25 +136,35 @@ export class PulseNetworkChartComponent extends PulseChartComponent implements O
132136
sets.packets.push(readPackets, writePackets);
133137

134138
const readDrops = {
135-
data: res.map(_ => +_.readDrops),
139+
data: res.map(_ => ({
140+
x: new Date(_.time),
141+
y: +_.readDrops
142+
})),
136143
label: `${this.translations['PULSE.LABELS.NETWORK_READ_DROPS']} ${aggregation}`
137144
};
138145
const writeDrops = {
139-
data: res.map(_ => +_.writeDrops),
146+
data: res.map(_ => ({
147+
x: new Date(_.time),
148+
y: +_.writeDrops
149+
})),
140150
label: `${this.translations['PULSE.LABELS.NETWORK_WRITE_DROPS']} ${aggregation}`
141151
};
142-
this.charts[2].labels = res.map(_ => new Date(_.time));
143152
sets.drops.push(readDrops, writeDrops);
144153

145154
const readErrors = {
146-
data: res.map(_ => +_.readErrors),
155+
data: res.map(_ => ({
156+
x: new Date(_.time),
157+
y: +_.readErrors
158+
})),
147159
label: `${this.translations['PULSE.LABELS.NETWORK_READ_ERRORS']} ${aggregation}`
148160
};
149161
const writeErrors = {
150-
data: res.map(_ => +_.writeErrors),
162+
data: res.map(_ => ({
163+
x: new Date(_.time),
164+
y: +_.writeErrors,
165+
})),
151166
label: `${this.translations['PULSE.LABELS.NETWORK_WRITE_ERRORS']} ${aggregation}`
152167
};
153-
this.charts[3].labels = res.map(_ => new Date(_.time));
154168
sets.errors.push(readErrors, writeErrors);
155169
});
156170

src/app/pulse/unitsUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ function getSize(size: number, units: Array<string>, kB: number) {
1616
let u = 0;
1717

1818
if (Math.abs(size) < kB) {
19-
return `${size} ${units[u]}`;
19+
if (Math.abs(size) <= 1) {
20+
return (Math.abs(size) % 1 === 0) ? `${size.toFixed(0)} ${units[u]}` : null;
21+
}
22+
return `${size.toFixed(1)} ${units[u]}`;
2023
}
2124
do {
2225
size /= kB;

0 commit comments

Comments
 (0)