r84957 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84956‎ | r84957 | r84958 >
Date:14:18, 29 March 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added name property parameter
Modified paths:
  • /trunk/extensions/SemanticResultFormats/GraphViz/SRF_Graph.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/GraphViz/SRF_Graph.php
@@ -23,7 +23,8 @@
2424 protected $m_graphSize = "";
2525 protected $m_labelArray = array();
2626 protected $m_graphColors = array( 'black', 'red', 'green', 'blue', 'darkviolet', 'gold', 'deeppink', 'brown', 'bisque', 'darkgreen', 'yellow', 'darkblue', 'magenta', 'steelblue2' );
27 -
 27+ protected $m_nameProperty = false;
 28+
2829 protected function readParameters( $params, $outputmode ) {
2930 SMWResultPrinter::readParameters( $params, $outputmode );
3031
@@ -44,6 +45,10 @@
4546
4647 $this->m_graphLink = array_key_exists( 'graphlink', $params ) && strtolower( trim( $params['graphlink'] ) ) == 'yes';
4748 $this->m_graphColor = array_key_exists( 'graphcolor', $params ) && strtolower( trim( $params['graphcolor'] ) ) == 'yes';
 49+
 50+ if ( array_key_exists( 'nameproperty', $params ) ) {
 51+ $this->m_nameProperty = trim( $params['nameproperty'] );
 52+ }
4853 }
4954
5055 protected function getResultText( /* SMWQueryResult */ $res, $outputmode ) {
@@ -107,12 +112,16 @@
108113
109114 // Loop throught all the parts of the field value.
110115 while ( ( $object = $resultArray->getNextObject() ) !== false ) {
111 - if ( $i == 0 ) {
112 - $firstColValue = $object->getShortText( $outputmode );
113 - $labelName = $resultArray->getPrintRequest()->getLabel();
 116+ $propName = $resultArray->getPrintRequest()->getLabel();
 117+ $isName = $this->m_nameProperty ? ( $i != 0 && $this->m_nameProperty === $propName ) : $i == 0;
 118+
 119+ if ( $isName ) {
 120+ $name = $object->getShortText( $outputmode );
114121 }
115 -
116 - $segments[] = $this->getGVForDataValue( $object, $outputmode, $i == 0, $firstColValue, $labelName );
 122+
 123+ if ( !( $this->m_nameProperty && $i == 0 ) ) {
 124+ $segments[] = $this->getGVForDataValue( $object, $outputmode, $isName, $name, $propName );
 125+ }
117126 }
118127 }
119128
@@ -126,13 +135,13 @@
127136 *
128137 * @param SMWDataValue $object
129138 * @param $outputmode
130 - * @param boolean $isFirstColumn
131 - * @param string $firstColValue
 139+ * @param boolean $isName Is this the name that should be used for the node?
 140+ * @param string $name
132141 * @param string $labelName
133142 *
134143 * @return string
135144 */
136 - protected function getGVForDataValue( SMWDataValue $object, $outputmode, $isFirstColumn, $firstColValue, $labelName ) {
 145+ protected function getGVForDataValue( SMWDataValue $object, $outputmode, $isName, $name, $labelName ) {
137146 $graphInput = '';
138147 $text = $object->getShortText( $outputmode );
139148
@@ -143,8 +152,8 @@
144153 $graphInput .= " \"$text\" [URL = \"$nodeLinkURL\"]; ";
145154 }
146155
147 - if ( !$isFirstColumn ) {
148 - $graphInput .= " \"$firstColValue\" -> \"$text\" "; // TODO
 156+ if ( !$isName ) {
 157+ $graphInput .= " \"$name\" -> \"$text\" ";
149158
150159 if ( $this->m_graphLabel && $this->m_graphColor ) {
151160 $graphInput .= ' [';
@@ -153,8 +162,7 @@
154163 $this->m_labelArray[] = $labelName;
155164 }
156165
157 - $key = array_search( $labelName, $this->m_labelArray, true );
158 - $color = $this->m_graphColors[$key];
 166+ $color = $this->m_graphColors[array_search( $labelName, $this->m_labelArray, true )];
159167
160168 if ( $this->m_graphLabel ) {
161169 $graphInput .= "label=\"$labelName\"";

Follow-up revisions

RevisionCommit summaryAuthorDate
r84958follow up to r84957; added param to reverse the relationjeroendedauw14:24, 29 March 2011

Status & tagging log