From 03aae4463ab0cf01ea44474b03cbc6c5e38a4523 Mon Sep 17 00:00:00 2001 From: bastianonm Date: Thu, 16 May 2013 11:54:44 +0000 Subject: [PATCH] * Added Chart zoom feature * Some small bug fixes --- WP-GPX-Maps.js | 82 ++++++++++++++++++++++++++++------ readme.txt | 5 ++- wp-gpx-maps.php | 6 ++- wp-gpx-maps_admin_settings.php | 4 +- 4 files changed, 79 insertions(+), 18 deletions(-) diff --git a/WP-GPX-Maps.js b/WP-GPX-Maps.js index 9e1d9ad..2366775 100644 --- a/WP-GPX-Maps.js +++ b/WP-GPX-Maps.js @@ -160,9 +160,18 @@ function _wpgpxmaps(params) var lng = params.langs; var pluginUrl = params.pluginUrl; + // Unit of measure settings + var l_s; + var l_x; + var l_y; + var l_grade = { suf : "%", dec : 1 }; + var l_hr = { suf : "", dec : 0 }; + var l_cad = { suf : "", dec : 0 }; + var el = document.getElementById("wpgpxmaps_" + targetId); var el_map = document.getElementById("map_" + targetId); var el_chart = document.getElementById("chart_" + targetId); + var el_report = document.getElementById("report_" + targetId); var mapWidth = el_map.style.width; @@ -600,8 +609,6 @@ function _wpgpxmaps(params) var valLen = graphDist.length; - var l_x; - var l_y; var l_y_arr = []; if (unit=="1") @@ -636,7 +643,62 @@ function _wpgpxmaps(params) var hoptions = { chart: { renderTo: 'hchart_' + params.targetId, - type: 'area' + type: 'area', + events: { + selection: function(event) { + + if (event.xAxis) { + + el_report.innerHTML = 'Zoom: '+ (event.xAxis[0].min).toFixed(l_x.dec) + ' ' + l_x.suf + ' -> '+ (event.xAxis[0].max).toFixed(decPoint) + ' ' + l_x.suf + '
'; + + var seriesLength = event.currentTarget.series.length; + + for (var i = 0; i < seriesLength; i++) { + + var dataX = {value: 0, count: 0}; + + var serie = event.currentTarget.series[i]; + var points = serie.points; + var min = event.xAxis[0].min, max = event.xAxis[0].max; + + for (var j = 0; j < points.length; j++) { + if (points[j].x >= min && points[j].x <= max) { + dataX.value += points[j].y; + dataX.count +=1; + } + } + + var name = serie.name; + + if (name == lng.altitude) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_y.dec) + " " + l_y.suf + "
"; + } else if (name == lng.speed) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_s.dec) + " " + l_s.suf + "
"; + } else if (name == lng.grade) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_grade.dec) + " " + l_grade.suf + "
"; + } else if (name == lng.cadence) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_cad.dec) + " " + l_cad.suf + "
"; + } else if (name == lng.heartRate) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_hr.dec) + " " + l_hr.suf + "
"; + } else + { + el_report.innerHTML += serie.name + ' avg: ' + dataX.value / dataX.count + "
"; + } + + + + + + } + + el_report.innerHTML += "
" + + } else { + el_report.innerHTML = ''; + } + } + }, + zoomType: 'x' }, title: { text: null @@ -665,7 +727,7 @@ function _wpgpxmaps(params) formatter: function() { if (marker) { - var hchart_xserie = hchart.xAxis[0].series[0].data; + var hchart_xserie = hchart.xAxis[0].series[0].data; for(var i=0; i
+
'. $error .'