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); window.postAjax('getRegionScoreDetails', {latE6:latE6,lngE6:lngE6}, regionScoreboardSuccess, regionScoreboardFailure); } function regionScoreboardFailure() { dialog({ title: 'Error loading region scores', text: 'Failed to load region scores - try again' }); } function regionScoreboardScoreHistoryChart(result) { // svg area 400x130. graph area 350x100, offset to 40,10 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 for (var t=0; t<2; t++) { var col = t==0 ? COLORS[TEAM_ENL] : COLORS[TEAM_RES]; 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))); // 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) { 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 regionScoreboardSuccess(data) { if (data.result === undefined) { return regionScoreboardFailure(); } // var checkpointTable = ''; // for (var i=0; i'; // } // if (data.result.scoreHistory.length == 0) { // checkpointTable += ''; // } // checkpointTable += '
#EnlightenedResistance
'+data.result.scoreHistory[i][1]+''+data.result.scoreHistory[i][2]+'
no checkpoint data
'; var agentTable = ''; for (var i=0; i'; } if (data.result.topAgents.length==0) { agentTable += ''; } agentTable += '
#Agent
'+agent.nick+'
no top agents
'; dialog({ title: 'Region scores for '+data.result.regionName, html: 'Region scores for '+data.result.regionName+'' +'
EnlightenedResistance
'+digits(data.result.gameScore[0])+''+digits(data.result.gameScore[1])+'
' +'Checkpoint history' +regionScoreboardScoreHistoryChart(data.result) +'Top agents' +agentTable, width: 450 }); }