我正在尝试使用ElkJS计算家谱的布局,并获得相当不错的结果。但是,我似乎无法使T型路口正常工作。
考虑一个有2个父母(P1, P2
)和3个孩子(P3, P4, P5
)的家庭。我添加了一个伪造的R1
节点,其大小为1x1,所有其他节点都连接到该节点,这是我正在使用的ELK JSON:
{
"id": "root",
"layoutOptions": {
"elk.algorithm": "layered",
"elk.direction": "DOWN",
"elk.edgeRouting": "ORTHOGONAL",
"elk.layered.mergeEdges": true
},
"children": [
{
"id": "P1",
"width": 100,
"height": 50,
"layoutOptions": { "elk.portConstraints": "FIXED_SIDE" },
"ports": [
{ "id": "P1:e", "layoutOptions": { "elk.port.side": "EAST" } },
{ "id": "P1:w", "layoutOptions": { "elk.port.side": "WEST" } }
]
},
{
"id": "P2",
"width": 100,
"height": 50,
"layoutOptions": { "elk.portConstraints": "FIXED_SIDE" },
"ports": [
{ "id": "P2:e", "layoutOptions": { "elk.port.side": "EAST" } },
{ "id": "P2:w", "layoutOptions": { "elk.port.side": "WEST" } }
]
},
{
"id": "P3",
"width": 100,
"height": 50,
"layoutOptions": { "elk.portConstraints": "FIXED_SIDE" },
"ports": [
{ "id": "P3:n", "layoutOptions": { "elk.port.side": "NORTH" } }
]
},
{
"id": "P4",
"width": 100,
"height": 50,
"layoutOptions": { "elk.portConstraints": "FIXED_SIDE" },
"ports": [
{ "id": "P4:n", "layoutOptions": { "elk.port.side": "NORTH" } }
]
},
{
"id": "P5",
"width": 100,
"height": 50,
"layoutOptions": { "elk.portConstraints": "FIXED_SIDE" },
"ports": [
{ "id": "P5:n", "layoutOptions": { "elk.port.side": "NORTH" } }
]
},
{
"id": "R1",
"width": 1,
"height": 1,
"layoutOptions": { "elk.portConstraints": "FIXED_SIDE" },
"ports": [
{ "id": "R1:n", "layoutOptions": { "elk.port.side": "NORTH" } },
{ "id": "R1:s", "layoutOptions": { "elk.port.side": "SOUTH" } }
]
}
],
"edges": [
{ "id": "E1", "sources": [ "P1:e" ], "targets": [ "R1:n" ] },
{ "id": "E2", "sources": [ "P2:w" ], "targets": [ "R1:n" ] },
{ "id": "E3", "sources": [ "R1:s" ], "targets": [ "P3:n" ] },
{ "id": "E4", "sources": [ "R1:s" ], "targets": [ "P4:n" ] },
{ "id": "E5", "sources": [ "R1:s" ], "targets": [ "P5:n" ] }
]
}
预期结果:
实际结果:
我正在实现一个从用户输入中绘制任意树的应用程序。因此,最佳解决方案不应依赖明确的端口侧规范。
是否可以解决此问题?
P。 S.与可视化工具一起使用JSON的有用链接:https://rtsys.informatik.uni-kiel.de/elklive/json.html