function google_chart_tools_views_plugin_style::render in Google Chart Tools 7
Render the display in this style.
Overrides views_plugin_style::render
File
- google_chart_tools_views/
views/ google_chart_tools_views_plugin_style.inc, line 116 - Contains the Google Chart Tools display plugin.
Class
- google_chart_tools_views_plugin_style
- The views style plugin.
Code
function render() {
$header = array();
$item = array();
// Special treat to OrgChart.
if ($this->options['type'] == 'OrgChart') {
foreach ($this
->render_fields($this->view->result) as $row_index => $row) {
foreach ($row as $key => $field) {
if (!$this->view->field[$key]->options['exclude']) {
$item[$row_index][] = $field;
}
}
}
}
else {
foreach ($this->view->field as $key => $field) {
if ($field->position !== 0 && !$field->options['exclude']) {
$column[] = !empty($field->options['label']) ? $field->options['label'] : $field->definition['title'];
}
}
foreach ($this
->render_fields($this->view->result) as $row_index => $row) {
foreach ($row as $key => $field) {
if (!$this->view->field[$key]->options['exclude']) {
if ($this->view->field[$key]->position === 0) {
$header[$row_index] = $field;
}
else {
$item[$row_index][] = strip_tags($field);
}
}
}
}
$item = _google_chart_tools_flip($item);
}
// Account for grouping field being set.
if (isset($this->options['grouping'][0])) {
_google_chart_tools_apply_grouping_conversion($header, $item);
}
// More flexible to allow for future option replacement.
$option_substitutions = array(
'vaxis_title',
'haxis_title',
'title',
);
// Allow the use of view build info substitutions.
$tokens = array();
if (!empty($this->view->build_info['substitutions'])) {
$tokens = $this->view->build_info['substitutions'];
}
$count = 0;
foreach ($this->view->display_handler
->get_handlers('argument') as $arg => $handler) {
$token = '%' . ++$count;
if (!isset($tokens[$token])) {
$tokens[$token] = '';
}
// Use strip tags as there should never be HTML in the title.
// However, we need to preserve special characters like " that
// were removed by check_plain().
$tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
}
// Loop through and replace view-tokens.
foreach ($option_substitutions as $option_name) {
$this->options[$option_name] = str_replace(array_keys($tokens), array_values($tokens), $this->options[$option_name]);
}
$settings['chart'][drupal_clean_css_identifier($this->view->name . '-' . $this->display->id)] = array(
'header' => !empty($header) ? $header : '',
'rows' => $item,
'columns' => !empty($column) ? $column : '',
'chartType' => $this->options['type'],
'options' => array(
'vAxis' => array(
'title' => $this->options['vaxis_title'],
),
'hAxis' => array(
'title' => $this->options['haxis_title'],
),
'forceIFrame' => FALSE,
'curveType' => $this->options['curve'] ? "function" : "none",
'is3D' => $this->options['3d'],
'isStacked' => $this->options['isstacked'],
'pointSize' => $this->options['pointsize'],
'colors' => $this->options['colors'] ? explode(",", str_replace(' ', '', $this->options['colors'])) : NULL,
'title' => $this->options['title'],
'width' => $this->options['width'],
'height' => $this->options['height'],
'allowHtml' => TRUE,
),
);
if (strpos($_GET['q'], 'admin/structure/views/nojs/preview') === FALSE) {
// Draw it.
$ret = draw_chart($settings);
return $ret['markup'];
}
}