[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[igraph] Re: Problem with layouts with GraphML
From: |
Dr Karl |
Subject: |
[igraph] Re: Problem with layouts with GraphML |
Date: |
Fri, 20 Nov 2009 01:05:19 -0800 (PST) |
User-agent: |
G2/1.0 |
Well, I think it may be easier to store the layout like this and later
make a post-processing of the XML to write the layout information with
the needed format. In fact I already have written a class in java to
insert custom data on every node, which I can re-use here to take the
values of the layout calculated by iGraph and set them in the format
that uses yFiles.
I'll try this approach and let you know what I did finally.
Best regards
On 20 nov, 09:51, Dr Karl <address@hidden> wrote:
> Hi Tamas,
>
> Thank you for your quick answer!!
>
> Well, I have done what you said in your message, and now
> my .graphml file has two attributes. This is my code, in case someone
> needs to add attributes as well:
>
> igraph_t g;
> igraph_matrix_t res;
> igraph_vector_t edges;
> igraph_vector_t col1;
> igraph_vector_t col2;
> igraph_i_set_attribute_table(&igraph_cattribute_table);
> igraph_vector_init(&edges, 4*relations.size());
> igraph_matrix_init(&res, 0, 0);
> int i = 0;
> for (vector<Relationship>::iterator it = relations.begin(); it!
> =relations.end(); ++it) {
> rel = (Relationship)*it;
> if (rel.AtoB>=1 && rel.BtoA>=1 &&
> (rel.AtoB+rel.BtoA)>=minLevels) {
> if (rel.AtoB>0 || rel.BtoA>0) {
> VECTOR(edges)[i] = rel.nodeA;
> i++;
> VECTOR(edges)[i] = rel.nodeB;
> i++;
> }
> }
> }
> igraph_vector_resize(&edges, i);
> igraph_create(&g, &edges, 0, IGRAPH_DIRECTED);
> igraph_layout_random(&g, &res);
> long size = igraph_matrix_nrow(&res);
> igraph_vector_init(&col1, size);
> igraph_vector_init(&col2, size);
> igraph_matrix_get_col(&res, &col1, 0);
> igraph_matrix_get_col(&res, &col2, 1);
> igraph_cattribute_VAN_setv(&g, "X", &col1);
> igraph_cattribute_VAN_setv(&g, "Y", &col2);
> FILE* graphml_file;
> graphml_file = fopen("test_graph_layouts_random.graphml","w");
> igraph_write_graph_graphml(&g, graphml_file);
> igraph_vector_destroy(&edges);
> igraph_vector_destroy(&col1);
> igraph_vector_destroy(&col2);
> igraph_destroy(&g);
> igraph_matrix_destroy(&res);
>
> Ok, now on every node I have two attributes, like this
>
> <node id="n0">
> <data key="X">-0.378323</data>
> <data key="Y">0.89578</data>
> </node>
>
> but on yEd generated graphs, the layout is set like this
>
> <node id="n0">
> <data key="d0"/>
> <data key="d1">
> <y:ShapeNode>
> <y:Geometry height="30.0" width="30.0" x="25.0" y="0.0"/>
> <y:Fill color="#CCCCFF" transparent="false"/>
> <y:BorderStyle color="#000000" type="line" width="1.0"/>
> <y:NodeLabel alignment="center" autoSizePolicy="content"
> fontFamily="Dialog" fontSize="12" fontStyle="plain"
> hasBackgroundColor="false" hasLineColor="false" height="4.0"
> modelName="internal" modelPosition="c" textColor="#000000"
> visible="true" width="4.0" x="13.0" y="13.0"/>
> <y:Shape type="rectangle"/>
> </y:ShapeNode>
> </data>
> </node>
>
> and before the <graph ...> tag
>
> <key attr.name="description" attr.type="string" for="node" id="d0"/>
> <key for="node" id="d1" yfiles.type="nodegraphics"/>
> <key attr.name="description" attr.type="string" for="edge" id="d2"/>
> <key for="edge" id="d3" yfiles.type="edgegraphics"/>
> <key for="graphml" id="d4" yfiles.type="resources"/>
>
> I only use yEd for quick viewing of the graph, but I assume that if a
> graph doesn't display correctly on yEd, it won't display correctly on
> my Flex web application based on yFiles either.
>
> So, is there a way I can attach something like <y:Geometry
> height="30.0" width="30.0" x="25.0" y="0.0"/> inside the <data
> key="d1"> attribute?? this is like nested attributes, whick I don't
> know if are supported by iGraph.
>
> Thank you very much.
>
> On 19 nov, 18:57, Tamas Nepusz <address@hidden> wrote:
>
>
>
>
>
> > Hi Karl,
>
> > > My problem is that if I open the resulting .graphml files with
> > > yEd (by yWorks), all the vertices are centered and it is impossible to
> > > see the graph.
>
> > This is because no layout information is saved in the GraphML file when
> > you export a graph from igraph. If you want to calculate a layout in
> > igraph and then store it in the GraphML file, you will need two things:
>
> > 1. Attach the (experimental) C attribute handler to igraph; these set
> > of functions are responsible for storing attributes properly in the
> > C layer. (The R and the Python interfaces use different attribute
> > handlers, that's why you have to attach the attribute handler
> > manually). See:http://igraph.sourceforge.net/doc/html/ch09s02.html
>
> > 2. Calculate a layout using some of the layout functions in igraph
> > and save the layout in an igraph_matrix_t.
>
> > 3. Extract the first and the second column of the matrix to two
> > igraph_vector_t variables.
>
> > 4. Copy the calculated coordinates from the vectors to two node
> > attributes (say, X and Y) using igraph_cattribute_VAN_setv or its
> > associated macro version called SETVANV.
>
> > 5. Save your graph into GraphML as you did before.
>
> > If you do this, the saved GraphML file will contain the calculated
> > layout information using the two node attributes. However, I don't know
> > whether yEd can be "convinced" to use these attributes for setting up
> > the layout in the graph view. When you save a graph from yEd into
> > GraphML format, yEd uses its own XML schema extensions to store the
> > layout and other visual properties of nodes and edges, and you cannot
> > reproduce that from igraph.
>
> > --
> > Tamas
>
> > _______________________________________________
> > igraph-help mailing list
> > address@hidden://lists.nongnu.org/mailman/listinfo/igraph-help
>
> _______________________________________________
> igraph-help mailing list
> address@hidden://lists.nongnu.org/mailman/listinfo/igraph-help