tripal_phylogeny.theme.inc 4.1 KB

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