Mercurial > repos > immport-devteam > cs_overview
comparison js/crossSamplePlots.js @ 2:a64ece32a01a draft default tip
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/cs_overview commit a46097db0b6056e1125237393eb6974cfd51eb41"
author | azomics |
---|---|
date | Tue, 28 Jul 2020 08:32:36 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:bca68066a957 | 2:a64ece32a01a |
---|---|
1 // Copyright (c) 2016 Northrop Grumman. | |
2 // All rights reserved. | |
3 var updateCSplots = function(plotconfig){ | |
4 plotconfig.selectedPopulations = []; | |
5 $(plotconfig.popSelectj).each(function() { | |
6 if (this.checked) { | |
7 plotconfig.selectedPopulations.push(parseInt(this.value)); | |
8 } | |
9 }); | |
10 if (plotconfig.hasOwnProperty("mtable")) { | |
11 // Update selected markers? | |
12 plotconfig.selectedMarkers = []; | |
13 $(plotconfig.mrkrSelectj).each(function() { | |
14 if (this.checked) { | |
15 plotconfig.selectedMarkers.push(parseInt(this.value)); | |
16 } | |
17 }); | |
18 // update plot | |
19 updateBoxplot(plotconfig); | |
20 } else { | |
21 updatePlot(plotconfig); | |
22 } | |
23 }; | |
24 | |
25 var displayPopulationLegend = function(plotconfig) { | |
26 $(plotconfig.table).empty(); | |
27 plotconfig.allPopulations.map(function(value,index) { | |
28 $(plotconfig.table).append('<tr><td align="center">' | |
29 + '<input type="checkbox" checked class=' + plotconfig.popSelect | |
30 + ' value=' + value + '/></td><td title="' + newPopNames[value] + '">' | |
31 + newPopNames[value] + '</td><td><span style="background-color:' | |
32 + color_palette[0][value][0] + '"> </span></td></tr>'); | |
33 }); | |
34 | |
35 $(plotconfig.popSelectAll).click(function() { | |
36 var checkAll = $(plotconfig.popSelectAll).prop('checked'); | |
37 if (checkAll) { | |
38 $(plotconfig.popSelectj).prop("checked", true); | |
39 } else { | |
40 $(plotconfig.popSelectj).prop("checked", false); | |
41 } | |
42 updateCSplots(plotconfig); | |
43 }); | |
44 | |
45 $(plotconfig.popSelectj).click(function() { | |
46 if ($(plotconfig.popSelectj).length == $(plotconfig.popSelectCheck).length) { | |
47 $(plotconfig.popSelectAll).prop("checked",true); | |
48 } else { | |
49 $(plotconfig.popSelectAll).prop("checked",false); | |
50 } | |
51 updateCSplots(plotconfig); | |
52 }); | |
53 | |
54 $(plotconfig.popSelectj).each(function() { | |
55 var selectedpopn = parseInt(this.value); | |
56 if ($.inArray(selectedpopn,plotconfig.selectedPopulations) > -1) { | |
57 this.checked = true; | |
58 } else { | |
59 this.checked = false; | |
60 } | |
61 }); | |
62 }; | |
63 | |
64 var displayToolbar = function(plotconfig){ | |
65 $(plotconfig.displaybutton).on("click",function() { | |
66 $(plotconfig.popSelectj).prop("checked", true); | |
67 $(plotconfig.popSelectAll).prop("checked", true); | |
68 if (plotconfig.hasOwnProperty("mtable")){ | |
69 $(plotconfig.displayMFI).prop("checked", false); | |
70 $(plotconfig.displayvalues).prop("checked", false); | |
71 $(plotconfig.mrkrSelectj).prop("checked", true); | |
72 $(plotconfig.mrkrSelectAll).prop("checked",true); | |
73 } | |
74 updateCSplots(plotconfig); | |
75 }); | |
76 | |
77 if (plotconfig.hasOwnProperty("mtable")){ | |
78 $(plotconfig.displayMFI).on("click", function(){ | |
79 updateCSplots(plotconfig); | |
80 }); | |
81 $(plotconfig.displayvalues).on("click", function(){ | |
82 updateCSplots(plotconfig); | |
83 }); | |
84 } | |
85 $(plotconfig.toggledisplayj).on("click",function() { | |
86 plotconfig.selectedPopulations = []; | |
87 $(plotconfig.popSelectj).each(function() { | |
88 if (this.checked) { | |
89 plotconfig.selectedPopulations.push(parseInt(this.value)); | |
90 } | |
91 }) | |
92 if (plotconfig.hasOwnProperty("mtable")){ | |
93 plotconfig.selectedMarkers = []; | |
94 $(plotconfig.mrkrSelectj).each(function() { | |
95 if (this.checked) { | |
96 plotconfig.selectedMarkers.push(parseInt(this.value)); | |
97 } | |
98 }); | |
99 var text = document.getElementById(plotconfig.toggledisplay).firstChild; | |
100 text.data = text.data == "View per marker" ? "View per population" : "View per marker"; | |
101 plotconfig.view = plotconfig.view == "p" ? "m" : "p"; | |
102 updateBoxplot(plotconfig); | |
103 } else { | |
104 var imgSrc = document.getElementById(plotconfig.toggledisplay); | |
105 imgSrc.src = imgSrc.src.endsWith("stackedsm.png") ? "/static/images/flowtools/barssm.png" : "/static/images/flowtools/stackedsm.png"; | |
106 plotconfig.type = plotconfig.type == "barplot" ? "areaplot" : "barplot"; | |
107 updatePlot(plotconfig); | |
108 } | |
109 }); | |
110 displayPlot(plotconfig); | |
111 }; | |
112 | |
113 var displayPlot = function(plotconfig) { | |
114 var h = $(window).height() - 200; | |
115 $(plotconfig.plotdivj).empty(); | |
116 $(plotconfig.plotdivj).height(h); | |
117 | |
118 if (plotconfig.hasOwnProperty("mtable")) { | |
119 var nbPop = Object.keys(plotconfig.csdata.mfi[plotconfig.mrkrNames[0]]).length + 2; | |
120 // Get Markers too | |
121 for (var i = 0, nbMarkers = plotconfig.mrkrNames.length; i < nbMarkers; i++) { | |
122 plotconfig.allMarkers.push(i); | |
123 plotconfig.selectedMarkers.push(i); | |
124 } | |
125 } else { | |
126 var nbPop = plotconfig.csdata[0].length; | |
127 } | |
128 | |
129 for (var i = 2; i < nbPop; i++) { | |
130 plotconfig.allPopulations.push(i - 1); | |
131 plotconfig.selectedPopulations.push(i - 1); | |
132 } | |
133 | |
134 $(window).on('resize',function() { | |
135 waitForFinalEvent(function() { | |
136 if (plotconfig.hasOwnProperty("mtable")){ | |
137 updateBoxplot(plotconfig); | |
138 } else { | |
139 updatePlot(plotconfig); | |
140 } | |
141 }, 500, "resizePlot"); | |
142 }); | |
143 | |
144 displayPopulationLegend(plotconfig); | |
145 if (plotconfig.hasOwnProperty("mtable")){ | |
146 displayMarkerTable(plotconfig); | |
147 updateBoxplot(plotconfig); | |
148 } else { | |
149 updatePlot(plotconfig); | |
150 } | |
151 }; | |
152 | |
153 var updatePlot = function(plotconfig) { | |
154 var h = $(window).height() - 200, | |
155 traces = [], | |
156 tmptraces = [], | |
157 x_values = [], | |
158 totals = []; | |
159 layout = {}; | |
160 | |
161 $(plotconfig.plotdivj).empty(); | |
162 $(plotconfig.plotdivj).height(h); | |
163 for (var i = 1, j = plotconfig.csdata.length; i < j; i++) { | |
164 x_values.push(newSmpNames[plotconfig.csdata[i][1]]); | |
165 } | |
166 | |
167 for (var k = 1, i = plotconfig.csdata.length; k < i; k++){ | |
168 totals[k] = 0; | |
169 for (var m = 2, o = plotconfig.csdata[0].length; m < o; m++){ | |
170 for (var n = 0, p = plotconfig.selectedPopulations.length; n < p; n++){ | |
171 if (plotconfig.csdata[0][m] === plotconfig.selectedPopulations[n]) { | |
172 totals[k] += plotconfig.csdata[k][m]; | |
173 } | |
174 } | |
175 } | |
176 } | |
177 | |
178 for (var i = 0, ii = plotconfig.selectedPopulations.length; i < ii; i++) { | |
179 pop = plotconfig.selectedPopulations[i]; | |
180 var popName = "Pop " + pop; | |
181 var y_values = []; | |
182 var obj; | |
183 | |
184 for (var j = 1, jj = plotconfig.csdata.length; j < jj; j++) { | |
185 var newvalue = (plotconfig.csdata[j][pop + 1] / totals[j]) * 100; | |
186 y_values.push(newvalue); | |
187 } | |
188 if (plotconfig.type === "areaplot") { | |
189 obj = { | |
190 x: x_values, | |
191 y: y_values, | |
192 hoverinfo: "x", | |
193 name: popName, | |
194 type: 'area', | |
195 fill: 'tonexty', | |
196 marker: {color: color_palette[0][pop][0]} | |
197 }; | |
198 } | |
199 if (plotconfig.type === "barplot") { | |
200 obj = { | |
201 x: x_values, | |
202 y: y_values, | |
203 hoverinfo: "x", | |
204 name: popName, | |
205 type: 'bar', | |
206 marker: {color: color_palette[0][pop][0]} | |
207 }; | |
208 } | |
209 tmptraces.push(obj) | |
210 } | |
211 | |
212 if (plotconfig.type === "barplot") { | |
213 layout = { | |
214 hovermode:'closest', | |
215 title: '', | |
216 barmode: 'stack', | |
217 showlegend: false, | |
218 yaxis: { | |
219 mirror: 'all', | |
220 tickmode: 'array', | |
221 ticktext: ["","20%", "40%", "60%", "80%", "100%"], | |
222 tickvals: [0,20,40,60,80,100], | |
223 title: 'Populations proportions in selected set', | |
224 titlefont: { | |
225 size: 16, | |
226 color: 'grey' | |
227 } | |
228 } | |
229 }; | |
230 traces = tmptraces; | |
231 } | |
232 if (plotconfig.type === "areaplot") { | |
233 function stacked(trcs) { | |
234 for(var i=1; i<trcs.length; i++) { | |
235 for(var j=0; j<(Math.min(trcs[i]['y'].length, trcs[i-1]['y'].length)); j++) { | |
236 trcs[i]['y'][j] += trcs[i-1]['y'][j]; | |
237 } | |
238 } | |
239 return trcs; | |
240 } | |
241 layout = { | |
242 title: '', | |
243 showlegend: false, | |
244 yaxis: { | |
245 mirror: 'all', | |
246 tickmode: 'array', | |
247 ticktext: ["","20%", "40%", "60%", "80%", "100%"], | |
248 tickvals: [0,20,40,60,80,100], | |
249 title: 'Populations proportions in selected set', | |
250 titlefont: { | |
251 size: 16, | |
252 color: 'grey' | |
253 } | |
254 }, | |
255 xaxis: { | |
256 autorange: false, | |
257 range: [-0.2, x_values.length - 0.8] | |
258 } | |
259 }; | |
260 traces = stacked(tmptraces); | |
261 } | |
262 Plotly.newPlot(plotconfig.plotdiv,traces,layout); | |
263 }; |