From c5ed07b74a245801d7fef0bfe2210003f6b8eb42 Mon Sep 17 00:00:00 2001 From: fkloft Date: Mon, 5 Jan 2015 16:18:57 +0100 Subject: [PATCH] Implement logarithmic scale for region scores @jonatkins You mentioned some devices not supporting Math.log10. This ships a custom implementation. Could you verify that this works? --- code/region_scoreboard.js | 54 +++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/code/region_scoreboard.js b/code/region_scoreboard.js index 1617c743..44829a07 100755 --- a/code/region_scoreboard.js +++ b/code/region_scoreboard.js @@ -18,9 +18,12 @@ function regionScoreboardFailure(dlg) { } -function regionScoreboardScoreHistoryChart(result) { +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; i (max/2)) { - vtickStep /= 2; + 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); + } } - for (var i=vtickStep; i<=max; i+=vtickStep) { + 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 += ';' @@ -102,6 +118,9 @@ function regionScoreboardScoreHistoryChart(result) { +'' +paths +otherSvg.join('') + +'' +''; return svg; @@ -119,13 +138,11 @@ function regionScoreboardScoreHistoryTable(result) { return table; } -function regionScoreboardSuccess(data,dlg) { +function regionScoreboardSuccess(data,dlg,logscale) { if (data.result === undefined) { return regionScoreboardFailure(dlg); } - - var agentTable = ''; for (var i=0; i' +'Region scores for '+data.result.regionName+'' +'
#Agent
'+teamRow[first]+teamRow[1-first]+'
' - +regionScoreboardScoreHistoryChart(data.result)+'' + +regionScoreboardScoreHistoryChart(data.result, logscale)+'' +'Checkpoint overview' +'
'+regionScoreboardScoreHistoryTable(data.result)+'
' +'Top agents' @@ -163,12 +180,10 @@ function regionScoreboardSuccess(data,dlg) { $('g.checkpoint', dlg).each(function(i, elem) { elem = $(elem); - console.log(elem.children()[0]); var tooltip = 'CP:\t'+elem.attr('data-cp') + '\nEnl:\t' + digits(elem.attr('data-enl')) + '\nRes:\t' + digits(elem.attr('data-res')); - console.log(tooltip); elem.tooltip({ content: convertTextToTableMagic(tooltip), position: {my: "center bottom", at: "center top-10"} @@ -179,4 +194,9 @@ function regionScoreboardSuccess(data,dlg) { header: 'b', heightStyle: "fill", }); + + $('foreignObject input', dlg).change(function(){ + var input = $(this); + regionScoreboardSuccess(data, dlg, input.prop('checked')); + }); }