tags:

views:

36

answers:

1

I'm using Protovis Arc layout and I'd like to color links between nodes accoriding to the 'value' property defined in dataset. How can I access it?

Dataset is defined like that: Nodes: ... {nodeName:"Books"} ...

Links: ... {source:1, target:4, value:20} ...

arc.link.add(pv.Line).strokeStyle(function(d) d.value > 10 ? "#cc0000" : "#eeeeee"); - does not work

+2  A: 

The d property refers to the node. There's no value attribute defined on the node in this case; the link weights are defined on the links, which is why the property function isn't doing what you expect.

You can rewrite your property function to access the link (rather than node) data. The link data is associated with the link's parent panel, and is available as the second argument:

.strokeStyle(function(d, p) p.value > 10 ? "#c00" : "#eee")

There's more of an explanation in the layout documentation. And see also the pv.Layout.Network API reference:

The link mark is added to a child panel, whose data property is defined as layout's links property. The link's data property is then a two-element array of the source node and target node. Thus, poperties such as strokeStyle and fillStyle can be overridden to compute properties from either the node data (the first argument) or the link data (the second argument; the parent panel data) dynamically.

mbostock