7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2013 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var Plotter = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var plotter = {}; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
30 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
32 |
*/ |
7604 |
25 Feb 19 |
nicklas |
plotter.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
34 |
{ |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
36 |
|
7604 |
25 Feb 19 |
nicklas |
// Plot size |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('width', 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('height', 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
40 |
|
7604 |
25 Feb 19 |
nicklas |
// Y-axis |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('yPresets', 'change', plotter.presetOnChange); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnExpressionBuilderY', plotter.openExpressionBuilder); |
7604 |
25 Feb 19 |
nicklas |
44 |
|
7604 |
25 Feb 19 |
nicklas |
// Plot type |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('plotTypeAssay', 'change', plotter.plotTypeOnChange); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('plotTypeAnnotation', 'change', plotter.plotTypeOnChange); |
7604 |
25 Feb 19 |
nicklas |
plotter.plotTypeOnChange(); |
7604 |
25 Feb 19 |
nicklas |
49 |
|
7604 |
25 Feb 19 |
nicklas |
// Buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnPreviewPlot', plotter.previewPlot); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnViewPlot', plotter.viewPlot); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnDownloadPlot', plotter.downloadPlot); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSavePlot', plotter.savePlotAs); |
7604 |
25 Feb 19 |
nicklas |
55 |
} |
7604 |
25 Feb 19 |
nicklas |
56 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.getPlotType = function() |
7604 |
25 Feb 19 |
nicklas |
58 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['plot']; |
7604 |
25 Feb 19 |
nicklas |
return Forms.getCheckedRadio(frm.plotType).value; |
7604 |
25 Feb 19 |
nicklas |
61 |
} |
7604 |
25 Feb 19 |
nicklas |
62 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.validateParameters = function() |
7604 |
25 Feb 19 |
nicklas |
64 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['plot']; |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.yFormula.value) == '') |
7604 |
25 Feb 19 |
nicklas |
67 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.yFormula, 'You must enter an expression for the Y axis'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
70 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
72 |
} |
7604 |
25 Feb 19 |
nicklas |
73 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.presetOnChange = function(event) |
7604 |
25 Feb 19 |
nicklas |
75 |
{ |
7604 |
25 Feb 19 |
nicklas |
var list = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var selected = list[list.selectedIndex]; |
7604 |
25 Feb 19 |
nicklas |
78 |
|
7604 |
25 Feb 19 |
nicklas |
var labelField = Doc.element(Data.get(list, 'label-id')); |
7604 |
25 Feb 19 |
nicklas |
var formulaField = Doc.element(Data.get(list, 'formula-id')); |
7604 |
25 Feb 19 |
nicklas |
81 |
|
7604 |
25 Feb 19 |
nicklas |
var frm = list.form; |
7604 |
25 Feb 19 |
nicklas |
if (frm.averageMethod) |
7604 |
25 Feb 19 |
nicklas |
84 |
{ |
7604 |
25 Feb 19 |
nicklas |
var avgMethod = Data.get(selected, 'average-method'); |
7604 |
25 Feb 19 |
nicklas |
Forms.selectListOption(frm.averageMethod, avgMethod); |
7604 |
25 Feb 19 |
nicklas |
87 |
} |
7604 |
25 Feb 19 |
nicklas |
88 |
|
7604 |
25 Feb 19 |
nicklas |
formulaField.value = selected.value; |
7604 |
25 Feb 19 |
nicklas |
if (labelField && selected.value != '') labelField.value = selected.text; |
7604 |
25 Feb 19 |
nicklas |
list.selectedIndex = 0; |
7604 |
25 Feb 19 |
nicklas |
92 |
} |
7604 |
25 Feb 19 |
nicklas |
93 |
|
7604 |
25 Feb 19 |
nicklas |
94 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.plotTypeOnChange = function() |
7604 |
25 Feb 19 |
nicklas |
96 |
{ |
7604 |
25 Feb 19 |
nicklas |
var plotType = plotter.getPlotType(); |
7604 |
25 Feb 19 |
nicklas |
var isAssayPlot = plotType == 'assay'; |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['plot']; |
7604 |
25 Feb 19 |
nicklas |
frm.annotationTypeId.disabled = isAssayPlot; |
7604 |
25 Feb 19 |
nicklas |
frm.subtype.disabled = !isAssayPlot; |
7604 |
25 Feb 19 |
nicklas |
102 |
} |
7604 |
25 Feb 19 |
nicklas |
103 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.openExpressionBuilder = function(event) |
7604 |
25 Feb 19 |
nicklas |
105 |
{ |
7604 |
25 Feb 19 |
nicklas |
var formulaField = Doc.element(Data.get(event.currentTarget, 'formula-id')); |
7604 |
25 Feb 19 |
nicklas |
107 |
|
7604 |
25 Feb 19 |
nicklas |
if (!formulaField.disabled) |
7604 |
25 Feb 19 |
nicklas |
109 |
{ |
7604 |
25 Feb 19 |
nicklas |
var title = Data.get(event.currentTarget, 'title'); |
7604 |
25 Feb 19 |
nicklas |
var formulaType = Data.get(event.currentTarget, 'formula-type'); |
7604 |
25 Feb 19 |
nicklas |
var rawDataType = Data.get(event.currentTarget, 'raw-data-type'); |
7604 |
25 Feb 19 |
nicklas |
var channels = Data.int(event.currentTarget, 'channels'); |
7604 |
25 Feb 19 |
nicklas |
var bioAssaySetId = Data.int(event.currentTarget, 'bioassayset'); |
7604 |
25 Feb 19 |
nicklas |
115 |
|
7604 |
25 Feb 19 |
nicklas |
Dialogs.openExpressionBuilder(formulaField, title, formulaType, rawDataType, channels, bioAssaySetId);0 |
7604 |
25 Feb 19 |
nicklas |
117 |
} |
7604 |
25 Feb 19 |
nicklas |
118 |
} |
7604 |
25 Feb 19 |
nicklas |
119 |
|
7604 |
25 Feb 19 |
nicklas |
120 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.generatePlotUrl = function(fullSize) |
7604 |
25 Feb 19 |
nicklas |
122 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (!plotter.validateParameters()) return null; |
7604 |
25 Feb 19 |
nicklas |
124 |
|
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['plot']; |
7604 |
25 Feb 19 |
nicklas |
var url = App.getRoot() + 'views/experiments/explorer/plot?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&bioAssaySetId='+Data.get('page-data', 'bioassayset'); |
7604 |
25 Feb 19 |
nicklas |
url += '&reporterIndex='+Data.get('page-data', 'reporter-index'); |
7604 |
25 Feb 19 |
nicklas |
url += '&positionIndex='+Data.get('page-data', 'position-index'); |
7604 |
25 Feb 19 |
nicklas |
url += '&title='+encodeURIComponent(frm.title.value); |
7604 |
25 Feb 19 |
nicklas |
url += '&subTitle='+encodeURIComponent(frm.subTitle.value); |
7604 |
25 Feb 19 |
nicklas |
if (fullSize) |
7604 |
25 Feb 19 |
nicklas |
133 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&width='+frm.width.value; |
7604 |
25 Feb 19 |
nicklas |
url += '&height='+frm.height.value; |
7604 |
25 Feb 19 |
nicklas |
136 |
} |
7604 |
25 Feb 19 |
nicklas |
137 |
|
7604 |
25 Feb 19 |
nicklas |
url += '&y='+encodeURIComponent(frm.yFormula.value); |
7604 |
25 Feb 19 |
nicklas |
url += '&yLog='+(frm.yLog.checked ? 1 : 0); |
7604 |
25 Feb 19 |
nicklas |
url += '&yLabel='+encodeURIComponent(frm.yLabel.value); |
7604 |
25 Feb 19 |
nicklas |
141 |
|
7604 |
25 Feb 19 |
nicklas |
var plotType = plotter.getPlotType(); |
7604 |
25 Feb 19 |
nicklas |
url += '&type='+plotType; |
7604 |
25 Feb 19 |
nicklas |
url += '&showXLabels='+(frm.hideXLabels.checked ? 0 : 1); |
7604 |
25 Feb 19 |
nicklas |
145 |
|
7604 |
25 Feb 19 |
nicklas |
if (plotType == 'assay') |
7604 |
25 Feb 19 |
nicklas |
147 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&subtype=' + frm.subtype.value; |
7604 |
25 Feb 19 |
nicklas |
if (frm.averageMethod) |
7604 |
25 Feb 19 |
nicklas |
150 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&averageMethod=' + frm.averageMethod.value; |
7604 |
25 Feb 19 |
nicklas |
152 |
} |
7604 |
25 Feb 19 |
nicklas |
153 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (plotType == 'annotation') |
7604 |
25 Feb 19 |
nicklas |
155 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&annotationTypeId=' + frm.annotationTypeId.value; |
7604 |
25 Feb 19 |
nicklas |
157 |
} |
7604 |
25 Feb 19 |
nicklas |
url += '&' + new Date().getTime(); |
7604 |
25 Feb 19 |
nicklas |
return url; |
7604 |
25 Feb 19 |
nicklas |
160 |
} |
7604 |
25 Feb 19 |
nicklas |
161 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.previewPlot = function() |
7604 |
25 Feb 19 |
nicklas |
163 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = plotter.generatePlotUrl(false); |
7604 |
25 Feb 19 |
nicklas |
if (url) |
7604 |
25 Feb 19 |
nicklas |
166 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&width=540&height=360'; |
7604 |
25 Feb 19 |
nicklas |
168 |
|
7604 |
25 Feb 19 |
nicklas |
var overlayImg = Doc.element('overlay'); |
7604 |
25 Feb 19 |
nicklas |
overlayImg.src = App.getRoot()+'images/plot_generating.gif'; |
7604 |
25 Feb 19 |
nicklas |
171 |
|
7604 |
25 Feb 19 |
nicklas |
var tmpPlot = new Image(); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(tmpPlot, 'load', plotter.previewLoaded); |
7604 |
25 Feb 19 |
nicklas |
tmpPlot.src = url; |
7604 |
25 Feb 19 |
nicklas |
175 |
} |
7604 |
25 Feb 19 |
nicklas |
176 |
} |
7604 |
25 Feb 19 |
nicklas |
177 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.previewLoaded = function(event) |
7604 |
25 Feb 19 |
nicklas |
179 |
{ |
7604 |
25 Feb 19 |
nicklas |
var tmpPlot = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
181 |
|
7604 |
25 Feb 19 |
nicklas |
var previewImg = Doc.element('preview'); |
7604 |
25 Feb 19 |
nicklas |
previewImg.src = tmpPlot.src; |
7604 |
25 Feb 19 |
nicklas |
184 |
|
7604 |
25 Feb 19 |
nicklas |
var overlayImg = Doc.element('overlay'); |
7604 |
25 Feb 19 |
nicklas |
overlayImg.src = App.getRoot() + 'images/blankbutton.gif'; |
7604 |
25 Feb 19 |
nicklas |
187 |
} |
7604 |
25 Feb 19 |
nicklas |
188 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.viewPlot = function() |
7604 |
25 Feb 19 |
nicklas |
190 |
{ |
7604 |
25 Feb 19 |
nicklas |
var plotUrl = plotter.generatePlotUrl(true); |
7604 |
25 Feb 19 |
nicklas |
if (plotUrl) |
7604 |
25 Feb 19 |
nicklas |
193 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['plot']; |
7604 |
25 Feb 19 |
nicklas |
var width = parseInt(frm.width.value); |
7604 |
25 Feb 19 |
nicklas |
var height = parseInt(frm.height.value); |
7604 |
25 Feb 19 |
nicklas |
if (!width || width < 600) width = 600; |
7604 |
25 Feb 19 |
nicklas |
if (!height || height < 400) height = 400; |
7604 |
25 Feb 19 |
nicklas |
var url = '../../plotter/view.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&title='+encodeURIComponent(frm.title.value); |
7604 |
25 Feb 19 |
nicklas |
url += '&plot='+encodeURIComponent(plotUrl); |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openPopup(url, 'ViewPlot', width+150, height+100); |
7604 |
25 Feb 19 |
nicklas |
203 |
} |
7604 |
25 Feb 19 |
nicklas |
204 |
} |
7604 |
25 Feb 19 |
nicklas |
205 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.downloadPlot = function() |
7604 |
25 Feb 19 |
nicklas |
207 |
{ |
7604 |
25 Feb 19 |
nicklas |
var plotUrl = plotter.generatePlotUrl(true); |
7604 |
25 Feb 19 |
nicklas |
if (plotUrl) |
7604 |
25 Feb 19 |
nicklas |
210 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = '../../plotter/download.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&plot='+encodeURIComponent(plotUrl); |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openPopup(url, 'DownloadPlot', 300, 200); |
7604 |
25 Feb 19 |
nicklas |
214 |
} |
7604 |
25 Feb 19 |
nicklas |
215 |
} |
7604 |
25 Feb 19 |
nicklas |
216 |
|
7604 |
25 Feb 19 |
nicklas |
plotter.savePlotAs = function() |
7604 |
25 Feb 19 |
nicklas |
218 |
{ |
7604 |
25 Feb 19 |
nicklas |
var plotUrl = plotter.generatePlotUrl(true); |
7604 |
25 Feb 19 |
nicklas |
if (plotUrl) |
7604 |
25 Feb 19 |
nicklas |
221 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = '../../plotter/save_as.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&plot='+encodeURIComponent(plotUrl); |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openPopup(url, 'SavePlotAs', 450, 300); |
7604 |
25 Feb 19 |
nicklas |
225 |
} |
7604 |
25 Feb 19 |
nicklas |
226 |
} |
7604 |
25 Feb 19 |
nicklas |
227 |
|
7604 |
25 Feb 19 |
nicklas |
return plotter; |
7604 |
25 Feb 19 |
nicklas |
229 |
}(); |
7604 |
25 Feb 19 |
nicklas |
230 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Plotter.initPage); |