vega icon indicating copy to clipboard operation
vega copied to clipboard

Vega gradient on SVG doesn't work with dynamic url

Open czhangsigmacomputing opened this issue 1 year ago • 0 comments

When using gradient color in vega with SVG renderer, vega will always add href() as base to gradient ref (related code is here).

This doesn't work for our application where we have click events on different elements and will update url href dynamically. The change of url will break the gradient ref.

For example, let's say my initial url is https://foo.com where I have a vega svg using gradient. The path in svg will be sth like <path fill="url(https://foo.com#gradient_0)">. Then if some click event update url be https://foo.com?bar=1, then the path url will be invalid and gradient cannot render correctly.

I have a codepen to reproduce this case: https://codepen.io/cheng_sigma/pen/rNEjLYO

Initial state: Screenshot 2024-07-29 at 11 42 50 AM

If you click the Click here to change url button to change url, then resize window to trigger a Vega re-render, the gradient will disappear: Screenshot 2024-07-29 at 11 43 55 AM

Here is a short video to show the case if it can be more clear:

https://github.com/user-attachments/assets/605deca3-641d-4bf8-aac5-927e60a092a5

czhangsigmacomputing avatar Jul 29 '24 18:07 czhangsigmacomputing