summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/scheduling/elimination.rb56
1 files changed, 32 insertions, 24 deletions
diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb
index 1ac696d..ca48f14 100644
--- a/lib/scheduling/elimination.rb
+++ b/lib/scheduling/elimination.rb
@@ -51,10 +51,16 @@ module Scheduling
def graph(current_user)
matches = @tournament_stage.matches_ordered
+ numTeams = @tournament_stage.tournament.min_teams_per_match
+ logBase = numTeams
+
# depth of SVG tree
- depth = Math.log2(matches.count).floor+1;
+ depth = Math.log(matches.count*(logBase-1),logBase).floor+1;
+
# height of SVG
- height = [200 * 2**Math.log2(matches.count).floor + 100, 500].max;
+ matchHeight = 50*logBase;
+ height = [(matchHeight+50) * logBase**(depth-1) + 100, 500].max;
+
lastrx = 0
lastry = 0
lastrh = 0
@@ -73,10 +79,12 @@ module Scheduling
</defs>
STRING
(1..matches.count).each do |i|
- rh = 100/(2**(depth-1)+1) - 5
+ matchDepth = Math.log(i*(logBase-1), logBase).floor+1
+ base = (logBase**(matchDepth-1)/(logBase-1)).ceil
+ rh = 100 / (logBase**(depth-1)+1) - 100/height;
rw = 100/(depth+1) - 5
- rx = 50/(depth+1) + 100/(depth+1)*(depth-(Math.log2(i).floor+1))
- ry = ( 100/(2**(Math.log2(i).floor)+1) + rh * 1.1 * (2**Math.log2(i).ceil-i))
+ rx = 50/(depth+1) + 100/(depth+1)*(depth-matchDepth)
+ ry = 100/(logBase**(matchDepth-1)+1) * (i-base+1) - rh/2
str += "\t<a id=\"svg-match-#{i}\" xlink:href=\"#{match_path(matches[i])}\"><g>\n"
str += "\t\t<rect height=\"#{rh}%\" width=\"#{rw}%\" x=\"#{rx}%\" y=\"#{ry}%\" fill=\"url(#gradMatch)\" rx=\"5px\" stroke-width=\"2\""
@@ -95,30 +103,29 @@ STRING
when 3
str += ' stroke="grey"'
end
- str += "/>\n"
- color = (matches[i].teams[0] and matches[i].teams[0].users.include?(current_user)) ? "#BCED91" : "white"
- str += "\t\t<rect width=\"#{rw-5}%\" height=\"#{rh/4}%\" x=\"#{rx + 2.5}%\" y=\"#{ry + rh/6}%\" fill=\"#{color}\" />\n"
- if matches[i].teams.first
- str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + rh/3}%\" font-size=\"#{rh}\">Team #{matches[i].teams.first.id}</text>\n"
- end
-
- str += "\t\t<text x=\"#{rx + 1.3*rw/3}%\" y=\"#{ry + 5.2*rh/9}%\" font-size=\"#{rh}\"> VS </text>\n"
+ str += "/>\n"
- color = (matches[i].teams[1] and matches[i].teams[1].users.include?(current_user)) ? "#BCED91" : "white"
- str += "\t\t<rect width=\"#{rw-5}%\" height=\"#{rh/4}%\" x=\"#{rx + 2.5}%\" y=\"#{ry + 3*rh/5}%\" fill=\"#{color}\" />\n"
- if matches[i].teams[1]
- str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + 4*rh/5}%\" font-size=\"#{rh}\">Team #{matches[i].teams[1].id}</text>\n"
+ t = 1
+ while t <= numTeams
+ color = (matches[i].teams[t-1] and matches[i].teams[t-1].users.include?(current_user)) ? "#BCED91" : "white"
+ str += "\t\t<rect width=\"#{rw-5}%\" height=\"#{rh*Float(30)/(matchHeight)}%\" x=\"#{rx + 2.5}%\" y=\"#{ry + (Float(t-1)/numTeams)*rh + 2 }%\" fill=\"#{color}\" />\n"
+ if matches[i].teams[t-1]
+ str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + (Float(t-1)/numTeams + Float(30)/(matchHeight))*rh}%\" font-size=\"#{rh}\">Team #{matches[i].teams[t-1].id}</text>\n"
+ end
+ if (t < numTeams)
+ str += "\t\t<text x=\"#{rx + 1.3*rw/3}%\" y=\"#{ry + (Float(20+35*(t))/matchHeight)*rh}%\" font-size=\"#{rh}\"> VS </text>\n"
+ end
+ t = t + 1
end
if i > 1
- str += "\t\t<line x1=\"#{rx+rw}%\" y1=\"#{ry+rh/2}%\" x2=\"#{lastrx}%\" y2=\"#{lastry+lastrh/2}%\" stroke=\"black\" stroke-width=\"2\" >\n"
- end
- if Math.log2(i+1) == Math.log2(i+1).ceil
- lastrx = rx
- lastry = ry
- lastrh = rh
- lastrw = rw
+ parent = (i+logBase-2)/logBase
+ pDepth = Math.log(parent*(logBase-1), logBase).floor+1
+ pBase = (logBase**(pDepth-1)/(logBase-1)).ceil
+ lastrx = 50/(depth+1) + 100/(depth+1)*(depth-pDepth)
+ lastry = 100/(logBase**(pDepth-1)+1) * (parent-pBase+1) - rh/2
+ str += "\t\t<line x1=\"#{rx+rw}%\" y1=\"#{ry+rh/2}%\" x2=\"#{lastrx}%\" y2=\"#{lastry+rh/2}%\" stroke=\"white\" stroke-width=\"2\" >\n"
end
str += "</g></a>\n"
end
@@ -126,5 +133,6 @@ STRING
return str
end
+
end
end