Comments

s.daniel’s picture

StatusFileSize
new39.11 KB

Example of a subgraph in graphviz:
dot code

digraph G {

	subgraph cluster_0 {
		style=filled;
		color=lightgrey;
		node [style=filled,color=white];
		a0 -> a1 -> a2 -> a3;
		label = "process #1";
	}

	subgraph cluster_1 {
		node [style=filled];
		b0 -> b1 -> b2 -> b3;
		label = "process #2";
		color=blue
	}
	start -> a0;
	start -> b0;
	a1 -> b3;
	b2 -> a3;
	a3 -> a0;
	a3 -> end;
	b3 -> end;

	start [shape=Mdiamond];
	end [shape=Msquare];
}

result

Source:
http://www.graphviz.org/content/cluster

clemens.tolboom’s picture

That dot file is the one I always refer to myself :)

One problem with graphviz implementation is one cannot link to a subgraph like a3 ->subgraph cluster_0

A problem for graph_phyz is it cannot know the contents of a subgraph like a3 -> b2

graph.inc and Graph API data structure lack the ability to register a link to a node in a subgraph.

Maybe we can introduce a namespace construct like sub1:a1 to trigger code to dig deeper (recursive) into the graph structure.

As each node has it's internal structure free at will it can contain sub graphs no problem.

Puzzle is the inter graph: do we need absolute path or relative?

a -> b
b:c -> a

leads to structure

[a][links][b]
[b][subgraph][c][links][???a]

Hope this helps a little.

We should read some docs too. Maybe http://en.wikipedia.org/wiki/Graph_theory has some useful ones.

clemens.tolboom’s picture

I just realize the above is not correct. Each 'node' must have a unique ID. Indicating it is a part of a subgraph is crap. a subgraph is just a grouping of unique IDs

@s.Daniel can you try do describe how one or more views can provide for your subgraphs?

See also #1396538: Should we merge multiple views outputs into 1 graph? or maybe views grouping could help?

clemens.tolboom’s picture

Problem with graphviz is linking to a subgraph. Say node A is a subgraph then it is not available for linking. But node A is a unique ID from Graph API perspective.

IE nodes A, B, C, D, E, F form a network like

digraph {
  subgraph cluster_a {
    label = "cluster_a"
    b
    c
  }

  subgraph cluster_e {
    label = "cluster_e"
    f
  }
  d
  f -> c
  d -> cluster_a
}

disallow for links like d -> cluster_a. But our data-structure is IE

$g['nodes']['A'] = array(...); // properties of node A
$g['nodes']['B'] = array(...); // properties of node B
... more nodes
$g['nodes']['F'] = array(...); // properties of node F

$g['nodes']['A']['subgraph']['nodes']['B'] = TRUE;
$g['nodes']['A']['subgraph']['nodes']['C'] = TRUE;
$g['nodes']['E']['subgraph']['nodes']['F'] = TRUE;

$g['nodes']['D']['links']['A'] = array(); // graphapi_to_dot() should retract this link
$g['nodes']['F']['links']['C'] = array();

The datastructure looks ok to me. We now can express node 'A' is a subgraph containing nodes 'B' and 'C'.

Next we need some primitives/functions to manipulate subgraphs.

// Adds a graph as children of the given node
function graphapi_add_subgraph($g, $node, $sub){};

// Adds a child to the given node
function graphapi_add_child_node($g, $node, $child){};

Note ours data-structure deflates the parent-child tree into a one level deep structure.

The renderer ie graph_phyz or graphviz need to do a topological sort to create their tree nature back.

@s.Daniel What do you think?

clemens.tolboom’s picture

Assigned: Unassigned » clemens.tolboom
Status: Active » Needs work

I did a first attempt. The graph from #1 should be possible.

But we need a solution for nested subgraphs. No a big deal but it needs some more time.

See

/**
 * Calculate the tree of subgraphs.
 * @return array tree structure of sub graphs
 */
function graphapi_get_graph_tree() {
  // TODO: provide a result
  return array();
}

@s.Daniel please test the current state and please help with the views question from #3

s.daniel’s picture

Good progress.

@s.Daniel can you try do describe how one or more views can provide for your subgraphs?

I'm not sure how the question is ment. If you are asking for my use case: I have a node with several taxonomy vocabularies as fields available. One of these fields can contain hirarchial terms. e.G. time > year > month > week > ...
In the node only the year is selected but in the display I think consider printing the whole tree as a subgraph with only the year linked to the main node.

Here is the dot output from admin/config/system/graphapi/demo/graphviz

digraph {
  node_graphapi_demo [
    label = "graphapi_demo"
  ]
  node_graphapi [
    label = "graphapi"
  ]
  node_thejit [
    label = "thejit"
  ]
  node_thejit_spacetree [
    label = "thejit_spacetree"
  ]
  node_thejit_forcedirected [
    label = "thejit_forcedirected"
  ]
  node_views [
    label = "views"
  ]
  node_views_ui [
    label = "views_ui"
  ]
  subgraph cluster_S {
    node_A
    node_B
    node_C
    label = "Subgraph if supported"
  }
  node_A [
    label = "A"
  ]
  node_B [
    label = "B"
  ]
  node_C [
    label = "C"
  ]
  node_graphapi_demo -> node_graphapi
  node_graphapi -> node_views
  node_graphapi -> node_A
  node_thejit -> node_thejit_spacetree
  node_thejit -> node_thejit_forcedirected
  node_thejit_spacetree -> node_graphapi
  node_thejit_forcedirected -> node_graphapi
  node_views_ui -> node_views
  node_A -> node_B
  node_A -> node_S
  node_B -> node_C
}

and here is the output run through graphviz_filter_filterproc:
graphviz subgraph wrong link

Regarding the data structure, topological sort etc. I am not sure yet. Can't we do something simple like:

if (empty($graph[$eid]['_subgraph'])) {
        $dot[] = "  node_$id -> node_$eid";
      }

The result looks good so far but I guess you are thinking of more advanced use cases which I don't consider yet.
graphviz subgraph wrong link removed

Links from/to subgraphs

There seems to bee a hacky solution for this in graphviz. I implemented this however I'm not sure if this is the way to go because of the subthree comment and beause it needs the settings: $dot[] = 'graph [fontsize=10 fontname="Verdana" compound=true];'; to work. Here is a simple patch. I've created a more advanced one as well but I mixed up changes so it would require cleanup which I'll do if you say that it's the way to go. I'll store my futur changes in a sandbox.

Here is the result of the code in the sandbox:
subgraph to subgraph links

s.daniel’s picture

@See: Here is the feature request for graphviz http://www.graphviz.org/mantisbt/view.php?id=1968
@Note (for myselfe): Currently I get the error

Graphviz encountered an error while rendering to format png:
Error: /home/drupalpro/websites/aaaaa/sites/default/files/graphviz/b774ae7203c05830a54f42426b5b3dc1.dot:5: syntax error near line 5<br />context: label = >>> "tid-73"; <<<

on every first load of a new graph rendered by graphviz which might be related to my latest changes.

clemens.tolboom’s picture

Nice finding: dot lingo : compound = TRUE

That brings us to the settings forms. Through views each graph has overall (graph) settings and node or link settings. So this compound setting should probably set on the graph and maybe node level.

You patch is too big. You prob downloaded a tarball?

You should add a remote to your sandbox I guess git add remote to Graph API.


+++ b/.gitignore
@@ -0,0 +1,2 @@
diff --git a/LICENSE.txt b/LICENSE.txt

Oeps

+++ b/modules/graph_phyz/graph_phyz.module
@@ -170,16 +170,16 @@ function template_preprocess_views_graphapi_style_graph_phyz(&$vars) {
-function theme_graph_phyz_container($variables) {
-  return graph_phyz_container($variables['graph'], $variables['config']);
+function theme_graph_phyz_container($vars) {
+  return graph_phyz_container($vars['graph'], $vars['config']);

Changing a var name ... why?

+++ b/modules/graphviz/graphviz.info
@@ -3,5 +3,6 @@ description = A text implementation of the Graphviz data structure
+dependencies[] = graphviz_filter
 

I'm not sure my dev env works with it :(

I prob should try it now there is a D7 version.

+++ b/modules/graphviz/graphviz.module
@@ -66,15 +57,73 @@ function graphviz_theme() {
+ * ¶
+ * @param type $vars ¶

Whitespace

+++ b/modules/graphviz/graphviz.module
@@ -90,21 +139,28 @@ function theme_graphapi_graphviz_graphapi($vars) {
 function graphviz_to_dot($graph) {

It should receive the $settings too.

The settings should contain the global graph and node and link settings.

I should have fixed this earliers. Sorry.

+++ b/modules/graphviz/graphviz.module
@@ -113,10 +169,19 @@ function graphviz_to_dot($graph) {
+      if (empty($graph[$eid]['_subgraph'])) { // node -> node
+        $dot[] = "  \"node_$id\" -> \"node_$eid\";";
+      } elseif (isset($graph[$eid]['_subgraph'])&& empty($graph[$id]['_subgraph'])) { // node -> subgraph
+        $tnode = $graph[$eid]['_subgraph'][0];
+        $dot[] = "  \"node_$id\" -> \"node_" . $tnode . "\" [lhead=cluster_" . $eid . "];";
+      } elseif (isset($graph[$eid]['_subgraph'])&& isset($graph[$id]['_subgraph'])) { // subgraph -> subgraph
+        $tnode = $graph[$eid]['_subgraph'][0];
+        $lnode = $graph[$id]['_subgraph'][0];
+        $dot[] = "  \"node_$lnode\" -> \"node_" . $tnode . "\" [lhead=cluster_" . $eid . " ltail=cluster_" . $id ."];";

Is this in line with latest version?!?

s.daniel’s picture

StatusFileSize
new11.81 KB

Thank you for your feedback.
You are probably right about the tarball. Must have mixxed something up here.

In first place I wanted the sandbox to be a place show what I'm working on atm. The big patch was not ment to be committed right away. However graphapi is allready added as a remote and I was able to pull your latest commits.

git remote -v
origin  http://git.drupal.org/project/graphapi.git (fetch)
origin  http://git.drupal.org/project/graphapi.git (push)
sandbox s.Daniel@git.drupal.org:sandbox/s.Daniel/1868566.git (fetch)
sandbox s.Daniel@git.drupal.org:sandbox/s.Daniel/1868566.git (push)
Changing a var name ... why?

When I read through the code it was easier for me to get with the same variable name used across the different submodules. I can change that back if you like.

I'm not sure my dev env works with it :(

I use http://drupal.org/project/drupalpro for development where setting up graphviz was very easy. Realy love working with it and it's good to try out stuff you don't want to mess up your envoironment with. Just

  • download the image
  • run it in virtualbox,
  • dl graphviz as described via at graphviz_filter,
  • setup a new site using drush qc --domain=graphviz.dev
  • cd ~/websites/graphviz.dev/sites/all/modules
  • git clone ...

Did you check the small patch? http://drupal.org/files/graphapi-subgraph_simple-1866760-6.patch

Is this in line with latest version?!?

08:30:53 (patches) ~/websites/...local/sites/all/modules/graphapi$ git merge 7.x-1.x patches -v
Already up-to-date. Yeeah!

Think so

I'll digg into the settings and create a better looking patch in a day or two. Attached is the current diff - again not really ready to be committed. It includes all my changes including Remove demo code from graphapi.module.

I should probably create a branch for each of the changes and merge them all into one feature branch to make it easier in the future to split up patches :/

s.daniel’s picture

Hmm graphviz has an incredible ammount of possible settings. Different rendering engines, output formats, attributes etc. And all of that in special combinations. Here is the attributes documentation e.g.: http://www.graphviz.org/content/attrs

I wonder now how much of that configuration we would want as a submodule of graph api?

clemens.tolboom’s picture

If you think graphviz_filter is the drupal only implementation we should move over all code over to that project.

But for now we can express each render engine (dot, neato, ... ) as a separate _graphapi_format.

clemens.tolboom’s picture

Project: Graph API » Graph Phyz
Version: 7.x-1.x-dev »

I move this issue to Graphviz project.

See it's Graph Phyz counterpart #1881376: Should we add subgraphs.

clemens.tolboom’s picture

Project: Graph Phyz » Graphviz
StatusFileSize
new67.1 KB

Graphviz now has settings in progress.

See /admin/config/system/graphapi/engines/graphviz

Graph API | Site-Install.png

I think we should not apply the patch from this issue.

Let's create a few new issues from this one ok?

- graph [fontsize=10 fontname="Verdana" compound=true] can be done through #1881430: Add useful attributes to the project.

The settings from mentioned issue are not yet applied through the theme function.

clemens.tolboom’s picture

Status: Needs work » Closed (won't fix)

#7 is done by #1881548: Convert PHP variables to the DOT text format
#10 is covered by #1881430: Add useful attributes to the project.
Original feature is now in #1881552: Add nested subgraphs

So I close this one as this was about sub graph support we now have in small.

Next time we must try to keep the issue on topic a little more. My bad too ;-)

clemens.tolboom’s picture

Please open new issues for items I've missed :-)