Javascript 在mxgraph中创建反向mxgraph分层布局
向社区致意!我目前正在创建一个自定义mxgraph编辑器,并使用不同的布局转换图形。我想将我的图形布局转换为Javascript 在mxgraph中创建反向mxgraph分层布局,javascript,mxgraph,jgraphx,jgraph,Javascript,Mxgraph,Jgraphx,Jgraph,向社区致意!我目前正在创建一个自定义mxgraph编辑器,并使用不同的布局转换图形。我想将我的图形布局转换为mxHierarchyCallayout,但相反(而不是自上而下,我希望它是自下而上)。我做什么和我想做什么的例子 我的图表 使用MXCallayout转换的我的图形 代码段: let layout=新布局(图形); 执行(graph.getDefaultParent()) 如何转换图形 我在MXHierarchyCallayout中发现有一个orientation成员变量,默认为“
mxHierarchyCallayout
,但相反(而不是自上而下
,我希望它是自下而上
)。我做什么和我想做什么的例子
我的图表
使用MXCallayout转换的我的图形
代码段:
let layout=新布局(图形);
执行(graph.getDefaultParent())代码>
如何转换图形
我在MXHierarchyCallayout中发现有一个orientation
成员变量,默认为“NORTH”。然而,当我尝试做以下事情时
let layout = new mxHierarchicalLayout(graph);
layout.orientation=mxConstants.DIRECTION_SOUTH;
layout.execute(graph.getDefaultParent());
图形超出了我的“画布”,无法查看以检查这是否是负责“反转”树的参数。有人能帮忙吗?提前谢谢
PS
当我使用layout.orientation=mxConstants.DIRECTION\u SOUTH代码>
布局似乎按照我的意愿进行了转换,但无法看到,因为svg元素的坐标为类型x=-10,y=-5(负数)
,有什么解决方法吗?已解决
我不知道为什么mxgraph在mxHierarchyCallAyout中具有orientation=south
的错误行为,但我成功地为我的问题创建了一个解决方案,因为我意识到新生成的布局将我的mxCell子对象放置在图形的北方(负y坐标)。所以我做的是在layout.execute(graph.getDefaultParent())之后代码>我获取图形的每个子元素,并检索最负的y坐标,然后将图形的所有单元格从其新坐标移动到一个新坐标,并以最负y坐标元素的绝对值递增
代码
function convertGraphToInverseHorizontalTree(){
let layout = new mxHierarchicalLayout(graph);
layout.orientation = mxConstants.DIRECTION_SOUTH;
layout.execute(graph.getDefaultParent());
graph.model.beginUpdate();
//get the most negative y
let mostNegativeY = getMostNegativeCoordinateY(graph);
let children = graph.getChildCells();
graph.moveCells(children, undefined , Math.abs(mostNegativeY));
graph.model.endUpdate();
}
function getMostNegativeCoordinateY(graph){
let children = graph.getChildCells();
let mostNegative = 10000;
for(let i = 0; i < children.length; i++){
if(children[i].geometry != undefined){
if(children[i].geometry.y < mostNegative){
mostNegative = children[i].geometry.y;
}
}
}
return mostNegative;
}
函数convertGraphToInverseHorizontalTree(){
让布局=新布局(图形);
layout.orientation=mxConstants.DIRECTION\u SOUTH;
执行(graph.getDefaultParent());
graph.model.beginUpdate();
//得到最负的y
设mostNegativeY=getMostNegativeCoordinateY(图);
让children=graph.getChildCells();
moveCells(children,未定义,Math.abs(mostNegativeY));
graph.model.endUpdate();
}
函数getMostNegativeCoordinateY(图形){
让children=graph.getChildCells();
设mostNegative=10000;
for(设i=0;i
现在图表是这样的