Sunday, 15 May 2011

javascript - d3.js using functions within d3.js-specific functions -



javascript - d3.js using functions within d3.js-specific functions -

i wondering if possible utilize functions within d3.js functions. clarify question, let's assume have colorscale

var colorscale = d3.scale.quantile() .domain([0,8]) .range(["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"]);

is there way create next work?

var colorscale = d3.scale.quantile() .domain([0,8]) .range(function(){return ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"]});

so returning entire argument function?

many knows!

thank explunit, lars , thomas

i have found adequate reply question though.

the reply is: yes it's possible , here how if know argument range going function:

var myfunction = function() {return ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"]} var colorscale = d3.scale.quantile() .domain([0,8]) .range(myfunction());

if not sure. can utilize d3.functor() work if pass value , not function. (if it's function):

var myfunction = function() {return ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"]} var myfunctionwrapped = d3.functor(myfunction); var colorscale = d3.scale.quantile() .domain([0,8]) .range(myfunctionwrapped());

and if value (or array):

var myfunction = ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"] var myfunctionwrapped = d3.functor(myfunction); var colorscale = d3.scale.quantile() .domain([0,8]) .range(myfunctionwrapped());

so recommend using d3.functor() since makes code more versatile.

javascript function d3.js visualization

No comments:

Post a Comment