You are here

visualization.module in Visualization API 8

Same filename and directory in other branches
  1. 7 visualization.module

File

visualization.module
View source
<?php

/**
 * Implements hook_theme().
 */
function visualization_theme() {
  return array(
    'visualization' => array(
      'variables' => array(
        'view' => NULL,
        'options' => array(
          'title' => NULL,
          'xAxis' => array(),
          'fields' => array(),
          'type' => 'line',
          'data' => array(),
        ),
      ),
      'file' => 'visualization.theme.inc',
      'template' => 'visualization',
    ),
  );
}

/**
 * Returns the name of the library that should be used to render a chart.
 *
 * Optionally one can pass a chart type to get the best library available
 * for that type.
 */
function visualization_plugin($type = FALSE) {
  $config = Drupal::config('visualization.settings');
  $preferred_plugin = $config
    ->get('library');
  $plugin_manager = Drupal::service('plugin.manager.visualization.handler');
  $plugins = $plugin_manager
    ->getDefinitions();
  if (!empty($plugins[$preferred_plugin])) {
    $id = $plugins[$preferred_plugin]['id'];
    $instance = $plugin_manager
      ->createInstance($id);
    if ($instance
      ->available() && (!empty($type) && in_array($type, $instance
      ->supportedTypes()))) {
      return $instance;
    }
  }

  // No prefered plugin found, let's return first found plugin.
  $first_plugin = reset($plugins);
  return $plugin_manager
    ->createInstance($first_plugin['id']);
}

Functions

Namesort descending Description
visualization_plugin Returns the name of the library that should be used to render a chart.
visualization_theme Implements hook_theme().