Using function as parameter to method

6 views
Skip to first unread message

robin girard

unread,
Dec 21, 2010, 2:00:43 PM12/21/10
to webvis
Hi all,
There not much I understand but I don't realise how it is possible to
put a function as a parameter to a method as
in the line .strokeStyle(function(d) d ? "#eee" : "#000") below. A
good start could be to be able to reproduce (without specifying the
successive lines 'by hands' or one by one...) the figure that arises
from the code below....

any idea ?

Best regards
Robin


/* Sizing and scales. */
var w = 400,
h = 200,
x = pv.Scale.linear(data, function(d) d.x).range(0, w),
y = pv.Scale.linear(0, 4).range(0, h);

/* The root panel. */
var vis = new pv.Panel()
.width(w)
.height(h)
.bottom(20)
.left(20)
.right(10)
.top(5);

/* Y-axis and ticks. */
vis.add(pv.Rule)
.data(y.ticks(5))
.bottom(y)
.strokeStyle(function(d) d ? "#eee" : "#000")
.anchor("left").add(pv.Label)
.text(y.tickFormat);
Reply all
Reply to author
Forward
0 new messages