protected function ChartsGraphsGoogleCharts::_encode_data in Charts and Graphs 6.2
Same name and namespace in other branches
- 7 apis/charts_graphs_google_charts/charts_graphs_google_charts.class.inc \ChartsGraphsGoogleCharts::_encode_data()
1 call to ChartsGraphsGoogleCharts::_encode_data()
- ChartsGraphsGoogleCharts::_get_url in apis/
charts_graphs_google_charts/ charts_graphs_google_charts.class.inc
File
- apis/
charts_graphs_google_charts/ charts_graphs_google_charts.class.inc, line 104 - Implementation of abstract class ChartsGraphsCanvas for Google Charts library.
Class
- ChartsGraphsGoogleCharts
- Implementation of abstract class ChartsGraphsCanvas for Google Charts library.
Code
protected function _encode_data() {
$series = $this->series;
$is_stacked = strpos($this->type, 'stacked') !== FALSE;
// Use zero as initial min to guarantee that the y axis show zero.
$min_y = 0;
$max_y = $is_stacked ? 0 : reset(reset($series));
$chds = '';
$chd = array();
$chdl = array();
$is_pie = strpos($this->type, 'pie') !== FALSE;
foreach ($series as $serie_name => $serie) {
if (!$is_pie) {
$chdl[] = $serie_name;
}
$min_serie = 0;
$max_serie = reset($serie);
$serie_as_string = '';
foreach ($serie as $val) {
$serie_as_string .= ',' . drupal_urlencode($val);
if ($val < $min_serie) {
$min_serie = $val;
}
elseif ($val > $max_serie) {
$max_serie = $val;
}
}
if ($min_serie < $min_y) {
$min_y = $min_serie;
}
if ($is_stacked) {
$max_y += $max_serie;
}
else {
if ($max_serie > $max_y) {
$max_y = $max_serie;
}
}
if (strlen($serie_as_string)) {
$serie_as_string = substr($serie_as_string, 1);
}
$chd[] = $serie_as_string;
}
/**
* Applying user defined min and max y axis values.
*/
if (isset($this->y_min)) {
$min_y = $this->y_min;
}
if (isset($this->y_max)) {
$max_y = $this->y_max;
}
$chds = drupal_urlencode($min_y) . ',' . drupal_urlencode($max_y);
if ($is_pie) {
$chdl = $this->x_labels;
$chl = reset($this->series);
}
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_DATA_PARAMETER] = CHARTS_GRAPHS_GOOGLE_CHARTS_DATA_STARTER . implode('|', $chd);
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_LEGEND] = implode('|', $chdl);
if ($is_pie) {
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_PIE_LABELS] = implode('|', $chl);
}
else {
if (strpos($this->type, 'side') === FALSE) {
$scale_axis_identifier = 1;
$text_labels_axis_identifier = 0;
$y_legend_axis = ',y';
}
else {
$scale_axis_identifier = 0;
$text_labels_axis_identifier = 1;
$y_legend_axis = ',x';
}
if ($this->y_legend) {
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_VISIBLE_AXIS_PARAMETER] .= $y_legend_axis;
$y_legend = '2:|' . drupal_urlencode($this->y_legend) . '|';
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_LABEL_POSITION] = '2,50';
}
else {
$y_legend = '';
}
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_CUSTOM_AXIS_LABELS] = $y_legend . $text_labels_axis_identifier . ':' . $this
->_get_encoded_text_labels();
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_MIN_MAX_PER_SERIE_PARAMETER] = $chds;
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_VISIBLE_AXIS_PARAMETER] = 'x,y';
/**
* Applying user defined min and max y axis values.
*/
if (isset($this->y_min)) {
$min_y = $this->y_min;
}
if (isset($this->y_max)) {
$max_y = $this->y_max;
}
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_AXIS_RANGE_PARAMETER] = $scale_axis_identifier . ',' . drupal_urlencode($min_y) . ',' . drupal_urlencode($max_y);
/**
* Applying user defined step for y axis values.
*/
if (isset($this->y_step)) {
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_AXIS_RANGE_PARAMETER] .= ',' . $this->y_step;
}
}
$colour_count = $this->colour_count_series ? count($series) : count(reset($series));
$colours = array_slice($this
->series_colours(), 0, $colour_count);
$pure_hex_colours = array();
foreach ($colours as $colour) {
$pure_hex_colours[] = substr($colour, -6);
}
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_SERIES_COLOUR] = implode(',', $pure_hex_colours);
if ($this->type == 'area') {
$fill_colour = array();
$i = 0;
foreach ($pure_hex_colours as $colour) {
$fill_colour[] = sprintf('%s,%s,%u,0,0', CHARTS_GRAPHS_GOOGLE_CHARTS_AREA_MARKER_STYLE, $colour, $i);
$i++;
}
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_MARKER_STYLE] = implode('|', $fill_colour);
}
if ($this->legend_pos) {
switch ($this->legend_pos) {
case 'top':
$chdlp = 't';
break;
case 'bottom':
$chdlp = 'b';
break;
case 'top_vert':
$chdlp = 'tv';
break;
case 'bottom_vert':
$chdlp = 'bv';
break;
case 'left':
$chdlp = 'l';
break;
default:
$chdlp = 'r';
}
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_LEGEND_POSITION] = $chdlp;
}
if ($this->title_colour) {
$this->parameters_to_send[CHARTS_GRAPHS_GOOGLE_CHARTS_CHART_TITLE_COLOUR] = $this->title_colour;
}
}