curveCubicX?

Open
#118 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
d3, javascript

Research direction

Start by reviewing the linked original discussion in d3-interpolate#49 and the spline interpolation references in the issue. The proposal is to add a d3-shape curve that keeps Y a function of X, but the issue asks for ideas on deriving Bézier control points and does not identify files or tests. Done would mean implementing the curve and validating that it passes through the supplied points while keeping a single Y value for each X.

Written by the indexing model from the issue text.

Description

Issue was originally in d3-interpolate#49

I'm proposing the addition of a new type of curve for d3-shape — aptly called curveCubicX by @mbostock on the original thread — that treats the Y coordinate as a function of the X coordinate, such that for any X coordinate there's a single corresponding Y value.

In the image below, the proposed curveCubicX in comparison with curveNatural and curveBasis:

36937290-cffd7590-1f19-11e8-82ce-8ede07b6e619

(the cubic curve is generated with a cubic spline interpolator through small line segments joining 1000 samples of <x, f(x)>)

The algorithm for the interpolator is described on Wikipedia (also of note is its talk page, which makes it apparent that the page suffered various incarnations of the algorithm, of various readability levels).

There are also some demos and implementations of the algorithm:

However, these are all oriented towards finding the interpolator function, and any SVG paths are drawn with sampling the function, and I am severely out of my comfort zone in regards to obtaining the Bézier control points needed to draw the SVG path, so I'm hoping for some pointers or ideas on the matter...

As for the utility: I started with trying to recreate the Curves interface in Adobe Photoshop, which seems to be using such a cubic spline to interpolate the values. For data visualization, on the one hand it maintains Y being a function of X which makes sense in most types of charts, and the spline does pass through all the points, but on the other hand it tends to overshoot much more than other types of curves.

Dominant language
JavaScript
Stars
2.5k
Forks
307
Avg merge
4h 16m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from d3/d3-shape

All issues in d3/d3-shape

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.