feat(tui): ntcharts latency line chart in inline detail panel
Replace block-element sparkline with ntcharts streamline chart in the inline detail panel. Renders a 4-row line chart with thin line style using the theme accent color. Auto-scales Y axis to latency range. Added github.com/NimbleMarkets/ntcharts v0.5.1 dependency (lipgloss v1 compatible). Min/Avg/Max stats rendered below the chart.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/NimbleMarkets/ntcharts/canvas/runes"
|
||||
"github.com/NimbleMarkets/ntcharts/linechart/streamlinechart"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
func (m Model) latencyChart(latencies []time.Duration, statuses []bool, width, height int) string {
|
||||
if len(latencies) == 0 || width < 10 || height < 3 {
|
||||
return ""
|
||||
}
|
||||
|
||||
lineStyle := lipgloss.NewStyle().Foreground(m.theme.Accent)
|
||||
slc := streamlinechart.New(width, height,
|
||||
streamlinechart.WithStyles(runes.ThinLineStyle, lineStyle),
|
||||
)
|
||||
|
||||
for i, l := range latencies {
|
||||
ms := float64(l.Milliseconds())
|
||||
if i < len(statuses) && !statuses[i] {
|
||||
ms = 0
|
||||
}
|
||||
slc.Push(ms)
|
||||
}
|
||||
slc.Draw()
|
||||
|
||||
return slc.View()
|
||||
}
|
||||
Reference in New Issue
Block a user