openflash chart max bug

alpapan - September 5, 2009 - 15:59
Project:Charts
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Hello

Here are some personal fixes and additions for the openflash module.
* when trying to create multiple charts, the max is preserved as it is set as global.
* I recommend set the maximum as max + 5% of the maximum value
* added a couple more attributes for the graph

Comments/additions ?
thanks
alexie

function _openflashchart_chart(&$chart, &$data) {
  if ($data['#title-size']){
    $chart->set_title($data['#title'],'{font-size: '.$data['#title-size'].'px;}');
  }
  else {
    $chart->set_title($data['#title'],'{font-size: 20px;}');
  }
  // fixes recommended by other posts in the issue queue
  $chart->set_width($data['#width']);
  $chart->set_height($data['#height']);
  $chart->set_bg_colour($data['#color']);
}


function _openflashchart_series_generic(&$chart, &$data, $series) {
  // when no series are requested, remove global as it causes to preserve the maximum with multiple
  if (!empty($series)){static $max;}

  // Get only the numeric values from the series
  $series_data = _charts_series_values($data[$series]);

  $chart->set_data($series_data);

  // Get the highest value on the series add 5%, to be a reference point
  $max = $max < max($series_data) ? max($series_data) : $max;
  $max=$max+($max/20);
  // Y labels
  $chart->set_y_max($max);

  // X labels
  // specify steps
  if (!empty($data['#x-steps'])){
    $chart->set_x_axis_steps($data['#x-steps']);
}

  $value_labels = array();
  $toogle = FALSE;
  foreach (array_keys($series_data) as $value) {
    if (empty($data[$series][$value]['#label'])) {
      $value_labels[] = '';
    }
    else {
      $value_labels[] = $data[$series][$value]['#label'];
        $toogle = TRUE;
    }
  }
  if (!empty($toogle) && empty($data['#no-x-labels'])){
    $chart->set_x_labels($value_labels);
    // the following allows to hide the axis labels by setting them to the same color as the background
    if (!empty($data['#no-x-axis-labels'])){
      $chart->set_x_label_style(0,$data['#color']);
    }
  }
  if (!empty($data['#x-legend'])){
    $chart->set_x_legend($data['#x-legend'],10);
  }

}

#1

ezra-g - October 26, 2009 - 15:43
Status:needs review» needs work

There is nothing to review here. It would be great if you could turn this proposed change into a patch so others could review it.

Thanks!

 
 

Drupal is a registered trademark of Dries Buytaert.