gka / d3-jetpack

🚀 Nifty convenience wrappers that speed up your daily work with d3.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

translate breaks if selection is empty

1wheel opened this issue · comments

need to exit early from this if node doesn't exist

 return this.node().getBBox ?
    this.attr('transform', function(d,i) {
      var p = typeof xy == 'function' ? xy.call(this, d,i) : xy;
      if (dim === 0) p = [p, 0]; else if (dim === 1) p = [0, p];
      return 'translate(' + p[0] +','+ p[1]+')';
    }) :

quick fix

var translateSelection = function(xy, dim) {
  var node = this.node()
  return !node ? this : node.getBBox ?
    this.attr('transform', function(d,i) {
      var p = typeof xy == 'function' ? xy.call(this, d,i) : xy;
      if (dim === 0) p = [p, 0]; else if (dim === 1) p = [0, p];
      return 'translate(' + p[0] +','+ p[1]+')';
    }) :
    this.style('transform', function(d,i) {
      var p = typeof xy == 'function' ? xy.call(this, d,i) : xy;
      if (dim === 0) p = [p, 0]; else if (dim === 1) p = [0, p];
      return 'translate(' + p[0] +'px,'+ p[1]+'px)';
    });
};