Mercurial > repos > other > exif-graphr
changeset 6:865243a387a5
Make sure that we position the swarm correctly after each update
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 29 May 2017 16:53:54 +0100 |
parents | 457823710044 |
children | a803fabf200e |
files | exif-graphr.js |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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