保存图形gdf文件的库
gdflib的Python项目详细描述
关于gdflib
gdflib是一个python包,用于转储gdf图形文件。
安装
gdflib可以从pypi安装:
easy_install gdflib
或:
pip install gdflib
应该只对大多数用户有效
用法
最简单的例子:
>>> from gdflib import GdfEntries, Node >>> >>> entities = GdfEntries() >>> entities.add_node(Node(name='node1', label='This is the first node')) >>> entities.add_node(Node(name='node2', label='This is the second node')) >>> entities.link('node1', 'node2') >>> print entities.dumps() nodedef>name , style INT, width DOUBLE, color VARCHAR, image VARCHAR, label VARCHAR, height DOUBLE, visible BOOLEAN, labelcolor VARCHAR, y DOUBLE, x DOUBLE, strokecolor VARCHAR, fixed BOOLEAN, labelvisible BOOLEAN node1,1,4.000000,cornflowerblue,,'This is the first node',4.000000,true,cornflowerblue,,,cadetblue,false,false node2,1,4.000000,cornflowerblue,,'This is the second node',4.000000,true,cornflowerblue,,,cadetblue,false,false edgedef>node1 , node2 , directed BOOLEAN, color VARCHAR, weight DOUBLE, width DOUBLE, label VARCHAR, visible BOOLEAN, labelcolor VARCHAR, labelvisible BOOLEAN node1,node2,true,dandelion,1.000000,3.000000,'1',true,dandelion,false
默认情况下,所有节点都实现为gdf定义的标准属性,未指定的属性将获得 默认值。 自定义节点可以通过声明性接口定义:
>>> from gdflib import String, Double >>> from gdflib import GdfEntries, Node >>> >>> class Product(Node): ... company = String(default='Unknown Company') ... price = Double(required=True) ... >>> entities = GdfEntries(Product) >>> entities.add_node(Product(name='node1', company='Custom Company', price=33.10)) >>> entities.add_node(Product(name='node2', label='Low Cost Product', price=18.21)) >>> entities.link('node1', 'node2') >>> entities.dumps() nodedef>name , style INT, width DOUBLE, color VARCHAR, image VARCHAR, label VARCHAR, height DOUBLE, visible BOOLEAN, labelcolor VARCHAR, y DOUBLE, x DOUBLE, strokecolor VARCHAR, fixed BOOLEAN, labelvisible BOOLEAN, company VARCHAR, price DOUBLE node1,1,4.000000,cornflowerblue,,'node1',4.000000,true,cornflowerblue,,,cadetblue,false,false,'Custom Company',33.100000 node2,1,4.000000,cornflowerblue,,'Low Cost Product',4.000000,true,cornflowerblue,,,cadetblue,false,false,'Unknown Company',18.210000 edgedef>node1 , node2 , directed BOOLEAN, color VARCHAR, weight DOUBLE, width DOUBLE, label VARCHAR, visible BOOLEAN, labelcolor VARCHAR, labelvisible BOOLEAN node1,node2,true,dandelion,1.000000,3.000000,'1',true,dandelion,false
gdflib还支持自定义边,这些边可以像自定义节点一样定义 通过子类化edge并提供附加属性。在这种情况下,而不是使用 link函数链接两个节点,应使用add_edge调用。