funny interaction between pv.Line and pv.Rule

10 views
Skip to first unread message

OliverM

unread,
Sep 8, 2010, 6:51:19 AM9/8/10
to protovis
Hi,

I'm new to protovis so amn't sure if I'm making a mistake or running
into a bug. I think the following code should show a line graph with a
horizontal rule at its base. Instead a vertical rule is added for
every point in the line. This is using protovis 3.2 on OS X in Safari
5 and Firefox 3.6. Strange behaviour is also seen when specifying
top(), left() or right(). If it is a bug I'll put it up on the
tracker.

Thanks,
Oliver.

var w = 150, h =150;
var tempScale = pv.Scale.linear(0, 12).range(0, h);
var tempVis = new pv.Panel()
.width(w)
.height(h)
.add(pv.Line)
.data([1, 1, 2, 3, 4, 2, 5, 7, 11])
.left(function() this.index * w/9)
.bottom(function(datum) tempScale(datum))
;
tempVis.add(pv.Rule)
.bottom(0);

tempVis.render();



Jason Davies

unread,
Sep 8, 2010, 11:37:10 AM9/8/10
to prot...@googlegroups.com
Hi Oliver,

On 8 Sep 2010, at 11:51, OliverM wrote:

> var w = 150, h =150;
> var tempScale = pv.Scale.linear(0, 12).range(0, h);
> var tempVis = new pv.Panel()
> .width(w)
> .height(h)
> .add(pv.Line)
> .data([1, 1, 2, 3, 4, 2, 5, 7, 11])
> .left(function() this.index * w/9)
> .bottom(function(datum) tempScale(datum))
> ;
> tempVis.add(pv.Rule)
> .bottom(0);
>
> tempVis.render();


Note that tempVis refers to the pv.Line mark added to the panel, hence 'tempVis.add(pv.Rule)' will inherit the properties of the pv.Line mark, and so will inherit its 'data' property too and will show for every datum. It also inherits the 'left' property, which is why vertical rules are showing rather than a horizontal one. To fix this you probably want something like:

var tempVis = new pv.Panel()
.width(w)

.height(h);

tempVis.add(pv.Line)


.data([1, 1, 2, 3, 4, 2, 5, 7, 11])
.left(function() this.index * w/9)
.bottom(function(datum) tempScale(datum));

tempVis.add(pv.Rule)
.bottom(0);

tempVis.render();

--
Jason Davies

www.jasondavies.com

OliverM

unread,
Sep 8, 2010, 1:50:36 PM9/8/10
to protovis
Hi Jason,

Thanks for your post - I just had a lightbulb moment as a result! I'd
not properly grasped the how the property chaining mechanism returned
the final version as you pointed out. Thanks! Hopefully things will
click now.

Oliver.
Reply all
Reply to author
Forward
0 new messages