diff --git a/data/clock.js b/data/clock.js index 16313d1..35cc30c 100644 --- a/data/clock.js +++ b/data/clock.js @@ -40,8 +40,7 @@ function onInit(connections){ }); vizcanvas.setAttribute('viewBox', '-350 -495 700 500'); drawTimes(); - drawText(); - drawTimerHand(); + updateTime(); connections.forEach(function(connection){ onConnection(connection); }); @@ -107,7 +106,7 @@ function onConnection(connection){ function onRemove(){ clearTimeout(handTimer); - clock.timeslots = {}; + clock.timeslots = new Array(96); resetCanvas(); }; @@ -193,16 +192,28 @@ function drawTimes(){ } function drawText(){ - vizcanvas.appendChild(svg('text', { - x: 0, - y: -80, - 'class': 'clock-time' - }, timeNow())); - vizcanvas.appendChild(svg('text', { - x: 0, - y: -40, - 'class': 'clock-date' - }, dateNow())); + var clocktime = document.querySelector('.clock-time'); + if (!clocktime){ + clocktime = svg('text', { + x: 0, + y: -80, + 'class': 'clock-time' + }, timeNow()); + vizcanvas.appendChild(clocktime); + }else{ + clocktime.firstChild.data = timeNow(); + } + var clockdate = document.querySelector('.clock-date'); + if (!clockdate){ + clockdate = svg('text', { + x: 0, + y: -40, + 'class': 'clock-date' + }, dateNow()); + vizcanvas.appendChild(clockdate); + }else{ + clockdate.firstChild.data = dateNow(); + } } function timeNow(){ @@ -246,17 +257,17 @@ function fadeEarlierTrackers(currentBucketIdx){ } } -var handTimer = null; +var clockTimer = null; var lastBucket = null; function drawTimerHand(time){ + console.log('drawTimerHand'); if (!time) time = new Date(); var hand = document.getElementById('timerhand'); if (!hand){ var hand = svg('g', {id: 'timerhand'}); hand.appendChild(svg('line', {x1: 0, y1: 0, x2: 400, y2: 0})); hand.appendChild(svg('path', {d: 'M47,-8 L47,8 73,5 73,-5 Z'})); - vizcanvas.appendChild(hand); } vizcanvas.appendChild(hand); if (!lastBucket){ @@ -267,9 +278,13 @@ function drawTimerHand(time){ fadeEarlierTrackers(lastBucket); } hand.setAttribute('transform', 'rotate(' + (timeToAngle(time) - 180) + ' ' + CENTRE + ') ' + HAND_TRANS); - handTimer = setTimeout(drawTimerHand, 1000); } +function updateTime(){ + drawTimerHand(); + drawText(); + clockTimer = setTimeout(updateTime, 1000); +} })(visualizations); diff --git a/package.json b/package.json index e609272..02e9e0a 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,6 @@ "description": "Testing a clean rewrite of Collusion", "author": "Dethe Elza", "license": "MPL 2.0", - "version": "0.31", + "version": "0.8", "id": "jid1-7OBiDHPW1YAPaQ" }