feat(chart): add MONOTONE line interpolation via LineInterpolation enum#206
Merged
Conversation
Replace the boolean smooth flag on ChartSpec.Line with a LineInterpolation enum (LINEAR / SMOOTH / MONOTONE) — one explicit knob for line shape. The new MONOTONE mode emits a Fritsch-Carlson monotone cubic: as smooth as the Catmull-Rom SMOOTH curve but constrained to never overshoot, so the line stays within the value range of the points it spans. All modes render through the same native PDF curve operators with zero tessellation, so geometry stays deterministic and the layout hot path is unchanged.
…NE comparison The hero preview now shows the two volatile-price cards stacked: SMOOTH crests above the data's peak (overshoot) while MONOTONE stays within the value range — the accuracy difference the new interpolation mode adds.
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.
Why
Smooth (Catmull-Rom) line charts look good but can overshoot local extremes — on sharp value swings the curve briefly leaves the range of the data it connects, so it claims values the data never had. There was no smooth-yet-accurate option: straight segments are exact but angular, the smooth curve is pretty but inaccurate.
What changed
LineInterpolationenum (LINEAR/SMOOTH/MONOTONE) replaces the booleansmoothflag onChartSpec.Line— a single explicit knob for line shape.MONOTONEemits a Fritsch-Carlson monotone cubic inLineChartLayout: as smooth asSMOOTH, but each span is constrained to stay within the value range of its two endpoints, so the curve never overshoots and preserves the data's rises and falls.PathNodeper run, zero tessellation — so geometry stays deterministic and the layout hot path is unchanged.smooth(true)→interpolation(LineInterpolation.SMOOTH)). The chart API is unreleased (@since 1.8.0), so no deprecation bridge was needed.ChartShowcaseExamplegains a SMOOTH-vs-MONOTONE comparison on a volatile series; the committedassets/readme/examples/chart-showcase.pdfpreview is refreshed.Verification
./mvnw test -pl .→ 1365 tests, 0 failures.ChartLayoutResolverTest.monotoneCurveStaysWithinTheDataRangeWhileSmoothOvershoots— proves the monotone curve's bounding box stays inside the LINEAR data range (ground truth) while SMOOTH bulges past the plateau.monotoneLineEmitsOneNativeBezierRun+ layout snapshotcharts/line_monotone.