@@ -6,6 +6,12 @@ import { CyCanvas, Particle, EnGraphNodeType, Particles, IntGraphMetrics } from
66import humanFormat from 'human-format' ;
77import 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+
915export 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 ( ) ;
0 commit comments