question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent gradient output between SVG and Canvas renderer for bar

See original GitHub issue

Take the following gradient-filled rectangle spec (v5.9.1):

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "width": 200,
  "height": 200,
  "padding": 5,
  "marks": [
    {
      "type": "rect",
      "encode": {
        "enter": {
          "x": {"value": 0},
          "x2": {"value": 100},
          "y": {"value": 0},
          "y2": {"value": 400},
          "fill": {
            "value": {
              "gradient": "linear",
              "stops": [
                {"color": "red", "offset": 0},
                {"color": "white", "offset": 0.5},
                {"color": "blue", "offset": 1}
              ],
              "x1": 1,
              "x2": 0,
              "y1": 1,
              "y2": 0
            }
          }
        }
      }
    }
  ]
}

The SVG renderer looks like:

Screen Shot 2020-02-03 at 16 29 48

But the canvas renderer (and exporting to a PNG) looks like:

visualization-12

This is similar to the bug reported at https://github.com/vega/vega/issues/2052 – the only difference seems to be that this only affects non-equilateral marks.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jheercommented, Mar 2, 2020

After further thought I found a potential solution: for non-axis-aligned gradients, we can instead render the gradient into an offscreen canvas (for which we can apply whatever transforms we like) and use that to generate a CanvasPattern that serves as an item’s fill / stroke. This is more costly (especially for large images or when using many gradient-filled objects) but perhaps that is OK given that this is a rare use case.

0reactions
marcpruxcommented, Mar 1, 2020

I agree that non-axis-aligned gradients will generally be rare, so I think this can be put on ice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Why do canvas functions createRadialGradient ...
Why do canvas functions createRadialGradient & addStopColor render inconsistent gradients with respect to their SVG counterparts?
Read more >
A Deep Dive Into The Wonderful World Of SVG Displacement ...
In this article, Dirk Weber explains the SVG `feDisplacementMap` ... Add a second layer and add a top to bottom gradient from rgb...
Read more >
A Compendium of SVG Information - CSS-Tricks
A GUI tool from Brent Jackson on visualizing/creathing the path syntax. SVG Patterns. In SVG you can fill shapes with colors and gradients,...
Read more >
CANVAS - The HTML Shark
The difference between CANVAS and SVG · CANVAS, SVG · Dependent on resolution; Does not support event handlers; Poor rendering of text; The...
Read more >
SVG2 Requirements Input - SVG - W3C
maybe, Erik, How does this differ from the buffered-rendering property? ... The SVG Tiny 1.2 SVGPath API is similar to what the Canvas...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found