diff --git a/plugins/portal-counts.user.js b/plugins/portal-counts.user.js
index 520e0514..47fb7ae6 100644
--- a/plugins/portal-counts.user.js
+++ b/plugins/portal-counts.user.js
@@ -2,7 +2,7 @@
// @id iitc-plugin-portals-count@yenky
// @name IITC plugin: Show total counts of portals
// @category Info
-// @version 0.0.10.@@DATETIMEVERSION@@
+// @version 0.1.0.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL @@UPDATEURL@@
// @downloadURL @@DOWNLOADURL@@
@@ -19,6 +19,7 @@
// PLUGIN START ////////////////////////////////////////////////////////
/* whatsnew
+* 0.1.0 : display graphs
* 0.0.10 : show in nav drawer on mobile devices
* 0.0.9 : fix for new intel map
* 0.0.8 : use dialog() instead of alert()
@@ -31,74 +32,157 @@
*/
// use own namespace for plugin
-window.plugin.portalcounts = function() {};
+window.plugin.portalcounts = {
+ BAR_TOP: 20,
+ BAR_HEIGHT: 180,
+ BAR_WIDTH: 25,
+ BAR_PADDING: 5,
+ RADIUS_INNER: 70,
+ RADIUS_OUTER: 100,
+ CENTER_X: 200,
+ CENTER_Y: 100,
+};
//count portals for each level available on the map
window.plugin.portalcounts.getPortals = function(){
//console.log('** getPortals');
- var retval=false;
+ var self = window.plugin.portalcounts;
var displayBounds = map.getBounds();
- window.plugin.portalcounts.enlP = 0;
- window.plugin.portalcounts.resP = 0;
- window.plugin.portalcounts.neuP = 0;
-
- window.plugin.portalcounts.PortalsEnl = new Array();
- window.plugin.portalcounts.PortalsRes = new Array();
+ self.enlP = 0;
+ self.resP = 0;
+ self.neuP = 0;
+
+ self.PortalsEnl = new Array();
+ self.PortalsRes = new Array();
for(var level = window.MAX_PORTAL_LEVEL; level > 0; level--){
- window.plugin.portalcounts.PortalsEnl[level] = 0;
- window.plugin.portalcounts.PortalsRes[level] = 0;
+ self.PortalsEnl[level] = 0;
+ self.PortalsRes[level] = 0;
}
-
+
$.each(window.portals, function(i, portal) {
- retval=true;
var level = portal.options.level;
var team = portal.options.team;
// just count portals in viewport
if(!displayBounds.contains(portal.getLatLng())) return true;
switch (team){
case 1 :
- window.plugin.portalcounts.resP++;
- window.plugin.portalcounts.PortalsRes[level]++;
+ self.resP++;
+ self.PortalsRes[level]++;
break;
case 2 :
- window.plugin.portalcounts.enlP++;
- window.plugin.portalcounts.PortalsEnl[level]++;
+ self.enlP++;
+ self.PortalsEnl[level]++;
break;
default:
- window.plugin.portalcounts.neuP++;
+ self.neuP++;
break;
}
});
-
+
//get portals informations from IITC
var minlvl = getMinPortalLevel();
+ var total = self.neuP + self.enlP + self.resP;
- var counts = '
';
- if(retval) {
- counts += ' | Enlightened | Resistance |
'; //'+window.plugin.portalcounts.enlP+' Portal(s)';
+ var counts = '';
+ if(total > 0) {
+ counts += ' | Enlightened | Resistance |
'; //'+self.enlP+' Portal(s)';
for(var level = window.MAX_PORTAL_LEVEL; level > 0; level--){
counts += 'Level '+level+' | ';
if(minlvl > level)
counts += 'zoom in to see portals in this level | ';
else
- counts += ''+window.plugin.portalcounts.PortalsEnl[level]+' | '+window.plugin.portalcounts.PortalsRes[level]+' | ';
+ counts += ''+self.PortalsEnl[level]+' | '+self.PortalsRes[level]+' | ';
counts += '
';
}
- counts += 'Total: | '+window.plugin.portalcounts.enlP+' | '+window.plugin.portalcounts.resP+' |
';
+ counts += 'Total: | '+self.enlP+' | '+self.resP+' |
';
counts += 'Neutral: | ';
if(minlvl > 0)
counts += 'zoom in to see unclaimed portals';
else
- counts += window.plugin.portalcounts.neuP;
- counts += ' |
';
+ counts += self.neuP;
+ counts += '
';
+ var svg = $('
';
+ counts += 'No Portals in range!
';
+ counts += '';
- var total = window.plugin.portalcounts.enlP + window.plugin.portalcounts.resP + window.plugin.portalcounts.neuP;
+ var total = self.enlP + self.resP + self.neuP;
var title = total + ' ' + (total == 1 ? 'portal' : 'portals');
if(typeof android !== 'undefined' && android && android.addPane) {
@@ -110,10 +194,102 @@ window.plugin.portalcounts.getPortals = function(){
dialog({
html: '' + counts + '
',
title: 'Portal counts: ' + title,
+ width: 'auto'
});
}
}
+window.plugin.portalcounts.makeBar = function(portals, text, color, shift) {
+ var self = window.plugin.portalcounts;
+ var g = $("").attr("transform", "translate("+shift+",0)");
+ var sum = portals.reduce(function(a,b){ return a+b });
+ var top = self.BAR_TOP;
+
+ if(sum != 0) {
+ for(var i=portals.length-1;i>=0;i--) {
+ if(!portals[i])
+ continue;
+ var height = self.BAR_HEIGHT * portals[i] / sum;
+ $("")
+ .attr({
+ x: 0,
+ y: top,
+ width: self.BAR_WIDTH,
+ height: height,
+ fill: COLORS_LVL[i]
+ })
+ .appendTo(g);
+ top += height;
+ }
+ }
+
+ $('')
+ .html(text)
+ .attr({
+ x: self.BAR_WIDTH * 0.5,
+ y: self.BAR_TOP * 0.75,
+ fill: color,
+ "text-anchor": "middle"
+ })
+ .appendTo(g);
+
+ return g;
+};
+
+window.plugin.portalcounts.makePie = function(startAngle, endAngle, color) {
+ var self = window.plugin.portalcounts;
+ var large_arc = (endAngle - startAngle) > 0.5 ? 1 : 0;
+
+ startAngle = 0.5 - startAngle;
+ endAngle = 0.5 - endAngle;
+
+ var p1x = Math.sin(startAngle * 2 * Math.PI) * self.RADIUS_INNER;
+ var p1y = Math.cos(startAngle * 2 * Math.PI) * self.RADIUS_INNER;
+ var p2x = Math.sin(endAngle * 2 * Math.PI) * self.RADIUS_INNER;
+ var p2y = Math.cos(endAngle * 2 * Math.PI) * self.RADIUS_INNER;
+
+ return $("")
+ .attr({
+ fill: color,
+ d: self.format("M %s,%s A %s,%s 0 %s 1 %s,%s L 0,0 z", p1x,p1y, self.RADIUS_INNER,self.RADIUS_INNER, large_arc, p2x,p2y)
+ });
+};
+
+window.plugin.portalcounts.makeRing = function(startAngle, endAngle, color) {
+ var self = window.plugin.portalcounts;
+ var large_arc = (endAngle - startAngle) > 0.5 ? 1 : 0;
+
+ startAngle = 0.5 - startAngle;
+ endAngle = 0.5 - endAngle;
+
+ var p1x = Math.sin(startAngle * 2 * Math.PI) * self.RADIUS_OUTER;
+ var p1y = Math.cos(startAngle * 2 * Math.PI) * self.RADIUS_OUTER;
+ var p2x = Math.sin(endAngle * 2 * Math.PI) * self.RADIUS_OUTER;
+ var p2y = Math.cos(endAngle * 2 * Math.PI) * self.RADIUS_OUTER;
+ var p3x = Math.sin(endAngle * 2 * Math.PI) * self.RADIUS_INNER;
+ var p3y = Math.cos(endAngle * 2 * Math.PI) * self.RADIUS_INNER;
+ var p4x = Math.sin(startAngle * 2 * Math.PI) * self.RADIUS_INNER;
+ var p4y = Math.cos(startAngle * 2 * Math.PI) * self.RADIUS_INNER;
+
+ return $("")
+ .attr({
+ fill: color,
+ d: self.format("M %s,%s ", p1x, p1y)
+ + self.format("A %s,%s 0 %s 1 %s,%s ", self.RADIUS_OUTER,self.RADIUS_OUTER, large_arc, p2x,p2y)
+ + self.format("L %s,%s ", p3x,p3y)
+ + self.format("A %s,%s 0 %s 0 %s,%s ", self.RADIUS_INNER,self.RADIUS_INNER, large_arc, p4x,p4y)
+ + "Z"
+ });
+};
+
+window.plugin.portalcounts.format = function(str) {
+ var re = /%s/;
+ for(var i = 1; i < arguments.length; i++) {
+ str = str.replace(re, arguments[i]);
+ }
+ return str;
+}
+
window.plugin.portalcounts.onPaneChanged = function(pane) {
if(pane == "plugin-portalcounts")
window.plugin.portalcounts.getPortals();
@@ -129,7 +305,7 @@ var setup = function() {
$('#toolbox').append(' Portal counts');
}
- $('head').append('');