Commit 1864102

Eric Bower  ·  2026-05-10 21:30:49 -0400 EDT
parent 4e11911
feat(tui): analytics now displays device breakdown

You can see mobile vs desktop
1 files changed,  +29, -0
+29, -0
......@@ -257,6 +257,10 @@ func (m *AnalyticsPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
257257 rightSurf.AddChild(0, ah, urlSurf)
258258 ah += int(urlSurf.Size.Height)
259259
260+ deviceSurf, _ := m.devices(rightCtx, data.Intervals).Draw(rightCtx)
261+ rightSurf.AddChild(0, ah, deviceSurf)
262+ ah += int(deviceSurf.Size.Height)
263+
260264 surf, _ := m.visits(rightCtx, data.Intervals).Draw(rightCtx)
261265 rightSurf.AddChild(0, ah, surf)
262266
......@@ -327,6 +331,31 @@ func (m *AnalyticsPage) urls(ctx vxfw.DrawContext, urls []*db.VisitUrl, label st
327331 return rightPane
328332 }
329333
334+func (m *AnalyticsPage) devices(ctx vxfw.DrawContext, intervals []*db.VisitInterval) vxfw.Widget {
335+ mobile, desktop := 0, 0
336+ for _, visit := range intervals {
337+ mobile += visit.MobileVisitors
338+ desktop += visit.DesktopVisitors
339+ }
340+ total := mobile + desktop
341+ mobilePct := 0.0
342+ desktopPct := 0.0
343+ if total > 0 {
344+ mobilePct = float64(mobile) / float64(total) * 100
345+ desktopPct = float64(desktop) / float64(total) * 100
346+ }
347+ kv := []Kv{
348+ {Key: "mobile", Value: fmt.Sprintf("%d (%.1f%%)", mobile, mobilePct)},
349+ {Key: "desktop", Value: fmt.Sprintf("%d (%.1f%%)", desktop, desktopPct)},
350+ }
351+ wdgt := NewKv(kv)
352+ rightPane := NewBorder(wdgt)
353+ rightPane.Width = ctx.Max.Width
354+ rightPane.Label = "devices"
355+ m.focusBorder(rightPane)
356+ return rightPane
357+}
358+
330359 func (m *AnalyticsPage) visits(ctx vxfw.DrawContext, intervals []*db.VisitInterval) vxfw.Widget {
331360 kv := []Kv{}
332361 w := 0