gpt4 book ai didi

protovis - 访问 Protovis 行中的值属性

转载 作者:行者123 更新时间:2023-12-02 19:14:23 26 4
gpt4 key购买 nike

我正在使用 Protovis Arc 布局,我想根据数据集中定义的“值”属性为节点之间的链接着色。我怎样才能访问它?

数据集定义如下:节点:...{nodeName:"书籍"}...

链接:...{源:1,目标:4,值:20}...

arc.link.add(pv.Line).StrokeStyle(function(d) d.value > 10 ? "#cc0000": "#eeeeee"); - 不起作用

最佳答案

d 属性指的是节点。在这种情况下,节点上没有定义value属性;链接权重是在链接上定义的,这就是属性函数没有执行您期望的操作的原因。

您可以重写属性函数来访问链接(而不是节点)数据。链接数据与链接的父面板关联,并可作为第二个参数使用:

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

layout documentation中有更多解释。另请参阅pv.Layout.Network API引用:

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.

关于protovis - 访问 Protovis 行中的值属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3031920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com