123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <?php
- function tripal_cv_chart($chart_id) {
-
-
- $tripal_mod = preg_replace("/^(tripal_.+?)_cv_chart_(.+)$/", "$1", $chart_id);
- $callback = $tripal_mod . "_cv_chart";
-
-
- $opt = call_user_func_array($callback, array($chart_id));
-
- $json_arr = tripal_cv_count_chart(
- $opt['count_mview'],
- $opt['cvterm_id_column'],
- $opt['count_column'],
- $opt['filter'],
- $opt['title'],
- $opt['type'],
- $opt['size']
- );
- $json_arr[] = $chart_id;
- return drupal_json($json_arr);
- }
-
- function tripal_cv_count_chart($cnt_table, $fk_column,
- $cnt_column, $filter = NULL, $title = '', $type = 'p3', $size='300x75') {
- if (!$type) {
- $type = 'p3';
- }
- if (!$size) {
- $size = '300x75';
- }
- if (!$filter) {
- $filter = '(1=1)';
- }
- $is_pie = 0;
- if (strcmp($type, 'p') == 0 or strcmp($type, 'p3') == 0) {
- $is_pie = 1;
- }
- $sql = "
- SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items
- FROM {$cnt_table} CNT
- INNER JOIN {cvterm} CVT on CNT.$fk_column = CVT.cvterm_id
- WHERE $filter
- ";
- $features = array();
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
- $data = array();
- $axis = array();
- $legend = array();
- $total = 0;
- $max = 0;
- $i = 1;
- while ($term = db_fetch_object($results)) {
- if ($is_pie) {
- $axis[] = "$term->name (" . number_format($term->num_items) . ")";
- $data[] = array($term->num_items, 0, 0);
- }
- else {
- $axis[] = "$term->name (" . number_format($term->num_items) . ")";
- $data[] = array($term->num_items);
-
- }
- if ($term->num_items > $max) {
- $max = $term->num_items;
- }
- $total += $term->num_items;
- $i++;
- }
-
- foreach ($data as &$set) {
- $set[0] = ($set[0] / $total) * 100;
- }
- $opt[] = array(
- data => $data,
- axis_labels => $axis,
- legend => $legend,
- size => $size,
- type => $type,
- bar_width => 10,
- bar_spacing => 0,
- title => $title
- );
-
- return $opt;
- }
|