Skip to content

feat(pulse): add a donut chart package - #42

Merged
ingvarch merged 1 commit into
mainfrom
feat/donut
Nov 9, 2026
Merged

ingvarch merged 1 commit into
mainfrom
feat/donut

Conversation

@ingvarch

@ingvarch ingvarch commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Description

Adds the package github.com/ingvarch/pulse/donut for dashboards that need the split of a whole at one moment, for example Kubernetes pods by phase, with the total in the middle. The line chart Model does not change, and the package imports only Lip Gloss.

  • donut.New(h, opts...) draws a ring h rows high and 2h columns wide; WithFrame(w, h, thickness, radius) draws a rectangular frame instead, with square or rounded corners. SetSections sets the sections, View draws, Legend prints ● Name Value entries on one line.
  • Sections go clockwise from 12 o'clock (the top center of a frame), in the order given. A frame is split by length along its middle line.
  • Each cell is split into square sub-pixels, and the shape and the section are decided per sub-pixel, so a ring needs no aspect correction.
  • Glyph sets: Braille (the default; works in nearly every terminal), Octants (Unicode 16 octants plus 26 older block characters, the smoothest edges, needs a terminal or font that has them), HalfBlocks. WithGlyphs and SetGlyphs choose one. There is no TERM detection.
  • A section with a non-zero value always gets a visible arc; the others shrink to make room. A section with value 0 (or a negative or non-finite value) is not drawn and stays in the legend.
  • In a cell where sections meet, two-color sets keep the two largest parts (the empty part counts as one), braille takes the section with the most dots. Colors come from the foreground of each section's style.
  • The center shows the total in bold and the label under it. The label is dropped when it does not fit in the hole, and both when the total does not fit. With a total of 0 the shape is drawn faint and the center shows 0.
  • View returns exactly h lines of equal width.
  • The octant table is built in code from the Unicode rule; its names were checked against UnicodeData.txt 16.0.0.
  • New guide docs/donut.md, screenshot assets/donut.png (Braille ring, HalfBlocks frame), demo examples/donut (pods by phase that change over time; g cycles glyph sets).

Open question from the issue, decided: the default glyph set is Braille, with no terminal detection.

Left for later: octants are covered by tests but not shown in a screenshot, because the screenshot font has no octant glyphs. The zero-value Model (without New) is not supported. A sum of values that overflows float64 shows +Inf.

Issues

Closes #14

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement / Refactoring

Checklist

  • I have read the CONTRIBUTING.md guide.
  • My code adheres to the project's code style and conventions (gofmt, go vet).
  • I have added tests that prove my fix is effective or that my feature works.
  • All existing and new tests pass (go test -race ./...) and everything builds (go build ./... and go -C examples build ./...).
  • I have updated any relevant documentation.

The new package donut draws the split of a whole at one moment: a ring,
or a rectangular frame, divided into sections clockwise from 12 o'clock,
with the total and a label in the middle and a one-line legend. Glyph
sets: Braille (the default), Octants and HalfBlocks. A non-zero section
always gets a visible arc. The line chart Model does not change.

Closes #14
@ingvarch ingvarch added the enhancement New feature or request label Nov 9, 2026
@ingvarch
ingvarch merged commit 958fd58 into main Nov 9, 2026
2 checks passed
@ingvarch
ingvarch deleted the feat/donut branch November 9, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: donut chart package

1 participant