I'm following the examples on http://adambom.github.io/parallel.js/
Example:
var p = new Parallel([0, 1, 2, 3, 4, 5, 6]),
log = function () { console.log(arguments); };
function fib(n) {
return n < 2 ? 1 : fib(n - 1) + fib(n - 2);
};
p.map(fib).then(log)
Works beautifully, now I want to apply the same concept on d3 objects.
I have a for loop that loops through a list of names:
for name in names by 1
// set some stuff
context = [....]
metrics = [....]
d3.select("#"+name)
.selectAll(".horizon")
.data(metrics).enter()
.insert("div", ".bottom")
.attr("class", "horizon")
.call context.horizon()
If I put the the content of the for loop in the function fib content it complains about "undefined d3 variable" ... but I feel like I'm missing the concept.
You can't parallelize the chain. There's nothing special about d3 here - when you chain calls, i.e. foo(a).bar(b).foobar(c)
it means that foo()
returns an object with method bar()
which in turn returns object with method foobar()
. This essentially means that you can't run foo()
and bar()
in parallel, because the latter requires result from the former.