@@ -375,14 +375,14 @@ func (i *StatsInspector) drawDashboard(cpu float64, mem uint64, limit uint64, rx
375375
376376 // 3. Network
377377 {
378- label := fmt .Sprintf ("Rx: %s/s Tx: %s/s" , daoCommon .FormatBytes (int64 (rx )), daoCommon .FormatBytes (int64 (tx )))
379- i .renderGraph (i .GraphNet , i .netRxHistory , label , asciigraph .Blue )
378+ label := fmt .Sprintf ("[green]●[-] Rx: %s/s [blue]●[-] Tx: %s/s" , daoCommon .FormatBytes (int64 (rx )), daoCommon .FormatBytes (int64 (tx )))
379+ i .renderGraphMany (i .GraphNet , [][] float64 { i .netRxHistory , i . netTxHistory }, label , [] asciigraph.AnsiColor { asciigraph . Green , asciigraph . Blue } )
380380 }
381381
382382 // 4. Disk
383383 {
384- label := fmt .Sprintf ("Read: %s/s Write: %s/s" , daoCommon .FormatBytes (int64 (dread )), daoCommon .FormatBytes (int64 (dwrite )))
385- i .renderGraph (i .GraphDisk , i . diskWriteHistory , label , asciigraph .Red )
384+ label := fmt .Sprintf ("[green]●[-] Read: %s/s [red]●[-] Write: %s/s" , daoCommon .FormatBytes (int64 (dread )), daoCommon .FormatBytes (int64 (dwrite )))
385+ i .renderGraphMany (i .GraphDisk , [][] float64 { i . diskReadHistory , i . diskWriteHistory } , label , [] asciigraph.AnsiColor { asciigraph . Green , asciigraph . Red } )
386386 }
387387}
388388
@@ -419,3 +419,48 @@ func (i *StatsInspector) renderGraph(tv *tview.TextView, data []float64, label s
419419 // TranslateANSI converts the color codes from asciigraph
420420 tv .SetText (tview .TranslateANSI (plot ))
421421}
422+
423+ func (i * StatsInspector ) renderGraphMany (tv * tview.TextView , data [][]float64 , label string , colors []asciigraph.AnsiColor ) {
424+ _ , _ , w , h := tv .GetInnerRect ()
425+
426+ // Asciigraph needs explicit resizing
427+ // Height must be >= 1. Width must be positive.
428+
429+ // Accounting for label text lines
430+ graphHeight := h - 2
431+ if graphHeight < 1 {
432+ graphHeight = 1
433+ }
434+
435+ graphWidth := w - 8 // Reserve space for axis labels (approx)
436+ if graphWidth < 10 {
437+ graphWidth = 10
438+ }
439+
440+ if len (data ) == 0 {
441+ return
442+ }
443+
444+ hasData := false
445+ for _ , series := range data {
446+ if len (series ) > 0 {
447+ hasData = true
448+ break
449+ }
450+ }
451+ if ! hasData {
452+ return
453+ }
454+
455+ plot := asciigraph .PlotMany (data ,
456+ asciigraph .Height (graphHeight ),
457+ asciigraph .Width (graphWidth ),
458+ asciigraph .SeriesColors (colors ... ),
459+ asciigraph .Caption (label ),
460+ )
461+
462+ // Reset bg to opaque before drawing
463+ tv .SetText ("" )
464+ // TranslateANSI converts the color codes from asciigraph
465+ tv .SetText (tview .TranslateANSI (plot ))
466+ }
0 commit comments