-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgraphvis.php
More file actions
116 lines (94 loc) · 3.87 KB
/
graphvis.php
File metadata and controls
116 lines (94 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
class GoogleChart
{
public $baseurl = 'http://chart.apis.google.com/chart';
public $type = 'gv';
public $size = array('width' => 300, 'height' => 200);
public $nodes = array();
public $nodeAttributes = array();
public function __construct($size = NULL, $type = NULL)
{
if($size)
$this->size = $size;
if($type)
$this->type = $type;
}
public function addNode($parentId, $id)
{
$parentId = preg_replace('/[^_0-9a-zA-Z\200-\377<>\'"=\/\-.:]+/u', ' ', $parentId);
$id = preg_replace('/[^_0-9a-zA-Z\200-\377<>\'"=\/\-:.]+/u', ' ', $id);
$this->nodes[$parentId][] = $id;
}
public function addNodeAttribute($id, $attribute, $value)
{
$id = preg_replace('/[^_0-9a-zA-Z\200-\377<>\'"=\/\-.:]+/u', ' ', $id);
$attribute = preg_replace('/[^_0-9a-zA-Z\200-\377<>\'"=\/\-.:]+/u', ' ', $attribute);
$value = preg_replace('/[^_0-9a-zA-Z\200-\377<>\'"=\/\-.:]+/u', ' ', $value);
$this->nodeAttributes[$id][$attribute] = $value;
}
public function render()
{
$nodes = '';
$nodeAttributes = '';
foreach($this->nodes as $parentId => $children)
{
foreach($children as $id)
{
if($parentId)
$nodes .= "\"{$parentId}\"->\"{$id}\";";
else
$nodes .= "\"{$id}\";";
}
}
foreach($this->nodeAttributes as $id => $attributes)
{
$childNodeAttributes = array();
foreach($attributes as $attribute => $value)
{
if(substr($value,0,1) == '<' && substr($value,-1,1) == '>')
$childNodeAttributes[] = "\"{$attribute}\"={$value}";
else
$childNodeAttributes[] = "\"{$attribute}\"=\"{$value}\"";
}
$nodeAttributes .= "\"{$id}\" [" . implode(',', $childNodeAttributes) . "];";
}
$size = "{$this->size['width']}x{$this->size['height']}";
$url = $this->baseurl . '?' . http_build_query(array(
'cht' => $this->type
,'chs' => $size
,'chl' => "digraph{{$nodes}{$nodeAttributes}}"
));
echo "<img src=\"{$url}\">";
// echo "<br/>" . urldecode($url);
}
}
$gc = new GoogleChart(array('width' => 600, 'height' => 500));
<cf_graphviz size="200x350">
<cf_graphviz_node id="Welcome Message" shape="box">
<cf_graphviz_node id="Powerdata Form" shape="hexagon" style="filled" color="salmon">
<cf_graphviz_node id="Reject Spam" shape="trapezium">
<cf_graphviz_node id="Email Form Data" shape="folder" style="filled" color="lightblue2">
<cf_graphviz_node id="Thankyou Message" shape="box">
<cf_graphviz_node id="Redirect to Home Page" shape="box3d">
<cf_graphviz_relation parent="Welcome Message" child="Powerdata Form">
<cf_graphviz_relation parent="Powerdata Form" child="Email Form Data">
<cf_graphviz_relation parent="Powerdata Form" child="Reject Spam">
<cf_graphviz_relation parent="Email Form Data" child="Thankyou Message">
<cf_graphviz_relation parent="Thankyou Message" child="Redirect to Home Page">
</cf_graphviz>
$gc->addNode('Welcome Message', 'Powerdata Form');
$gc->addNode('Powerdata Form', 'Email Form Data');
$gc->addNode('Powerdata Form', 'Reject Spam');
$gc->addNode('Email Form Data', 'Thankyou Message');
$gc->addNode('Thankyou Message', 'Redirect to Home Page');
$gc->addNodeAttribute('Welcome Message', 'shape', 'box');
$gc->addNodeAttribute('Powerdata Form', 'shape', 'hexagon');
$gc->addNodeAttribute('Powerdata Form', 'style', 'filled');
$gc->addNodeAttribute('Powerdata Form', 'color', 'salmon');
$gc->addNodeAttribute('Reject Spam', 'shape', 'trapezium');
$gc->addNodeAttribute('Email Form Data', 'shape', 'folder');
$gc->addNodeAttribute('Email Form Data', 'style', 'filled');
$gc->addNodeAttribute('Email Form Data', 'color', 'lightblue2');
$gc->addNodeAttribute('Thankyou Message', 'shape', 'box');
$gc->addNodeAttribute('Redirect to Home Page', 'shape', 'box3d');
$gc->render();