diff --git a/plugins/compute-ap-stats.user.js b/plugins/compute-ap-stats.user.js
index 3c0e8bd7..0af36254 100644
--- a/plugins/compute-ap-stats.user.js
+++ b/plugins/compute-ap-stats.user.js
@@ -21,7 +21,25 @@ 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':'#ffce00', 'font-size':'90%', 'padding':'4px 2px'});
+
+ // do an initial calc for sidebar sizing purposes
+ 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() {
+ var result = window.plugin.compAPStats.compAPStats();
+ $('#available_ap_display').html("Available AP in this area:
Enlightened:\t" +
+ digits(result[1]) + "
Resistance:\t" + digits(result[0]));
}
window.plugin.compAPStats.compAPStats = function() {
@@ -34,11 +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;
@@ -89,18 +111,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();
}