Skip to content

Commit

Permalink
Use toastr to support showing multiple toast messages at once, with a…
Browse files Browse the repository at this point in the history
… fancy UI (#519)

* throttled onwheel event

* reduced throttle

* ENH: Add in toastr

Need to update tests

* update JS test re: dependency paths

I don't think any of these were used by the tests so it doesn't really
matter, but may as well be thorough. tests still pass.

* DOC: Change "Main CI" -> "Main CI + McHelper"

* STY: prettify!

* DOC: punctuation

* MNT: rm now unused custom toast css

Co-authored-by: kwcantrell <cantrell.kalen@gmail.com>
  • Loading branch information
fedarko and kwcantrell authored Jun 10, 2021
1 parent 4f1ed07 commit df3a4da
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Also lints and stylechecks the code (both Python and JS).
# When tests pass, this runs "make docs" to generate various test QIIME 2
# visualizations (.qzv files) and uploads them to McHelper.
name: Main CI
name: Main CI + McHelper

# Controls when the action will run.
on:
Expand Down
27 changes: 27 additions & 0 deletions DEPENDENCY_LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,30 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

## toastr
License retrieved from
https://github.com/CodeSeven/toastr/blob/master/LICENSE on May 26, 2021.
```
MIT License
Copyright (c) 2017 Toastr Maintainers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Empress
[![Main CI](https://github.com/biocore/empress/actions/workflows/main.yml/badge.svg)](https://github.com/biocore/empress/actions/workflows/main.yml)
[![Main CI + McHelper](https://github.com/biocore/empress/actions/workflows/main.yml/badge.svg)](https://github.com/biocore/empress/actions/workflows/main.yml)
[![Standalone CI](https://github.com/biocore/empress/actions/workflows/standalone.yml/badge.svg)](https://github.com/biocore/empress/actions/workflows/standalone.yml)
[![PyPI](https://img.shields.io/pypi/v/empress.svg)](https://pypi.org/project/empress)

Expand Down
17 changes: 0 additions & 17 deletions empress/support_files/css/empress.css
Original file line number Diff line number Diff line change
Expand Up @@ -645,23 +645,6 @@ p.side-header button:hover,
width: 150px;
}

/* toast */

#toast {
position: absolute;
min-width: 250px;
margin-left: -125px;
background-color: black;
opacity: 0.75;
color: white;
text-align: center;
border-radius: 5px;
padding: 15px;
left: 50%;
bottom: 50%;
max-height: 100%;
}

#menu-box p {
max-width: 500px;
font-size: small;
Expand Down
14 changes: 12 additions & 2 deletions empress/support_files/js/animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,12 @@ define(["Colorer", "util"], function (Colorer, util) {
var obs = frame.obs;

if (Object.keys(keyInfo).length === 0) {
util.toastMsg("No unique branches found for this frame");
util.toastMsg(
"Animation warning",
"No unique branches found for this frame.",
(duration = 3000),
(toastType = "warning")
);
}

// draw new legend
Expand Down Expand Up @@ -280,7 +285,12 @@ define(["Colorer", "util"], function (Colorer, util) {
!scope.pause &&
scope.curFrame + 1 === scope.totalFrames
) {
util.toastMsg("Animation Complete.");
util.toastMsg(
"Animation complete.",
"",
(duration = 3000),
(toastType = "success")
);
}
}, 0);
};
Expand Down
7 changes: 6 additions & 1 deletion empress/support_files/js/emperor-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ ec.controllers.animations.addEventListener("animation-ended", function (
) {
// if the animation ends enable the controls
animationPanel.setEnabled(true);
util.toastMsg("Animation Complete.");
util.toastMsg(
"Animation complete.",
"",
(duration = 3000),
(toastType = "success")
);
});

ec.controllers.color.addEventListener("value-double-clicked", function (
Expand Down
17 changes: 13 additions & 4 deletions empress/support_files/js/empress.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,11 @@ define([
legends.push(...this._barplotPanel.getLegends());
}
if (legends.length === 0) {
util.toastMsg("No active legends to export.", 5000);
util.toastMsg(
"Export error",
"No active legends to export.",
(duration = 5000)
);
return null;
} else {
return ExportUtil.exportLegendSVG(legends);
Expand Down Expand Up @@ -1920,7 +1924,7 @@ define([
'the feature metadata field "' +
layer.colorByFMField +
'" has less than 2 unique numeric values.';
util.toastMsg(msg, 5000);
util.toastMsg("Barplot coloring error", msg, (duration = 5000));
throw msg;
}
fm2color = colorer.getMapRGB();
Expand All @@ -1947,7 +1951,11 @@ define([
} catch (err) {
// Fail gracefully, similarly to how we handle Colorer errors
// above
util.toastMsg(err.message, 5000);
util.toastMsg(
"Barplot length-scaling error",
err.message,
(duration = 5000)
);
throw err.message;
}
}
Expand Down Expand Up @@ -3657,7 +3665,8 @@ define([
Empress.prototype.showNodeMenuForName = function (nodeName) {
if (!this._tree.containsNode(nodeName)) {
util.toastMsg(
"The node '" + nodeName + "' is not present in the phylogeny"
"Node menu error",
"The node '" + nodeName + "' is not present in the phylogeny."
);
return;
}
Expand Down
9 changes: 7 additions & 2 deletions empress/support_files/js/layouts-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,19 @@ define(["underscore", "VectorOps", "util"], function (_, VectorOps, util) {
var NO_LENGTHS_CHANGED_MSG =
"It doesn't look like any branch lengths were changed " +
"by the current method of modifying branch lengths.";
var NO_LENGTHS_CHANGED_DURATION = 3000;
var NO_LENGTHS_CHANGED_DURATION = 6000;
var TOL = 0.000001;

/**
* Raises a toast message telling the user that no branch lengths changed.
*/
function noLengthsChangedMsg() {
util.toastMsg(NO_LENGTHS_CHANGED_MSG, NO_LENGTHS_CHANGED_DURATION);
util.toastMsg(
"Warning about selected branch length method",
NO_LENGTHS_CHANGED_MSG,
(duration = NO_LENGTHS_CHANGED_DURATION),
(toastType = "warning")
);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion empress/support_files/js/side-panel-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ define(["underscore", "Colorer", "util"], function (_, Colorer, util) {
var keyInfo = this.empress.colorBySampleCat(colBy, col, reverse);
if (keyInfo === null) {
util.toastMsg(
"No unique branches found for this metadata category"
"Sample metadata coloring error",
"No unique branches found for this metadata category."
);
this.sUpdateBtn.classList.remove("hidden");
return;
Expand Down
31 changes: 19 additions & 12 deletions empress/support_files/js/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["underscore"], function (_) {
define(["underscore", "toastr"], function (_, toastr) {
/**
* Remove all non unique keys
* Note: keys are referring to empress._treeData (i.e. postorder position of
Expand Down Expand Up @@ -131,19 +131,26 @@ define(["underscore"], function (_) {
}

/**
* Display a message in a toast element.
* Display a message in a toast element using toastr!
*
* @param {String} msg - message to display
* @param {Number} duration - milliseconds to keep toast visible (optional)
* Defaults to 3000 ms (i.e. 3 seconds).
* See https://codeseven.github.io/toastr/demo.html.
*
* @param {String} msgTitle Short title of a message to display.
* @param {String} msgBody Message body text. This can be "", in which case
* only the title will be shown.
* @param {Number} duration Milliseconds to keep toast visible (optional).
* Defaults to 3000 ms (i.e. 3 seconds).
* @param {String} toastType The "type" of toast to show (optional).
* If specified, this should be one of
* "success", "info", "warning", "error".
* Defaults to "error", since as of writing most
* of the toasts we throw are error messages.
*/
function toastMsg(msg, duration = 3000) {
var toast = document.getElementById("toast");
toast.innerHTML = msg;
toast.classList.remove("hidden");
setTimeout(function () {
toast.classList.add("hidden");
}, duration);
function toastMsg(msgTitle, msgBody, duration = 3000, toastType = "error") {
toastr[toastType](msgBody, msgTitle, {
timeOut: duration,
positionClass: "toast-bottom-left",
});
}

/**
Expand Down
25 changes: 12 additions & 13 deletions empress/support_files/templates/empress-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<title>Empress</title>
<link rel='stylesheet' type="text/css" href='{{ base_url }}/css/empress.css'>
<link rel='stylesheet' type="text/css" href='{{ base_url }}/vendor/spectrum.min.css'>
<link rel='stylesheet' type="text/css" href='{{ base_url }}/vendor/toastr.min.css'>
<script src='{{ base_url }}/vendor/require-2.1.22.min.js'></script>
{{ emperor_base_dependencies }}
{{ emperor_style }}
Expand Down Expand Up @@ -32,9 +33,6 @@
{% include 'side-panel.html'%}
</div>

<!-- toast -->
<div id="toast" class="hidden"></div>

<!-- show control panel button -->
<button id="show-ctrl" title="Show control panel" class="hidden unselectable-text">&#9699;</button>

Expand Down Expand Up @@ -94,6 +92,7 @@ <h3 id="menu-sm-header">Sample Presence Information</h3>
'chroma' : './vendor/chroma.min',
'underscore' : './vendor/underscore-min',
'spectrum' : './vendor/spectrum.min',
'toastr' : './vendor/toastr.min',
'filesaver': './vendor/FileSaver.min',

'ByteArray' : './js/byte-array',
Expand All @@ -120,16 +119,16 @@ <h3 id="menu-sm-header">Sample Presence Information</h3>
});

empressRequire(['jquery', 'glMatrix', 'chroma', 'underscore', 'spectrum',
'filesaver', 'ByteArray', 'BPTree', 'Camera', 'Drawer',
'SidePanel', 'AnimationPanel', 'Animator', 'BarplotLayer',
'BarplotPanel', 'BIOMTable', 'Empress', 'Legend',
'Colorer', 'VectorOps', 'CanvasEvents', 'SelectedNodeMenu',
'util', 'LayoutsUtil', 'ExportUtil'],
function($, gl, chroma, underscore, spectrum, filesaver, ByteArray,
BPTree, Camera, Drawer, SidePanel, AnimationPanel, Animator,
BarplotLayer, BarplotPanel, BIOMTable, Empress, Legend,
Colorer, VectorOps, CanvasEvents, SelectedNodeMenu, util,
LayoutsUtil, ExportUtil) {
'toastr', 'filesaver', 'ByteArray', 'BPTree', 'Camera',
'Drawer', 'SidePanel', 'AnimationPanel', 'Animator',
'BarplotLayer', 'BarplotPanel', 'BIOMTable', 'Empress',
'Legend', 'Colorer', 'VectorOps', 'CanvasEvents',
'SelectedNodeMenu', 'util', 'LayoutsUtil', 'ExportUtil'],
function($, gl, chroma, underscore, spectrum, toastr, filesaver,
ByteArray, BPTree, Camera, Drawer, SidePanel, AnimationPanel,
Animator, BarplotLayer, BarplotPanel, BIOMTable, Empress,
Legend, Colorer, VectorOps, CanvasEvents, SelectedNodeMenu,
util, LayoutsUtil, ExportUtil) {
// initialze the tree and model
var tree = new BPTree(
{{ tree }},
Expand Down
1 change: 1 addition & 0 deletions empress/support_files/vendor/toastr.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit df3a4da

Please sign in to comment.