# HG changeset patch # User IBBoard # Date 1496519654 -3600 # Node ID a803fabf200ef72124fa4a55d98fa48aee095dc2 # Parent 865243a387a54ae2a3a000878f20cedfba396439 Fix overflow for bee positions with lots of photos at one time diff -r 865243a387a5 -r a803fabf200e exif-graphr.js --- 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