【发布时间】:2011-07-28 00:10:03
【问题描述】:
我是 javascript 编码的新手 - 任何人都可以帮助我使用 InfoVis Spacetree 吗?我正在尝试将某个级别节点的宽度和高度设置为小于其余节点。好像我把它放在数据中:{} 但是当我尝试data:{"$height":"30"} 时,它搞砸了整棵树......
【问题讨论】:
标签: javascript coding-style infovis thejit space-tree
我是 javascript 编码的新手 - 任何人都可以帮助我使用 InfoVis Spacetree 吗?我正在尝试将某个级别节点的宽度和高度设置为小于其余节点。好像我把它放在数据中:{} 但是当我尝试data:{"$height":"30"} 时,它搞砸了整棵树......
【问题讨论】:
标签: javascript coding-style infovis thejit space-tree
像这样设置 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");
}
谢谢。
【讨论】:
我这样做的方式是在这些特殊节点的数据数组中放入一些信息,然后在绘制它的时候,我将只对这些节点进行修改。
数据:
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 Creation 的代码:
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 正在查看节点的数据以查看它是否是特殊的。然后你可以只修改这些节点。
【讨论】: