Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(svg): fix transparent color makes element not interactable in SSR and fix platform compatibility #15029

Closed
mindon opened this issue May 25, 2021 · 7 comments · Fixed by ecomfe/zrender#767
Labels
compatibility en This issue is in English SSR Server Side Rendering SVG
Milestone

Comments

@mindon
Copy link

mindon commented May 25, 2021

Version

v5.1.1

Reproduction link

https://uzihu.csb.app/

Steps to reproduce

  1. render with option
     const option = {
        grid: {
          show: true,
          borderWidth: 3,
          fill: "transparent",
          borderColor: "rgba(255,0,0,1)"
        },
        toolbox: {
          feature: {
            saveAsImage: {
              name: "demo",
              type: "svg"
            }
          }
        }
      };
  1. click save to image to download the svg result

  2. drag the svg file into Powerpoint or Inkscape

What is expected?

  1. transparent background

  2. red border

What is actually happening?

  1. black background

  2. black background grid without border


valid SVG11 colors https://www.w3.org/TR/SVG11/types.html#DataTypeColor

@echarts-bot
Copy link

echarts-bot bot commented May 25, 2021

Hi! We've received your issue and please be patient to get responded. 🎉
The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that it contains a minimum reproducible demo and necessary images to illustrate. Otherwise, our committers will ask you to do so.

A minimum reproducible demo should contain as little data and components as possible but can still illustrate your problem. This is the best way for us to reproduce it and solve the problem faster.

You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to dev@echarts.apache.org. Please attach the issue link if it's a technical question.

If you are interested in the project, you may also subscribe our mailing list.

Have a nice day! 🍵

@echarts-bot echarts-bot bot added bug en This issue is in English pending We are not sure about whether this is a bug/new feature. waiting-for: community labels May 25, 2021
@plainheart plainheart added compatibility SVG and removed bug pending We are not sure about whether this is a bug/new feature. waiting-for: community labels May 28, 2021
plainheart added a commit to ecomfe/zrender that referenced this issue May 28, 2021
1) fix apache/echarts#15023, rect path can't be closed.
2) fix apache/echarts#15029 normalize color when using SVG renderer to support more cases, for example, some tools/platforms can't recognize the alpha in color.
3) fix eslint error about `for-in`.
@pissang pissang added this to the 5.2.0 milestone May 29, 2021
@KamilKozera
Copy link

KamilKozera commented May 5, 2024

Hi,

I encountered identical problem today while converting SVG to PDF with Inkscape. Inkscape interprets fill:'transparent' as fill:'black'. Here's a quick solution that might help anyone facing the same issue:

Replace 'transparent' with 'none' after setting the chart option and rendering the chart. This ensures that the code executes after the SVG content has been generated and is present in the DOM, allowing it to modify the SVG attributes as desired.

jsfiddle

var transparentElements = document.querySelectorAll('svg [fill="transparent"]');
transparentElements.forEach(function(element) {
  element.setAttribute('fill', 'none');
});

@plainheart
Copy link
Member

plainheart commented May 8, 2024

@KamilKozera Thanks for your feedback. I believe this can work before v5.5.0 as ecomfe/zrender#767 fixed it. But in v5.5.0, to escape the behavior that fill: 'none' makes the SVG element not respond, the new SSR feature (see commit) overrides the none value to transparent, which brings this issue back unexpectedly. I will take a look if it can do the overriding conditionally.

cc: @Ovilia

TODOs:

  • standard color issue
  • potential text misplacement

@Ovilia
Copy link
Contributor

Ovilia commented Jun 28, 2024

@plainheart I have no objection to ecomfe/zrender#1076 but from the spec, we can see that transparent is a valid value for fill. Does this problem cause by the bug of SVG implementation of Powerpoint and Inkscape?

@Ovilia
Copy link
Contributor

Ovilia commented Jun 28, 2024

And from

A component must not be named ‘none’, because that would clash with the token for missing values.

we can know that the meaning of none is more like we don't know the color value for this element rather than this element doesn't have a color value.

So I think it should make sense to set transparent to elements without color.

That being said, if there is a bug with some implementation software, we could change as your PR to prevent exposing the bug.

@plainheart
Copy link
Member

plainheart commented Jun 28, 2024

  1. The change from 'transparent' to 'none' is to solve the compatibility issue in Powerpoint and Inkscape.
  2. 'none' makes the element not interactable, so you changed it back to 'transparent' in this commit.
  3. ecomfe/zrender#1076 is to solve both issues, we still use 'none' for no background while making the element interactable via setting the pointer-events attribute to 'visible'.

@Ovilia
Copy link
Contributor

Ovilia commented Jun 28, 2024

Thanks for clarifying the context, which I really got confused about. I've merged that PR. Thanks!

@Ovilia Ovilia closed this as completed Jun 28, 2024
@Ovilia Ovilia added the SSR Server Side Rendering label Jun 28, 2024
@Ovilia Ovilia changed the title invalid transparent and rgba colors in saved SVG file fix(svg): invalid transparent and rgba colors in exported SVG file Jun 28, 2024
@plainheart plainheart changed the title fix(svg): invalid transparent and rgba colors in exported SVG file fix(svg): fix none' color makes element not interactable and fix the compatibility Jul 18, 2024
@plainheart plainheart changed the title fix(svg): fix none' color makes element not interactable and fix the compatibility fix(svg): fix transparent color makes element not interactable and fix the compatibility Jul 18, 2024
@plainheart plainheart changed the title fix(svg): fix transparent color makes element not interactable and fix the compatibility fix(svg): fix transparent color makes element not interactable in SSR and fix platform compatibility Jul 18, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
compatibility en This issue is in English SSR Server Side Rendering SVG
Projects
None yet
5 participants