diff --git a/tabs/receiver.js b/tabs/receiver.js index 89bb7e10..98593ba0 100644 --- a/tabs/receiver.js +++ b/tabs/receiver.js @@ -157,10 +157,6 @@ function tab_initialize_receiver() { var samples = 0; - var margin = {top: 20, right: 20, bottom: 10, left: 40}; - var width = $('#RX_plot').width() - margin.left - margin.right; - var height = $('#RX_plot').height() - margin.top - margin.bottom; - var svg = d3.select("svg"); function update_ui() { @@ -212,12 +208,21 @@ function tab_initialize_receiver() { // update required parts of the plot var widthScale = d3.scale.linear(). - domain([(samples - 299), samples]). - range([0, width]); + domain([(samples - 299), samples]); var heightScale = d3.scale.linear(). - domain([800, 2200]). - range([height, 0]); + domain([800, 2200]); + + function update_receiver_plot_size() { + var margin = {top: 20, right: 20, bottom: 10, left: 40}; + var width = $('#RX_plot').width() - margin.left - margin.right; + var height = $('#RX_plot').height() - margin.top - margin.bottom; + widthSclae.range([0, width]); + heightScale.range([height, 0]); + } + + update_receiver_plot_size(); + var xGrid = d3.svg.axis(). scale(widthScale). diff --git a/tabs/sensors.js b/tabs/sensors.js index 16bca564..dbc6d9db 100644 --- a/tabs/sensors.js +++ b/tabs/sensors.js @@ -40,22 +40,27 @@ function tab_initialize_sensors() { return sampleNumber + 1; } - function initGraphHelpers(selector, sampleNumber, heightDomain) { + function updateGraphHelperSize(selector, helpers) { var margin = {top: 20, right: 20, bottom: 10, left: 40}; var width = $(selector).width() - margin.left - margin.right; var height = $(selector).height() - margin.top - margin.bottom; + helpers.widthScale.range([0, width]); + helpers.heightScale.range([height, 0]); + } + + function initGraphHelpers(selector, sampleNumber, heightDomain) { var helpers = {selector: selector, dynamicHeightDomain: !heightDomain}; helpers.widthScale = d3.scale.linear() .clamp(true) - .domain([(sampleNumber - 299), sampleNumber]) - .range([0, width]); + .domain([(sampleNumber - 299), sampleNumber]); helpers.heightScale = d3.scale.linear() .clamp(true) - .domain(heightDomain || [1, -1]) - .range([height, 0]); + .domain(heightDomain || [1, -1]); + + updateGraphHelperSize(selector, helpers); helpers.xGrid = d3.svg.axis() .scale(helpers.widthScale)