Mercurial > repos > other > exif-graphr
changeset 7:a803fabf200e
Fix overflow for bee positions with lots of photos at one time
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 03 Jun 2017 20:54:14 +0100 |
parents | 865243a387a5 |
children | 58bd10d0c78e |
files | exif-graphr.js |
diffstat | 1 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/exif-graphr.js Mon May 29 16:53:54 2017 +0100 +++ b/exif-graphr.js Sat Jun 03 20:54:14 2017 +0100 @@ -246,7 +246,9 @@ var timelineScale = d3.scaleTime().rangeRound([0,960]); var timelineAxis = d3.axisBottom(timelineScale); var timelineAxes = timeline.append("g").attr("transform", "translate(0,75)"); -var timelineNodes = timeline.append("g"); +var timelineNodes = timeline.append("g").attr("transform", "translate(0,75)"); +var furthestBee = -Infinity; +var maxBeeDistance = 70; function update() { var photos = []; @@ -374,12 +376,21 @@ .orientation('horizontal') .side('symetric') .arrange(); + furthestBee = d3.max(swarm, function(bee) { return Math.abs(bee.y);}); var nodes = timelineNodes.selectAll('circle') .data(swarm); nodes.exit().remove(); var newNodes = nodes.enter().append('circle'); nodes.merge(newNodes) .attr('cx', function(bee) { return bee.x; }) - .attr('cy', function(bee) { return bee.y + 75; }) + .attr('cy', function(bee) { return calculateBeeY(bee); }) .attr('r', 4) +} + +function calculateBeeY(bee) { + if (furthestBee < maxBeeDistance) { + return bee.y; + } else { + return bee.y % maxBeeDistance; + } } \ No newline at end of file