我正在尝试通过单击强制定向网络中的节点来更新条形图的内容。目前,我正在尝试将主面板上的“mousemove”事件与“point”事件一起使用,该事件会更新变量 activeNode,然后通知我希望访问哪一行。我在主面板中的点事件没有更新 activeNode 并且它始终设置为其默认值这一事实时遇到了麻烦。尝试到处寻找解决此问题的方法,但我认为我缺少一些更基本的概念。
这是代码...
var w = document.body.clientWidth,
h = document.body.clientHeight,
colors = pv.Colors.category19(),
activeNode = 0;
var vis = new pv.Panel()
.width(w)
.height(h)
.fillStyle("white")
.event("mousemove", pv.Behavior.point(Infinity));
var force = vis.add(pv.Layout.Force)
.width(w-200)
.nodes(miserables.nodes)
.links(miserables.links);
force.link.add(pv.Line);
force.node.add(pv.Dot)
.def("o",-1)
.size(function(d) (d.linkDegree + 10) * Math.pow(this.scale, -1.5))
.fillStyle(function(d) d.fix ? "brown" : colors(d.group))
.strokeStyle(function() this.fillStyle().darker())
.lineWidth(1)
.title(function(d) this.index)
.event("mousedown", pv.Behavior.drag())
.event("drag", force)
.event("point", function() {activeNode = this.index; return vis;});
vis.add(pv.Label).top(20).left(w/2).text("activeNode = " + activeNode);
vis.add(pv.Bar)
.data(topw[activeNode].splice(0))
.top(function(d) this.index * 30)
.left(w-80)
.width(15)
.height(20)
.anchor("left").add(pv.Label)
.textAlign("right")
.text(function(d) d[0]);
vis.render();