Vega-lite: Displaced chart with extreme spline tension values

Created on 29 Nov 2019  Â·  6Comments  Â·  Source: vega/vega-lite

Not sure where this sits on the _bug <—> feature request_ spectrum, but I've logged it here as bug as it results in unexpected behaviour...

When interpolating a line using cardinal splines with extreme tension values outside [0, 1], the plot can be unexpectedly displaced. This is includes the entire plot area, and the data view rectangle relative to the title. The displacement can be beyond the visible path of the interpolated line, making it difficult to compose multiple views.

splineTension

While the schema suggests the tension value should be between 0 and 1, there are definitely cases where values outside this range are useful (e.g. this example, but even setting tension to -1 is useful for creating rounded shapes:

Screen Shot 2019-11-29 at 13 39 48

Setting "clip" : true helpfully clips the view to the rectangle defined by the axes, but it would be more useful if the unclipped area was that of the larger of this rectangle and the minimum enclosing rectangle the interpolated line path. I would also propose that the [0, 1] tension range be removed from the schema given legitimate uses of values beyond this range.

Minimum working example:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "width": 300,
  "height": 300,
  "title": { "text": "Overshooting splines"},
  "background": "papayawhip",
  "data": {
    "values": [
      { "x": 20, "y": 10},
      { "x": 30, "y": 30},
      { "x": 50, "y": 10}
    ]
  },
  "encoding": {
    "x": { "field": "x", "type": "quantitative"},
    "y": { "field": "y", "type": "quantitative"}
  },
  "mark": {
    "type": "line",
    "tension": -7,
    "clip": false,
    "interpolate": "cardinal-closed",
    "point": { "stroke": "black"}
  }
}
Bug

All 6 comments

The displacement you're seeing here stems from the naive bounds calculation that vega-scenegraph uses for bezier curves: we simply include all control points.

If we can identify a more accurate -- but computationally cheap -- method, then the extreme displacement could be avoided and hopefully no clipping is necessary.

Thanks Jeff.

De Casteljau's algorthm looks promising, although I don't know in practice how 'computationally cheap' you need it to be.

I'm looking into it. I think we can directly solve for extrema (set the derivative of the Bezier equations to zero) rather than use an iterative method.

Should we change the schema to allow tension values outside of [0,1]?

I tightened the bounds calculations in vega/vega#2213, will be included in Vega v5.9.0.

I don't see why the schema can't be more permissive.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcnuttandrew picture mcnuttandrew  Â·  3Comments

kanitw picture kanitw  Â·  3Comments

learnwithratnesh picture learnwithratnesh  Â·  4Comments

fuglede picture fuglede  Â·  4Comments

mcnuttandrew picture mcnuttandrew  Â·  3Comments