scale, coord, render: axis breaks and folds, marked or not drawn - #53
Merged
Merged
Conversation
A linear or time axis can now leave intervals out. scale.Break and scale.TimeBreak take one interval out, for a chart where one value would flatten the rest. scale.Fold and scale.TimeFold take many out, for stretches the reader does not want to see, such as a machine's idle periods. figure.SpansWhere reads those periods out of a table. Map stays continuous. A value inside a cut maps across the gap and the panel's clip hides it, so Invert is exact and a bar across a break is still one bar with its middle missing. The gap is a device length that render sets through scale.Breaker. It is switched off under any coord that cannot mark a break, and on second axes, because a break without its mark lies about distances. Only Cartesian marks one: it cuts the clip into one rectangle per kept piece, splits axis and grid lines, and draws a slash or a zigzag over the data. A cut that reaches an end of the domain trims the axis. Ticks use one step for the length the axis still shows. Lookup is a binary search, so an axis with hundreds of folds allocates nothing per row (BenchmarkFolded1k/100k are in the allocation gate). The dialect spells cuts and folds as "cuts" and "folds". The accessible description names them. Charts without breaks draw exactly what they drew; every golden file and documentation figure is unchanged. See ADR 0083. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A linear or time axis can now leave intervals out, and the gap is always marked. See ADR 0083.
scale.Break(lo, hi)andscale.TimeBreak(from, to). Use one for a chart where a single outlier would flatten every other bar.scale.Fold(ivs...)andscale.TimeFold(spans...). Use them for many stretches the reader does not want to look at, such as a machine's idle periods. A fold leaves a narrow gap and gets a small slash, never a zigzag.figure.SpansWhere(tbl, "start", "end", "state", "Inaktiv")reads the folds out of a table.SpansFunc,IntervalsWhereandIntervalsFunccover other tests and numeric axes.AxisBreakGap,AxisBreakSize,AxisBreakMark,AxisFoldGapandAxisFoldSize, set throughtheme.AxisBreaksandtheme.AxisFolds.BreakSlash(//) is the default andBreakZigzagis the alternative."cuts"and"folds"."breaks"is already the colour scale's class boundaries.How it works
Mapstays continuous. A value inside a cut maps across the gap and the panel's clip hides it.Invertstays exact, and a bar across the break is still one bar with its middle missing.scale.Breaker. Under any coord other than Cartesian, and on second axes, render switches breaks off, because a break without its mark lies about distances.BenchmarkFolded1kandBenchmarkFolded100kboth come out at 102 allocs and are now in the allocation gate.What does not change
gallery -checkreports the documentation figures up to date.axis-break,axis-break-zigzagandmachine-folds.axis-break-slash,axis-break-zigzag,axis-break-timeandaxis-folds.Known cost
A broken chart's clip is several rectangles, so gg masks it instead of scissoring it. Only charts with a break pay this.
Test plan
go test ./...in the core and inbackend/gg, including the gallery tests-raceon scale, coord, render and the root package; a parallel facet with a break is byte-identical to the serial oneBenchmarkFolded1kagainstBenchmarkFolded100k🤖 Generated with Claude Code