-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First commit. Module is in D8 structure #14
base: 7.x-1.x
Are you sure you want to change the base?
Changes from 4 commits
4d0a5d4
91833a4
73b131d
9756297
9969a90
e231691
ea52c9d
9f2a757
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* TripalD3 provides a number of color schemes with configuration for site admin | ||
|
@@ -74,10 +73,10 @@ function tripald3_tripald3_color_schemes() { | |
* Retrieve a list of available color schemes. | ||
*/ | ||
function tripald3_get_color_schemes() { | ||
|
||
$schemes = module_invoke_all('tripald3_color_schemes'); | ||
// Listen for all available modules (enabled) implementing tripald3_color_schemes | ||
// to register a custom colour scheme. | ||
$schemes = \Drupal::moduleHandler()->invokeAll('tripald3_color_schemes'); | ||
return $schemes; | ||
|
||
} | ||
|
||
/** | ||
|
@@ -110,21 +109,19 @@ function tripald3_get_scheme_colors($scheme_id, $type, $scheme = array()) { | |
/** | ||
* Register Color Schemes with Javascript | ||
*/ | ||
function tripald3_register_colorschemes() { | ||
function tripald3_register_colorschemes($default) { | ||
|
||
$jsSettings = array('tripalD3' => array()); | ||
|
||
$schemes = tripald3_get_color_schemes(); | ||
foreach ($schemes as $id => $scheme) { | ||
|
||
$jsSettings['tripalD3']['colorSchemes'][$id]['name'] = $scheme['name']; | ||
$jsSettings['tripalD3']['colorSchemes'][$id]['quantitative'] = tripald3_get_scheme_colors($id, 'quantitative', $scheme); | ||
$jsSettings['tripalD3']['colorSchemes'][$id]['categorical'] = tripald3_get_scheme_colors($id, 'categorical', $scheme); | ||
$jsSettings['colorSchemes'][$id]['name'] = $scheme['name']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you drop the tripalD3 key here? This was a Drupal standard to reduce the chance of collisions in js settings between modules. |
||
$jsSettings['colorSchemes'][$id]['quantitative'] = tripald3_get_scheme_colors($id, 'quantitative', $scheme); | ||
$jsSettings['colorSchemes'][$id]['categorical'] = tripald3_get_scheme_colors($id, 'categorical', $scheme); | ||
} | ||
|
||
// Add in the currently selected scheme. | ||
$jsSettings['tripalD3']['colorSchemes']['selected'] = variable_get('tripald3_colorScheme', 'BlOr'); | ||
drupal_add_js($jsSettings, 'setting'); | ||
$jsSettings['colorSchemes']['selected'] = $default; | ||
|
||
return $jsSettings; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,120 @@ | ||||||||
<?php | ||||||||
/** | ||||||||
* @file | ||||||||
* Tripal D3 chado databse API | ||||||||
* @see important note on Pedigree in Controller/TripalD3RelationshipJsonController. | ||||||||
*/ | ||||||||
|
||||||||
/** | ||||||||
* Fetch relationship from congiuration variable. | ||||||||
*/ | ||||||||
function tripald3_get_stockrelationship() { | ||||||||
// Used to allow admin to choose which relationships to follow. | ||||||||
// Sorted alphabetically. | ||||||||
$rel_options = array(); | ||||||||
|
||||||||
// Get relationships for the settings form. | ||||||||
$sql = " | ||||||||
SELECT sr.type_id, cvt.name as type_name | ||||||||
FROM {stock_relationship} sr | ||||||||
LEFT JOIN {cvterm} cvt ON cvt.cvterm_id=sr.type_id | ||||||||
GROUP BY sr.type_id, cvt.name | ||||||||
ORDER BY count(sr.*) desc | ||||||||
"; | ||||||||
|
||||||||
$rels = chado_query($sql); | ||||||||
foreach ($rels as $r) { | ||||||||
$rel_options[ $r->type_id ] = $r->type_name; | ||||||||
} | ||||||||
|
||||||||
asort($rel_options); | ||||||||
return $rel_options; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* API: check if this node would consist of a single level tree with no leaves. | ||||||||
* | ||||||||
* @param $stock_id | ||||||||
* The unique identifier of the root stock/germplasm. | ||||||||
* @return | ||||||||
* TRUE if there are no approved relationships attached to the root node | ||||||||
* and FALSE otherwise. | ||||||||
*/ | ||||||||
function tripald3_is_node_leafless_tree($stock_id) { | ||||||||
$relationship_types = tripald3_get_pedigree_relationship_types(); | ||||||||
|
||||||||
// Check relationships where the root is the subject. | ||||||||
$subject_rels = 0; | ||||||||
if (!empty($relationship_types['subject'])) { | ||||||||
$vars = array(':stock_id' => $stock_id); | ||||||||
$rel_placeholders = array(); | ||||||||
foreach ($relationship_types['subject'] as $k => $type_name) { | ||||||||
$vars[':reltype' . $k] = $type_name; | ||||||||
$rel_placeholders[] = ':reltype' . $k; | ||||||||
} | ||||||||
$sql = 'SELECT count(*) as num_relationships | ||||||||
FROM {stock_relationship} sr | ||||||||
LEFT JOIN {cvterm} cvt ON sr.type_id=cvt.cvterm_id | ||||||||
WHERE subject_id=:stock_id | ||||||||
AND cvt.name IN (' . implode(',', $rel_placeholders) . ')'; | ||||||||
$subject_rels = chado_query($sql, $vars)->fetchField(); | ||||||||
} | ||||||||
|
||||||||
// Check relationships where the root is the object. | ||||||||
$object_rels = 0; | ||||||||
if (!empty($relationship_types['object'])) { | ||||||||
$vars = array(':stock_id' => $stock_id); | ||||||||
$rel_placeholders = array(); | ||||||||
foreach ($relationship_types['object'] as $k => $type_name) { | ||||||||
$vars[':reltype' . $k] = $type_name; | ||||||||
$rel_placeholders[] = ':reltype' . $k; | ||||||||
} | ||||||||
$sql = 'SELECT count(*) as num_relationships | ||||||||
FROM {stock_relationship} sr | ||||||||
LEFT JOIN {cvterm} cvt ON sr.type_id=cvt.cvterm_id | ||||||||
WHERE object_id=:stock_id | ||||||||
AND cvt.name IN (' . implode(',', $rel_placeholders) . ')'; | ||||||||
$object_rels = chado_query($sql, $vars)->fetchField(); | ||||||||
} | ||||||||
|
||||||||
// If there are any relationships then return FALSE else return TRUE | ||||||||
$total = $subject_rels + $object_rels; | ||||||||
if ($total) { | ||||||||
return FALSE; | ||||||||
} | ||||||||
else { | ||||||||
return TRUE; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Restrict datapoints to this subset only. | ||||||||
*/ | ||||||||
function tripald3_get_pedigree_relationship_types() { | ||||||||
$rels_to_restrict = \Drupal::state()->get('tripald3_stock_pedigree_rels', NULL); | ||||||||
|
||||||||
if (!$rels_to_restrict) { | ||||||||
// Get relationships used in stock table. | ||||||||
$rels = array(); | ||||||||
$sql = "SELECT sr.type_id, cvt.name as type_name | ||||||||
FROM {stock_relationship} sr | ||||||||
LEFT JOIN {cvterm} cvt ON cvt.cvterm_id=sr.type_id | ||||||||
GROUP BY sr.type_id, cvt.name | ||||||||
ORDER BY count(sr.*) desc"; | ||||||||
|
||||||||
$rel_query = chado_query($sql); | ||||||||
foreach ($rel_query as $r) { | ||||||||
$rels[$r->type_id] = $r->type_name; | ||||||||
} | ||||||||
|
||||||||
$rels_to_restrict = array( | ||||||||
'object' => array(), | ||||||||
'subject' => $rels | ||||||||
); | ||||||||
} | ||||||||
else { | ||||||||
$rels_to_restrict = unserialize($rels_to_restrict); | ||||||||
} | ||||||||
|
||||||||
return $rels_to_restrict; | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should have a newline at the end of files.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Auto-resize svg canvass, default to false | ||
tripald3_autoResize: FALSE | ||
# Colour scheme, default to Blue orange. | ||
tripald3_colorScheme: BlOr | ||
# Stock pedigree terms used, default to empty. | ||
tripald3_stock_pedigree_rels: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
div.test, pre.data, div.chart { | ||
border: 1px solid #e0e0d8; | ||
} | ||
|
||
div.test { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-around; | ||
height: 400px; | ||
} | ||
|
||
div.test div.chart { | ||
padding: 15px; | ||
} | ||
|
||
div.test pre { | ||
margin: 0; | ||
overflow: scroll; | ||
font-size: 10px; | ||
flex-grow: 1; | ||
} | ||
|
||
div.test svg { | ||
border: 1px solid #e0e0d8; | ||
} | ||
|
||
div#test0 { | ||
height: 100px; | ||
} | ||
|
||
div#test0 .data { | ||
color: red; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a non-backwards compatible change to the API. You need to provide a default for $default to minimize changes needed for others to upgrade their modules.