From 4581df14f11dd4709a8fc90547fcd1b8d617e7ce Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sat, 16 Jun 2012 04:49:35 +0200 Subject: [PATCH] handle resize events --- html/force.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/html/force.js b/html/force.js index 4a993ab..5a6de9b 100644 --- a/html/force.js +++ b/html/force.js @@ -27,8 +27,27 @@ function getOffset( el ) { var offset = getOffset(document.getElementById('chart')) -var w = window.innerWidth - offset.left, - h = window.innerHeight - offset.top - 1 +var w, h + +resize() + +window.onresize = resize + +function resize() { + var offset = getOffset(document.getElementById('chart')) + + w = window.innerWidth - offset.left + h = window.innerHeight - offset.top - 1 + + d3.select("#chart") + .attr("width", w).attr("height", h) + + if (vis) + vis.attr("width", w).attr("height", h) + + if (force) + force.size([w, h]).start() +} function next_style() { var s;