From 0210d69177017204f09e9da8b2a8f065b6bfc219 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 10 Feb 2016 17:08:11 -0500 Subject: [PATCH] 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. --- js/lib/d3.dimensions.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/lib/d3.dimensions.js b/js/lib/d3.dimensions.js index 7f9ef0521..d54a05e25 100644 --- a/js/lib/d3.dimensions.js +++ b/js/lib/d3.dimensions.js @@ -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]}); };