Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
family_graphviz.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Generate family relation graph
9  *
10  * @author Anakeen 2008
11  * @version $Id: family_graphviz.php,v 1.1 2008/07/11 13:17:31 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  * @global id Http var : document id to affect
18  * @global type Http var : type of graph
19  * @global format Http var : file format pnh or svg
20  * @global orient Http var :orientation TB (TopBottom) or LR (LeftRight)
21  * @global size Http var : global size of graph
22  */
23 // refreah for a classname
24 // use this only if you have changed title attributes
25 include_once ("FDL/Lib.Attr.php");
26 include_once ("FDL/Class.DocFam.php");
27 
28 $dbaccess = $appl->GetParam("FREEDOM_DB");
29 if ($dbaccess == "") {
30  print "Database not found : param FREEDOM_DB";
31  exit;
32 }
33 
34 $docid = GetHttpVars("docid", 0); // special docid
35 $type = GetHttpVars("type"); // type of graph
36 $orient = GetHttpVars("orient", "LR"); // type of graph
37 $isize = GetHttpVars("size", "10"); // size of graph
38 $ratio = GetHttpVars("ratio", "auto"); // ratio of graph
39 $q = new QueryDb($dbaccess, "DocAttr");
40 //$q->AddQuery("type='docid'");
41 $ta = $q->Query(0, 0, "TABLE");
42 
43 $q = new QueryDb($dbaccess, "DocFam");
44 $tf = $q->Query(0, 0, "TABLE");
45 foreach ($tf as $k => $v) {
46  if ($v["name"] != '') {
47 
48  $tname[$v["id"]] = $v["name"];
49  }
50 }
51 
52 $fampattern = '/,' . implode($tname, '[,\)]|,') . '[,\)]/';
53 //print $fampattern;
54 foreach ($ta as $k => $v) {
55  if ($v['phpfunc'][0] != ':') {
56  if (preg_match($fampattern, $v['phpfunc'], $match)) {
57  if ((count($match) > 0) && ($match[0] != "")) {
58  $rel[] = array(
59  "aid" => $v["id"],
60  "alabel" => $v["labeltext"],
61  "x" => $v["phpfunc"],
62  "sourcefam" => $tname[$v["docid"]],
63  "ciblefam" => str_replace(array(
64  ',',
65  ')'
66  ) , '', $match[0])
67  );
68  }
69  }
70  }
71 }
72 //print_r2($rel);
73 
75 if ($isize == "auto") $size = "";
76 else {
77  if ($isize == "A4") {
78  $size = "size=\"7.6,11!\";"; // A4 whith 1.5cm margin
79 
80  } else {
81  if (preg_match("/([0-9\.]+),([0-9\.]+)/", $isize, $reg)) {
82  $size = sprintf("size=\"%.2f,%.2f!\";", floatval($reg[1]) / 2.54, floatval($reg[2]) / 2.54);
83  } else {
84  $isize = sprintf("%.2f", floatval($isize) / 2.54);
85  $size = "size=\"$isize,$isize!\";";
86  }
87  }
88 }
89 $statefontsize = 13;
92 
93 foreach ($rel as $k => $v) {
94 
95  $line[] = sprintf('"%s" -> "%s" [labelfontsize=6,color=darkblue label="%s"];', str_replace(" ", "\\n", ($v["sourcefam"])) , str_replace(" ", "\\n", ($v["ciblefam"])) , $v["aid"]);
96  // $line[]='"'.utf8_encode(_($v["e1"])).'" -> "'.utf8_encode(_($v["e2"])).' [label="'..'";';
97 
98 }
99 //$line[]='"'.str_replace(" ","\\n",_($doc->firstState)).'" [shape = doublecircle,style=filled, width=1.5, fixedsize=true,fontsize='.$statefontsize.',fontname=sans];';;
100 $title = "reference";
101 $dot = "digraph \"" . $title . "\" {
102  ratio=\"$ratio\";
103  rankdir=$rankdir;
104  $size
105  bgcolor=\"transparent\";
106  {rank=1; \"$ft\";}
107  splines=false;
108  node [shape = circle, style=filled, fixedsize=true,width=1.5, fontsize=$statefontsize, fontname=sans];\n";
109 
110 $dot.= implode($line, "\n");
111 $dot.= "\n}";
112 
113 print $dot;
114 ?>
← centre documentaire © anakeen - published under CC License - Dynacase