From 07b7601b000697eb23acc12c0173308f696f4bd5 Mon Sep 17 00:00:00 2001 From: nbonniere Date: Thu, 14 Sep 2017 17:10:38 -0400 Subject: [PATCH 1/4] Add baro_update function --- barogram.js | 57 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/barogram.js b/barogram.js index 3085515..ce88f88 100644 --- a/barogram.js +++ b/barogram.js @@ -28,13 +28,14 @@ var yAxis = []; // optional scale labels var margin = 10; // all around line graph var X_legend = 0; var Y_legend = 0; -var maxAlt = 5000; +var maxAlt = 1000; var X_lines = 5+1; -var Y_lines = 5+1; +var Y_lines = 5+1; var currentUnit = ""; var scaleFlag = 0; var X_offset = 0; var Y_offset = margin+X_legend; +var reScale = 0; // show altitude scale on the graph function plotScale() { @@ -89,37 +90,17 @@ function baro_Init() { Y_min = 0; baroCanvas = document.getElementById("div_baro"); - baroCanvas.height = parseInt(document.getElementById("dbaro").offsetHeight, 10); baroCtx = baroCanvas.getContext("2d"); - baroCtx.fillStyle = "#808080"; // color of text - baroCtx.font = "12px Arial"; baroScale = document.getElementById("div_baroScale"); - baroScale.height = parseInt(document.getElementById("dbaro").offsetHeight, 10); baroScaleCtx = baroScale.getContext("2d"); - baroScaleCtx.fillStyle = "#808080"; // color of text - baroScaleCtx.font = "12px Arial"; baroMarker = document.getElementById("div_baroMark"); - baroMarker.height = parseInt(document.getElementById("dbaro").offsetHeight, 10); baroMarkCtx = baroMarker.getContext("2d"); - baroMarkCtx.fillStyle = "#808080"; // color of text - baroMarkCtx.font = "12px Arial"; - - xWidth = baroCanvas.width; - yHeight = baroCanvas.height - X_legend - 2*margin; - - yScale = (yHeight) / (Y_max - Y_min); - xScale = (xWidth) / (X_max - X_min); - - plotScale(); - plotGrid(); - // create a clipping region - simpler than checking X_min -// baroCtx.beginPath(); -// baroCtx.rect(0, margin+X_legend, 0+xWidth, margin+X_legend+yHeight); -// baroCtx.clip(); + baro_update(); } + String.prototype.toSeconds = function () { if (!this) return null; var hms = this.split(':'); return (+hms[0]) * 60 * 60 + (+hms[1]) * 60 + (+hms[2] || 0); } // plot a line with color and [x,y] array - rely on clipping region @@ -153,7 +134,8 @@ yHeight = baroCanvas.height - X_legend - 2*margin; // auto adjust the range // (unit == "i") ? maxRange = Math.ceil((maxRange+250)/2000)*2000 : maxRange = Math.ceil((maxRange+100)/1000)*1000; // 2000 ft or 1000 m increments (unit == "i") ? maxRange = Math.ceil((maxRange+500)/1000)*1000 : maxRange = Math.ceil((maxRange+250)/500)*500; // 1000 ft or 500 m increments - if ((maxRange != Y_max) || (unit != currentUnit)) { + if ((maxRange != Y_max) || (unit != currentUnit) || (reScale == 1) { + reScale = 0; currentUnit = unit; Y_max = maxRange; yScale = (yHeight) / (Y_max - Y_min) * m2ft[unit]; // adjust scale with unit here to avoid and extra multiply every y point @@ -173,6 +155,31 @@ yHeight = baroCanvas.height - X_legend - 2*margin; scaleFlag = 0; } +// on window re-size, update the baro scaling +function baro_update() { +// document.getElementById('div_baro').height = dbaro.clientHeight; + baroCanvas.height = dbaro.clientHeight; + // need to update after size change (?) + baroScaleCtx.fillStyle = "#808080"; // color of text + baroScaleCtx.font = "12px Arial"; + +// document.getElementById('div_baroScale').height = dbaro.clientHeight; + baroScale.height = dbaro.clientHeight; + // need to update after size change (?) + baroScaleCtx.fillStyle = "#808080"; // color of text + baroScaleCtx.font = "12px Arial"; + +// document.getElementById('div_baroMark').height = dbaro.clientHeight; + baroMarker.height = dbaro.clientHeight; + // need to update after size change (?) + baroMarkCtx.fillStyle = "#808080"; // color of text + baroMarkCtx.font = "12px Arial"; + + // flag re-scale required at next refresh + reScale = 1; + baro_plotRefresh(); +} + // set the time and altitude scales on the barogram function Set_XY_Scale(tim,alt) { if (scaleFlag++ == 0) { // use first item as a reference From 1b6bb9900783420f15785c68089a996ef5d98978 Mon Sep 17 00:00:00 2001 From: nbonniere Date: Thu, 14 Sep 2017 17:13:16 -0400 Subject: [PATCH 2/4] Add window-resize listener --- cunimb.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cunimb.js b/cunimb.js index 2ba858e..07c6cb0 100644 --- a/cunimb.js +++ b/cunimb.js @@ -1926,4 +1926,10 @@ function initialize() { // barogram plotting baro_Init(); + + // re-scale baro after window resize + google.maps.event.addDomListener(window, "resize", function() { + baro_update(); + }); + } From 1418d1536d72f8bd28dbf94184ef9e2302e3d37c Mon Sep 17 00:00:00 2001 From: nbonniere Date: Thu, 14 Sep 2017 17:21:51 -0400 Subject: [PATCH 3/4] Update barogram.js --- barogram.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barogram.js b/barogram.js index ce88f88..a916543 100644 --- a/barogram.js +++ b/barogram.js @@ -134,7 +134,7 @@ yHeight = baroCanvas.height - X_legend - 2*margin; // auto adjust the range // (unit == "i") ? maxRange = Math.ceil((maxRange+250)/2000)*2000 : maxRange = Math.ceil((maxRange+100)/1000)*1000; // 2000 ft or 1000 m increments (unit == "i") ? maxRange = Math.ceil((maxRange+500)/1000)*1000 : maxRange = Math.ceil((maxRange+250)/500)*500; // 1000 ft or 500 m increments - if ((maxRange != Y_max) || (unit != currentUnit) || (reScale == 1) { + if ((maxRange != Y_max) || (unit != currentUnit) || (reScale == 1)) { reScale = 0; currentUnit = unit; Y_max = maxRange; From b0efb53c378427cbb8c3d7e2b3f1c0d9b40ff0cd Mon Sep 17 00:00:00 2001 From: nbonniere Date: Tue, 23 Jan 2018 16:09:40 -0500 Subject: [PATCH 4/4] Fix missing altitude-stick on offline markers. --- cunimb.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/cunimb.js b/cunimb.js index 07c6cb0..f77de43 100644 --- a/cunimb.js +++ b/cunimb.js @@ -1069,8 +1069,8 @@ function gesmark() { window[stickvar].set('nom', "" + cn + " - " + ps); window[stickvar].set('baton', "" + stickvar); -// window[stickvar].getPath().push(posi); -// window[stickvar].getPath().push(posiBaton); + window[stickvar].getPath().push(posi); + window[stickvar].getPath().push(posiBaton); // création du Marker window[markvar] = new google.maps.Marker({ @@ -1142,6 +1142,14 @@ function gesmark() { if (++ccolor == tcolor.length) ccolor = 0; } // fin du if typeof... + if (stick === 1) { + window[stickvar].setOptions({visible: true}); + window[markvar].setPosition(posiBaton); // déplace le marker + } else { + window[stickvar].setOptions({visible: false}); + window[markvar].setPosition(posi); // déplace le marker + } + var difalt = vz * 1; colcn = window[polyvar].strokeColor; @@ -1169,22 +1177,21 @@ function gesmark() { if (window[polyvar].getPath().getLength() >= pathl) window[polyvar].getPath().removeAt(0); // remove first point of the trace } - window[polyvar].getPath().push(posi); // ajout d'une position sur le tracé // window[markvar].setPosition(posi); // déplace le marker - if (stick === 1) { - window[stickvar].setOptions({visible: true}); - window[markvar].setPosition(posiBaton); // déplace le marker + // if (stick === 1) { + // window[stickvar].setOptions({visible: true}); + // window[markvar].setPosition(posiBaton); // déplace le marker // window[stickvar].getPath().pop(); // déplace le baton // window[stickvar].getPath().pop(); // for now - better way ? // window[stickvar].getPath().push(posi); // window[stickvar].getPath().push(posiBaton); window[stickvar].getPath().setAt(0,posi); window[stickvar].getPath().setAt(1,posiBaton); - } else { - window[stickvar].setOptions({visible: false}); - window[markvar].setPosition(posi); // déplace le marker - } + // } else { + // window[stickvar].setOptions({visible: false}); + // window[markvar].setPosition(posi); // déplace le marker + // } // change l'altitude affichée window[markvar].setTitle("" + cn + " - " + ps + " @ " + (alt * m2ft[unit]).toFixed() + am2ft[unit] + " @ " + tim);