From 3a5741d9ed767d3b28c3752891fa18421cf46f98 Mon Sep 17 00:00:00 2001 From: cTn Date: Mon, 21 Apr 2014 12:14:03 +0200 Subject: [PATCH] reorganizing update helpers --- tabs/receiver.js | 25 ++++++++++++------------- tabs/sensors.js | 15 +++++++-------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/tabs/receiver.js b/tabs/receiver.js index 9932547f..499ec5c6 100644 --- a/tabs/receiver.js +++ b/tabs/receiver.js @@ -156,9 +156,18 @@ function tab_initialize_receiver() { } var samples = 0; - var svg = d3.select("svg"); + var width, height, widthScale, heightScale; + function update_receiver_plot_size() { + var margin = {top: 20, right: 20, bottom: 10, left: 40}; + width = $('#RX_plot').width() - margin.left - margin.right; + height = $('#RX_plot').height() - margin.top - margin.bottom; + + widthScale.range([0, width]); + heightScale.range([height, 0]); + } + function update_ui() { meter_array[0].val(RC.throttle); meter_values_array[0].text('[ ' + RC.throttle + ' ]'); @@ -207,24 +216,14 @@ function tab_initialize_receiver() { } // update required parts of the plot - var widthScale = d3.scale.linear(). + widthScale = d3.scale.linear(). domain([(samples - 299), samples]); - var heightScale = d3.scale.linear(). + heightScale = d3.scale.linear(). domain([800, 2200]); - var margin, width, height; - function update_receiver_plot_size() { - margin = {top: 20, right: 20, bottom: 10, left: 40}; - width = $('#RX_plot').width() - margin.left - margin.right; - height = $('#RX_plot').height() - margin.top - margin.bottom; - widthScale.range([0, width]); - heightScale.range([height, 0]); - } - update_receiver_plot_size(); - var xGrid = d3.svg.axis(). scale(widthScale). orient("bottom"). diff --git a/tabs/sensors.js b/tabs/sensors.js index 247545ab..9ba822e4 100644 --- a/tabs/sensors.js +++ b/tabs/sensors.js @@ -40,14 +40,13 @@ function tab_initialize_sensors() { return sampleNumber + 1; } - var margin, width, height; function updateGraphHelperSize(selector, helpers) { - margin = {top: 20, right: 20, bottom: 10, left: 40}; - width = $(selector).width() - margin.left - margin.right; - height = $(selector).height() - margin.top - margin.bottom; + var margin = {top: 20, right: 20, bottom: 10, left: 40}; + helpers.width = $(selector).width() - margin.left - margin.right; + helpers.height = $(selector).height() - margin.top - margin.bottom; - helpers.widthScale.range([0, width]); - helpers.heightScale.range([height, 0]); + helpers.widthScale.range([0, helpers.width]); + helpers.heightScale.range([helpers.height, 0]); } function initGraphHelpers(selector, sampleNumber, heightDomain) { @@ -67,14 +66,14 @@ function tab_initialize_sensors() { .scale(helpers.widthScale) .orient("bottom") .ticks(5) - .tickSize(-height, 0, 0) + .tickSize(-helpers.height, 0, 0) .tickFormat(""); helpers.yGrid = d3.svg.axis() .scale(helpers.heightScale) .orient("left") .ticks(5) - .tickSize(-width, 0, 0) + .tickSize(-helpers.width, 0, 0) .tickFormat(""); helpers.xAxis = d3.svg.axis()