Skip to content

Commit ba90798

Browse files
author
mbrill-nt
committed
#59 Change unit type for data
1 parent 7bf8be9 commit ba90798

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

src/options/DefaultSettings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ export const DefaultSettings: PanelSettings = {
6666
],
6767

6868
drillDownLink: '',
69+
timeFormat: 'm',
6970
};

src/options/options.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,20 @@ export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>
187187
defaultValue: DefaultSettings.showBaselines,
188188
})
189189

190+
.addSelect({
191+
path: 'timeFormat',
192+
name: 'Maximum Time Unit to Resolve',
193+
description:
194+
'This setting controls to which time unit time values will be resolved to. ' +
195+
'Each value always includes the smaller units.',
196+
category: ['General Settings'],
197+
settings: {
198+
options: [{value: 'ms', label: 'ms' }, {value: 's', label: 's' }, {value: 'm', label: 'm' }],
199+
},
200+
defaultValue: DefaultSettings.timeFormat
201+
},
202+
)
203+
190204
//Appearance
191205
.addColorPicker({
192206
path: 'style.healthyColor',

src/panel/canvas/graph_canvas.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import { CyCanvas, Particle, EnGraphNodeType, Particles, IntGraphMetrics } from
66
import humanFormat from 'human-format';
77
import assetUtils from '../asset_utils';
88

9+
const scaleValues = [
10+
{unit: "ms", factor: 1},
11+
{unit: "s", factor: 1000},
12+
{unit: "m", factor: 60000}
13+
]
14+
915
export default class CanvasDrawer {
1016
readonly colors = {
1117
default: '#bad5ed',
@@ -71,14 +77,20 @@ export default class CanvasDrawer {
7177
this.offscreenCanvas = document.createElement('canvas');
7278
this.offscreenContext = this.offscreenCanvas.getContext('2d');
7379

74-
this.timeScale = new humanFormat.Scale({
75-
ms: 1,
76-
s: 1000,
77-
min: 60000,
78-
});
7980
this.repaint(true);
8081
}
8182

83+
_getTimeScale(timeUnit: any) {
84+
const scale: any = {}
85+
for(const scaleValue of scaleValues) {
86+
scale[scaleValue.unit] = scaleValue.factor;
87+
if(scaleValue.unit === timeUnit) {
88+
return scale;
89+
}
90+
}
91+
return scale;
92+
}
93+
8294
resetAssets() {
8395
this.imageAssets = {};
8496
}
@@ -312,6 +324,8 @@ export default class CanvasDrawer {
312324
}
313325

314326
_drawEdgeLabel(ctx: CanvasRenderingContext2D, edge: cytoscape.EdgeSingular) {
327+
const { timeFormat } = this.controller.getSettings();
328+
315329
const midpoint = edge.midpoint();
316330
const xMid = midpoint.x;
317331
const yMid = midpoint.y;
@@ -322,9 +336,11 @@ export default class CanvasDrawer {
322336
const requestCount = _.defaultTo(metrics.rate, -1);
323337
const errorCount = _.defaultTo(metrics.error_rate, -1);
324338

339+
const timeScale = new humanFormat.Scale(this._getTimeScale(timeFormat));
340+
325341
if (duration >= 0) {
326342
const decimals = duration >= 1000 ? 1 : 0;
327-
statistics.push(humanFormat(duration, { scale: this.timeScale, decimals }));
343+
statistics.push(humanFormat(duration, { scale: timeScale, decimals }));
328344
}
329345
if (requestCount >= 0) {
330346
const decimals = requestCount >= 1000 ? 1 : 0;
@@ -536,13 +552,16 @@ export default class CanvasDrawer {
536552
}
537553

538554
_drawNodeStatistics(ctx: CanvasRenderingContext2D, node: cytoscape.NodeSingular) {
555+
const { timeFormat } = this.controller.getSettings()
539556
const lines: string[] = [];
540557

541558
const metrics: IntGraphMetrics = node.data('metrics');
542559
const requestCount = _.defaultTo(metrics.rate, -1);
543560
const errorCount = _.defaultTo(metrics.error_rate, -1);
544561
const responseTime = _.defaultTo(metrics.response_time, -1);
545562

563+
const timeScale = new humanFormat.Scale(this._getTimeScale(timeFormat));
564+
546565
if (requestCount >= 0) {
547566
const decimals = requestCount >= 1000 ? 1 : 0;
548567
lines.push('Requests: ' + humanFormat(requestCount, { decimals }));
@@ -558,7 +577,7 @@ export default class CanvasDrawer {
558577
if (this.controller.getSettings().sumTimings.value) {
559578
labelText = 'Total Resp. Time: ';
560579
}
561-
lines.push(labelText + humanFormat(responseTime, { scale: this.timeScale, decimals }));
580+
lines.push(labelText + humanFormat(responseTime, { scale: timeScale, decimals }));
562581
}
563582

564583
const pos = node.position();

src/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface PanelSettings {
1010
dataMapping: DataMapping;
1111
drillDownLink: string;
1212
showBaselines: IntSwitch;
13+
timeFormat: string;
1314
}
1415

1516
export interface DataMapping {

0 commit comments

Comments
 (0)