socle

drop an other-chip that would read 0.0%

commit 307eaf9bb4288f1b499e4b7dda3d47b02bb0c008 · parent 86d336b148 · browse this tree
Ximianth, 2026-10-26 23:04:59 UTC

mdbase live showed it: a tail share too small to round visible produced a
legend chip claiming 0.0%, which is noise, not composition.
diff --git a/pages.go b/pages.go
index 55f32c2..9fc9775 100644
--- a/pages.go
+++ b/pages.go
@@ -166,7 +166,8 @@ type langSeg struct {
 
 // langSegments shapes language stats for the meter: the top languages by bytes,
 // with the tail -- and anything whose share rounds below a visible 0.1% -- folded
-// into one trailing "other" segment.  No classified bytes at all means no meter.
+// into one trailing "other" segment; an "other" that itself rounds invisible is
+// dropped rather than shown as a 0.0% chip.  No classified bytes means no meter.
 func langSegments(stats []langStat) []langSeg {
 	var total int64
 	for _, st := range stats {
@@ -187,8 +188,8 @@ func langSegments(stats []langStat) []langSeg {
 		}
 		segs = append(segs, langSeg{Name: st.name, Pct: pct(st.bytes), Color: enry.GetColor(st.name)})
 	}
-	if other > 0 {
-		segs = append(segs, langSeg{Name: "other", Pct: pct(other)})
+	if p := pct(other); other > 0 && p != "0.0" {
+		segs = append(segs, langSeg{Name: "other", Pct: p})
 	}
 	return segs
 }
diff --git a/pages_test.go b/pages_test.go
index 0993c5b..adc676a 100644
--- a/pages_test.go
+++ b/pages_test.go
@@ -120,9 +120,15 @@ func TestLangSegments(t *testing.T) {
 		}
 	})
 	t.Run("invisible shares fold into other", func(t *testing.T) {
+		segs := langSegments([]langStat{{"Go", 10000}, {"Ada", 4}, {"Zig", 3}})
+		if len(segs) != 2 || segs[1] != (langSeg{"other", "0.1", ""}) {
+			t.Fatalf("segments = %+v, want Go and a 0.1%% other", segs)
+		}
+	})
+	t.Run("an invisible other is dropped entirely", func(t *testing.T) {
 		segs := langSegments([]langStat{{"Go", 100000}, {"Rust", 10}})
-		if len(segs) != 2 || segs[1].Name != "other" {
-			t.Fatalf("segments = %+v, want Go and other", segs)
+		if len(segs) != 1 || segs[0].Name != "Go" {
+			t.Fatalf("segments = %+v, want Go alone: a chip reading 0.0%% is noise", segs)
 		}
 	})
 }