我的代码基于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;
}
谢谢,劳尔