You are here

function d3_libraries_info in d3.js 7

Implements hook_libraries_info().

File

./d3.module, line 269
D3 module file for creating visualizations with d3.js.

Code

function d3_libraries_info() {
  $libraries = array();

  // Drupal ext adds behaviors and d3 global object.
  $libraries['d3.drupal'] = array(
    'name' => 'D3 Drupal ext',
    'vendor url' => 'http://drupal.org/sandbox/asherry/1477334',
    'files' => array(
      'js' => array(
        'd3.js',
      ),
    ),
    'path' => 'js',
    'library path' => drupal_get_path('module', 'd3'),
    'dependencies' => array(
      'd3',
    ),
    'version' => '1',
  );
  $lib = variable_get('d3_library_source', 'lib');
  $ver = variable_get('d3_library_version', 3);
  if ($lib == 'cdn') {
    $options = array(
      'lines' => 4,
      'file' => "https://d3js.org/d3.v{$ver}.min.js",
    );
    $libraries['d3'] = array(
      'name' => 'D3',
      'vendor url' => 'https://d3js.org/',
      'download url' => 'https://d3js.org/',
      // This will bypass the check for file_exists.
      'installed' => TRUE,
      // For easy reference later.
      'cdn' => TRUE,
      'library path' => 'https://d3js.org',
      'files' => array(
        'js' => array(
          'data' => "d3.v{$ver}.min.js",
        ),
      ),
      'version' => $ver,
    );
    return $libraries;
  }

  // Path to library, (if installed).
  $path = libraries_get_path('d3');
  if ($path) {
    $files = array();

    // In the repository the files might me named d3.js and d3.min.js.
    $files += file_scan_directory($path, '/d3.js|d3.min.js/');

    // They could also have the version # in the file name.
    $files += file_scan_directory($path, '/d3.v[0-9](.min)?.js/');

    // If we don't have any files we shouldn't add the library at all.
    // This will fire drupal error and direct the user to reports.
    if (count($files) == 0) {
      return $libraries;
    }
    $file = NULL;

    // Find the file that matches the specified version.
    foreach ($files as $a_file) {

      // Assume files named d3.js or d3.min.js are version 3
      if ($ver === 3 && ($a_file->filename === "d3.js" || $a_file->filename === "d3.min.js") || $a_file->filename === "d3.v{$ver}.js" || $a_file->filename === "d3.v{$ver}.min.js") {
        $file = $a_file;
      }
    }
    if (!$file) {
      $file = array_shift($files);
    }
    $libraries['d3'] = array(
      'name' => 'D3',
      'vendor url' => 'https://d3js.org/',
      'download url' => 'https://d3js.org/',
      'files' => array(
        'js' => array(
          $file->filename,
        ),
      ),
      'version' => $ver,
    );
  }
  return $libraries;
}