Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

svg with viewBox attribute results in clipped image. #44

Merged
merged 2 commits into from
Sep 21, 2015

Conversation

cjb06776
Copy link
Contributor

@cjb06776 cjb06776 commented Sep 3, 2015

Fix clipped images when svg specifies a viewbox attribute, as reported in #43

Also includes fix for incorrect handling of width attribute when the value is percent that was suggested in #42

… percent (e.g. '100%')

Fix clipped images when svg specifies a viewbox attribute.
@exupero
Copy link
Owner

exupero commented Sep 3, 2015

  1. Would you create an HTML file with a simple example that reproduces this problem so we can verify future changes don't break it? index.html has several different scenarios, if that helps. Don't worry about integrating with index.html; that can be done later.
  2. It looks like you've only addressed width and not height.
  3. Currently, the fallback values of width (box.width, clone.style.width, etc.) are parsed to integers, but these changes parse only the clone's explicit width. I don't see any reason parsing to an int should be necessary. Can you confirm?

@exupero
Copy link
Owner

exupero commented Sep 3, 2015

Also, check the current index.html in a browser to make sure these changes don't cause any regressions compared to http://exupero.org/saveSvgAsPng/

@cjb06776
Copy link
Contributor Author

cjb06776 commented Sep 3, 2015

  1. I created a sample - viewboxtest.html. It is mostly self contained, but I wasn't able to completely reduce it to a trivial example (it uses d3 and an angular directive to create the svg, which is similar to how my app does things and how I was able to reproduce it). Example below of the problem occurring without and with the fix:
    image
  2. Yeah, you are right. I took your suggested snippet as is, and didn't look at it closer - expanded it to include height as well.
  3. The styles do appear to need parseInt still in my tests. box.[width | height] doesn't from my observations, but the getComputedStyle method I see does return things in the form of "123px" for example. I've corrected this.
  4. I checked index.html, and it looks like it is working as expected.

@exupero
Copy link
Owner

exupero commented Sep 15, 2015

Looks good. One last question: did you find that box.width and box.height are already integers?

@cjb06776
Copy link
Contributor Author

Looks good. One last question: did you find that box.width and box.height are already integers?

Yes.

exupero added a commit that referenced this pull request Sep 21, 2015
svg with viewBox attribute results in clipped image.
@exupero exupero merged commit fafe545 into exupero:gh-pages Sep 21, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants