Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  43] [ 6]  / answers: 1 / hits: 13256  / 11 Years ago, mon, december 9, 2013, 12:00:00

I can change the value of the text with a smooth little tween, but every time I am emptying one svg and creating a new one. This eventually loads the DOM up with empty SVGs. How can I get rid of them?



D3:



var vis = d3.select(#visualisation),
commasFormatter = '$' + d3.format(,.0f),
numVis = d3.select(#defecit),
defTotal = d3.select(#defense);


function init () {
//Initialize mean text
numVis.append(text)
.attr(id, meantext)
.attr(y, 40)
.attr(x, 118)
.style(font-size, 26px)
.style(font-family,Arial, Helvetica, sans-serif)
.style('font-weight', 'bold')
.style('text-color', '#525252');

defTotal.append(text)
.attr(id, defense)
.attr(y, 0)
.attr(x, 0)
.style(font-size, 16px)
.style(font-family,Arial, Helvetica, sans-serif)
.style('font-weight', 'bold')
.style('text-color', '#525252');

d3.select(#meantext)
.transition()
.duration(500)
.ease('linear')
.tween(text, function() {
var i = d3.interpolate(this.textContent, dollars.value);
return function(t) {
this.textContent = '$' + d3.format(,)(Math.round(i(t)));
};
})

//Doing something like this didn't work - kept giving me an error that the object array had no exit function
d3.select(meantext).exit().remove()



}

More From » svg

 Answers
20

You can remove a specific element, do d3.select(#idOfElement).remove(). There's no need for .exit() here as no data is being matched and bound.


[#49694] Sunday, December 8, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raveno

Total Points: 453
Total Questions: 92
Total Answers: 92

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
raveno questions
;