You are here

function _gd_image_chart_vbar2d in Charts 6

1 call to _gd_image_chart_vbar2d()
gd_image_chart_image in gd_image_chart/gd_image_chart.inc

File

gd_image_chart/gd_image_chart.inc, line 174
@author Mads Peter Henderson http://drupal.org/user/421971

Code

function _gd_image_chart_vbar2d($image, $data, $series_count, $base, $padding, $vmargin, $hmargin, $ysize, $yscale, $xsize, $labelfont, $text_color) {

  // columns and x labels
  $padding = 3;

  // half of spacing between columns
  $series_handled = 0;
  foreach (element_children($data) as $series) {
    $color_html = empty($data[$series]['#color']) ? '#000000' : $data[$series]['#color'];
    $color_rgb = _gd_image_chart_html2rgb($color_html);
    $color = imagecolorallocate($image, $color_rgb[0], $color_rgb[1], $color_rgb[2]);
    $series_data = _charts_series_values($data[$series]);
    foreach ($series_data as $xval => $yval) {

      // vertical columns
      $ymax = $vmargin + $ysize;
      $ymin = $ymax - (int) ($yval * $yscale);
      $xmax = $hmargin + ($xval + 1) * $base - $padding;
      $xmin = $hmargin + $xval * $base + $padding;
      $xdelta = $xmax - $xmin;
      $xmax += $xdelta * ($series_handled + ($series_count - 1) * $xval);
      $xmin += $xdelta * ($series_handled + ($series_count - 1) * $xval);
      imagefilledrectangle($image, $xmin, $ymin, $xmax, $ymax, $color);

      // x labels
      if ($series_handled == 0) {

        //Only print labels for first series - avoid duplicates
        if (empty($data[$series][$xval]['#label'])) {
          $value_label = '';
        }
        else {
          $value_label = $data[$series][$xval]['#label'];
        }
        $txtsz = imagefontwidth($labelfont) * drupal_strlen($value_label);
        $xpos = $xmin + (int) (($xdelta * $series_count - $txtsz) / 2);
        $xpos = max($xmin, $xpos);
        $ypos = $ymax + 3;

        // distance from x axis
        imagestring($image, $labelfont, $xpos, $ypos, $value_label, $text_color);
      }
    }
    $series_handled += 1;
  }
}