Giter VIP home page Giter VIP logo

Comments (5)

wout avatar wout commented on August 16, 2024

Yes this is expected. You should use the transfrom() method instead:

el.transform('matrix', '1,0,0,-1,0,0')

Transform values are numerically stored in order to be able to animate them. Or rather, not having to parse them over and over again. That is why all transformation should be applied through the transform() method.

The example above can also be achieved like this:

el.transform({ d: -1 })

As in matrix(a,b,c,d,e,f).

from svg.js.

sergi avatar sergi commented on August 16, 2024

Right. So if I want to apply a scaleY of -1 and then later move the element 100px to the right I should to something like:

el.transform({ d: -1 });
//Other stuff happens, time passes
el.transform({ e: el.transform().x + 100 });

(e meaning the x component of the matrix, I assume that it could also be x instead of e). Please correct me if I'm wrong.

from svg.js.

wout avatar wout commented on August 16, 2024

Well, not exactly. Translations and matrices are applied separately. In other words, transformations are not combined into a matrix. If you move an element with:

rect.transform({ x: 100, y: 50 })

The value of the transform attribute will be translate(100,50).

If you add a matrix transformation afterwards, let's say:

rect.transform({ d: -1 })

The value of the transform attribute will be translate(100,50) matrix(1,0,0,-1,0,0).

Transformations are combined in svg. Recalculating transformations into a singular matrix would remove that.

To be honest, I have been thinking about going that way (one matrix to rule them all). But I decided to stay as close as possible to SVG's native behaviour.

from svg.js.

wout avatar wout commented on August 16, 2024

Are you with me on this?

from svg.js.

sergi avatar sergi commented on August 16, 2024

Yeah. Perhaps adding extra utility methods that translate, scale, etc.
using matrix transformations is not a bad idea though (I am doing all with
matrix operations now). You could prefix them and keep the svg-standard
methods for users that prefer 1:1 mapping with the generated svg .

On the other hand, I would always expect that svg.js takes the most
performing path, regardless of the methods I use. For example, if I do
obj.x = 10 I would expect that a matrix transformation is applied behind
the scenes, if that's more performing.

On Friday, May 24, 2013, Wout Fierens wrote:

Are you with me on this?


Reply to this email directly or view it on GitHubhttps://github.com//issues/38#issuecomment-18420057
.

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.