Have cycling option for scoreboard

This commit is contained in:
Neale Pickett 2010-09-09 16:51:11 -06:00
parent fd8f53dae3
commit 7aa23aadb5
2 changed files with 24 additions and 7 deletions

View File

@ -95,7 +95,7 @@ BEGIN {
# Get team colors and names # Get team colors and names
for (team in teams) { for (team in teams) {
fn = "/var/lib/ctf/teams/colors/" team ".color" fn = "/var/lib/ctf/teams/colors/" team
getline colors_by_team[team] < fn getline colors_by_team[team] < fn
close(fn) close(fn)
@ -129,12 +129,12 @@ BEGIN {
# Provide raw data for the chart # Provide raw data for the chart
print " <script type=\"application/javascript\">" print " <script type=\"application/javascript\">"
print "function draw() {" print "function init() {"
printf("plot(\"chart\", %d, %.2f, {\n", tslen, maxscore) printf(" plot(\"chart\", %d, %.2f, {\n", tslen, maxscore)
c = 0 c = 0
for (team in teams) { for (team in teams) {
if (maxscores_by_team[team] / maxscore < 0.01) continue if (maxscores_by_team[team] / maxscore < 0.01) continue
printf("\"%s\": [\"#%s\",[", team, colors_by_team[team]) printf(" \"%s\": [\"#%s\",[", team, colors_by_team[team])
for (i = 1; i < tslen; i += 1) { for (i = 1; i < tslen; i += 1) {
time = timestamps[i] time = timestamps[i]
printf("[%d,%.2f],", printf("[%d,%.2f],",
@ -142,9 +142,13 @@ BEGIN {
} }
printf("]],\n"); printf("]],\n");
} }
print "});" print " });"
print " if (location.hash) {"
print " cycle();"
print " setInterval(cycle, 10000);"
print " }"
print "}" print "}"
print "window.onload = draw;" print "window.onload = init;"
print " </script>" print " </script>"
# Set up team colors and a few page-specific styles # Set up team colors and a few page-specific styles
@ -161,7 +165,7 @@ BEGIN {
print " <body>" print " <body>"
print " <h1>Scoreboard</h1>" print " <h1>Scoreboard</h1>"
print "<p id=\"debug\"></p>" print "<p id=\"debug\"></p>"
print " <table class=\"scoreboard\">" print " <table id=\"scoreboard\">"
print " <tr>" print " <tr>"
print " <th>Overall</th>" print " <th>Overall</th>"

View File

@ -105,3 +105,16 @@ function restore(cls) {
} }
var state = 0;
function cycle() {
if (state == 0) {
v = document.getElementById("scoreboard");
i = document.getElementById("chart");
} else {
v = document.getElementById("chart");
i = document.getElementById("scoreboard");
}
v.style.display = "block";
i.style.display = "none";
state = (state + 1) % 2;
}