Changeset 217596
- Timestamp:
- 03/14/2010 08:24:32 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cyclopress/branches/cp2/classes/cy_google_charts.php
r217586 r217596 96 96 97 97 // get all the chart data 98 $data = array(); 98 $x_data = array(); 99 $y_data = array(); 99 100 if (count($rides)) { 100 101 … … 104 105 $r->load($row); 105 106 106 $data[$r->get_startdate('Y-m-d_H:i:s')] = number_format($row[$chart->field], 1); 107 $x_data[] = $r->get_startdate('Y-m-d_H:i:s'); 108 $y_data[] = number_format($row[$chart->field], 1); 109 //$data[$r->get_startdate('Y-m-d_H:i:s')] = number_format($row[$chart->field], 1); 107 110 108 111 } … … 117 120 // send off to google and cache the images 118 121 // check if it's a line chart or a bar chart and retrieve the right one 119 $chart->url = $this->get_line_chart($ data, false, true);120 $chart->thumb_url = $this->get_line_chart($ data, true, true);122 $chart->url = $this->get_line_chart($x_data, $y_data, false, true); 123 $chart->thumb_url = $this->get_line_chart($x_data, $y_data, true, true); 121 124 122 125 // save the chart's new hash and url … … 132 135 * Using only a Google URL is not desirable due to API request limits. 133 136 * 134 * @param array $data An associative array. The keys are the X data, values are the Y data. 137 * @param array $x_data The X data. 138 * @param array $y_data The Y data. 135 139 * @param boolean $is_thumb True if the chart URL to be returned should be a thumbnail. False for full size. 136 140 * @param boolean $is_by_date True if the X data represents dates. 137 141 */ 138 public function get_line_chart( $data, $is_thumb=false, $is_by_date=true) {142 public function get_line_chart(&$x_data, &$y_data, $is_thumb=false, $is_by_date=true) { 139 143 140 144 // no data? get out of here... 141 if ( !count($ data) ) {145 if ( !count($y_data) ) { 142 146 // alternatively return a URL to a "not found" image 143 147 return '<span class="error">Unable to get chart image. There was no data in your query.</span>'; 144 148 } 145 146 // get each data set separately147 $x_data = array_keys($data);148 $y_data = array_values($data);149 149 150 150 // get max/min … … 152 152 $max = max($y_data); 153 153 154 // counts 155 $num_x_data = count($x_data); 156 $num_y_data = count($y_data); 157 154 158 // get nice tick ranges for the data 155 159 $range = $max - $min; 156 160 $smart_min = ($min > ($range*0.1)) ? floor($min - ($range*0.1)) : 0; // avoid too much space at the bottom of the chart 157 list($x_tick_range, $x_lower_bound, $x_upper_bound) = $this->get_chart_step_size(7, ( count($x_data)-1), 1);161 list($x_tick_range, $x_lower_bound, $x_upper_bound) = $this->get_chart_step_size(7, ($num_x_data-1), 1); 158 162 list($y_tick_range, $y_lower_bound, $y_upper_bound) = $this->get_chart_step_size(8, $max, $smart_min); 159 163 … … 164 168 // map dates onto x labels if they're dates 165 169 if ($is_by_date) { 166 $x_ date_labels = array();170 $x_labels = array(); 167 171 foreach($x_label_positions as $xpos) { 168 $index = round($xpos / 100 * ( count($x_data)- 1) );172 $index = round($xpos / 100 * ($num_x_data - 1) ); 169 173 $time = strtotime(str_replace('_', ' ', $x_data[$index])); 170 $x_ date_labels[] = urlencode(date("M j, 'y", $time));174 $x_labels[] = urlencode(date("M j, 'y", $time)); 171 175 } 172 $x_labels = $x_date_labels;173 176 } 174 177
Note: See TracChangeset
for help on using the changeset viewer.