trinary / d3-transform

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

Append one transform chain to another (concat chains) #14

Closed sompylasar closed 9 years ago

sompylasar commented 9 years ago

If you have two existing transform objects, it would be great if you could append one to another after constructing. This is required for better transform reuse.

Example (zoom with a center point):

import d3Transform from 'd3-transform';

const zoomTransform = d3Transform().scale(1.5);

// The 'x' and 'y' are calculated from the bounding box.
const originForwardTransform= d3Transform().translate([ x, y ]);
const originBackwardTransform= d3Transform().translate([ -x, -y ]);

// Notice the order.
const zoomCenteredTransform = d3Transform()
  .concat(originForwardTransform)
  .concat(zoomTransform)
  .concat(originBackwardTransform);
seliopou commented 9 years ago

Should be easy to implement. seq may be a better name than concat, as it connotes more of an operation on actions rather than slapping together data.