Skip to content

Commit a9b73ff

Browse files
committed
Add toggle to change timezone to UTC for Nakama Console graphs
1 parent 72eb462 commit a9b73ff

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

console/ui/src/app/status/status.component.html

+13-7
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,20 @@ <h6 class="mr-2 d-inline font-weight-bold">An error occurred: {{error}}</h6>
4141
</tbody>
4242
</table>
4343

44-
<form [formGroup]="rangeForm">
45-
<div class="row no-gutters justify-content-end">
46-
<div class="col-12 text-right">
47-
<span>View:</span>
44+
<div class="row no-gutters align-items-center justify-content-end col-12 text-right">
45+
<form [formGroup]="utcForm">
46+
<span>UTC:</span>
47+
<input type="checkbox" class="ml-1" id="isUTC" formControlName="isUTC" (change)=setIsUTC($event) value="true">
48+
</form>
49+
<form [formGroup]="rangeForm">
50+
<span class="ml-3">View:</span>
4851
<div class="btn-group" ngbDropdown role="group">
4952
<select formControlName="rangeMinutes" class="custom-select custom-select-sm ml-3" (change)=setRange($event)>
5053
<option *ngFor="let key of rangesKeys | sortNumbers" value="{{key}}">{{ranges[key]}}</option>
5154
</select>
5255
</div>
53-
</div>
54-
</div>
55-
</form>
56+
</form>
57+
</div>
5658

5759
<div class="row">
5860
<div class="col-6 d-inline-flex justify-content-between align-items-center">
@@ -78,6 +80,7 @@ <h6 class="mr-2 d-inline font-weight-bold">An error occurred: {{error}}</h6>
7880
[yAxis]="true"
7981
xAxisLabel="Time"
8082
yAxisLabel="Latency (ms)"
83+
[xAxisTickFormatting]="xAxisFormatFn"
8184
[yScaleMin]="0"
8285
[roundDomains]="true"
8386
[results]="latencyGraphData">
@@ -108,6 +111,7 @@ <h6 class="mr-2 d-inline font-weight-bold">An error occurred: {{error}}</h6>
108111
[yAxis]="true"
109112
xAxisLabel="Time"
110113
yAxisLabel="Request Count"
114+
[xAxisTickFormatting]="xAxisFormatFn"
111115
[yScaleMin]="0"
112116
[roundDomains]="true"
113117
[results]="rateGraphData">
@@ -151,6 +155,7 @@ <h6 class="mr-2 d-inline font-weight-bold">An error occurred: {{error}}</h6>
151155
[yAxis]="true"
152156
xAxisLabel="Time"
153157
yAxisLabel="Input (kb/s)"
158+
[xAxisTickFormatting]="xAxisFormatFn"
154159
[yScaleMin]="0"
155160
[roundDomains]="true"
156161
[results]="inputGraphData">
@@ -181,6 +186,7 @@ <h6 class="mr-2 d-inline font-weight-bold">An error occurred: {{error}}</h6>
181186
[yAxis]="true"
182187
xAxisLabel="Time"
183188
yAxisLabel="Output (kb/s)"
189+
[xAxisTickFormatting]="xAxisFormatFn"
184190
[yScaleMin]="0"
185191
[roundDomains]="true"
186192
[results]="outputGraphData">

console/ui/src/app/status/status.component.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class StatusComponent implements OnInit, OnDestroy {
3232
public latencyGraphData = [];
3333
public inputGraphData = [];
3434
public outputGraphData = [];
35+
public utcForm: UntypedFormGroup;
3536
public rangeForm: UntypedFormGroup;
3637
public readonly ranges = {
3738
1: 'last 1 minute',
@@ -42,7 +43,7 @@ export class StatusComponent implements OnInit, OnDestroy {
4243
};
4344
public rangesKeys = Object.keys(this.ranges).map(n => +n);
4445
public readonly colorScheme = {
45-
domain: ['#5AA454', '#E44D25', '#1e59cf', '#7aa3e5', '#a8385d', '#d0bd00']
46+
domain: ['#5AA454', '#E44D25', '#1e59cf', '#7aa3e5', '#a8385d', '#d0bd00'],
4647
};
4748
private readonly samples = 60; // Number of samples in the series
4849
private refreshTimer: Observable<number>;
@@ -55,6 +56,9 @@ export class StatusComponent implements OnInit, OnDestroy {
5556
) {}
5657

5758
ngOnInit(): void {
59+
this.utcForm = this.formBuilder.group({
60+
isUTC: false, // Default show in local timezone
61+
});
5862
this.rangeForm = this.formBuilder.group({
5963
rangeMinutes: [10], // Default range to 10 min window
6064
});
@@ -162,9 +166,19 @@ export class StatusComponent implements OnInit, OnDestroy {
162166

163167
public setRange(event): void {
164168
this.rangeForm.reset({rangeMinutes: +event.target.value});
169+
}
170+
171+
public setIsUTC(event): void {
172+
this.utcForm.reset({isUTC: event.target.checked});
165173
this.reset();
166174
}
167175

176+
private formatDateLocal = new Intl.DateTimeFormat(navigator.languages.slice(), { hour: "2-digit", minute: "2-digit" });
177+
private formatDateUTC = new Intl.DateTimeFormat(navigator.languages.slice(), { hour: "2-digit", minute: "2-digit", timeZone: "UTC" });
178+
179+
// Declared as fat arrow to avoid having to bind it in xAxisTickFormatting (see https://github.com/swimlane/ngx-charts/issues/261)
180+
xAxisFormatFn = (value) => this.utcForm?.value.isUTC ? this.formatDateUTC.format(value) : this.formatDateLocal.format(value);
181+
168182
private reset(): void {
169183
this.consoleService.getStatus('').subscribe(data => {
170184
this.initData(data.nodes.map(n => n.name));

0 commit comments

Comments
 (0)