# HG changeset patch # User IBBoard # Date 1496073234 -3600 # Node ID 865243a387a54ae2a3a000878f20cedfba396439 # Parent 457823710044b58f47a807616fd9107953bf52e4 Make sure that we position the swarm correctly after each update diff -r 457823710044 -r 865243a387a5 exif-graphr.js --- a/exif-graphr.js Mon May 29 16:08:09 2017 +0100 +++ b/exif-graphr.js Mon May 29 16:53:54 2017 +0100 @@ -362,7 +362,10 @@ function update_beeswarm(photos) { var datedPhotos = photos.filter(function(d) { return d.timestamp != ''; }); - timelineScale.domain([d3.min(datedPhotos, function(val) { return new Date(val.timestamp); }), d3.max(datedPhotos, function(val) { return new Date(val.timestamp); })]); + var domain = [d3.min(datedPhotos, function(val) { return new Date(val.timestamp); }), d3.max(datedPhotos, function(val) { return new Date(val.timestamp); })]; + var domainSpread = domain[1].getTime() - domain[0].getTime(); + domain = [new Date(domain[0].getTime() - (domainSpread * 0.01)), new Date(domain[1].getTime() + (domainSpread * 0.01))]; + timelineScale.domain(domain); timelineAxes.call(timelineAxis); var swarm = d3.beeswarm() .data(datedPhotos) @@ -371,11 +374,12 @@ .orientation('horizontal') .side('symetric') .arrange(); - timelineNodes.selectAll('circle') - .data(swarm) - .enter() - .append('circle') + 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; }) + .attr('cy', function(bee) { return bee.y + 75; }) .attr('r', 4) } \ No newline at end of file