Index: trunk/extensions/SemanticResultFormats/GraphViz/SRF_Graph.php |
— | — | @@ -1,82 +1,60 @@ |
2 | 2 | <?php |
3 | | -/** |
4 | | - * Print query results as a graph. |
5 | | - * @author Frank Dengler |
6 | | - * |
7 | | - */ |
8 | 3 | |
9 | 4 | /** |
10 | | - * New implementation of SMW's printer for result in a graph. |
11 | | - * This SMW printer requires the mediawiki graphviz extention. |
| 5 | + * SMW result printer for graphs using graphViz. |
| 6 | + * In order to use this printer you need to have both |
| 7 | + * the graphViz library installed on your system and |
| 8 | + * have the graphViz MediaWiki extension installed. |
| 9 | + * |
| 10 | + * @file SRF_Graph.php |
| 11 | + * @ingroup SemanticResultFormats |
12 | 12 | * |
13 | | - * @note AUTOLOADED |
| 13 | + * @licence GNU GPL v2+ |
| 14 | + * @author Frank Dengler |
| 15 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 16 | */ |
15 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
16 | | - die( 'Not an entry point.' ); |
17 | | -} |
18 | | - |
19 | 17 | class SRFGraph extends SMWResultPrinter { |
20 | 18 | protected $m_graphName = 'QueryResult'; |
21 | | - protected $m_graphLabel = false; |
22 | | - protected $m_graphColor = false; |
23 | | - protected $m_graphLegend = false; |
24 | | - protected $m_graphLink = false; |
| 19 | + protected $m_graphLabel; |
| 20 | + protected $m_graphColor; |
| 21 | + protected $m_graphLegend; |
| 22 | + protected $m_graphLink; |
25 | 23 | protected $m_rankdir = "LR"; |
26 | 24 | protected $m_graphSize = ""; |
27 | 25 | protected $m_labelArray = array(); |
28 | 26 | protected $m_graphColors = array( 'black', 'red', 'green', 'blue', 'darkviolet', 'gold', 'deeppink', 'brown', 'bisque', 'darkgreen', 'yellow', 'darkblue', 'magenta', 'steelblue2' ); |
29 | 27 | |
30 | 28 | protected function readParameters( $params, $outputmode ) { |
31 | | - |
32 | 29 | SMWResultPrinter::readParameters( $params, $outputmode ); |
33 | 30 | |
34 | 31 | if ( array_key_exists( 'graphname', $params ) ) { |
35 | | - |
36 | 32 | $this->m_graphName = trim( $params['graphname'] ); |
37 | | - |
38 | 33 | } |
| 34 | + |
39 | 35 | if ( array_key_exists( 'graphsize', $params ) ) { |
40 | | - |
41 | 36 | $this->m_graphSize = trim( $params['graphsize'] ); |
42 | | - |
43 | 37 | } |
44 | | - if ( array_key_exists( 'graphlegend', $params ) ) { |
| 38 | + |
| 39 | + $this->m_graphLegend = array_key_exists( 'graphlegend', $params ) && strtolower( trim( $params['graphlegend'] ) ) == 'yes'; |
| 40 | + $this->m_graphLabel = array_key_exists( 'graphlabel', $params ) && strtolower( trim( $params['graphlabel'] ) ) == 'yes'; |
45 | 41 | |
46 | | - if ( strtolower( trim( $params['graphlegend'] ) ) == 'yes' ) $this->m_graphLegend = true; |
47 | | - |
48 | | - } |
49 | | - |
50 | | - if ( array_key_exists( 'graphlabel', $params ) ) { |
51 | | - |
52 | | - if ( strtolower( trim( $params['graphlabel'] ) ) == 'yes' ) $this->m_graphLabel = true; |
53 | | - |
54 | | - } |
55 | 42 | if ( array_key_exists( 'rankdir', $params ) ) { |
56 | | - |
57 | 43 | $this->m_rankdir = strtoupper( trim( $params['rankdir'] ) ); |
58 | | - |
59 | 44 | } |
60 | | - if ( array_key_exists( 'graphlink', $params ) ) { |
61 | | - |
62 | | - if ( strtolower( trim( $params['graphlink'] ) ) == 'yes' ) $this->m_graphLink = true; |
63 | | - |
64 | | - } |
65 | | - if ( array_key_exists( 'graphcolor', $params ) ) { |
66 | | - |
67 | | - if ( strtolower( trim( $params['graphcolor'] ) ) == 'yes' ) $this->m_graphColor = true; |
68 | | - |
69 | | - } |
70 | | - |
| 45 | + |
| 46 | + $this->m_graphLink = array_key_exists( 'graphlink', $params ) && strtolower( trim( $params['graphlink'] ) ) == 'yes'; |
| 47 | + $this->m_graphColor = array_key_exists( 'graphcolor', $params ) && strtolower( trim( $params['graphcolor'] ) ) == 'yes'; |
71 | 48 | } |
| 49 | + |
72 | 50 | protected function getResultText( $res, $outputmode ) { |
73 | | - $wgGraphVizSettings = new GraphVizSettings; |
74 | | - $this->isHTML = true; |
| 51 | + $wgGraphVizSettings = new GraphVizSettings; |
| 52 | + $this->isHTML = true; |
| 53 | + |
| 54 | + $key = 0; |
| 55 | + // Create text graph |
| 56 | + $graphInput = ''; |
| 57 | + $legendInput = ''; |
75 | 58 | |
76 | | - $key = 0; |
77 | | - // Create text graph |
78 | | - $graphInput = ''; |
79 | | - $legendInput = ''; |
80 | | - |
81 | 59 | $graphInput .= "digraph $this->m_graphName {"; |
82 | 60 | if ( $this->m_graphSize != '' ) $graphInput .= "size=\"$this->m_graphSize\";"; |
83 | 61 | $graphInput .= "rankdir=$this->m_rankdir;"; |
— | — | @@ -149,18 +127,20 @@ |
150 | 128 | } |
151 | 129 | $result .= "</P>"; |
152 | 130 | } |
| 131 | + |
153 | 132 | return $result; |
154 | 133 | } |
155 | 134 | |
156 | 135 | function getParameters() { |
157 | 136 | return array( |
158 | | - array('name' => 'graphname', 'type' => 'string', 'description' => wfMsg('srf_paramdesc_graphname')), |
159 | | - array('name' => 'graphsize', 'type' => 'int', 'description' => wfMsg('srf_paramdesc_graphsize')), |
160 | | - array('name' => 'graphlegend', 'type' => 'enumeration', 'description' => wfMsg('srf_paramdesc_graphlegend'), 'values'=>array('yes', 'no')), |
161 | | - array('name' => 'graphlabel', 'type' => 'enumeration', 'description' => wfMsg('srf_paramdesc_graphlabel'), 'values'=>array('yes', 'no')), |
162 | | - array('name' => 'rankdir', 'type' => 'string', 'description' => wfMsg('srf_paramdesc_rankdir')), |
163 | | - array('name' => 'graphlink', 'type' => 'enumeration', 'description' => wfMsg('srf_paramdesc_graphlink'), 'values'=>array('yes', 'no')), |
164 | | - array('name' => 'graphcolor', 'type' => 'enumeration', 'description' => wfMsg('srf_paramdesc_graphcolor'), 'values'=>array('yes', 'no')) |
| 137 | + array( 'name' => 'graphname', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_graphname' ) ), |
| 138 | + array( 'name' => 'graphsize', 'type' => 'int', 'description' => wfMsg( 'srf_paramdesc_graphsize' ) ), |
| 139 | + array( 'name' => 'graphlegend', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_graphlegend' ), 'values'=> array( 'yes', 'no' ) ), |
| 140 | + array( 'name' => 'graphlabel', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_graphlabel' ), 'values'=> array( 'yes', 'no' ) ), |
| 141 | + array( 'name' => 'rankdir', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_rankdir' ) ), |
| 142 | + array( 'name' => 'graphlink', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_graphlink' ), 'values'=> array( 'yes', 'no' ) ), |
| 143 | + array( 'name' => 'graphcolor', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_graphcolor' ), 'values'=> array( 'yes', 'no' ) ) |
165 | 144 | ); |
166 | 145 | } |
| 146 | + |
167 | 147 | } |