使用 Layout.Force 时在原型中缩放
我正在使用 protovis 网站上找到的示例来显示图形的节点 http://vis .stanford.edu/protovis/ex/force.html
例如,我根本无法使用 2 倍缩放来初始化图形,因此启动时它看起来不会那么小。
<script type="text/javascript+protovis">
var w = document.body.clientWidth,
h = document.body.clientHeight,
colors = pv.Colors.category19();
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)
.nodes(miserables.nodes)
.links(miserables.links);
force.link.add(pv.Line);
force.node.add(pv.Dot)
.size(function(d) (d.linkDegree + 4) * 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) d.nodeName)
.event("mousedown", pv.Behavior.drag())
.event("drag", force);
vis.render();
</script>
I am using the example found on protovis site to display the nodes of a graph http://vis.stanford.edu/protovis/ex/force.html
I simply cannot initialize the graph with a zoom of 2x for example, so it won't look that small when started.
<script type="text/javascript+protovis">
var w = document.body.clientWidth,
h = document.body.clientHeight,
colors = pv.Colors.category19();
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)
.nodes(miserables.nodes)
.links(miserables.links);
force.link.add(pv.Line);
force.node.add(pv.Dot)
.size(function(d) (d.linkDegree + 4) * 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) d.nodeName)
.event("mousedown", pv.Behavior.drag())
.event("drag", force);
vis.render();
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须按照所述使用 pv.Panel 的 Transform() 方法
vis.transform(pv.Transform.identity.scale(2));
You'll have to use the transform() method of pv.Panel as described here. Put the following line right behind
vis.render();
, it should work. Maybe you'll need to translate it additionally though.vis.transform(pv.Transform.identity.scale(2));