首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript InfoVis Spacetree单个节点样式

Javascript InfoVis Spacetree单个节点样式
EN

Stack Overflow用户
提问于 2011-04-02 05:29:20
回答 2查看 4.9K关注 0票数 2

我是javascript编程的新手--有没有人能帮助我使用InfoVis Spacetree?我正在尝试将某个级别的节点的宽度和高度设置为比其他级别的节点小。看起来我把它放在了数据中:{},但当我尝试data:{"$height":"30"}时,它搞砸了整个树……

EN

回答 2

Stack Overflow用户

发布于 2011-05-05 22:54:21

我这样做的方式,是把一些信息放在这些特殊节点的数据数组中,然后在绘制它的时候,我将只在这些节点上进行修改。

数据:

代码语言:javascript
复制
var json = 
{
    'id':'id0.0',  
    'name':'Root',  
    'data':
    {
        'mytype':'1'
    }, 

    'children':
    [
        {
            'id':'id1.0',  
            'name':'Node 1.0', 
            'data':
            {
                'mytype':'2'
            }, 

            'children':
            [
                {
                    'id':'id2.0',  
                    'name':'Node 2.0'
                }, 

                {
                    'id':'id2.1',  
                    'name':'Node 2.1'
                }, 

                {
                    'id':'id2.2',  
                    'name':'Node 2.2'
                }
            ]
        }
    ]
};

因此,您可以看到一些节点具有名为mytype的数据元素,在绘制树时,您必须注意这些数据元素。为此,您必须实现onBeforePlotNode函数。此方法对于在打印前更改节点样式非常有用。

下面是创建SpaceTree的代码,它将处理特殊节点:

代码语言:javascript
复制
myTree = new $jit.ST({
    //id of viz container element
    injectInto: 'MyGraph',
    orientation: 'top',
    duration: 200,
    transition: $jit.Trans.Quart.easeInOut,
    levelDistance: 50,


    //enable panning
    Navigation: 
    {
      enable:true,
      panning:true,
      zooming:20
    },


    //set node and edge styles
    //set overridable=true for styling individual
    //nodes or edges
    Node: {
        overridable: true,  
        autoWidth: true,  
        autoHeight: true,  
        type: 'rectangle'  
    },

    Edge: {
        type: 'bezier',
        overridable: true
    },


    onBeforePlotNode: function(node)
    {
        //if(node.data.class == 'node') 
        if(node.data.mytype == '2') 
        {
            node.data.$height = 60;                    
        }
    },
});

您可以看到OnBeforePlotNode正在查看节点的数据,以确定它是否是一个特殊的数据。则只能修改这些节点。

票数 6
EN

Stack Overflow用户

发布于 2012-01-09 17:49:51

如下所示设置offSetX和offSetY位置:

代码语言:javascript
复制
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的高度以适应整个图形。我使用方向作为'top‘。

代码语言:javascript
复制
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");
    }

谢谢。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5519097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档