Skip to content

Feat/line graph smoothing#1312

Open
nebojsa-peric wants to merge 5 commits into
masterfrom
feat/line-graph-smoothing
Open

Feat/line graph smoothing#1312
nebojsa-peric wants to merge 5 commits into
masterfrom
feat/line-graph-smoothing

Conversation

@nebojsa-peric

Copy link
Copy Markdown
Collaborator

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; smoothingRatio applies to bezier only.
  • New litmus (features/charts/line-graph/SmoothingOvershoot.js) compares both
    modes side by side on datasets engineered to trigger overshoot.
  • Verified numerically: sampled curves stay within [dataMin, dataMax] on all
    litmus datasets and edge cases (two-point spans, duplicate x).
image

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant