tripal_phylogeny.theme.inc 4.7 KB

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