function tripal_phylogeny_prepare_tree_viewer
2.x tripal_phylogeny.theme.inc | tripal_phylogeny_prepare_tree_viewer($phylotree) |
3.x tripal_chado.phylotree.inc | tripal_phylogeny_prepare_tree_viewer($phylotree) |
Prepares a phylogenetic tree for viewing.
Parameters
$phylotree:
3 calls to tripal_phylogeny_prepare_tree_viewer()
- operation__phylotree_vis_formatter::view in tripal_chado/
includes/ TripalFields/ operation__phylotree_vis/ operation__phylotree_vis_formatter.inc - tripal_phylogeny_preprocess_tripal_phylogeny_phylogram in legacy/
tripal_phylogeny/ theme/ tripal_phylogeny.theme.inc - Implements hook_preprocess_hook()
- tripal_phylogeny_preprocess_tripal_phylogeny_taxonomic_tree in legacy/
tripal_phylogeny/ theme/ tripal_phylogeny.theme.inc - Implements hook_preprocess_hook()
File
- tripal_chado/
includes/ tripal_chado.phylotree.inc, line 7 - This file contains the functions used for administration of the module
Code
function tripal_phylogeny_prepare_tree_viewer($phylotree) {
// Don't prepare for viewing more than once.
if (property_exists($phylotree, 'prepared_to_view') and
$phylotree->prepared_to_view == TRUE) {
return;
}
$module_path = drupal_get_path('module', 'tripal_chado');
drupal_add_js('https://d3js.org/d3.v3.min.js', 'external');
drupal_add_js("$module_path/theme/js/d3.phylogram.js");
drupal_add_js("$module_path/theme/js/tripal_phylogeny.js");
drupal_add_css("$module_path/theme/css/tripal_phylogeny.css");
drupal_add_library('system', 'ui.dialog');
// Don't show tick marks for the taxonomy tree.
$skip_ticks = 0;
if ($phylotree->type_id->name == 'taxonomy' or $phylotree->type_id->name == 'Species tree') {
$skip_ticks = 1;
}
// Get the node colors as set by the administrator.
$colors = array();
$color_defaults = variable_get("tripal_phylogeny_org_colors", array('1' => array('organism' => '', 'color' => '')));
foreach ($color_defaults as $i => $details) {
if ($details['organism']) {
// Strip the [id:xxx] from the name
$organism_id = preg_replace('/^.+\[id: (\d+)\].*$/', '\1', $details['organism']);
$colors[$organism_id] = $details['color'];
}
}
drupal_add_js(array(
'tripal_chado' => array(
'phylotree_url' => url('phylotree/' . $phylotree->phylotree_id),
'phylotree_theme_url' => url($module_path . '/theme'),
'tree_options' => array(
'phylogram_width' => variable_get('tripal_phylogeny_default_phylogram_width', 350),
'root_node_size' => variable_get('tripal_phylogeny_default_root_node_size', 3),
'interior_node_size' => variable_get('tripal_phylogeny_default_interior_node_size', 1),
'leaf_node_size' => variable_get('tripal_phylogeny_default_leaf_node_size', 6),
'skipTicks' => $skip_ticks,
),
'org_colors' => $colors,
),
), 'setting');
if (!property_exists($phylotree, 'has_nodes')) {
// If the nodes haven't loaded then set a value so the template can
// choose not to show the phylogram.
$values = array('phylotree_id' => $phylotree->phylotree_id);
$options = array('limit' => 1, 'offset' => 0, 'has_record' => 1);
$phylotree->has_nodes = chado_select_record('phylonode', array('phylonode_id'), $values, $options);
}
if (!property_exists($phylotree, 'has_features')) {
// If the nodes haven't loaded then set a value so the template can
// choose not to show the circular dendrogram. The chado_select_record()
// API call can't do this query so we have to do it manually.
$sql = "
SELECT count(*) as num_features
FROM {phylonode}
WHERE NOT feature_id IS NULL and phylotree_id = :phylotree_id
LIMIT 1 OFFSET 0
";
$phylotree->has_features = chado_query($sql, array(':phylotree_id' => $phylotree->phylotree_id))->fetchField();
}
$phylotree->prepared_to_view = TRUE;
}