Index: trunk/extensions/SemanticResultFormats/jqPlot/SRF_jqPlotBar.php |
— | — | @@ -94,6 +94,8 @@ |
95 | 95 | $labels = array(); |
96 | 96 | // print all result rows |
97 | 97 | $count = 0; |
| 98 | + $max_number = 0; |
| 99 | + $min_number = 0; |
98 | 100 | while ( $row = $res->getNext() ) { |
99 | 101 | $name = $row[0]->getNextObject()->getShortWikiText(); |
100 | 102 | foreach ( $row as $field ) { |
— | — | @@ -105,7 +107,13 @@ |
106 | 108 | $nr = $object->getNumericValue(); |
107 | 109 | } |
108 | 110 | $count++; |
109 | | - |
| 111 | + if ( $nr > $max_number ) { |
| 112 | + $max_number = $nr; |
| 113 | + } |
| 114 | + if ( $nr < $min_number ) { |
| 115 | + $min_number = $nr; |
| 116 | + } |
| 117 | + |
110 | 118 | if ( $this->m_bardirection == 'horizontal' ) { |
111 | 119 | $numbers[] = "[$nr, $count]"; |
112 | 120 | } else { |
— | — | @@ -124,7 +132,7 @@ |
125 | 133 | $labels_axis ="xaxis"; |
126 | 134 | $numbers_axis = "yaxis"; |
127 | 135 | $angle_val = -40; |
128 | | - $barmargin= 30; |
| 136 | + $barmargin = 6; |
129 | 137 | if ( $this->m_bardirection == 'horizontal' ) { |
130 | 138 | $labels_axis ="yaxis"; |
131 | 139 | $numbers_axis ="xaxis"; |
— | — | @@ -133,6 +141,43 @@ |
134 | 142 | } |
135 | 143 | $barwidth = 20; // width of each bar |
136 | 144 | $bardistance = 4; // distance between two bars |
| 145 | + |
| 146 | + // Calculate the tick values for the numbers, based on the |
| 147 | + // lowest and highest number. jqPlot has its own option for |
| 148 | + // calculating ticks automatically - "autoscale" - but it |
| 149 | + // currently (September 2010) fails for numbers less than 1, |
| 150 | + // and negative numbers. |
| 151 | + // If both max and min are 0, just escape now. |
| 152 | + if ( $max_number == 0 && $min_number == 0 ) { |
| 153 | + return null; |
| 154 | + } |
| 155 | + // Make the max and min slightly larger and bigger than the |
| 156 | + // actual max and min, so that the bars don't directly touch |
| 157 | + // the top and bottom of the graph |
| 158 | + if ( $max_number > 0 ) { $max_number += .001; } |
| 159 | + if ( $min_number < 0 ) { $min_number -= .001; } |
| 160 | + if ( $max_number == 0 ) { |
| 161 | + $multipleOf10 = 0; |
| 162 | + $maxAxis = 0; |
| 163 | + } else { |
| 164 | + $multipleOf10 = pow( 10, floor( log( $max_number, 10 ) ) ); |
| 165 | + $maxAxis = ceil( $max_number / $multipleOf10 ) * $multipleOf10; |
| 166 | + } |
| 167 | + if ( $min_number == 0 ) { |
| 168 | + $negativeMultipleOf10 = 0; |
| 169 | + $minAxis = 0; |
| 170 | + } else { |
| 171 | + $negativeMultipleOf10 = -1 * pow( 10, floor( log( -1 * $min_number, 10 ) ) ); |
| 172 | + $minAxis = ceil( $min_number / $negativeMultipleOf10 ) * $negativeMultipleOf10; |
| 173 | + } |
| 174 | + $numbers_ticks = ''; |
| 175 | + $biggerMultipleOf10 = max( $multipleOf10, -1 * $negativeMultipleOf10 ); |
| 176 | + $lowestTick = floor( $minAxis / $biggerMultipleOf10 + .001 ); |
| 177 | + $highestTick = ceil( $maxAxis / $biggerMultipleOf10 - .001 ); |
| 178 | + for ( $i = $lowestTick; $i <= $highestTick; $i++ ) { |
| 179 | + $numbers_ticks .= ($i * $biggerMultipleOf10) . ", "; |
| 180 | + } |
| 181 | + |
137 | 182 | $js_bar =<<<END |
138 | 183 | <script type="text/javascript"> |
139 | 184 | jQuery.noConflict(); |
— | — | @@ -141,6 +186,9 @@ |
142 | 187 | plot1 = jQuery.jqplot('$barID', [[$numbers_str]], { |
143 | 188 | title: '{$this->m_charttitle}', |
144 | 189 | seriesColors: ['$this->m_barcolor'], |
| 190 | + seriesDefaults: { |
| 191 | + fillToZero: true |
| 192 | + }, |
145 | 193 | series: [ { |
146 | 194 | renderer: jQuery.jqplot.BarRenderer, rendererOptions: { |
147 | 195 | barDirection: '{$this->m_bardirection}', |
— | — | @@ -158,7 +206,7 @@ |
159 | 207 | } |
160 | 208 | }, |
161 | 209 | $numbers_axis: { |
162 | | - autoscale: true, |
| 210 | + ticks: [$numbers_ticks], |
163 | 211 | label: '{$this->m_numbersaxislabel}' |
164 | 212 | } |
165 | 213 | } |