예제 #1
0
 public function draw_summary_chart($gb_captions)
 {
     $f = $this->init_module(Libs_OpenFlashChart::module_name());
     //row summary numeric
     $f2 = $this->init_module(Libs_OpenFlashChart::module_name());
     //row summary currency
     $fc = $this->init_module(Libs_OpenFlashChart::module_name());
     //columns summary numeric
     $fc2 = $this->init_module(Libs_OpenFlashChart::module_name());
     //columns summary currency
     $title = new OFC_Elements_Title("Summary by row");
     $f->set_title($title);
     $f2->set_title($title);
     if (!empty($this->categories)) {
         $labels = array();
         $labels_c = array();
         foreach ($this->categories as $q => $c) {
             if ($this->format[$c] == 'currency') {
                 $labels_c[] = strip_tags($c);
             } else {
                 $labels[] = strip_tags($c);
             }
         }
         $x_ax = new OFC_Elements_Axis_X();
         $x_ax->set_labels_from_array($labels);
         $f->set_x_axis($x_ax);
         $x_ax = new OFC_Elements_Axis_X();
         $x_ax->set_labels_from_array($labels_c);
         $f2->set_x_axis($x_ax);
     }
     $title = new OFC_Elements_Title("Summary by column");
     $fc->set_title($title);
     $fc2->set_title($title);
     $labels = array();
     foreach ($gb_captions as $cap) {
         $labels[] = $cap['name'];
     }
     $x_ax = new OFC_Elements_Axis_X();
     $x_ax->set_labels_from_array($labels);
     $fc->set_x_axis($x_ax);
     $fc2->set_x_axis($x_ax);
     $max = 5;
     $max2 = 5;
     $maxc = 5;
     $maxc2 = 5;
     $curr = false;
     $num = false;
     $col_total = array();
     $color = 0;
     foreach ($this->ref_records as $k => $r) {
         $results = call_user_func($this->display_cell_callback, $r);
         $ref_rec = call_user_func($this->ref_record_display_callback, $r, true);
         $bar = new OFC_Charts_Bar_Glass();
         $bar->set_colour(self::$colours[$color % count(self::$colours)]);
         $color++;
         $bar->set_key(strip_tags($ref_rec), 10);
         if (empty($this->categories)) {
             $total = 0;
             $i = 0;
             foreach ($results as &$res_ref) {
                 if (is_array($res_ref)) {
                     $res_ref = array_pop($res_ref);
                 }
                 $val = strip_tags($res_ref);
                 $total += $val;
                 if (!isset($this->cols_total[$i])) {
                     $this->cols_total[$i] = array();
                 }
                 $this->cols_total[$i][0] += $val;
                 $i++;
             }
             $bar->set_values(array($total));
             if ($this->format == 'currency') {
                 if ($total > $max2) {
                     $max2 = $total;
                 }
                 $f2->add_element($bar);
                 $curr = true;
             } else {
                 if ($total > $max) {
                     $max = $total;
                 }
                 $f->add_element($bar);
                 $num = true;
             }
         } else {
             $bar_c = new OFC_Charts_Bar_Glass();
             $bar_c->set_colour(self::$colours[$color % count(self::$colours)]);
             $bar_c->set_key(strip_tags($ref_rec), 10);
             $arr = array();
             $arr_c = array();
             foreach ($this->categories as $q => $c) {
                 $total = 0;
                 if (!isset($this->cols_total[$c])) {
                     $this->cols_total[$c] = array();
                 }
                 $i = 0;
                 foreach ($results as $v) {
                     if (is_array($v[$c])) {
                         $v[$c] = reset($v[$c]);
                     }
                     $val = (double) strip_tags($v[$c]);
                     $total += $val;
                     if (!isset($this->cols_total[$c][$i])) {
                         $this->cols_total[$c][$i] = 0;
                     }
                     $this->cols_total[$c][$i] += $val;
                     $i++;
                 }
                 if ($this->format[$c] == 'currency') {
                     $arr_c[] = $total;
                     if ($max2 < $total) {
                         $max2 = $total;
                     }
                 } else {
                     $arr[] = $total;
                     if ($max < $total) {
                         $max = $total;
                     }
                 }
             }
             if (!empty($arr)) {
                 $bar->set_values($arr);
                 $f->add_element($bar);
                 $num = true;
             }
             if (!empty($arr_c)) {
                 $bar_c->set_values($arr_c);
                 $f2->add_element($bar_c);
                 $curr = true;
             }
         }
     }
     if ($num) {
         $y_ax = new OFC_Elements_Axis_Y();
         $y_ax->set_range(0, $max);
         $y_ax->set_steps($max / 10);
         $f->set_y_axis($y_ax);
         $f->set_width(950);
         $f->set_height(400);
         $this->display_module($f);
         print '<br>';
     }
     if ($curr) {
         $y_ax = new OFC_Elements_Axis_Y();
         $y_ax->set_range(0, $max2);
         $y_ax->set_steps($max2 / 10);
         $f2->set_y_axis($y_ax);
         $f2->set_width(950);
         $f2->set_height(400);
         $this->display_module($f2);
         print '<br>';
     }
     if (empty($this->categories)) {
         $bar = new OFC_Charts_Bar_Glass();
         $bar->set_colour(self::$colours[0]);
         $bar->set_key('Total', 10);
         $mm = 5;
         $values = array();
         foreach ($this->cols_total as $val) {
             $rval = $val[0];
             if ($mm < $rval) {
                 $mm = $rval;
             }
             $values[] = $rval;
         }
         $bar->set_values($values);
         if ($this->format == 'currency') {
             $maxc2 = $mm;
             $fc2->add_element($bar);
         } else {
             $maxc = $mm;
             $fc->add_element($bar);
         }
     } else {
         $i = 0;
         foreach ($this->cols_total as $k => $arr) {
             $bar = new OFC_Charts_Bar_Glass();
             $bar->set_colour(self::$colours[$i % count(self::$colours)]);
             $bar->set_key(strip_tags($k), 10);
             $bar->set_values($arr);
             $mm = 5;
             foreach ($arr as $val) {
                 if ($mm < $val) {
                     $mm = $val;
                 }
             }
             if ($this->format[$k] == 'currency') {
                 if ($mm > $maxc2) {
                     $maxc2 = $mm;
                 }
                 $fc2->add_element($bar);
             } else {
                 if ($mm > $maxc) {
                     $maxc = $mm;
                 }
                 $fc->add_element($bar);
             }
             $i++;
         }
     }
     if ($num) {
         $y_ax = new OFC_Elements_Axis_Y();
         $y_ax->set_range(0, $maxc);
         $y_ax->set_steps($maxc / 10);
         $fc->set_y_axis($y_ax);
         $fc->set_width(950);
         $fc->set_height(400);
         $this->display_module($fc);
         print '<br>';
     }
     if ($curr) {
         $y_ax = new OFC_Elements_Axis_X();
         $y_ax->set_range(0, $maxc2);
         $y_ax->set_steps($maxc2 / 10);
         $fc2->set_y_axis($y_ax);
         $fc2->set_width(950);
         $fc2->set_height(400);
         $this->display_module($fc2);
         print '<br>';
     }
 }