【问题标题】:Javascript InfoVis SpaceTree: prevent the selected node centering on the canvassJavascript InfoVis SpaceTree:防止选定节点以画布为中心
【发布时间】:2010-12-11 18:08:54
【问题描述】:

我正在使用 Javascript InfoVis SpaceTree。我有一棵如下所示的树:

但是我想选择“NOW”节点,以便它突出显示返回根节点的路径,但防止该节点居中。即:

我试过setPos(),但这不起作用。

有什么想法吗?

这是一个 github 存储库,其中包含完整的、独立的源代码副本(遗憾的是,自从我最初提出这个问题以来,我的网站已经消失了):

https://github.com/kevinkenny/so4418163

在示例中,文件ex2.html 包含生成第一张图像的标记,ex3.html 包含呈现底部图像的标记。

【问题讨论】:

  • 我会放几个截图,这样这个问题就不会因为我的意外链接腐烂而变得无用。
  • 如果链接没有损坏.. *sigh*.. 有完全相同的问题,但因为我不知道groupthatgeom 指的是下面,这个问题已经死在水里了。
  • 给我一个小时左右,可能需要一些跟踪。
  • 哈哈,是的,老实说,我什至没想到有人会回头看看这篇文章有多老。更不用说你真的找到了代码,真正的荣誉!它帮助了很多!您对帖子的更改足以让我将其更改为赞成票,也非常感谢您的帮助! :)
  • 工厂。很高兴这能有所帮助。虽然伊沃(见他的回答)是真正的英雄,他把我从失败的重力井中拉了出来。

标签: javascript visualization charts infovis


【解决方案1】:

啊,图库又搞砸了:D

让我们再看看那个 select 函数,特别是 onComplete 回调:

onComplete: function(){ // what a mess!
    group.hide(group.prepare(getNodesToHide.call(that)), complete); // hide the nodes???
    geom.setRightLevelToShow(node, canvas); // guess what this already moves stuff around!
    that.compute("current"); // recomputes the graphs position
    that.graph.eachNode(function(n) { // sets up the moved node positions
        var pos = n.pos.getc(true);
        n.startPos.setc(pos.x, pos.y);
        n.endPos.setc(pos.x, pos.y);
        n.visited = false; 
    });

    // hey look! We don't use a global translation offset! So we need to translate the HTML stuff extra
    var offset = { x: complete.offsetX, y: complete.offsetY };
    that.geom.translate(node.endPos.add(offset).$scale(-1), ["start", "current", "end"]);

    // show the nodes again?
    group.show(getNodesToShow.call(that));              

    // the first useful call in here, redraw the updated graph!
    that.plot();
    complete.onAfterCompute(that.clickedNode); // callback better leave them here
    complete.onComplete();
}

因此,既然您根本不想要任何重新定位,我们可以重构(也称为删除某些行)它:

onComplete: function(){             
    that.plot();
    complete.onAfterCompute(that.clickedNode);
    complete.onComplete();
}

看,妈!我节省了大量字节!!!这就是所有需要的休息对图表没有任何重要作用。

当然,只是去掉这个功能可能有一天会让你反胃,所以我们应该在select 中添加一个center 参数:

select: function(id, center, onComplete) {

....

onComplete: function(){
    if (center) {
        group.hide(group.prepare(getNodesToHide.call(that)), complete);
        geom.setRightLevelToShow(node, canvas);
        that.compute("current");
        that.graph.eachNode(function(n) { 
            var pos = n.pos.getc(true);
            n.startPos.setc(pos.x, pos.y);
            n.endPos.setc(pos.x, pos.y);
            n.visited = false; 
        });
        var offset = { x: complete.offsetX, y: complete.offsetY };
        that.geom.translate(node.endPos.add(offset).$scale(-1), ["start", "current", "end"]);
    }
    group.show(getNodesToShow.call(that));              
    that.plot();
    complete.onAfterCompute(that.clickedNode);
    complete.onComplete();
}

【讨论】:

    【解决方案2】:

    像这样设置 offSetX 和 offSetY 位置:

    var st = new $jit.ST({
        'injectInto': 'infovis',
        //set duration for the animation
        duration: 800,
        //set animation transition type
        transition: $jit.Trans.Quart.easeInOut,
        //set distance between node and its children
        levelDistance: 50,
        //set max levels to show. Useful when used with
        //the request method for requesting trees of specific depth
        levelsToShow: 4,
        orientation: 'top',
        align: 'center',
        //set node and edge styles
        //set overridable=true for styling individual
        //nodes or edges 
        offsetX: 0, offsetY: 110,
        Node: {
            height: 30,
            width: 31,
            //use a custom
            //node rendering function
            type: 'nodeline',
            color: '#f76b14',
            lineWidth: 1,
            align: "center",
            overridable: true
        },
    

    infovis div,即保存空间树的 div 有时不会显示整个图表。 在 onComplete 事件中添加以下代码就可以了。

    这将设置 div 的高度以适应整个图表。 我将方向用作“顶部”。

    onComplete: function () {
            var LastnodeTop = 0;
            $("div.node").each(function () {
                var pos = $(this).position();
                if (pos.top > LastnodeTop)
                    LastnodeTop = pos.top;
            });
            var LastnodeTopStr = LastnodeTop.toString();
            LastnodeTopStr = LastnodeTopStr.substring(0, 4);
            var LastnodeTopInt = parseInt(LastnodeTopStr) + 100;            
            $("#infovis").attr("style", "height:" + LastnodeTopInt + "px");
        }
    

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-03
      • 2011-07-28
      • 2014-08-03
      • 2012-03-27
      • 2012-04-05
      • 2013-05-07
      • 2011-05-26
      • 2014-06-29
      相关资源
      最近更新 更多