/* ____ _____ _ _ _ _ _ _ _ / __ \ / ____| (_) | | | \ | | | | | | | | | |_ __ ___ _ __ | | __| |_ __| | ___ _ __ | \| | ___| |___ _____ _ __| | __ | | | | '_ \ / _ \ '_ \ | | |_ | | |/ _` |/ _ \ '__| | . ` |/ _ \ __\ \ /\ / / _ \| '__| |/ / | |__| | |_) | __/ | | | | |__| | | | (_| | __/ | | |\ | __/ |_ \ V V / (_) | | | < \____/| .__/ \___|_| |_| \_____|_|_|\__,_|\___|_| |_| \_|\___|\__| \_/\_/ \___/|_| |_|\_\ | | |_| */ // barogram option var baroCanvas; var baroScale; var baroMarker; var baroCtx; var baroScaleCtx; var baroMarkCtx; var X_max; var X_min; var Y_max; var Y_min; var xScale; var yScale; var xWidth; var yHeight; var xAxis = []; // optional scale labels var yAxis = []; // optional scale labels var margin = 10; // all around line graph var X_legend = 0; var Y_legend = 0; var maxAlt = 5000; var X_lines = 5+1; var Y_lines = 5+1; var currentUnit = ""; var scaleFlag = 0; var X_offset = 0; var Y_offset = margin+X_legend; // show altitude scale on the graph function plotScale() { // var TxtWidth = baroCtx.measureText(xAxis[0]).width; // var TxtHeight = baroCtx.measureText(xAxis[0]).height; var TxtHeight = 10; baroScaleCtx.strokeStyle="#c0c0c0"; // color of axis text baroScaleCtx.beginPath(); // print parameters on X axis if (xAxis.length == X_lines) { for (i=0;i 1) { // plot the altitude data baroCtx.strokeStyle=dColor; // color of line baroCtx.beginPath(); baroCtx.moveTo((dataSet[0][0]-X_min) * xScale + X_offset, yHeight-(dataSet[0][1] * yScale) + Y_offset); for (i=1 ;i60 ? 900 : pathl*10); // 5, 10 else 15 minutes xScale = (xWidth) / (X_max - X_min); // update the altitude scale var maxRange = maxAlt * m2ft[unit]; // 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)) { 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 // auto adjust the grid spacing // (unit == "i") ? Y_lines = (Y_max / 1000) + 1 : Y_lines = (Y_max / 500) + 1; // 1000 ft or 500 m grid steps (unit == "i") ? Y_lines = (Y_max / 1000) + 1 : Y_lines = (Y_max / 250) + 1; // 1000 ft or 250 m grid steps baroScaleCtx.clearRect(0, 0, baroScale.width, baroScale.height); plotScale(); } // erase the plot (and grid) // baroCtx.clearRect(0, margin+X_legend, margin+X_legend+xWidth, margin+X_legend+yHeight); baroCtx.clearRect(0, 0, baroCanvas.width, baroCanvas.height); plotGrid(); // re-plot the grid // erase the markers baroMarkCtx.clearRect(0, 0, baroMarker.width, baroMarker.height); // reset the flag scaleFlag = 0; } // set the time and altitude scales on the barogram function Set_XY_Scale(tim,alt) { if (scaleFlag++ == 0) { // use first item as a reference X_max = tim.toSeconds(); maxAlt = +alt; // '+' used for conversion from string to integer } else { if (X_max < tim.toSeconds()) { X_max = tim.toSeconds(); } if (maxAlt < +alt) { maxAlt = +alt; } } }