Inconsistent gradient output between SVG and Canvas renderer for bar
See original GitHub issueTake 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:
But the canvas renderer (and exporting to a PNG) looks like:
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:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.I agree that non-axis-aligned gradients will generally be rare, so I think this can be put on ice.