Javascript 使用Python创建/编辑mxgraph模型
是否可以使用Python创建、编辑mxgraph模型,或将其从JSON或XML数据转换为mxgraph格式?如果是这样的话,怎么做呢?我在不同的网站上搜索,但找不到解决方案(例如JSON数据) 没有一种“统一”的方法来使用mxgraph。。。您可以创建具有各种形状的各种类型的节点。。。MxGraph允许您以JSON和XML格式导入和导出图形,但首先需要创建一个与MxGraph兼容的JSON或XML格式的图形以供读取 在这里,您可以找到一个向JSON导入和从JSON导入代码的示例: 正如您在JSON中看到的,您需要指定节点的各个方面(几何体、父节点、边、可连接性等)。与XML类似 我不是Python方面的专家,但您应该做的是将JSON转换为MxGraph可以实际读取的内容 JSON示例:Javascript 使用Python创建/编辑mxgraph模型,javascript,python,python-3.x,mxgraph,Javascript,Python,Python 3.x,Mxgraph,是否可以使用Python创建、编辑mxgraph模型,或将其从JSON或XML数据转换为mxgraph格式?如果是这样的话,怎么做呢?我在不同的网站上搜索,但找不到解决方案(例如JSON数据) 没有一种“统一”的方法来使用mxgraph。。。您可以创建具有各种形状的各种类型的节点。。。MxGraph允许您以JSON和XML格式导入和导出图形,但首先需要创建一个与MxGraph兼容的JSON或XML格式的图形以供读取 在这里,您可以找到一个向JSON导入和从JSON导入代码的示例: 正如您在JS
{
"graph": [
{
"value": {
"name": "Daffy Duck"
},
"geometry": {
"x": 90,
"y": 60,
"width": 120,
"height": 30,
"relative": false,
"TRANSLATE_CONTROL_POINTS": true,
"alternateBounds": null,
"sourcePoint": null,
"targetPoint": null,
"points": null,
"offset": null
},
"id": "2",
"vertex": true,
"connectable": true,
"parent": "1",
"source": null,
"target": null,
"edges": [
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "4",
"edge": true,
"parent": "1",
"source": "2",
"target": "3",
"mxObjectId": "mxCell#7"
}
],
"mxObjectId": "mxCell#6"
},
{
"value": {
"name": "Bugs Bunny"
},
"geometry": {
"x": 1020,
"y": 60,
"width": 120,
"height": 30,
"relative": false,
"TRANSLATE_CONTROL_POINTS": true,
"alternateBounds": null,
"sourcePoint": null,
"targetPoint": null,
"points": null,
"offset": null
},
"id": "3",
"vertex": true,
"connectable": true,
"parent": "1",
"source": null,
"target": null,
"edges": [
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "4",
"edge": true,
"parent": "1",
"source": "2",
"target": "3",
"mxObjectId": "mxCell#7"
}
],
"mxObjectId": "mxCell#8"
},
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "4",
"edge": true,
"parent": "1",
"source": "2",
"target": "3",
"mxObjectId": "mxCell#7"
},
{
"value": {
"name": "Elmer Fudd"
},
"geometry": {
"x": 90,
"y": 220,
"width": 120,
"height": 30,
"relative": false,
"TRANSLATE_CONTROL_POINTS": true,
"alternateBounds": null,
"sourcePoint": null,
"targetPoint": null,
"points": null,
"offset": null
},
"id": "5",
"vertex": true,
"connectable": true,
"parent": "1",
"source": null,
"target": null,
"edges": [
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "7",
"edge": true,
"parent": "1",
"source": "5",
"target": "6",
"mxObjectId": "mxCell#10"
}
],
"mxObjectId": "mxCell#9"
},
{
"value": {
"name": "Tasmanian Devil"
},
"geometry": {
"x": 1020,
"y": 220,
"width": 120,
"height": 30,
"relative": false,
"TRANSLATE_CONTROL_POINTS": true,
"alternateBounds": null,
"sourcePoint": null,
"targetPoint": null,
"points": null,
"offset": null
},
"id": "6",
"vertex": true,
"connectable": true,
"parent": "1",
"source": null,
"target": null,
"edges": [
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "7",
"edge": true,
"parent": "1",
"source": "5",
"target": "6",
"mxObjectId": "mxCell#10"
}
],
"mxObjectId": "mxCell#11"
},
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "7",
"edge": true,
"parent": "1",
"source": "5",
"target": "6",
"mxObjectId": "mxCell#10"
}
]
}
谢谢你的回复!然而,我正在进行的项目需要一种类似蟒蛇的方式来完成。很好,如果有人能给出一个如何做到这一点的线索。有没有现成的方法可以做到这一点,或者我们必须用Python实现一个方法?有趣的是,我目前正在搜索相同的方法。考虑到mxGraph在前端,所以从DJANGO或Tornado中的API生成JSON应该很容易@marco谢谢
{
"graph": [
{
"value": {
"name": "Daffy Duck"
},
"geometry": {
"x": 90,
"y": 60,
"width": 120,
"height": 30,
"relative": false,
"TRANSLATE_CONTROL_POINTS": true,
"alternateBounds": null,
"sourcePoint": null,
"targetPoint": null,
"points": null,
"offset": null
},
"id": "2",
"vertex": true,
"connectable": true,
"parent": "1",
"source": null,
"target": null,
"edges": [
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "4",
"edge": true,
"parent": "1",
"source": "2",
"target": "3",
"mxObjectId": "mxCell#7"
}
],
"mxObjectId": "mxCell#6"
},
{
"value": {
"name": "Bugs Bunny"
},
"geometry": {
"x": 1020,
"y": 60,
"width": 120,
"height": 30,
"relative": false,
"TRANSLATE_CONTROL_POINTS": true,
"alternateBounds": null,
"sourcePoint": null,
"targetPoint": null,
"points": null,
"offset": null
},
"id": "3",
"vertex": true,
"connectable": true,
"parent": "1",
"source": null,
"target": null,
"edges": [
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "4",
"edge": true,
"parent": "1",
"source": "2",
"target": "3",
"mxObjectId": "mxCell#7"
}
],
"mxObjectId": "mxCell#8"
},
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "4",
"edge": true,
"parent": "1",
"source": "2",
"target": "3",
"mxObjectId": "mxCell#7"
},
{
"value": {
"name": "Elmer Fudd"
},
"geometry": {
"x": 90,
"y": 220,
"width": 120,
"height": 30,
"relative": false,
"TRANSLATE_CONTROL_POINTS": true,
"alternateBounds": null,
"sourcePoint": null,
"targetPoint": null,
"points": null,
"offset": null
},
"id": "5",
"vertex": true,
"connectable": true,
"parent": "1",
"source": null,
"target": null,
"edges": [
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "7",
"edge": true,
"parent": "1",
"source": "5",
"target": "6",
"mxObjectId": "mxCell#10"
}
],
"mxObjectId": "mxCell#9"
},
{
"value": {
"name": "Tasmanian Devil"
},
"geometry": {
"x": 1020,
"y": 220,
"width": 120,
"height": 30,
"relative": false,
"TRANSLATE_CONTROL_POINTS": true,
"alternateBounds": null,
"sourcePoint": null,
"targetPoint": null,
"points": null,
"offset": null
},
"id": "6",
"vertex": true,
"connectable": true,
"parent": "1",
"source": null,
"target": null,
"edges": [
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "7",
"edge": true,
"parent": "1",
"source": "5",
"target": "6",
"mxObjectId": "mxCell#10"
}
],
"mxObjectId": "mxCell#11"
},
{
"value": "Edge",
"geometry": {
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"relative": true
},
"id": "7",
"edge": true,
"parent": "1",
"source": "5",
"target": "6",
"mxObjectId": "mxCell#10"
}
]
}