From 9b59a5e88ee687229a982f4daa18890962e5c706 Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 10 Dec 2010 18:34:02 +0100 Subject: [PATCH] nedap poll feedback in frontend --- index.html | 5 ++++- quiz.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 721a3a3..d90812e 100644 --- a/index.html +++ b/index.html @@ -30,7 +30,10 @@

Welches Land erlaubt Filesharing für private Zwecke straffrei?

-
+
+

http://poll.c3d2.de/

+ +
    diff --git a/quiz.js b/quiz.js index 331d91f..b42c5b7 100644 --- a/quiz.js +++ b/quiz.js @@ -213,6 +213,66 @@ function takeJoker(activePlayer, joker) { sendToBackend({ nedap: { joker: { question: q.text, answers: q.answers } } }); + + $('#nedap').show(); + var scores = [0, 0, 0, 0]; + var redraw = function() { + var canvas = $('#polls')[0]; + var w = canvas.width, h = canvas.height; + var ctx = canvas.getContext('2d'); + ctx.fillStyle = '#20203f'; + ctx.fillRect(0, 0, w, h); + + var total = 0; + for(var i = 0; i < scores.length; i++) { + total += scores[i]; + } + if (total < 1) + total = 1; + + for(var i = 0; i < scores.length; i++) { + /* Bounds */ + var x1, y1, x2, y2; + if (i == 0 || i == 2) { + x1 = w * 0.05; + x2 = w * 0.45; + } + if (i == 1 || i == 3) { + x1 = w * 0.55; + x2 = w * 0.95; + } + if (i == 0 || i == 1) { + y1 = h * 0.05; + y2 = h * 0.45; + } + if (i == 2 || i == 3) { + y1 = h * 0.55; + y2 = h * 0.95; + } + + /* Fill */ + ctx.fillStyle = '#ccc'; + var barHeight = (y2 - y1) * scores[i] / total; +console.log({x1:x1,y1:y1,x2:x2,y2:y2,barHeight:barHeight}); + ctx.fillRect(x1, y2 - barHeight, x2 - x1, barHeight); + + /* Outline */ + ctx.strokeStyle = 'white'; + ctx.beginPath(); + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y1); + ctx.lineTo(x2, y2); + ctx.lineTo(x1, y2); + ctx.lineTo(x1, y1); + ctx.stroke(); + } + }; + onBackendMessage = function(msg) { + if (msg.nedap && msg.nedap.scores) + scores = msg.nedap.scores; +console.log('scores: '+JSON.stringify(scores)); + redraw(); + }; } } @@ -347,7 +407,8 @@ function switchToGame() { } }; - $('#polls').hide(); + $('#nedap').hide(); + onBackendMessage = null; // Instantly show the question: $('#game').show(); }