Mercurial > hg > mood-conductor
diff mcserver/static/app.js @ 11:2c3fe4b24640
update python static folder
author | mgeorgi |
---|---|
date | Fri, 22 Jun 2012 11:24:19 +0100 |
parents | 180274c3b48a |
children | 49cfd3ad1fe7 |
line wrap: on
line diff
--- a/mcserver/static/app.js Fri Jun 22 11:01:34 2012 +0100 +++ b/mcserver/static/app.js Fri Jun 22 11:24:19 2012 +0100 @@ -4,12 +4,10 @@ this.marker = document.getElementById('marker'); this.label = document.getElementById('label'); - this.canvas.addEventListener('mousedown', this.onMouseDown.bind(this)); - this.canvas.addEventListener('mousemove', this.onMouseMove.bind(this)); - this.canvas.addEventListener('mouseup', this.onMouseUp.bind(this)); + this.canvas.addEventListener('click', this.onMouseUp.bind(this)); - this.request("/moods.csv", this.loadMoods.bind(this)); - this.background(); + this.request("/moodconductor/moods.csv", this.loadMoods.bind(this)); + this.draw(); }, tl: { r: 200, g: 0, b: 0 }, @@ -25,7 +23,7 @@ }; }, - background: function() { + draw: function() { var step = 20; var ctx = this.canvas.getContext("2d"); ctx.clearRect(0, 0, 320, 320); @@ -39,6 +37,8 @@ ctx.fillRect(x, y, step, step); } } + + ctx.beginPath(); ctx.strokeStyle = "rgb(0,0,0)"; ctx.moveTo(0, 160); ctx.lineTo(320, 160); @@ -72,6 +72,13 @@ ctx.font = "16px Arial"; ctx.fillText("Arousal", 0, 0); ctx.restore(); + + if (this.marker) { + ctx.fillStyle = "rgba(0, 0, 0, 0.5)"; + ctx.beginPath(); + ctx.arc(this.marker.x, this.marker.y, 20, 0, Math.PI*2, true); + ctx.fill(); + } }, loadMoods: function(text) { @@ -102,49 +109,34 @@ request.send(null); }, - onMouseDown: function(event) { - this.mouseDown = true; - this.setMarker(event.pageX, event.pageY); + onMouseUp: function(event) { + event.preventDefault(); + this.setMarker(event); + this.sendPosition(event); + this.draw(); }, - onMouseMove: function(event) { - if (this.mouseDown) { - this.setMarker(event.pageX, event.pageY); - } + sendPosition: function(event) { + var x = event.pageX / 320; + var y = 1 - event.pageY / 320; + + this.request("/moodconductor/mood?x=" + x + "&y=" + y); }, - onMouseUp: function(event) { - this.mouseDown = false; - this.setMarker(event.pageX, event.pageY); - this.sendPosition(event.pageX, event.pageY); - }, + setMarker: function(event) { + this.marker = { + x: event.pageX, + y: event.pageY + }; - sendPosition: function(pageX, pageY) { - var x = pageX / 320; - var y = 1 - pageY / 320; - this.request("/mood?x=" + x + "&y=" + y); - }, - - setMarker: function(pageX, pageY) { - this.background(); - this.drawMarker(pageX, pageY); - - var x = pageX / 320; - var y = 1 - pageY / 320; + var x = event.pageX / 320; + var y = 1 - event.pageY / 320; var mood = this.findMood(x, y); this.label.innerHTML = mood.label; this.mood = mood; }, - - drawMarker: function(x, y) { - var ctx = this.canvas.getContext("2d"); - ctx.fillStyle = "rgba(0, 0, 0, 0.5)"; - ctx.beginPath(); - ctx.arc(x, y, 20, 0, Math.PI*2, true); - ctx.fill(); - }, findMood: function(x, y) { var distance = 1;