Skip to content

Feat/line graph smoothing - #1312

Merged
mstijak merged 7 commits into
masterfrom
feat/line-graph-smoothing
Jul 30, 2026
Merged

Feat/line graph smoothing#1312
mstijak merged 7 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.
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.
@nebojsa-peric

Copy link
Copy Markdown
Collaborator Author

Proposed changelog & breaking-changes entries

Since smooth now always renders monotone curves (bezier smoothing removed, smoothingRatio deprecated and ignored), this likely warrants a changelog entry with a breaking-changes note. Proposal below — the version number is a placeholder, adjust to whatever the release ends up being.

homedocs/src/pages/changelog.mdx:

## 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

homedocs/src/pages/docs/intro/breaking-changes.mdx (new section above 26.3.1):

## 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.

@mstijak
mstijak merged commit 1dd21be into master Jul 30, 2026
1 check passed
@mstijak
mstijak deleted the feat/line-graph-smoothing branch July 30, 2026 11:33
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.

2 participants