5

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

在此处输入图像描述

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

在此处输入图像描述

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

有任何想法吗?

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

https://github.com/kevinkenny/so4418163

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

4

2 回答 2

9

啊,那又把图形库搞砸了: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();
}

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

当然,仅仅摆脱这个功能可能有一天会让你反感,所以我们应该添加一个center参数select

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();
}
于 2010-12-11T18:18:23.887 回答
1

像这样设置 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");
    }

谢谢。

于 2012-01-09T09:33:21.410 回答