r84952 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84951‎ | r84952 | r84953 >
Date:11:42, 29 March 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some cleanup of the graph format
Modified paths:
  • /trunk/extensions/SemanticResultFormats/GraphViz/SRF_Graph.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/GraphViz/SRF_Graph.php
@@ -1,82 +1,60 @@
22 <?php
3 -/**
4 - * Print query results as a graph.
5 - * @author Frank Dengler
6 - *
7 - */
83
94 /**
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
1212 *
13 - * @note AUTOLOADED
 13+ * @licence GNU GPL v2+
 14+ * @author Frank Dengler
 15+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1416 */
15 -if ( !defined( 'MEDIAWIKI' ) ) {
16 - die( 'Not an entry point.' );
17 -}
18 -
1917 class SRFGraph extends SMWResultPrinter {
2018 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;
2523 protected $m_rankdir = "LR";
2624 protected $m_graphSize = "";
2725 protected $m_labelArray = array();
2826 protected $m_graphColors = array( 'black', 'red', 'green', 'blue', 'darkviolet', 'gold', 'deeppink', 'brown', 'bisque', 'darkgreen', 'yellow', 'darkblue', 'magenta', 'steelblue2' );
2927
3028 protected function readParameters( $params, $outputmode ) {
31 -
3229 SMWResultPrinter::readParameters( $params, $outputmode );
3330
3431 if ( array_key_exists( 'graphname', $params ) ) {
35 -
3632 $this->m_graphName = trim( $params['graphname'] );
37 -
3833 }
 34+
3935 if ( array_key_exists( 'graphsize', $params ) ) {
40 -
4136 $this->m_graphSize = trim( $params['graphsize'] );
42 -
4337 }
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';
4541
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 - }
5542 if ( array_key_exists( 'rankdir', $params ) ) {
56 -
5743 $this->m_rankdir = strtoupper( trim( $params['rankdir'] ) );
58 -
5944 }
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';
7148 }
 49+
7250 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 = '';
7558
76 - $key = 0;
77 - // Create text graph
78 - $graphInput = '';
79 - $legendInput = '';
80 -
8159 $graphInput .= "digraph $this->m_graphName {";
8260 if ( $this->m_graphSize != '' ) $graphInput .= "size=\"$this->m_graphSize\";";
8361 $graphInput .= "rankdir=$this->m_rankdir;";
@@ -149,18 +127,20 @@
150128 }
151129 $result .= "</P>";
152130 }
 131+
153132 return $result;
154133 }
155134
156135 function getParameters() {
157136 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' ) )
165144 );
166145 }
 146+
167147 }

Status & tagging log