Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00128 function tripal_cv_chart($chart_id) { 00129 // parse out the tripal module name from the chart_id to find out 00130 // which Tripal "hook" to call: 00131 $tripal_mod = preg_replace("/^(tripal_.+?)_cv_chart_(.+)$/", "$1", $chart_id); 00132 $callback = $tripal_mod . "_cv_chart"; 00133 00134 // now call the function in the module responsible for the chart to fill out 00135 // an options array needed by the tripal_cv_count_chart call below. 00136 $opt = call_user_func_array($callback, array($chart_id)); 00137 00138 // build the JSON array to return to the javascript caller 00139 $json_arr = tripal_cv_count_chart( 00140 $opt['count_mview'], 00141 $opt['cvterm_id_column'], 00142 $opt['count_column'], 00143 $opt['filter'], 00144 $opt['title'], 00145 $opt['type'], 00146 $opt['size'] 00147 ); 00148 $json_arr[] = $chart_id; // add the chart_id back into the json array 00149 00150 return drupal_json($json_arr); 00151 00152 } 00153 00188 function tripal_cv_count_chart($cnt_table, $fk_column, 00189 $cnt_column, $filter = NULL, $title = '', $type = 'p3', $size='300x75') { 00190 00191 if (!$type) { 00192 $type = 'p3'; 00193 } 00194 00195 if (!$size) { 00196 $size = '300x75'; 00197 } 00198 00199 if (!$filter) { 00200 $filter = '(1=1)'; 00201 } 00202 00203 $is_pie = 0; 00204 if (strcmp($type, 'p') == 0 or strcmp($type, 'p3') == 0) { 00205 $is_pie = 1; 00206 } 00207 $sql = " 00208 SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items 00209 FROM {$cnt_table} CNT 00210 INNER JOIN {cvterm} CVT on CNT.$fk_column = CVT.cvterm_id 00211 WHERE $filter 00212 "; 00213 00214 $features = array(); 00215 $results = chado_query($sql); 00216 $data = array(); 00217 $axis = array(); 00218 $legend = array(); 00219 $total = 0; 00220 $max = 0; 00221 $i = 1; 00222 while ($term = db_fetch_object($results)) { 00223 00224 if ($is_pie) { 00225 $axis[] = "$term->name (" . number_format($term->num_items) . ")"; 00226 $data[] = array($term->num_items, 0, 0); 00227 } 00228 else { 00229 $axis[] = "$term->name (" . number_format($term->num_items) . ")"; 00230 $data[] = array($term->num_items); 00231 //$legend[] = "$term->name (" . number_format($term->num_items) . ")"; 00232 } 00233 if ($term->num_items > $max) { 00234 $max = $term->num_items; 00235 } 00236 $total += $term->num_items; 00237 $i++; 00238 } 00239 // convert numerical values into percentages 00240 foreach ($data as &$set) { 00241 $set[0] = ($set[0] / $total) * 100; 00242 } 00243 $opt[] = array( 00244 data => $data, 00245 axis_labels => $axis, 00246 legend => $legend, 00247 size => $size, 00248 type => $type, 00249 00250 bar_width => 10, 00251 bar_spacing => 0, 00252 title => $title 00253 ); 00254 // $opt[] = $sql; 00255 00256 return $opt; 00257 }