Use getBoundingClientRect for dimensions instead of offsetHeight/offsetWidth

`offsetHeight`/`offsetWidth` does not work for SVG Elements except in Chrome
and this support is being removed from Chrome soon:

>'SVGElement.offsetWidth' is deprecated and will be removed in M50, around
April 2016. See https://www.chromestatus.com/features/5724912467574784 for
more details.
This commit is contained in:
Bryan Housel
2016-02-10 17:08:11 -05:00
parent e38ea2ab60
commit 0210d69177
+4 -2
View File
@@ -1,8 +1,10 @@
d3.selection.prototype.dimensions = function (dimensions) {
if (!arguments.length) {
var node = this.node();
return [node.offsetWidth,
node.offsetHeight];
if (!node) return;
var cr = node.getBoundingClientRect();
return [cr.width, cr.height];
}
return this.attr({width: dimensions[0], height: dimensions[1]});
};