You are here

function _gd_image_chart_line2d in Charts 6

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

File

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

Code

function _gd_image_chart_line2d($image, $data, $series_count, $base, $padding, $vmargin, $hmargin, $ysize, $yscale, $xsize, $labelfont, $text_color) {
  $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]);
    $y0_pos = $vmargin + $ysize;
    $xpos_prev = FALSE;
    $ypos_prev = FALSE;
    foreach ($series_data as $xval => $yval) {
      $xpos = $hmargin + ($xval + 1) * $base - $padding;
      $ypos = $y0_pos - (int) ($yval * $yscale);
      if ($xpos_prev && $ypos_prev) {
        imageline($image, $xpos_prev, $ypos_prev, $xpos, $ypos, $color);
      }
      $xpos_prev = $xpos;
      $ypos_prev = $ypos;

      // 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 = $xpos - $txtsz / 2;
        $ypos = $y0_pos + 3;

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