1

我的代码基于Force-Directed Layouts的 protovis 示例代码。我想添加根据链接的值使用滑块动态过滤链接的功能。我已经有一个基本的滑块工作。我不知道如何更新 Network 对象,以便仅呈现值大于滑块值的链接。有谁知道如何做到这一点?

创建图表的代码是

var minLinkValue = 2;
var vis = new pv.Panel()
    .width(w)
    .height(h)
    .fillStyle("white")
    .event("mousedown", pv.Behavior.pan())
    .event("mousewheel", pv.Behavior.zoom());

var force = vis.add(pv.Layout.Force);
force.nodes(grafica.nodes);
force.links(grafica.links.filter(function(d) { return d.value > minLinkValue} ));

force.link.add(pv.Line);

force.node.add(pv.Dot)
    .fillStyle(function(d) { return color(d) })         
    .strokeStyle(function() { return this.fillStyle().darker() })
    .lineWidth(1)
    .title(function(d) { return d.nodeName })
    .visible(function(d) { return d.linkDegree > 0 })
    .event("mousedown", pv.Behavior.drag());

vis.render();

我用 html5 创建滑块

<input type="range" min="0" max="20" value="2" step="1" onchange="setAndShowNewValue(this.value)" />
<span id="range">2</span>

并设置新的最小值

    function setAndShowNewValue(newValue)
    {
        document.getElementById("range").innerHTML=newValue;
        minLinkValue = newValue;
    }

谢谢,劳尔

4

1 回答 1

0

好的,答案在Protovis google group的一个帖子中

所以,我所做的是创建以下函数并在更新链接允许的最小值后调用它:

function filterLinks() { 
        force.links(grafica.links.filter(function(d) { return d.value > 
minLinkValue} )); 
        force.reset(); 
} 

然后我按照提到的线程中的建议修复了 protovis 中的代码

于 2011-03-17T23:29:21.350 回答