How does d3 handle concurrency issue?

41 views
Skip to first unread message

Kirti Bhardwaj

unread,
Nov 27, 2015, 12:52:05 PM11/27/15
to d3-js
I have a finalData = [obj,obj]

after each ajax call my data changes and on success I call my graph function.Now if I do a join on key, let us say d.date.

finalData at first call = [{date: 'x',value:'m'}]

finalData after second call = [{date: 'x',value:'m'}, {date:'y', value: 'n'}]

Now d3 will plot three lines for it if my second call is done before enter function is called.

How, do I make sure d3 plots two lines in all cases.

Is this solvable by using d3 itself?

peter royal

unread,
Nov 27, 2015, 12:55:34 PM11/27/15
to d3...@googlegroups.com, Kirti Bhardwaj

When calling selection.data, use the 2nd argument,

https://github.com/mbostock/d3/wiki/Selections#data

 

that argument is a function that should return a key for each data item (probably the date in your case)

 

that should prevent multiple lines.

 

-pete

--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

-- 
(peter.royal|osi)@pobox.com - http://fotap.org/~osi

Kirti Bhardwaj

unread,
Nov 27, 2015, 1:18:18 PM11/27/15
to d3-js, kirti.s...@gmail.com
I am using the second argument however, as you can see the index as well as value of key, which is definitely date in this case, is same.

And as the element has not been entered yet in first call, it goes on to enter the data for the same key again. 

that is, 

if var vis = d3.select('svg').selectAll('.line');

before first enter vis.length = 0;

and as second enter coincides with first, vis.length becomes 3 even though, two elements out of the have the same key value.

peter royal

unread,
Nov 27, 2015, 5:40:06 PM11/27/15
to d3...@googlegroups.com, kirti.s...@gmail.com
Can you provide some example code? Javascript is single-threaded so I’m confused as to how you’re having re-entracy problems

pete

Kirti Bhardwaj

unread,
Nov 28, 2015, 2:35:20 AM11/28/15
to d3-js, kirti.s...@gmail.com
Hey Pete,

This is what had me baffled too.
Finally, solved it, turns out a delay of 1000 ms on enter for transition was causing the issue.

Thanks a ton, much appreciated :)

Kirti
Reply all
Reply to author
Forward
0 new messages