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
1@@ -257,6 +257,10 @@ func (m *AnalyticsPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
2 rightSurf.AddChild(0, ah, urlSurf)
3 ah += int(urlSurf.Size.Height)
4
5+ deviceSurf, _ := m.devices(rightCtx, data.Intervals).Draw(rightCtx)
6+ rightSurf.AddChild(0, ah, deviceSurf)
7+ ah += int(deviceSurf.Size.Height)
8+
9 surf, _ := m.visits(rightCtx, data.Intervals).Draw(rightCtx)
10 rightSurf.AddChild(0, ah, surf)
11
12@@ -327,6 +331,31 @@ func (m *AnalyticsPage) urls(ctx vxfw.DrawContext, urls []*db.VisitUrl, label st
13 return rightPane
14 }
15
16+func (m *AnalyticsPage) devices(ctx vxfw.DrawContext, intervals []*db.VisitInterval) vxfw.Widget {
17+ mobile, desktop := 0, 0
18+ for _, visit := range intervals {
19+ mobile += visit.MobileVisitors
20+ desktop += visit.DesktopVisitors
21+ }
22+ total := mobile + desktop
23+ mobilePct := 0.0
24+ desktopPct := 0.0
25+ if total > 0 {
26+ mobilePct = float64(mobile) / float64(total) * 100
27+ desktopPct = float64(desktop) / float64(total) * 100
28+ }
29+ kv := []Kv{
30+ {Key: "mobile", Value: fmt.Sprintf("%d (%.1f%%)", mobile, mobilePct)},
31+ {Key: "desktop", Value: fmt.Sprintf("%d (%.1f%%)", desktop, desktopPct)},
32+ }
33+ wdgt := NewKv(kv)
34+ rightPane := NewBorder(wdgt)
35+ rightPane.Width = ctx.Max.Width
36+ rightPane.Label = "devices"
37+ m.focusBorder(rightPane)
38+ return rightPane
39+}
40+
41 func (m *AnalyticsPage) visits(ctx vxfw.DrawContext, intervals []*db.VisitInterval) vxfw.Widget {
42 kv := []Kv{}
43 w := 0