From 96af626bd7e207384a1c20990639a964753a994e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sat, 1 Dec 2012 08:16:50 -0800 Subject: [PATCH] Add d3.selection.prototype.size --- index.html | 1 + js/id/id.js | 2 +- js/id/renderer/map.js | 14 +++++++++----- js/lib/d3.size.js | 8 ++++++++ test/index.html | 1 + 5 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 js/lib/d3.size.js diff --git a/index.html b/index.html index 44d5fb8b2..bc8950ff6 100644 --- a/index.html +++ b/index.html @@ -18,6 +18,7 @@ + diff --git a/js/id/id.js b/js/id/id.js index fab9fdd1d..7f05425da 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -130,7 +130,7 @@ var iD = function(container) { }); window.onresize = function() { - map.setSize([m.node().offsetWidth, m.node().offsetHeight]); + map.setSize(m.size()); }; d3.select(document).on('keydown', function() { diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index e045e5120..b9dcd9eb0 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -248,10 +248,14 @@ iD.Map = function(elem, connection) { .classed('active', classActive); } - function setSize(x) { - dimensions = x; - var attr = { width: dimensions[0], height: dimensions[1] }; - surface.attr(attr).selectAll('#clip-rect').attr(attr); + function setSize(size) { + dimensions = size; + + surface + .size(dimensions) + .selectAll('#clip-rect') + .size(dimensions); + tileclient.setSize(dimensions); return map; } @@ -532,7 +536,7 @@ iD.Map = function(elem, connection) { map.flush = flush; map.dblclickEnable = dblclickEnable; - setSize([parent.node().offsetWidth, parent.node().offsetHeight]); + setSize(parent.size()); hideInspector(); redraw(); diff --git a/js/lib/d3.size.js b/js/lib/d3.size.js new file mode 100644 index 000000000..01ec8183a --- /dev/null +++ b/js/lib/d3.size.js @@ -0,0 +1,8 @@ +d3.selection.prototype.size = function (size) { + if (!arguments.length) { + var node = this.node(); + return [node.offsetWidth, + node.offsetHeight]; + } + return this.attr({width: size[0], height: size[1]}); +}; diff --git a/test/index.html b/test/index.html index a7abe9c64..7d8e4b878 100644 --- a/test/index.html +++ b/test/index.html @@ -14,6 +14,7 @@ +