javascript - Transitioning xAxis and data at the same time - D3.js -
i'm trying create sort of timeline chart using d3.js. i've got of control logic worked out data points aren't behaving expected move between pages. timeline shows 3 hour window of data collection lasting 1 week. user can click arrows @ left , right move forwards , backwards in 3 hour blocks.
as result of fetching next 3 hours worth of data on each click, expected exit() function contain of previous data points, because should leaving screen, doesn't seem happen. instead removes 5 of 10 points on first page. behaviour want not using exit() , manually forcing removal of points i'd rather understand why it's not working exit().
to complicate matters, data exits , enters chart transitioned in right left. @ same time transition domain bounds of xaxis give appearance of user moving forward in time. i'm starting suspect transition causing exit() function confused should , shouldn't on chart.
i've included section of code deals removal of elements exiting chart. let me know if other code snippets needed.
elements = svg.selectall('.news').data(data.items); // remove var exitinglabels = elements.exit(), updatinglabels = elements, creatinglabels = elements.enter(); console.log(exitinglabels.selectall('rect')); console.log(updatinglabels.selectall('rect')); console.log(creatinglabels); exitinglabels.selectall('circle') .transition() .duration(1500) .ease('sin-in-out') .attr('cx', function(d){return x($window.moment(d.date, 'yyyy-mm-ddthh:mm:ss.000z').clone().subtract(scope.zoomlevels[scope.zoomlevel].value, scope.zoomlevels[scope.zoomlevel].unit).format('x')) + 29;}); exitinglabels.selectall('line') .transition() .duration(1500) .ease('sin-in-out') .attr('x1', function(d){return x($window.moment(d.date, 'yyyy-mm-ddthh:mm:ss.000z').clone().subtract(scope.zoomlevels[scope.zoomlevel].value, scope.zoomlevels[scope.zoomlevel].unit).format('x')) + 29;}) .attr('x2', function(d){return x($window.moment(d.date, 'yyyy-mm-ddthh:mm:ss.000z').clone().subtract(scope.zoomlevels[scope.zoomlevel].value, scope.zoomlevels[scope.zoomlevel].unit).format('x')) + 29;}); exitinglabels.selectall('rect') .transition() .duration(1500) .ease('sin-in-out') .attr('x', function(d){return x($window.moment(d.date, 'yyyy-mm-ddthh:mm:ss.000z').clone().subtract(scope.zoomlevels[scope.zoomlevel].value, scope.zoomlevels[scope.zoomlevel].unit).format('x'));}); exitinglabels.selectall(function() { return this.getelementsbytagname('foreignobject'); }) .transition() .duration(1500) .ease('sin-in-out') .attr('x', function(d){return x($window.moment(d.date, 'yyyy-mm-ddthh:mm:ss.000z').clone().subtract(scope.zoomlevels[scope.zoomlevel].value, scope.zoomlevels[scope.zoomlevel].unit).format('x'));}); exitinglabels.transition() .delay(1600) .each('end', function(a){console.log(a);}) .remove(); data.items result of async call fetch new data, code within callback of function.
you need specify key function .data(), otherwise match index. e.g. .data(data.items, function(d) { return d; }) match actual data.
Comments
Post a Comment