Jonah
Jonah

Reputation: 16202

D3: callback function when selection operation completes?

I have a line graph that can have hundreds of simultaneous lines on it, like so:

many lines on graph

Sometimes a new line will be added that has a max value greater than the max value of any existing line, forcing a rescaling and forcing all existing lines to be redrawn. That means code as simple as:

updateSelection.attr("d", function(d) { return line(d) });

can take a few seconds to complete. So I'd like to display an "updating..." message to the user while the operation is occuring, and then remove the message when the operation is finished. But I don't see any way to attach an "onComplete" callback like this to the selection methods. Is this possible? If not, are there are any workarounds?

Upvotes: 1

Views: 264

Answers (1)

Kevin Schmid
Kevin Schmid

Reputation: 771

Append it before you begin to redraw the graph, and then remove it right after the lines of code that redraw the graph. Performing those operations with selections is synchronous.

Upvotes: 2

Related Questions