tripal.d3js.api.inc

Provides the API for loading d3js onto pages.

File

tripal/api/tripal.d3js.api.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Provides the API for loading d3js onto pages.
  6. */
  7. /**
  8. * @defgroup tripal_d3js_api d3js
  9. * @ingroup tripal_api
  10. * @{
  11. * D3.js is a JavaScript library for producing dynamic, interactive data
  12. * visualizations in web browsers. It makes use of the widely implemented SVG,
  13. * HTML5, and CSS standards. For more information on how to use d3js please see
  14. * https://github.com/d3/d3.
  15. *
  16. * For an example of d3 usage in Tripal please review
  17. * tripal_chado/includes/tripal_chado.phylotree.inc and
  18. * tripal_chado/theme/js/d3.phylogram.js
  19. *
  20. * @}
  21. */
  22. /**
  23. * Load D3.js releated javascripts for the current page.
  24. *
  25. * @ingroup tripal_d3js_api
  26. */
  27. function tripal_add_d3js() {
  28. $library = array('loaded' => FALSE);
  29. // First try to load d3.js using the libraries API.
  30. // This will work if the site admin has saved d3.js in their libraries folder.
  31. if (module_exists('libraries_api')) {
  32. $library = libraries_load('d3');
  33. }
  34. // If we were not able to load d3.js using the libraries API
  35. // then revert to loading the remote files manually.
  36. if (!isset($library['loaded']) OR !$library['loaded']) {
  37. // If SSL is being used then use a secure CDN for d3.js
  38. if (isset($_SERVER['HTTPS'])) {
  39. drupal_add_js('https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js');
  40. }
  41. else {
  42. drupal_add_js('http://d3js.org/d3.v3.min.js');
  43. }
  44. }
  45. }