Git Product home page Git Product logo

Comments (5)

xaedes avatar xaedes commented on March 28, 2024

A simple text tweening implementation I use:

  var textTweenID = 0;
  transition.textTween = function(tween, precision) {

    /** @this {Element} */
    function textTween(d, i) {
      var f = tween.call(this, d, i, this.textContent);
      return function(t) {
        this.textContent = f(t);
      };
    }
    tweens["text." + textTweenID] = textTween;
    textTweenID++;
    return transition;
  };
  
  transition.text = function(value) {

    return transition.textTween(d3_transitionTween(value));
  };

Btw: I would love to see transition "step" events!

from d3.

mbostock avatar mbostock commented on March 28, 2024

Thanks for the suggestion. Text transitions will be in the next release! See commit @222629a7a774ce15f3c8 for details.

I haven't decided whether to add "step" events yet. I'm a bit worried about the overhead on dispatching every tick times every element, when in the common case there is no step event listener. If I can find a way around that, it should be a no-brainer to add.

from d3.

mbostock avatar mbostock commented on March 28, 2024

Fixed in 2.0.0, using custom tweens.

from d3.

tandu avatar tandu commented on March 28, 2024

Should I write custom tween as in example above to fire step events?

from d3.

mbostock avatar mbostock commented on March 28, 2024

Something like this:

transition.tween("name", function(d, i) {
  return function(t) {
    // this function is called with the easing parameter t in [0,1]
  };
});

The name is used as an identifier so that you can replace the tween later. For example, attr("foo", "bar") uses the name "attr.foo".

from d3.

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.