1
我試圖通過單擊強制定向網絡中的節點來更新條形圖的內容。目前,我試圖在主面板上使用「點」事件來更新變量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();
謝謝 - 你們或多或少都是原初大師我在很多這些問題上看到你。 – shigeta 2011-07-09 04:50:05
@shigeta - 我看到你無恥的努力讓我回答你的其他Protovis問題:)。顯然它有效 - 爲奉承獲得一分。 – nrabinowitz 2011-07-09 14:59:33