Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the node coordinates #12

Closed
Sophivorus opened this issue Jun 6, 2015 · 1 comment
Closed

How to get the node coordinates #12

Sophivorus opened this issue Jun 6, 2015 · 1 comment
Labels

Comments

@Sophivorus
Copy link

I'm trying to find the way to get the node coordinates or my graph. Say I do a basic graph:

$Graph = new Fhaculty\Graph\Graph;

$Vertex1 = $Graph->createVertex();
$Vertex2 = $Graph->createVertex();
$Vertex1->createEdge( $Vertex2 );

$GraphViz = new Graphp\GraphViz\GraphViz;
$data = $GraphViz->createImageData( $Graph );
$image = imagecreatefromstring( $data );
header( 'Content-Type: image/png' );
imagepng( $image );

According to the official Graphviz documentation there is a node attribute called 'pos' that should give me what I want. Also, I'm using dot, and according to this related question at StackOverflow the 'pos' attribute should work with dot. But I don't know the right way to get it. I've been trying things like:

$Vertex1->getAttribute( 'graphviz.pos' );

Because I know that things like the following work:

$Vertex1->getAttribute( 'graphviz.label' );

However I bet that 'label' and 'pos' work very different internally. I imagine that the 'pos' attribute should only be available after rendering the graph with createImageData. But even if I try to get 'pos' after createImageData, I get nothing. Anyone knows how can I get the coordinates of the nodes of the graph?

@clue clue added the question label Jun 29, 2015
@clue
Copy link
Member

clue commented Jun 29, 2015

This is an excellent question, thanks for posting 👍

I think this (again!) boils down to a lack of documentation (#2) :)

It's tempting to think that accessing the graphviz.pos attribute should return the position within the graph.

However, the attributes only contain those values that are actually set via your own code.

This is because this library only exports a Graph instance and all of its attributes into a format that the GraphViz tool can read in order to produce a resulting graph image. This means that it never actually knows the position of the individual elements.

I've just filed ticket #15 as a feature request so that we could eventually also have a dot importer. This would allow us to do the following:

  • Export the Graph instance into the dot format
  • Pass this intermediary dot script as input to GraphViz, asking for dot output
  • Read in (import / parse) the resulting dot output
  • Access all automatically generated attributes such as node position etc.

@clue clue closed this as completed Jun 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants