开发者

Scaling in protovis when using Layout.Force

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 +开发者_C百科 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>


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));

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜