Feat/line graph smoothing - #1312
Merged
Merged
Conversation
Adds a litmus example demonstrating how smooth line rendering overshoots the actual data range on steep slopes (steps, spikes, zeros, uneven x spacing), making values appear incorrect. Dashed MarkerLines mark the data min/max so any curve crossing them is an overshoot artifact.
Adds monotone cubic interpolation (Fritsch-Carlson, same algorithm
as d3 curveMonotoneX) as an alternative smoothing mode. Unlike the
default bezier smoothing, the monotone curve never overshoots the
vertical range of the data, so flat segments stay flat and steep
transitions cannot produce phantom values.
smooth={true} keeps the existing bezier behavior and smoothingRatio
continues to apply to it; smooth=monotone ignores the ratio.
Works for both line and area rendering.
The smoothing-overshoot litmus now renders two identical charts
side by side with a smoothing mode selector on each for direct
comparison.
Keep monotone cubic interpolation as the only smoothing algorithm on LineGraph - smooth=true now renders monotone curves that never overshoot the vertical range of the data. Remove the bezier-based smoothing code and deprecate smoothingRatio, which is now ignored since monotone interpolation has no configurable curvature. Update the litmus examples and homedocs accordingly.
Collaborator
Author
Proposed changelog & breaking-changes entriesSince
## cx\@26.8.0
**Breaking Changes**
- `LineGraph` smooth line rendering now uses monotone cubic interpolation instead of cubic Bézier curves. The smoothed curve never overshoots the vertical range of the data, so graphs no longer suggest values that don't exist — most noticeable around spikes and steep slopes next to flat segments. Existing charts using `smooth` will render slightly differently ([#1312](https://github.com/codaxy/cxjs/pull/1312))
- `smoothingRatio` on `LineGraph` is deprecated and ignored — monotone interpolation has no configurable curvature. It is safe to remove it from existing code. See [Breaking Changes](/docs/intro/breaking-changes#2680---linegraph-smoothing) for details
## 26.8.0 - LineGraph Smoothing
`LineGraph` smooth line rendering (`smooth={true}`) now uses monotone cubic interpolation instead of cubic Bézier curves.
### Why This Change?
Bézier-based smoothing overshoots the actual data range on steep slopes next to flat segments (steps, spikes, zeros),
making the graph suggest values that don't exist in the data — e.g. a smoothed line dipping below zero next to a spike.
Monotone cubic interpolation keeps the curve within the vertical bounds of the data, so smoothed charts remain truthful.
### What To Expect
- No code changes are required — `smooth` keeps working as before.
- Smoothed lines and areas render slightly differently: tighter around spikes and steep slopes, with no dips or bumps
beyond the actual data range.
- `smoothingRatio` is deprecated and ignored, as monotone interpolation has no configurable curvature.
It is safe to remove it from existing code. |
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.
LineGraph: monotone smoothing mode (
smooth="monotone")Bezier smoothing (
smooth={true}) overshoots the data range on steep slopes —curves dip below zero on non-negative series or bulge past the actual maximum,
making values appear that don't exist in the data.
This PR adds
smooth="monotone": monotone cubic interpolation (Fritsch–Carlson,same algorithm as d3's
curveMonotoneX). Tangents are clamped at local extrema,so the curve is guaranteed to stay within the vertical bounds of the data. Works
for both line and area rendering.
smooth={true}is unchanged;smoothingRatioapplies to bezier only.features/charts/line-graph/SmoothingOvershoot.js) compares bothmodes side by side on datasets engineered to trigger overshoot.
[dataMin, dataMax]on alllitmus datasets and edge cases (two-point spans, duplicate x).