GithubHelp home page GithubHelp logo

Comments (5)

mbostock avatar mbostock commented on April 25, 2024 2

Thank you for your patience. I’ll close, but I’ll also mention that I would like to change how interpolateTransform works in #44, such that we interpolate transform function lists (when the start and end transform have the same structure) rather than matrices. I think that would also address your needs here: since translate(1,1) and translate(0,0) have the same structure, we would return translate(0, 0) at the end (instead of the empty transform) if #44 were implemented.

But implementing this is non-trivial so I haven’t yet found time to do it. Contributions welcome!

from d3-interpolate.

mbostock avatar mbostock commented on April 25, 2024 1

That’s not how d3.interpolateTransformSvg works; it decomposes the given transformation into a standard representation, and then interpolates that. So, it’s not guaranteed that the interpolated value at t = 1 is string-equal to the target value a, just that the two will be equivalent transforms. This property is true of many of D3’s interpolators. For example, d3.interpolate("red", "blue")(1) returns "rgb(0, 0, 255)", which is the standard representation of a color in CSS.

When you say “a code that tries to get the current transform value for calculating the next one will break”, what do you mean? d3.interpolateTransformSvg seems to work fine when interpolating from the empty string to a non-empty transform:

d3.interpolateTransformSvg("", "translate(100, 0)")(0.5) // "translate(50, 0)"

from d3-interpolate.

mbostock avatar mbostock commented on April 25, 2024

Isn’t the empty string equivalent to translate(0,0)? What’s the problem?

from d3-interpolate.

GerardoFurtado avatar GerardoFurtado commented on April 25, 2024

The problem is just lack of consistency. The interpolator should return the target value for t = 1 no matter what, not deciding for an empty string: using an empty string with attr() actually removes the attribute, turning this...

<foo transform="translate(x,y)"></foo>

...into this:

<foo transform></foo>

Thus, in the next iteration, a code that tries to get the current transform value for calculating the next one will break.

from d3-interpolate.

GerardoFurtado avatar GerardoFurtado commented on April 25, 2024

I meant a code that uses attr("transform") or this.getAttribute("transform") to get the current transform value.

Anyway, now I see this is by design. Thanks for your explanation, as always it was very useful.

from d3-interpolate.

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.