Index: trunk/extensions/SemanticResultFormats/GraphViz/SRF_Graph.php |
— | — | @@ -23,7 +23,8 @@ |
24 | 24 | protected $m_graphSize = ""; |
25 | 25 | protected $m_labelArray = array(); |
26 | 26 | 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 | + |
28 | 29 | protected function readParameters( $params, $outputmode ) { |
29 | 30 | SMWResultPrinter::readParameters( $params, $outputmode ); |
30 | 31 | |
— | — | @@ -44,6 +45,10 @@ |
45 | 46 | |
46 | 47 | $this->m_graphLink = array_key_exists( 'graphlink', $params ) && strtolower( trim( $params['graphlink'] ) ) == 'yes'; |
47 | 48 | $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 | + } |
48 | 53 | } |
49 | 54 | |
50 | 55 | protected function getResultText( /* SMWQueryResult */ $res, $outputmode ) { |
— | — | @@ -107,12 +112,16 @@ |
108 | 113 | |
109 | 114 | // Loop throught all the parts of the field value. |
110 | 115 | 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 ); |
114 | 121 | } |
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 | + } |
117 | 126 | } |
118 | 127 | } |
119 | 128 | |
— | — | @@ -126,13 +135,13 @@ |
127 | 136 | * |
128 | 137 | * @param SMWDataValue $object |
129 | 138 | * @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 |
132 | 141 | * @param string $labelName |
133 | 142 | * |
134 | 143 | * @return string |
135 | 144 | */ |
136 | | - protected function getGVForDataValue( SMWDataValue $object, $outputmode, $isFirstColumn, $firstColValue, $labelName ) { |
| 145 | + protected function getGVForDataValue( SMWDataValue $object, $outputmode, $isName, $name, $labelName ) { |
137 | 146 | $graphInput = ''; |
138 | 147 | $text = $object->getShortText( $outputmode ); |
139 | 148 | |
— | — | @@ -143,8 +152,8 @@ |
144 | 153 | $graphInput .= " \"$text\" [URL = \"$nodeLinkURL\"]; "; |
145 | 154 | } |
146 | 155 | |
147 | | - if ( !$isFirstColumn ) { |
148 | | - $graphInput .= " \"$firstColValue\" -> \"$text\" "; // TODO |
| 156 | + if ( !$isName ) { |
| 157 | + $graphInput .= " \"$name\" -> \"$text\" "; |
149 | 158 | |
150 | 159 | if ( $this->m_graphLabel && $this->m_graphColor ) { |
151 | 160 | $graphInput .= ' ['; |
— | — | @@ -153,8 +162,7 @@ |
154 | 163 | $this->m_labelArray[] = $labelName; |
155 | 164 | } |
156 | 165 | |
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 )]; |
159 | 167 | |
160 | 168 | if ( $this->m_graphLabel ) { |
161 | 169 | $graphInput .= "label=\"$labelName\""; |