Skip to content

feat(pulse): add a logarithmic Y scale with WithLogScale - #38

Merged
ingvarch merged 2 commits into
mainfrom
feat/log-scale
Nov 9, 2026
Merged

ingvarch merged 2 commits into
mainfrom
feat/log-scale

Conversation

@ingvarch

@ingvarch ingvarch commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Description

Adds a logarithmic Y scale for metrics that span orders of magnitude, such as latency, where a linear scale presses normal traffic against the bottom row.

  • WithLogScale, SetLogScale and LogScale(). Values map to rows by log10; values at or below zero are drawn as gaps. Push, Last, SeriesData and legends keep the real values.
  • Range fix-ups when drawing: a non-positive minimum becomes max / 10, both bounds non-positive give 1..10. Min() and Max() keep the stored range.
  • Ticks at the powers of ten, with 2x and 5x values when fewer than two powers fit, thinned to the chart height (scale.LogTicks). Auto range widens to whole decades (scale.LogRange).
  • Thresholds follow the same mapping; a threshold at or below zero draws nothing.
  • Zero baseline, symmetric range, inverted series, negative styles and zero-crossing fill are ignored on a log scale; the docs say so. The fill goes down to the bottom row.
  • Renderers get an unexported plot-space Chart (range 0..decades, values log10(v / lo)), so the Chart interface and the renderers do not change.
  • New section "Logarithmic Scale" in docs/axes-and-grid.md with the logscale screenshot.

Bugs found and fixed along the way:

  • SetSymmetric(true) after turning auto range off mirrored the range set before auto range, not the range last drawn.
  • On amd64, math.Log reads the exponent from the bits, so Log10 of a subnormal value is off by many decades. The decade search now corrects the guess in a loop (CI on Ubuntu caught it).

Left for later:

  • No Bubble Tea demo toggles the log scale.

Issues

Closes #10

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.

Values map to rows by log10; values at or below zero are gaps. Ticks go at
the powers of ten (scale.LogTicks), auto range widens to whole decades
(scale.LogRange), and thresholds follow the same mapping. Renderers get a
plot-space Chart, so neither the Chart interface nor the renderers change.

SetSymmetric after turning auto range off now mirrors the last drawn range
instead of the range set before auto range.

Closes #10
@ingvarch ingvarch added the enhancement New feature or request label Nov 9, 2026
math.Log on amd64 reads the exponent from the bits, so Log10 of a subnormal
value is off by many decades. decadeOf now corrects the guess in a loop.
@ingvarch
ingvarch merged commit 74e7d38 into main Nov 9, 2026
2 checks passed
@ingvarch
ingvarch deleted the feat/log-scale branch November 9, 2026 21:49
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: logarithmic Y scale

1 participant