From 4d374ac7ad76d35373567ce7aef6dcf851c788b3 Mon Sep 17 00:00:00 2001 From: Dave Frame Date: Thu, 21 Feb 2013 21:25:05 -0700 Subject: [PATCH 1/4] updated the compute-ap-stats plugin to auto-calcuate on window change, and display in the sidebar updated the #portaldetails min-height to 569 to correct a pre-existing sizing bug. --- plugins/compute-ap-stats.user.js | 35 +++++++++++++++++++------------- style.css | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/plugins/compute-ap-stats.user.js b/plugins/compute-ap-stats.user.js index 3c0e8bd7..6618801d 100644 --- a/plugins/compute-ap-stats.user.js +++ b/plugins/compute-ap-stats.user.js @@ -21,9 +21,29 @@ if(typeof window.plugin !== 'function') window.plugin = function() {}; window.plugin.compAPStats = function() {}; window.plugin.compAPStats.setupCallback = function() { - $('#toolbox').append('Compute AP Stats '); + // add a new div to the bottom of the sidebar and style it + $('#sidebar').append("
"); + $('#available_ap_display').css({'color':'yellow', 'font-size':'90%', 'padding':'4px 2px'}); + + // do an initial calc for sizing purposes + window.plugin.compAPStats.onPositionMove(); + + //redefine the max size of the sidebar so its actually visible + $('#scrollwrapper').css('max-height', ($('#sidebar').get(0).scrollHeight+3) + 'px'); + + //make the value update on map position changes + map.on('moveend zoomend', window.plugin.compAPStats.onPositionMove); } +window.plugin.compAPStats.onPositionMove = function() { + $('#available_ap_display').empty(); + $('#available_ap_display').append('Available AP in this area:
'); + var result = window.plugin.compAPStats.compAPStats(); + $('#available_ap_display').append(' Enlightened:\t' + digits(result[1]) + '
'); + $('#available_ap_display').append(' Resistance:\t' + digits(result[0])); +} + + window.plugin.compAPStats.compAPStats = function() { var totalAP_RES = 0; @@ -34,7 +54,6 @@ window.plugin.compAPStats.compAPStats = function() { var allEnlEdges = []; var allEnlFields = []; - // Grab every portal in the viewable area and compute individual AP stats $.each(window.portals, function(ind, portal) { var d = portal.options.details; @@ -89,18 +108,6 @@ window.plugin.compAPStats.compAPStats = function() { return [totalAP_RES, totalAP_ENL]; } -window.plugin.compAPStats.guess = function() { - var res = window.plugin.compAPStats.compAPStats(); - var totalAP_RES = res[0]; - var totalAP_ENL = res[1]; - - var s = 'Calculated AP gain potential:\n\n'; - s += 'Available Resistance AP:\t' + digits(totalAP_RES) + '\n'; - s += 'Available Enlightened AP:\t' + digits(totalAP_ENL) + '\n'; - - alert(s); -} - var setup = function() { window.plugin.compAPStats.setupCallback(); } diff --git a/style.css b/style.css index 8a110b96..fbb6dead 100644 --- a/style.css +++ b/style.css @@ -609,7 +609,7 @@ aside { * content when first selecting a portal) */ #portaldetails { - min-height: 553px; + min-height: 569px; } From 8517e128d13ff3a62f57c3be6c62c6c5525d278a Mon Sep 17 00:00:00 2001 From: Dave Frame Date: Fri, 22 Feb 2013 11:22:36 -0700 Subject: [PATCH 2/4] fixed code review bugs noted by breunigs --- plugins/compute-ap-stats.user.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/plugins/compute-ap-stats.user.js b/plugins/compute-ap-stats.user.js index 6618801d..edc0857d 100644 --- a/plugins/compute-ap-stats.user.js +++ b/plugins/compute-ap-stats.user.js @@ -22,28 +22,22 @@ window.plugin.compAPStats = function() {}; window.plugin.compAPStats.setupCallback = function() { // add a new div to the bottom of the sidebar and style it - $('#sidebar').append("
"); - $('#available_ap_display').css({'color':'yellow', 'font-size':'90%', 'padding':'4px 2px'}); + $('#sidebar').append('
'); + $('#available_ap_display').css({'color':'#ffce00', 'font-size':'90%', 'padding':'4px 2px'}); - // do an initial calc for sizing purposes + // do an initial calc for sidebar sizing purposes window.plugin.compAPStats.onPositionMove(); - //redefine the max size of the sidebar so its actually visible - $('#scrollwrapper').css('max-height', ($('#sidebar').get(0).scrollHeight+3) + 'px'); - - //make the value update on map position changes + // make the value update on map position changes map.on('moveend zoomend', window.plugin.compAPStats.onPositionMove); } window.plugin.compAPStats.onPositionMove = function() { - $('#available_ap_display').empty(); - $('#available_ap_display').append('Available AP in this area:
'); var result = window.plugin.compAPStats.compAPStats(); - $('#available_ap_display').append(' Enlightened:\t' + digits(result[1]) + '
'); - $('#available_ap_display').append(' Resistance:\t' + digits(result[0])); + $('#available_ap_display').html("Available AP in this area:
 Enlightened:\t" + + digits(result[1]) + "
 Resistance:\t" + digits(result[0])); } - window.plugin.compAPStats.compAPStats = function() { var totalAP_RES = 0; From 19990b940bb50ec39311f6ff5735fbf22c13f60e Mon Sep 17 00:00:00 2001 From: Dave Frame Date: Fri, 22 Feb 2013 14:34:25 -0700 Subject: [PATCH 3/4] small fixes: hooking the data response handler instead of the map update so we only calcuate with complete data. scrubbing the portal list for out of view portals to avoid counting out of bounds portals --- plugins/compute-ap-stats.user.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/compute-ap-stats.user.js b/plugins/compute-ap-stats.user.js index edc0857d..0af36254 100644 --- a/plugins/compute-ap-stats.user.js +++ b/plugins/compute-ap-stats.user.js @@ -28,8 +28,12 @@ window.plugin.compAPStats.setupCallback = function() { // do an initial calc for sidebar sizing purposes window.plugin.compAPStats.onPositionMove(); - // make the value update on map position changes - map.on('moveend zoomend', window.plugin.compAPStats.onPositionMove); + // make the value update when the map data updates + var handleDataResponseOrig = window.handleDataResponse; + window.handleDataResponse = function(data, textStatus, jqXHR) { + handleDataResponseOrig(data, textStatus, jqXHR); + window.plugin.compAPStats.onPositionMove(); + } } window.plugin.compAPStats.onPositionMove = function() { @@ -48,10 +52,15 @@ window.plugin.compAPStats.compAPStats = function() { var allEnlEdges = []; var allEnlFields = []; + var displayBounds = map.getBounds(); + // Grab every portal in the viewable area and compute individual AP stats $.each(window.portals, function(ind, portal) { var d = portal.options.details; + // eliminate offscreen portals (selected, and in padding) + if(!displayBounds.contains(portal.getLatLng())) return true; + var portalStats = getAttackApGain(d); var portalSum = portalStats.resoAp + portalStats.captureAp; From 83420a4bbf19ff8b7554ddbeaeda823330b92e46 Mon Sep 17 00:00:00 2001 From: Dave Frame Date: Fri, 22 Feb 2013 17:02:49 -0700 Subject: [PATCH 4/4] reverted style.css to previous commit(a23f1ecb29b5eb557578fa03a907d7c71be1380e) making style change request a separate bug. --- style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/style.css b/style.css index fbb6dead..8a110b96 100644 --- a/style.css +++ b/style.css @@ -609,7 +609,7 @@ aside { * content when first selecting a portal) */ #portaldetails { - min-height: 569px; + min-height: 553px; }