我是javascript编程的新手--有没有人能帮助我使用InfoVis Spacetree?我正在尝试将某个级别的节点的宽度和高度设置为比其他级别的节点小。看起来我把它放在了数据中:{},但当我尝试data:{"$height":"30"}时,它搞砸了整个树……
发布于 2011-05-05 22:54:21
我这样做的方式,是把一些信息放在这些特殊节点的数据数组中,然后在绘制它的时候,我将只在这些节点上进行修改。
数据:
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的代码,它将处理特殊节点:
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正在查看节点的数据,以确定它是否是一个特殊的数据。则只能修改这些节点。
发布于 2012-01-09 17:49:51
如下所示设置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的高度以适应整个图形。我使用方向作为'top‘。
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");
}谢谢。
https://stackoverflow.com/questions/5519097
复制相似问题