Read positions from dot files

Asked by tcb

Can the DOT file importer be modified to allow reading position attributes in .dot files?

I have some dot files that I have produced with my own layout algorithms, and while gephi reads them just fine, it ignores the positions of the nodes. Some of the other graph formats allow reading position attributes, and it would be useful if the DOT importer could do this too. From a quick look at the code, it should be a straightforward enough matter of reading the 'pos' attribute (ImporterDOT.java), relevant details on the dot format are here:

http://www.graphviz.org/doc/info/attrs.html#a:pos

Is this planned at some stage? Is anyone working on it?

regards...

Question information

Language:
English Edit question
Status:
Solved
For:
Gephi Edit question
Assignee:
No assignee Edit question
Solved by:
tcb
Solved:
Last query:
Last reply:
Revision history for this message
Sébastien Heymann (sebastien.heymann) said :
#1

Hi,

It's not planned but I filled in the Idea List : http://wiki.gephi.org/index.php/Ideas#IO

You're also free to add the support of the positions and submit a patch, we would integrate it with pleasure.

Best

Revision history for this message
tcb (tcb) said :
#2

Thanks for the reply.

I understand the dot file format must be a pretty low priority, but its also about the simplest format, at least the subset of it that I use- so this would make gephi quite useful for me.

If I can find the time I'll certainly take a look at making a patch.

regards

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#3

Hi, that would be great if you could write a patch!

Feel free to ask for some help, I'm sure that could be achieved quickly.

Best

Revision history for this message
tcb (tcb) said :
#4

Hi,

This is a first attempt at a patch to read positions from DOT files. It seems to import my dot files with positions just fine. It should work for 3D as well as 2D- but I have only tested 2D. I don't know how to handle the error messages- from looking at the rest of the code I added a new one "importerDOT_error_posunreachable".

The position tag for the nodes should be of the form:

  pos="x, y"

It would be nice to be able to specify the size of the nodes too- I'll look into that soon.

--- ImportPlugin/src/org/gephi/io/importer/plugin/file/ImporterDOT.java.orig 2010-06-15 18:23:46.000000000 +0100
+++ ImportPlugin/src/org/gephi/io/importer/plugin/file/ImporterDOT.java 2010-06-15 19:29:33.000000000 +0100
@@ -194,6 +194,33 @@
                     report.logIssue(new Issue(NbBundle.getMessage(ImporterDOT.class, "importerDOT_error_colorunreachable", streamTokenizer.lineno()), Issue.Level.WARNING));
                     streamTokenizer.pushBack();
                 }
+ } else if (streamTokenizer.sval.equalsIgnoreCase("pos")) {
+ streamTokenizer.nextToken();
+ if (streamTokenizer.ttype == '=') {
+ streamTokenizer.nextToken();
+ if (streamTokenizer.ttype == StreamTokenizer.TT_WORD || streamTokenizer.ttype == '"') {
+ try{
+ String[] positions = streamTokenizer.sval.split(",");
+ if(positions.length == 2) {
+ nodeDraft.setX(Float.parseFloat(positions[0]));
+ nodeDraft.setY(Float.parseFloat(positions[1]));
+ } else if(positions.length == 3) {
+ nodeDraft.setX(Float.parseFloat(positions[0]));
+ nodeDraft.setY(Float.parseFloat(positions[1]));
+ nodeDraft.setZ(Float.parseFloat(positions[2]));
+ }
+
+ } catch(Exception e) {
+
+ }
+ } else {
+ report.logIssue(new Issue(NbBundle.getMessage(ImporterDOT.class, "importerDOT_error_posunreachable", streamTokenizer.lineno()), Issue.Level.WARNING));
+ streamTokenizer.pushBack();
+ }
+ } else {
+ report.logIssue(new Issue(NbBundle.getMessage(ImporterDOT.class, "importerDOT_error_posunreachable", streamTokenizer.lineno()), Issue.Level.WARNING));
+ streamTokenizer.pushBack();
+ }
             } else if (streamTokenizer.sval.equalsIgnoreCase("style")) {
                 streamTokenizer.nextToken();
                 if (streamTokenizer.ttype == '=') {

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#5

Great! I'll integrate it in the next release

I created a bug here (https://bugs.launchpad.net/gephi/+bug/594793), you can create a patch for the modifications you did?

Do
bzr send -o mychanges.patch
to create the patch file, and then uploaded it to the bug :)