tripal_phylogeny.theme.inc

  1. 2.x tripal_phylogeny/theme/tripal_phylogeny.theme.inc
  2. 3.x legacy/tripal_phylogeny/theme/tripal_phylogeny.theme.inc

File

tripal_phylogeny/theme/tripal_phylogeny.theme.inc
View source
  1. <?php
  2. function tripal_phylogeny_prepare_tree_viewer($phylotree) {
  3. // Don't prepare for viewing more than once.
  4. if (property_exists($phylotree, 'prepared_to_view') and
  5. $phylotree->prepared_to_view == TRUE) {
  6. return;
  7. }
  8. $module_path = drupal_get_path('module', 'tripal_phylogeny');
  9. drupal_add_js('https://d3js.org/d3.v3.min.js', 'external');
  10. drupal_add_js("$module_path/theme/js/d3.phylogram.js");
  11. drupal_add_js("$module_path/theme/js/tripal_phylogeny.js");
  12. drupal_add_css("$module_path/theme/css/tripal_phylogeny.css");
  13. drupal_add_library('system', 'ui.dialog');
  14. // Don't show tick marks for the taxonomy tree.
  15. $skip_ticks = 0;
  16. if ($phylotree->type_id->name == 'taxonomy') {
  17. $skip_ticks = 1;
  18. }
  19. // Get the tree options as set by the administrator.
  20. $options = json_encode(array(
  21. 'phylogram_width' => variable_get('tripal_phylogeny_default_phylogram_width', 350),
  22. 'root_node_size' => variable_get('tripal_phylogeny_default_root_node_size', 3),
  23. 'interior_node_size' => variable_get('tripal_phylogeny_default_interior_node_size', 0),
  24. 'leaf_node_size' => variable_get('tripal_phylogeny_default_leaf_node_size', 6),
  25. 'skipTicks' => $skip_ticks,
  26. ));
  27. // Get the node colors as set by the administrator.
  28. $colors = array();
  29. $color_defaults = variable_get("tripal_phylogeny_org_colors", array('1' => array('organism' => '', 'color' => '')));
  30. foreach ($color_defaults as $i => $details) {
  31. if ($details['organism']) {
  32. $colors[$details['organism']] = $details['color'];
  33. }
  34. }
  35. $colors = json_encode($colors);
  36. // Add javascript data needed for this tree.
  37. drupal_add_js(
  38. ' // var having URL of json data source for charting
  39. var phylotreeDataURL = baseurl + "/ajax/chado_phylotree/' . $phylotree->phylotree_id . '/json";
  40. // var with path to our theme, for use by javascript functions.
  41. var pathToTheme = baseurl + "/' . $module_path . '/theme";
  42. // var with custom options
  43. var treeOptions = ' . $options . ';
  44. // var with the organism colors
  45. var organismColors = ' . $colors . ';',
  46. 'inline'
  47. );
  48. if (!property_exists($phylotree, 'has_nodes')) {
  49. // If the nodes haven't loaded then set a value so the template can
  50. // choose not to show the phylogram.
  51. $values = array('phylotree_id' => $phylotree->phylotree_id);
  52. $options = array('limit' => 1, 'offset' => 0, 'has_record' => 1);
  53. $phylotree->has_nodes = chado_select_record('phylonode', array('phylonode_id'), $values, $options);
  54. }
  55. if (!property_exists($phylotree, 'has_features')) {
  56. // If the nodes haven't loaded then set a value so the template can
  57. // choose not to show the circular dendrogram. The chado_select_record()
  58. // API call can't do this query so we have to do it manually.
  59. $sql = "
  60. SELECT count(*) as num_features
  61. FROM {phylonode}
  62. WHERE NOT feature_id IS NULL and phylotree_id = :phylotree_id
  63. LIMIT 1 OFFSET 0
  64. ";
  65. $phylotree->has_features = chado_query($sql, array(':phylotree_id' => $phylotree->phylotree_id))->fetchField();
  66. }
  67. $phylotree->prepared_to_view = TRUE;
  68. }
  69. /**
  70. * Implements hook_preprocess_hook()
  71. *
  72. * @param $variables
  73. */
  74. function tripal_phylogeny_preprocess_tripal_phylogeny_phylogram(&$variables) {
  75. $phylotree = $variables['node']->phylotree;
  76. tripal_phylogeny_prepare_tree_viewer($phylotree);
  77. }
  78. /**
  79. * Implements hook_preprocess_hook()
  80. *
  81. * @param $variables
  82. */
  83. function tripal_phylogeny_preprocess_tripal_phylogeny_taxonomic_tree(&$variables) {
  84. $phylotree = $variables['node']->phylotree;
  85. tripal_phylogeny_prepare_tree_viewer($phylotree);
  86. }