You are here

webform_charts.module in Webform Charts 7

Enhances the "Analyze" section of Webform nodes with customizable charts.

File

webform_charts.module
View source
<?php

/**
 * @file
 * Enhances the "Analyze" section of Webform nodes with customizable charts.
 */

/**
 * Implements hook_permission().
 */
function webform_charts_permission() {
  return array(
    'configure webform component charts' => array(
      'title' => t('Configure Webform component charts'),
      'description' => t('Allows users to edit individual charts in the analysis tab of Webform-enabled node.'),
    ),
  );
}

/**
 * Implements hook_theme().
 */
function webform_charts_theme() {
  $theme = array(
    'webform_charts_edit_chart' => array(
      'render element' => 'form',
      'file' => 'includes/webform_charts.pages.inc',
    ),
    'webform_charts_colors_element' => array(
      'render element' => 'element',
      'file' => 'includes/webform_charts.pages.inc',
    ),
  );
  return $theme;
}

/**
 * Implements hook_library().
 */
function webform_charts_library() {
  $path = drupal_get_path('module', 'webform_charts');
  $libraries['webform_charts.admin'] = array(
    'title' => 'Webform charts admin',
    'version' => '1.x',
    'css' => array(
      $path . '/css/webform-charts.css' => array(),
    ),
    'js' => array(
      $path . '/js/webform-charts.js' => array(),
    ),
  );
  $libraries['webform_charts.admin.highcharts'] = array(
    'title' => 'Webform charts admin Highcharts-specific integration',
    'version' => '1.x',
    'js' => array(
      $path . '/js/webform-charts.highcharts.js' => array(),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_webform_analysis_alter().
 */
function webform_charts_webform_analysis_alter(&$analysis) {
  module_load_include('inc', 'webform_charts', 'includes/webform_charts.pages');
  if (!empty($analysis['data'])) {
    _webform_charts_webform_analysis_alter($analysis);
  }
}

/**
 * Public function for rendering a chart for a particular Webform component.
 *
 * @param object $node
 *   The node whose components are being analyzed.
 * @param array $component
 *   The component whose data is being analyzed.
 *
 * @return array
 *   A renderable chart array.
 */
function webform_charts_component_chart($node, $component) {
  module_load_include('inc', 'webform_charts', 'includes/webform_charts.pages');
  $analysis_data = webform_component_invoke($component['type'], 'analysis', $component);
  return _webform_charts_component_chart($node, $component, $analysis_data);
}

/**
 * Wrapper around webform_charts_default_settings(), merging in our own settings.
 */
function webform_charts_default_settings($node, $component, $data) {
  module_load_include('inc', 'charts', 'includes/charts.pages');
  $data += array(
    'table_header' => NULL,
  );
  $options = charts_default_settings();
  $options = array_merge($options, array(
    'type' => count($data['table_header']) || !empty($component['extra']['multiple']) ? 'column' : 'pie',
    'legend' => isset($data['table_header']) ? TRUE : FALSE,
    'legend_position' => 'right',
    'tooltips' => TRUE,
    'data_labels' => isset($data['table_header']) ? FALSE : TRUE,
    'stacking' => FALSE,
  ));
  return $options;
}

Functions

Namesort descending Description
webform_charts_component_chart Public function for rendering a chart for a particular Webform component.
webform_charts_default_settings Wrapper around webform_charts_default_settings(), merging in our own settings.
webform_charts_library Implements hook_library().
webform_charts_permission Implements hook_permission().
webform_charts_theme Implements hook_theme().
webform_charts_webform_analysis_alter Implements hook_webform_analysis_alter().