首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Python创建/编辑mxgraph模型

使用Python创建/编辑mxgraph模型
EN

Stack Overflow用户
提问于 2020-06-16 17:05:57
回答 1查看 663关注 0票数 0

可以使用Python创建、编辑mxgraph模型或将其从JSON或XML数据转换为mxgraph格式吗?如果是这样,怎么做呢?我在各个网站上都找不到解决方案(一个JSON数据示例);

代码语言:javascript
复制
  {
    name: 'Globals',    
    parentObjects: []
  },

  {
    name: 'Customer',
    included: true,    
    parentObjects: [
      {
        name: 'Globals',
      }
    ],
  },

  {
    name: 'Product',
    included: true,    
    parentObjects: [
      {
        name: 'Globals',
      }
    ],
  },

  {
    name: 'Transaction',
    included: true,    
    parentObjects: [
      {
        name: 'Customer',
      },
      {
        name: 'Product',
      }
    ],
  }
EN

回答 1

Stack Overflow用户

发布于 2020-06-25 00:05:39

没有一种“统一”的方式来使用mxgraph...您可以创建具有各种形状的各种类型的节点...MxGraph允许您以JSON和XML格式导入和导出图形,但首先您需要创建一个与MxGraph兼容的JSON或XML格式的图形以供读取。

在这里,您可以找到一个与JSON相互导入的代码示例:Example

正如您在JSON中看到的,您需要指定节点的各个方面(几何图形、父节点、边、可连接性等)。类似于XML...

我不是Python方面的专家,但您应该做的是将您的JSON转换为MxGraph实际可读的内容……

JSON示例:

代码语言:javascript
复制
{
    "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"
        }
    ]
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62404874

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档