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

Can't .center() to percent values #60

Closed
mreq opened this issue Jul 16, 2013 · 6 comments
Closed

Can't .center() to percent values #60

mreq opened this issue Jul 16, 2013 · 6 comments
Labels

Comments

@mreq
Copy link

mreq commented Jul 16, 2013

Minimal (not) working example: http://jsfiddle.net/mreq/LP7sa/

Error: Invalid value for <rect> attribute x="NaN"
Error: Invalid value for <rect> attribute y="NaN"

There's a few more %-related issues (am working on a responsive app, where everything is in given relative). I'll try to pinpoint all of them.

@wout
Copy link
Member

wout commented Jul 16, 2013

That is not possible indeed. You can only use % values with center on cicrle and ellipse elements, because they are natively moved by their centre. The opposite is true for move on circle and ellipse. You can't use % values there but you can with rect and image.

I have looked into implementing this but it is virtually impossible without adding 2k of code to the library. Because it would involve adding event listeners to the svg canvas so when it is resized the "fake" centered elements are moved accordingly.

@mreq
Copy link
Author

mreq commented Jul 16, 2013

Interesting, I thought a single condition could fix that. That's what I'm doing atm:

# TODO: won't have to do this once svg.js is fixed 
if @isEllipse
    @field.center '50%', '50%'
else
    x = 50 - @fieldWidth/2
    y = 50 - @fieldHeight/2
    @field.move "#{ x }%", "#{ y }%"

@wout
Copy link
Member

wout commented Jul 16, 2013

That's the easy part. But that if the svg canvas is resized? Or the nested svg...

@mreq
Copy link
Author

mreq commented Jul 16, 2013

You're right. A generic solution is not an easy one. I am indeed listening to a resize event and updating some sort of an aspect ratio. Closing this as WONTFIX. Might update the README maybe ;)

@mreq mreq closed this as completed Jul 16, 2013
@wout
Copy link
Member

wout commented Jul 16, 2013

I just came up with an idea to fix it without an event listener. I'll look into it this week.

@achalddave
Copy link

Out of curiosity, what was this idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants