You are here

class google_chart_tools_views_plugin_style in Google Chart Tools 7

The views style plugin.

Hierarchy

Expanded class hierarchy of google_chart_tools_views_plugin_style

1 string reference to 'google_chart_tools_views_plugin_style'
google_chart_tools_views_views_plugins in google_chart_tools_views/views/google_chart_tools_views.views.inc
Implements hook_views_plugins().

File

google_chart_tools_views/views/google_chart_tools_views_plugin_style.inc, line 12
Contains the Google Chart Tools display plugin.

View source
class google_chart_tools_views_plugin_style extends views_plugin_style {
  function option_definition() {
    $options = parent::option_definition();
    $options['title'] = array(
      'default' => '',
    );
    $options['haxis_title'] = array(
      'default' => '',
    );
    $options['vaxis_title'] = array(
      'default' => '',
    );
    $options['type'] = array(
      'default' => GOOGLE_CHART_TOOLS_DEFAULT_CHART,
    );
    $options['width'] = array(
      'default' => 600,
    );
    $options['height'] = array(
      'default' => 400,
    );
    $options['curve'] = array(
      'default' => 0,
    );
    $options['3d'] = array(
      'default' => 0,
    );
    $options['isstacked'] = array(
      'default' => FALSE,
    );
    $options['pointsize'] = array(
      'default' => 0,
    );
    $options['colors'] = array(
      'default' => '',
    );
    return $options;
  }
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    // Only allow grouping on the first column.
    $form['grouping'] = array_slice($form['grouping'], 0, 1);
    $form['grouping'][0]['field']['#options'] = array_slice($form['grouping'][0]['field']['#options'], 0, 2);
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#description' => t('Chart title. You may use "%" in your text to represent values that will be used for contextual filters.'),
      '#default_value' => $this->options['title'],
    );
    $form['haxis_title'] = array(
      '#type' => 'textfield',
      '#title' => t('hAxis Title'),
      '#description' => t('Horizontal axis title. You may use "%" in your text to represent values that will be used for contextual filters.'),
      '#default_value' => $this->options['haxis_title'],
    );
    $form['vaxis_title'] = array(
      '#type' => 'textfield',
      '#title' => t('vAxis Title'),
      '#description' => t('Vertical axis title. You may use "%" in your text to represent values that will be used for contextual filters.'),
      '#default_value' => $this->options['vaxis_title'],
    );
    $form['type'] = array(
      '#type' => 'select',
      '#options' => google_chart_tools_load_types(),
      '#title' => t('Type'),
      '#description' => t('Chart type, see <a href="https://google-developers.appspot.com/chart/interactive/docs/gallery">Google Chart Tools gallery</a>.'),
      '#required' => TRUE,
      '#description' => t('Ex. LineChart, PieChart, ColumnChart, AreaChart, Gauge, BarChart, etc....'),
      '#default_value' => $this->options['type'],
    );
    $form['width'] = array(
      '#type' => 'textfield',
      '#title' => t('Width'),
      '#description' => t('Chart width in pixels'),
      '#size' => 8,
      '#required' => TRUE,
      '#default_value' => $this->options['width'],
    );
    $form['height'] = array(
      '#type' => 'textfield',
      '#title' => t('Height'),
      '#description' => t('Chart height in pixels'),
      '#size' => 8,
      '#required' => TRUE,
      '#default_value' => $this->options['height'],
    );
    $form['curve'] = array(
      '#type' => 'checkbox',
      '#title' => t('Curve'),
      '#description' => t('Use a curve function'),
      '#default_value' => $this->options['curve'],
    );
    $form['3d'] = array(
      '#type' => 'checkbox',
      '#title' => t('3D'),
      '#description' => t('Make chart 3D'),
      '#default_value' => $this->options['3d'],
    );
    $form['isstacked'] = array(
      '#type' => 'checkbox',
      '#title' => t('Stack results'),
      '#description' => t('Render Bar Chart items on top of each other'),
      '#default_value' => $this->options['isstacked'],
    );
    $form['pointsize'] = array(
      '#type' => 'textfield',
      '#title' => t('Data point size'),
      '#description' => t('Pixel radius to allow for datapoints to be sized'),
      '#size' => 10,
      '#default_value' => $this->options['pointsize'],
    );
    $form['colors'] = array(
      '#type' => 'textfield',
      '#title' => t('Colors'),
      '#description' => t('A color strings separated by commas. Ex. red, #004411'),
      '#size' => 32,
      '#default_value' => $this->options['colors'],
    );
  }
  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'];
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
google_chart_tools_views_plugin_style::options_form function Provide a form to edit options for this plugin. Overrides views_plugin_style::options_form
google_chart_tools_views_plugin_style::option_definition function Information about options for all kinds of purposes will be held here. Overrides views_plugin_style::option_definition
google_chart_tools_views_plugin_style::render function Render the display in this style. Overrides views_plugin_style::render
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::options_submit public function Handle any special handling on the validate form. 9
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::summary_title public function Returns the summary of the settings in the display. 8
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin_style::$row_plugin public property The row plugin, if it's initialized and the style itself supports it.
views_plugin_style::$row_tokens public property Store all available tokens row rows.
views_plugin_style::build_sort public function Called by the view builder to see if this style handler wants to interfere with the sorts. If so it should build; if it returns any non-TRUE value, normal sorting will NOT be added to the query. 1
views_plugin_style::build_sort_post public function Called by the view builder to let the style build a second set of sorts that will come after any other sorts in the view. 1
views_plugin_style::destroy public function Destructor. Overrides views_object::destroy
views_plugin_style::even_empty public function Should the output of the style plugin be rendered even if it's empty. 1
views_plugin_style::get_field public function Get a rendered field.
views_plugin_style::get_field_value public function Get the raw field value.
views_plugin_style::get_row_class public function Return the token replaced row class for the specified row.
views_plugin_style::init public function Initialize a style plugin.
views_plugin_style::options_validate public function Validate the options form. Overrides views_plugin::options_validate
views_plugin_style::pre_render public function Allow the style to do stuff before each row is rendered.
views_plugin_style::query public function Add anything to the query that we might need to. Overrides views_plugin::query 2
views_plugin_style::render_fields public function Render all of the fields for a given style and store them on the object.
views_plugin_style::render_grouping public function Group records as needed for rendering.
views_plugin_style::render_grouping_sets public function Render the grouping sets.
views_plugin_style::tokenize_value public function Take a value and apply token replacement logic to it.
views_plugin_style::uses_fields public function Return TRUE if this style also uses fields.
views_plugin_style::uses_row_class public function Return TRUE if this style also uses a row plugin.
views_plugin_style::uses_row_plugin public function Return TRUE if this style also uses a row plugin.
views_plugin_style::uses_tokens public function Return TRUE if this style uses tokens.
views_plugin_style::validate public function Validate that the plugin is correct and can be saved. Overrides views_plugin::validate