Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

SVG background image does not render in IE #795

Closed
i2shar opened this issue Jan 12, 2015 · 12 comments
Closed

SVG background image does not render in IE #795

i2shar opened this issue Jan 12, 2015 · 12 comments
Labels
browser-bug A problem in the browser itself

Comments

@i2shar
Copy link

i2shar commented Jan 12, 2015

If a node has a SVG background image, it does not render in IE 11. A png does.
SVGs render fine in Chrome, Firefox and Safari.

Here's the plunker: http://plnkr.co/edit/wLuoon?p=preview

@maxkfranz
Copy link
Member

I suspect this is an issue with IE itself. It seems some SVGs work, others don't.

@maxkfranz maxkfranz added the browser-bug A problem in the browser itself label Jan 30, 2015
@i2shar
Copy link
Author

i2shar commented Feb 2, 2015

That may not be the case .. if you open the SVG directly in IE, it renders fine. Its only through cytoscape that it doesn't render as a background image. Do you have an example of an SVG that does work in IE?

@maxkfranz
Copy link
Member

Please note as noted in another, similar ticket that SVGs are rendered differently in the DOM than in canvas. Cytoscape.js can not change it if IE renders SVGs incorrectly in canvas.

You could try with a simple <canvas> with context.drawImage() to confirm whether IE can render your SVG in canvas. Ref : https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D.drawImage

I do not have access to IE, though I suspect the issue is on their side (especially since there is no issue in other browsers). And if so, it would probably make sense for us to file a bug with them.

@jstaehli
Copy link

Could you check this again please? For me this problem does not only exist in IE but also in Firefox (Chrome works). Normally I have no SVG problems in Firefox. Could this problem be related to Cytoscape.js?

@maxkfranz
Copy link
Member

I have confirmed it functioning correctly on Firefox:

screen shot 2015-03-23 at 15 49 29

You can try this yourself on the debug page with gnu.svg.

There is probably a problem with your SVG file. It could be it's invalid, it could be too large for the browser, etc. You'll have to investigate and see with your file.

@i2shar
Copy link
Author

i2shar commented Mar 23, 2015

I verified that this was indeed an IE bug (not surprised). I reported it here : https://connect.microsoft.com/IE/feedbackdetail/view/1161278/canvas-does-not-render-scaled-svg-image

If you are inclined, you can verify it here: http://plnkr.co/edit/kEMS7G?p=preview

For my case, both Chrome and Firefox (both on Mac) worked fine.

@jstaehli
Copy link

Thank you very much for your answer. You are right, the gnu.svg example works in Firefox. Strange... So I probably have to check my SVGs.

I tried your plnkr.co example. It works great in Chrome. However both Internet Explorer AND Firefox can't draw the second one on my PC... I am using Firefox 36.0.4 on Windows 7. If I click on Draw2 in Firefox the Console outputs "IndexSizeError: Index or size is negative or greater than the allowed amount" (script.js:17:0)

@i2shar
Copy link
Author

i2shar commented Mar 23, 2015

I tried the plunkr again on Firefox and it doesn't seem to be working. The issue is that clipping the image outside the bounds of the image size doesn't work in both FF and IE, whereas clipping the images inside or outside the bounds of the images size doesn't work in IE at all, but works in FF

Consider the drawImage() API (as used in the plunkr): https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage

ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);

Case 1: If sx=0 and sWidth <= dWidth
Works in FF, not in IE.

Case 2: If sx=0 and sWidth > dWidth
Does not work in FF and IE - throws IndexSizeError in FF.

Both cases work in Chrome.

So in the plunkr drawImage2() for Firefox,
ctx.drawImage(image, 0, 0, 40, 51, 0, 0, 41, 51); works but
ctx.drawImage(image, 0, 0, 42, 51, 0, 0, 41, 51); throws IndexSizeError.

I am wondering if cytoscape.js is scaling the image per Case 1 when rendering and if that is causing IE to not render the images at all.

@maxkfranz can you confirm?

@maxkfranz
Copy link
Member

Ref : https://github.com/cytoscape/cytoscape.js/blob/v2.3.11/src/extensions/renderer.canvas.drawing-images.js#L101

Example with gnu.svg:

screen shot 2015-03-24 at 9 14 03 am

No problem on the latest Firefox. If there's a problem, I don't think it's with Cy.js. Please investigate your SVG file.

@jstaehli
Copy link

Thanks. I think I found out what the problem with my SVGs is: They have no width and height attributes in the svg element. If I add something like
<svg ... height="1in" width="1in" ...>...</svg>
or
<svg ... height="1cm" width="1cm" ...>...</svg>
it works in Firefox! However with Percentages e.g.
<svg ... height="100%" width="100%" ...>...</svg>
it does not work anymore. Is this a Browser problem or a Cytoscape.js problem? (Again: Chrome has no problems with the missing width/height attributes)

@jstaehli
Copy link

By the way: I just found out that IE sometimes renders SVG in Cytoscape.js if you add
<meta http-equiv="X-UA-Compatible" content="IE=9">
to the header... (At least at my local example, not when trying this in jsbin.com) However I'm not sure if I want to have this line in my HTML :-)

@maxkfranz
Copy link
Member

You ought to specify pixels for SVG if you want it to render well in the browser. The size only matters as a relative viewport size for the inner elements. SVG is scalable vector graphics, after all...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser-bug A problem in the browser itself
Projects
None yet
Development

No branches or pull requests

3 participants