Code Monkey home page Code Monkey logo

Comments (6)

wout avatar wout commented on May 18, 2024

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.

from svg.js.

mreq avatar mreq commented on May 18, 2024

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 }%"

from svg.js.

wout avatar wout commented on May 18, 2024

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

from svg.js.

mreq avatar mreq commented on May 18, 2024

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 ;)

from svg.js.

wout avatar wout commented on May 18, 2024

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

from svg.js.

achalddave avatar achalddave commented on May 18, 2024

Out of curiosity, what was this idea?

from svg.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.