trinary / d3-transform

add an interface for svg transform attributes in d3.js
MIT License
160 stars 17 forks source link

seq: add support for sequencing existing transforms #15

Closed seliopou closed 9 years ago

seliopou commented 9 years ago
var shift   = d3Transform.translate([x, y]),
    unshift = d3Transform.translate([-x, -y]);

shift.seq(unshift) /* identity (if the floats work out) */

I'll change the operation name (seq currently) to whatever the consensus name is.

Closes #14

sompylasar commented 9 years ago

@seliopou Great, thanks! Maybe add a readme item for this into the Composition section, too.

seliopou commented 9 years ago

@sompylasar Done.

@trinary, have a look and see what you think. It's my opinion that it's worthwhile having something like this in the library.

trinary commented 9 years ago

Agreed. I think there's another tweak to make when it comes to sequenced functions, though:

var t1 = d3Transform().translate(function(d) { return [d,1]; });
var t2 = d3Transform().translate(function(d) { return [1,d]; });
var seq = t1.seq(t2);

seq(5) => "translate(5,1) translate(1,)"

I started to write some tests and ran into that. :)

trinary commented 9 years ago

@seliopou I haven't taken a second look on this yet, did you want me to dig in?

seliopou commented 9 years ago

Ugh, sorry been distracted with other things. Wanna have a look?

trinary commented 9 years ago

I have this working with a couple tests on https://github.com/trinary/d3-transform/tree/seliopou-master, take a look @seliopou . I think we just need to deal with the evaluated seq the same as a chain. Sorry it took so long to work on this. :) If that change looks ok you can pull it back on this branch and merge, I can update npm/bower whenever after that. Also you're added as a collaborator because why on earth wasn't that already done?