Feat/line graph smoothing#1312
Open
nebojsa-peric wants to merge 5 commits into
Open
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.
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).