Skip to content
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

Draft
wants to merge 8 commits into
base: 7.x-1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
339 changes: 0 additions & 339 deletions LICENSE

This file was deleted.

39 changes: 0 additions & 39 deletions README.md

This file was deleted.

19 changes: 8 additions & 11 deletions includes/color_scheme.inc → api/color_scheme.inc
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
Expand Down Expand Up @@ -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;

}

/**
Expand Down Expand Up @@ -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) {
Copy link
Member

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.


$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'];
Copy link
Member

Choose a reason for hiding this comment

The 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;
}
120 changes: 120 additions & 0 deletions api/pedigree.inc
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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a newline at the end of files.

Suggested change
}
}

Binary file added config/.DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions config/install/tripald3.settings.yml
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:
Binary file added css/.DS_Store
Binary file not shown.
33 changes: 33 additions & 0 deletions css/testpage.css
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;
}
3 changes: 1 addition & 2 deletions css/tripald3.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.tripald3-diagram {
width: 500px;
}
Expand Down Expand Up @@ -66,5 +65,5 @@ svg.tripald3-tree .tree-node {
}

.tripald3-default-watermark {
background-image: url(watermark.png);
background-image: url('../templates/image/watermark.png');
}
2 changes: 1 addition & 1 deletion css/watermark.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
}

.tripald3-default-watermark {
background-image: url(watermark.png);
background-image: url('../templates/image/watermark.png');
}
4 changes: 2 additions & 2 deletions docs/api/placeWatermark.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This function places a watermark overlay to diagrams to indicate proprietary con
// Draw.
tripalD3.drawFigure(data, {'chartType' : 'multidonut', 'elementId' : 'multidonut', ....});

// Watermark. Use default image in ``/css/watermark.png`` as watermark.
// Watermark. Use default image in ``/templates/image/watermark.png`` as watermark.
tripalD3.placeWatermark();

// OR use alternate image.
Expand All @@ -31,7 +31,7 @@ def ``placeWatermark(options)``:

:options: A javascript object with the following key:

:watermark: by default this function will use the image located in ``/css/watermark.png`` as the preselected watermark. This can be
:watermark: by default this function will use the image located in ``/templates/image/watermark.png`` as the preselected watermark. This can be
used when site requires a unified watermark across all visualizations (site-wide), simply by replacing the said image with
the desired logotype (be sure to use the same filename). If the site requires a different image for one diagram in a page to another
diagram in another page, this option can be used to alter the default watermark by supplying a path to an image (see example).
Binary file modified docs/config.1.color_scheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/dev_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ This guide contains tutorials for using the Tripal D3.js API to add diagrams to
Additional Information
------------------------

- Examples on how to use each chart in ``templates/tripald3_demo_page.tpl.php`` and viewed at Admin » Tripal » Extension Modules » Tripal D3 Diagrams » Demo
- Examples on how to use each chart in ``templates/tripald3_demo_page.html.twig`` and viewed at Admin » Tripal » Extension Modules » Tripal D3 Diagrams » Demo
- In-code documentation for all functions and chart types in `js/tripalD3.*.js`
4 changes: 2 additions & 2 deletions docs/dev_guide/color_scheme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Making your own colour scheme available to this module is as simple as implement
$color_schemes = array();

// This key should be unique across colour schemes.
$color_schemes['PrpGr'] = array(
$color_schemes['BlkGr'] = array(
// This name will show up in the colour scheme configuration
'name' => 'Purple-Green',
'name' => 'Black-Green',
// These are the colours your colour scheme consists of.
'colors' => array('#3d4051', '#753fb0', '#8f7abf', '#294090', '#6683c3', '#0C6758', '#7AB318', '#A0C55E', '#9fa7a3'),
'pick order' => array(
Expand Down
Loading