我已经用 networkx 生成了一个图形,并将其导出为一个 .dot 文件以进行可视化。
.dot 文件看起来不错,有我创建的节点和节点属性,还有边缘数据(via
如下),一切就绪。
我的问题是如何在 linux 上可视化这些数据?我试过gephi,它看起来是其中最有能力的,但它没有检测到边缘属性(via
)。
我需要能够以交互方式探索数据。
这是一个简化的点文件,它显示了相同的行为
strict digraph G {
"README.md";
"src/modules/books/email_bk_title.php" [created="[466]"];
"functions/mysql/tmp" [created="[23, 43]"];
"src/modules/login/login_check.php" [created="[198]"];
"src/post_process_loader.php" [created="[178]"];
"src/style.css";
"src/templates/default/js/bootstrap-tooltip.js" [created="[8]"];
"src/webroot/templates/default/js/bootstrap-modal.js" [created="[23]"];
"src/webroot/templates/default/js/bootstrap-transition.js" [created="[23]"];
"src/templates/default/js/bootstrap-collapse.js" [created="[8]"];
"src/modules/books/tmp";
"src/templates/default/css/bootstrap.css" [created="[8]"];
"LICENSE.txt" [created="[6]"];
"src/templates/default/js/bootstrap.js" [created="[8]"];
"docs/app_skel_design.md" [created="[39]"];
"src/webroot/templates/default/js/bootstrap-button.js" [created="[23]"];
"src/templates/default/js/google-code-prettify/prettify.css" [created="[8]"];
"src/templates/default/js/bootstrap-tab.js" [created="[8]"];
"src/modules/logout/logout_bl.php" [created="[280]"];
"functions/books/tmp" [created="[23, 43]"];
"src/modules/admin/tmp";
"src/modules/register/tmp" [created="[73, 94]"];
"docs/database/db_constraints_behavior.md" [created="[38]"];
"src/webroot/templates/default/js/bootstrap-scrollspy.js" [created="[23]"];
"uploads/tmp" [created="[237]"];
"src/modules/login/login.php" [created="[127]"];
"src/resources/books/books.php" [created="[306, 366, 518]"];
"src/resource_holder.php" [created="[221, 250, 304, 428]"];
"src/modules/session/session_start.php" [created="[177]"];
"src/webroot/templates/default/index.html" [created="[23]"];
".gitignore" [created="[170, 289]"];
"src/functions/mysql/tmp" [created="[44]"];
"src/webroot/templates/default/js/bootstrap.js" [created="[23]"];
"src/modules/user/user_bl.php" [created="[142, 169, 439]"];
"src/modules/logout/logout.php" [created="[156, 270]"];
"src/webroot/templates/default/js/bootstrap-tooltip.js" [created="[23]"];
"src/modules/base/functions.php" [created="[64, 158, 232, 233, 254]"];
"src/resources/base/functions.php";
"docs/roadmap/v0.2.0-v0.4.0.txt" [created="[209]"];
"src/templates/default/js/bootstrap-typeahead.js" [created="[8]"];
"docs/database/mylibrary.sql" [created="[29]"];
"src/resource_holder.php.php" [created="[216]"];
"src/webroot/templates/default/js/bootstrap-popover.js" [created="[23]"];
"src/modules/register/register.php" [created="[93, 110, 455, 457]"];
"src/webroot/style.css" [created="[41, 46, 63, 126]"];
"src/webroot/templates/default/js/jquery.js" [created="[23]"];
"docs/install on windows.md" [created="[500, 501, 502, 503]"];
"src/webroot/templates/default/js/google-code-prettify/prettify.css" [created="[23]"];
"src/templates/default/js/bootstrap-alert.js" [created="[8]"];
"src/modules/books/books_bl.php" [created="[125, 514]"];
"src/webroot/module_holder.php" [created="[51, 89]"];
"src/webroot/templates/default/js/bootstrap-dropdown.js" [created="[23]"];
"src/templates/default/js/README.md" [created="[8]"];
"src/webroot/templates/default/js/bootstrap-typeahead.js" [created="[23]"];
"src/resources/register/register_BL.php" [created="[243]"];
"src/webroot/index.php" [created="[41, 52, 113, 136, 181]"];
"docs/wireframe/my-library.ep" [created="[7]"];
"webroot/uploads/tmp";
"src/functions/base/functions.php" [created="[48]"];
"src/webroot/templates/default/js/bootstrap.min.js" [created="[23]"];
"src/functions/admin/tmp" [created="[44]"];
"src/templates/default/js/bootstrap-carousel.js" [created="[8]"];
"src/modules/recover/tmp" [created="[72, 535]"];
"src/modules/register/content.php" [created="[92, 111]"];
"docs/roadmap/roadmap.md";
"src/resources/authentication/authentication.php" [created="[255, 277, 382, 449, 460, 462]"];
"src/webroot/templates/default/css/bootstrap-responsive.css" [created="[23]"];
"src/resources/admin/admin.php" [created="[403, 414, 419, 484, 487]"];
"src/webroot/templates/default/js/bootstrap-carousel.js" [created="[23]"];
"src/webroot/templates/default/js/bootstrap-collapse.js" [created="[23]"];
"src/modules/books/books.php" [created="[117, 440]"];
"src/functions/user/tmp" [created="[44]"];
"functions/user/tmp" [created="[23, 43]"];
"src/templates/default/js/bootstrap-scrollspy.js" [created="[8]"];
"webroot/style.css";
"src/modules/admin/admin.php" [created="[296, 303, 383, 397, 412, 421, 473, 491]"];
"functions/admin/tmp" [created="[23, 43]"];
"src/webroot/templates/default/js/bootstrap-alert.js" [created="[23]"];
"src/webroot/templates/default/js/google-code-prettify/prettify.js" [created="[23]"];
"src/functions/books/tmp" [created="[44]"];
"src/templates/default/js/bootstrap.min.js" [created="[8]"];
"src/webroot/layout.php" [created="[41, 45, 84]"];
"src/modules/admin/admin_bl.php" [created="[297, 369, 398, 438, 493]"];
"src/webroot/templates/default/css/docs.css" [created="[23]"];
"src/modules/user/tmp";
"src/modules/mysql/tmp";
"src/modules/mysql/connect.php" [created="[91]"];
"src/resources/upload/upload.php" [created="[290, 389]"];
"src/dependency_loader.php" [created="[95]"];
"docs/structure.md" [created="[16, 49]"];
"src/templates/default/js/bootstrap-button.js" [created="[8]"];
"config/mysql_credentials.php-dist" [created="[170]"];
"src/webroot/templates/default/js/README.md" [created="[23]"];
"src/templates/default/js/bootstrap-modal.js" [created="[8]"];
"src/templates/default/index.html" [created="[8]"];
"src/templates/default/js/bootstrap-popover.js" [created="[8]"];
"docs/roadmap/roadmap_gantt.gan" [created="[18]"];
"src/resources/autologin/autologin.php" [created="[241]"];
"src/templates/default/js/bootstrap-transition.js" [created="[8]"];
"src/resources/mysql/mysql.php";
"src/modules/mysql/mysql.php" [created="[82]"];
"src/resources_loader.php" [created="[214]"];
"src/modules/home/home.php" [created="[64]"];
"webroot/index.php";
"src/modules/user/user.php" [created="[141, 164]"];
"README.MD" [created="[0, 1]"];
"src/templates/default/css/docs.css" [created="[8]"];
"docs/features.md" [created="[4]"];
"src/modules/upload/upload_bl.php" [created="[236]"];
"src/templates/default/css/bootstrap-responsive.css" [created="[8]"];
"src/webroot/templates/default/js/application.js" [created="[23]"];
"src/layout.php";
"src/templates/default/js/google-code-prettify/prettify.js" [created="[8]"];
"src/modules/login/login_BL.php" [created="[146]"];
"src/empty" [created="[5, 8]"];
"src/resources/user/user.php" [created="[426, 434, 522]"];
"src/resources/session/session_start.php";
"src/modules/register/validation_mail_content.php" [created="[480]"];
"src/resources/login/login_bl.php" [created="[242]"];
"src/modules/login/login_bl.php";
"src/modules/session/session_destroy.php" [created="[177, 186]"];
"src/pre_process_loader.php" [created="[179]"];
"src/router.php" [created="[78]"];
"src/resources/session/session_destroy.php";
"src/modules/login/tmp" [created="[71, 124]"];
"src/moduleBL_loader.php" [created="[112]"];
"src/webroot/templates/default/js/bootstrap-tab.js" [created="[23]"];
"src/modules/register/register_BL.php" [created="[121, 448]"];
"src/templates/default/js/bootstrap-dropdown.js" [created="[8]"];
"src/module_holder.php";
"src/webroot/templates/default/css/bootstrap.css" [created="[23]"];
"src/modules/upload/upload.php" [created="[235]"];
"src/templates/default/js/jquery.js" [created="[8]"];
"src/templates/default/js/application.js" [created="[8]"];
"todo.txt" [created="[31]"];
"src/style.css" -> "src/webroot/style.css" [via=99];
"uploads/tmp" -> "webroot/uploads/tmp" [via=394];
"src/modules/session/session_start.php" -> "src/resources/session/session_start.php" [via=212];
"src/functions/mysql/tmp" -> "src/modules/mysql/tmp" [via=64];
"src/modules/base/functions.php" -> "src/resources/base/functions.php" [via=257];
"docs/roadmap/v0.2.0-v0.4.0.txt" -> "docs/roadmap/roadmap.md" [via=227];
"src/webroot/style.css" -> "src/style.css" [via=86];
"src/webroot/style.css" -> "webroot/style.css" [via=172];
"src/webroot/module_holder.php" -> "src/module_holder.php" [via=86];
"src/resources/register/register_BL.php" -> "src/modules/register/register_BL.php" [via=256];
"src/webroot/index.php" -> "webroot/index.php" [via=172];
"src/functions/admin/tmp" -> "src/modules/admin/tmp" [via=64];
"src/functions/user/tmp" -> "src/modules/user/tmp" [via=64];
"src/functions/books/tmp" -> "src/modules/books/tmp" [via=64];
"src/webroot/layout.php" -> "src/layout.php" [via=86];
"src/modules/mysql/mysql.php" -> "src/resources/mysql/mysql.php" [via=211];
"README.MD" -> "README.md" [via=3];
"src/modules/login/login_BL.php" -> "src/modules/login/login_bl.php" [via=173];
"src/resources/login/login_bl.php" -> "src/modules/login/login_bl.php" [via=256];
"src/modules/session/session_destroy.php" -> "src/resources/session/session_destroy.php" [via=212];
}
在networkx中,我像这样创建它
filegraph = nx.DiGraph()
for cid, commit in enumerate(raw.commits):
raw_creations = [info['path'] for info in raw.commits[cid]['info'] if info['type'] & RawRepo.TYPE_NEW]
for path in raw_creations:
if path in filegraph:
attrs = filegraph.node[path]
if 'created' in attrs:
attrs['created'].append(cid)
else:
print("not in created")
else:
print("created", path)
attrs = {'created': [cid]}
filegraph.add_node(path, attr_dict=attrs)
raw_renames = {info['from']:info['to'] for info in raw.commits[cid]['info'] if info['type'] & RawRepo.TYPE_RENAME}
for fr, to in raw_renames.items():
print("rename",fr,"->",to)
filegraph.add_edge(fr, to)
filegraph.edge[fr][to]['via'] = cid
#filegraph.add_edge(fr, to, attr_dict={'via':cid})
nx.drawing.nx_pydot.write_dot(filegraph, 'filenames.dot')
我试过的另一个查看器ZGRViewer也没有显示该数据。
更新
使用 cytoscape 3.0.0-beta1 时,当导入使用 networkx 导出为
nx.readwrite.gml.write_gml(filegraph, 'filenames.gml')
错误是
java.text.ParseException: Bad value associated with key modified
at org.cytoscape.io.internal.read.gml.GMLParser.parseList(GMLParser.java:192)
at org.cytoscape.io.internal.read.gml.GMLParser.parseValue(GMLParser.java:293)
at org.cytoscape.io.internal.read.gml.GMLParser.parseList(GMLParser.java:189)
at org.cytoscape.io.internal.read.gml.GMLParser.parseValue(GMLParser.java:293)
at org.cytoscape.io.internal.read.gml.GMLParser.parseList(GMLParser.java:189)
at org.cytoscape.io.internal.read.gml.GMLNetworkReader.run(GMLNetworkReader.java:190)
at org.cytoscape.work.internal.task.JDialogTaskManager$TaskThread.run(JDialogTaskManager.java:241)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
pool-11-thread-1 WARN [org.cytoscape.work.internal.task.JDialogTaskManager] - Caught exception executing task.
java.lang.RuntimeException: Bad value associated with key modified
at org.cytoscape.io.internal.read.gml.GMLNetworkReader.run(GMLNetworkReader.java:193)
at org.cytoscape.work.internal.task.JDialogTaskManager$TaskThread.run(JDialogTaskManager.java:241)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
cytoscape 2.8.3 中的错误如下所示: