diff --git a/js/expression-fix.js b/js/expression-fix.js new file mode 100644 index 0000000..6264baa --- /dev/null +++ b/js/expression-fix.js @@ -0,0 +1,749 @@ +(function ($) { + + Drupal.behaviors.expression = { + attach: function (context, settings) { + // Define variables + this.heatMapRaw = JSON.parse(settings.heatMapRaw); + this.selectedAnalysis = settings.selectedAnalysis; + this.feature_id = settings.feature_id; + this.heatMapTotal = ''; + this.heatMap = []; + this.currentSorting = $('#propertySortMenu').find(':selected').text(); + this.currentColor = $('#propertyColorMenu').find(':selected').text(); + this.downloadMessage = $(''); + this.downloadLink = $('#expressionDownloadLink'); + this.base_url = settings.basePath; + var link = this.base_url + 'analysis-expression/download?feature_ids=' + this.feature_id + '&analysis_id=' + this.selectedAnalysis; + $('#expressionDownloadLink').attr('href', link); + + //spacing variables + this.margin = {top: 50, bottom: 100, horizontal: 20}; + this.height = 500; + this.barwidth = 10 + this.scaleSize = this.barwidth * 4.5 //this is a thumbnail estimate, im not sure of a better way to do it + this.barSpacing = this.barwidth/2 + + + + // Activate plot + this.expNormal(); + this.attachEventListeners(); + }, + + /** + * Attach events to all of our elements here. + */ + attachEventListeners: function () { + $('#show-non-zero-only').on('click', this.nonZero.bind(this)); + $('#reset-expression-plot').on('click', this.expNormal.bind(this)); + $('#analyses-dropdown').on('change', this.analysisChanged.bind(this)); + $(window).on('resize', this.expNormal.bind(this)); + $(document).on('tripal_ds_pane_expanded', this.expNormal.bind(this)); + + // If the selector changes, rebuild the figure + $(document).on('change', '#propertySortMenu', function (e) { + this.currentSorting = e.target.value; + d3.selectAll('chart').remove(); + this.drawPlot(); + }.bind(this)); + + // If the selector changes, rebuild the figure + $(document).on('change', '#propertyColorMenu', function (e) { + this.currentColor = e.target.value; + d3.selectAll('chart').remove(); + this.drawPlot(); + }.bind(this)); + + var _that = this; + this.downloadLink.after(this.downloadMessage); + this.downloadLink.on('click', function (e) { + _that.initiateDownload.call(this, e, _that); + }); // Do not bind this here + }, + + /** + * Create an iframe to start the download. + * + * @param {Object} e event + * @param {Object} object this + */ + initiateDownload: function (e, object) { + e.preventDefault(); + var src = $(this).attr('href'); + var iframe = $('