Persist dimensions in property to avoid reflow

This commit is contained in:
Bryan Housel
2016-02-12 17:12:03 -05:00
parent 9a1b7628ba
commit 3b0347eebc

View File

@@ -3,8 +3,15 @@ d3.selection.prototype.dimensions = function (dimensions) {
var node = this.node();
if (!node) return;
var cr = node.getBoundingClientRect();
return [cr.width, cr.height];
var prop = this.property('__dimensions__');
if (!prop) {
var cr = node.getBoundingClientRect();
prop = [cr.width, cr.height];
this.property('__dimensions__', prop);
}
return prop;
}
this.property('__dimensions__', [dimensions[0], dimensions[1]]);
return this.attr({width: dimensions[0], height: dimensions[1]});
};