window.regionScoreboard = function() { // TODO: rather than just load the region scores for the center of the map, display a list of regions in the current view // and let the user select one (with automatic selection when just one region, and limited to close enough zooms so list size is reasonable) var latLng = map.getCenter(); var latE6 = Math.round(latLng.lat*1E6); var lngE6 = Math.round(latLng.lng*1E6); var dlg = dialog({title:'Region scores',html:'Loading regional scores...',width:450,minHeight:320}); window.postAjax('getRegionScoreDetails', {latE6:latE6,lngE6:lngE6}, function(res){regionScoreboardSuccess(res,dlg);}, function(){regionScoreboardFailure(dlg);}); } function regionScoreboardFailure(dlg) { dlg.html('Failed to load region scores - try again'); } function regionScoreboardScoreHistoryChart(result, logscale) { // svg area 400x130. graph area 350x100, offset to 40,10 if(!Math.log10) Math.log10 = function(x) { return Math.log(x) / Math.LN10; }; var max = Math.max(result.gameScore[0],result.gameScore[1],10); //NOTE: ensure a min of 10 for the graph var items = []; //we'll copy the items to an array indexed by checkpoint number - easier to access! for (var i=0; i0 && items[i-1] !== undefined) { for (var t=0; t<2; t++) { teamPaths[t].push('M'+(x-10)+','+scale(items[i-1][t])+' L'+x+','+scale(items[i][t])); } } // markers otherSvg.push(''); otherSvg.push(''); for (var t=0; t<2; t++) { var col = t==0 ? COLORS[TEAM_ENL] : COLORS[TEAM_RES]; otherSvg.push(''); } otherSvg.push(''); } } var paths = ''; // graph tickmarks - horizontal var ticks = []; for (var i=5; i<=35; i+=5) { var x=i*10+40; ticks.push('M'+x+',10 L'+x+',110'); otherSvg.push(''+i+''); } // vertical // first we calculate the power of 10 that is smaller than the max limit var vtickStep = Math.pow(10,Math.floor(Math.log10(max))); var vticks = []; if(logscale) { for(var i=0;i<4;i++) { vticks.push(vtickStep); vtickStep /= 10; } } else { // this could be between 1 and 10 grid lines - so we adjust to give nicer spacings if (vtickStep < (max/5)) { vtickStep *= 2; } else if (vtickStep > (max/2)) { vtickStep /= 2; } for (var i=vtickStep; i<=max; i+=vtickStep) { vticks.push(i); } } vticks.forEach(function(i) { var y = scale(i); ticks.push('M40,'+y+' L390,'+y); var istr = i>=1000000000 ? i/1000000000+'B' : i>=1000000 ? i/1000000+'M' : i>=1000 ? i/1000+'k' : i; otherSvg.push(''+istr+''); }); paths += ';' for (var t=0; t<2; t++) { var col = t==0 ? COLORS[TEAM_ENL] : COLORS[TEAM_RES]; if (teamPaths[t].length > 0) { paths += ''; } var y = scale(result.gameScore[t]); paths += ''; } var svg = '
' +'' +paths +otherSvg.join('') +'' +'
'; return svg; } function regionScoreboardScoreHistoryTable(result) { var history = result.scoreHistory; var table = ''; for(var i=0; i'; } table += '
CheckpointEnlightenedResistance
' + digits(history[i][1]) + '' + digits(history[i][2]) + '
'; return table; } function regionScoreboardSuccess(data,dlg,logscale) { if (data.result === undefined) { return regionScoreboardFailure(dlg); } var agentTable = ''; for (var i=0; i'; } if (data.result.topAgents.length==0) { agentTable += ''; } agentTable += '
#Agent
'+agent.nick+'
no top agents
'; var maxAverage = Math.max(data.result.gameScore[0], data.result.gameScore[1], 1); var teamRow = []; for (var t=0; t<2; t++) { var team = t==0 ? 'Enlightened' : 'Resistance'; var teamClass = t==0 ? 'enl' : 'res'; var teamCol = t==0 ? COLORS[TEAM_ENL] : COLORS[TEAM_RES]; var barSize = Math.round(data.result.gameScore[t]/maxAverage*200); teamRow[t] = ''+team+''+digits(data.result.gameScore[t])+'
'; } var first = PLAYER.team == 'RESISTANCE' ? 1 : 0; // we need some divs to make the accordion work properly dlg.html('
' +'Region scores for '+data.result.regionName+'' +'
'+teamRow[first]+teamRow[1-first]+'
' +regionScoreboardScoreHistoryChart(data.result, logscale)+'
' +'Checkpoint overview' +'
'+regionScoreboardScoreHistoryTable(data.result)+'
' +'Top agents' +'
'+agentTable+'
' +'
'); $('g.checkpoint', dlg).each(function(i, elem) { elem = $(elem); var tooltip = 'CP:\t'+elem.attr('data-cp') + '\nEnl:\t' + digits(elem.attr('data-enl')) + '\nRes:\t' + digits(elem.attr('data-res')); elem.tooltip({ content: convertTextToTableMagic(tooltip), position: {my: "center bottom", at: "center top-10"} }); }); $('.cellscore', dlg).accordion({ header: 'b', heightStyle: "fill", }); $('input.logscale', dlg).change(function(){ var input = $(this); regionScoreboardSuccess(data, dlg, input.prop('checked')); }); }