comparison js/overview.js @ 1:b5453d07f740 draft default tip

"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/flow_overview commit 65373effef15809f3db0e5f9603ef808f4110aa3"
author azomics
date Wed, 29 Jul 2020 17:03:53 -0400
parents
children
comparison
equal deleted inserted replaced
0:8283ff163ba6 1:b5453d07f740
1 // Copyright (c) 2016 Northrop Grumman.
2 // All rights reserved.
3
4 var scatterData2D = {};
5 var scatterData3D = {};
6 var scatterData3DMFI = {};
7 var scatterDataMFI = {};
8 var tableContent;
9 var newNames ={};
10 var configbp = {};
11 var bpurl = "./boxplotData.json";
12
13 var waitForFinalEvent = (function () {
14 var timers = {};
15 return function (callback, ms, uniqueId) {
16 if (!uniqueId) {
17 uniqueId = "Don't call this twice without a uniqueId";
18 }
19 if (timers[uniqueId]) {
20 clearTimeout (timers[uniqueId]);
21 }
22 timers[uniqueId] = setTimeout(callback, ms);
23 };
24 })();
25
26 var updateOverviewPlotDisplay = function(data) {
27 $('#overviewPlotDiv').empty();
28 $('#overviewPlotDiv').html(data);
29 };
30
31 var displayMFI = function() {
32 var url = "flow.mfi_pop";
33 d3.text(url, function(error, data){
34 var mfiHdgs = [],
35 pp = [],
36 mfiTableData = [],
37 mfiTableHeadings = [],
38 mfiTargets = [],
39 mfiTableHTML = '<table id="mfitable" class="dtable display compact" cellspacing="0" width="100%"/>',
40 popcol = 1,
41 mfiEditorData =[];
42
43 if (error){
44 alert("Problem retrieving data");
45 return;
46 }
47 mfiHdgs = data.split("\n")[0].split("\t");
48 pp = mfiHdgs.pop();
49 mfiHdgs.unshift(pp);
50 mfiHdgs.unshift("Comment");
51 data = d3.tsv.parse(data);
52 function handleSubmit(method, url, d, successCallBack, errorCallBack) {
53 var output = {data : mfiTableData};
54 successCallBack(output);
55 }
56
57 $('#mfiDiv').empty();
58 mfiTableData = $.extend(true,[],data);
59 mfiTableData.forEach(function(d){
60 d.Comment = d.Population;
61 newNames[parseInt(d.Population)] = d.Comment;
62 });
63 //var mfiData = mfiTableData.filter(function(d){return d});
64 tableContent = $.extend(true, [], mfiTableData);
65 mfiHdgs.forEach(function(d,i) {
66 mfiTableHeadings.push({"data": d, "title": d});
67 mfiEditorData.push({"label" : d, "name" : d});
68 });
69
70 for (var i = 2, j = mfiHdgs.length - 2; i<j; i++){
71 mfiTargets.push(i);
72 }
73
74 $('#mfiDiv').html(mfiTableHTML);
75 var editor = new $.fn.dataTable.Editor({
76 ajax: handleSubmit,
77 table: '#mfitable',
78 fields: mfiEditorData,
79 idSrc: 'Population'
80 });
81 $('#mfitable').on('click', 'tbody td:first-child', function (e) {
82 editor.bubble(this);
83 });
84 var mfiTable = $('#mfitable').DataTable({
85 columns: mfiTableHeadings,
86 data: mfiTableData,
87 order: [[ popcol, "asc" ]],
88 pageLength: 25,
89 dom: '<"top"Bi>t<"bottom"lp><"clear">',
90 columnDefs: [{
91 targets: mfiTargets,
92 className: "dt-body-right",
93 render: function(data, type, row){
94 return parseFloat(data).toFixed(2);
95 }
96 }, {
97 targets: [mfiHdgs.length - 2],
98 className: "dt-body-right"
99 }, {
100 targets: [mfiHdgs.length-1],
101 className: "dt-body-right",
102 render: function(data, type, row){
103 return parseFloat(data).toFixed(2) + '%';
104 }
105 }
106 ],
107 buttons: [
108 'copy', 'pdfHtml5','csvHtml5', 'colvis'
109 ],
110 colReorder: {fixedColumnsLeft:1},
111 select: true
112 });
113 editor.on('preSubmit', function(e, object, action){
114 var data = object.data;
115 var key = Object.keys(data)[0];
116 var count = object.data[key]['Comment'];
117 mfiTableData.forEach(function(d) {
118 if (d.Population === key) {
119 d.Comment = count;
120 newNames[parseInt(d.Population)] = count;
121 }
122 });
123 tableContent = $.extend(true, [], mfiTableData);
124 });
125 });
126 };
127
128 var displayOverviewPlot = function() {
129 var url = "flow.overview";
130 $.ajax({
131 url: url,
132 dataType: "text",
133 success: function(data) {
134 updateOverviewPlotDisplay(data);
135 }
136 });
137 };
138
139 var displayScatter2D = function() {
140 var url = "flow.sample";
141 $.ajax({
142 url: url,
143 dataType: "text",
144 success: function(text) {
145 var mfi_url = "flow.mfi_pop";
146 $.ajax({
147 url: mfi_url,
148 dataType: "text",
149 success: function(mfi_text) {
150 scatterDataMFI = new processMFI(mfi_text);
151 scatterData2D = new processData(text);
152 displayScatterToolbar2D();
153 displayScatterPopulation2D();
154 processScatterData2D();
155 processScatterDataMFI2D();
156 displayScatterPlot2D();
157 $(window).on('resize',function() {
158 waitForFinalEvent(function() {
159 processScatterData2D();
160 displayScatterPlot2D();
161 }, 500, "resize2D");
162 });
163 }
164 });
165 }
166 });
167 };
168
169 var displayScatter3D = function() {
170 var url = "flow.sample";
171 $.ajax({
172 url: url,
173 dataType: "text",
174 success: function(text) {
175 var mfi_url = "flow.mfi_pop";
176 $.ajax({
177 url: mfi_url,
178 dataType: "text",
179 success: function(mfi_text) {
180 scatterData3DMFI = new processMFI(mfi_text);
181 scatterData3D = new processData(text);
182 displayScatterToolbar3D();
183 displayScatterPopulation3D();
184 processScatterData3D();
185 processScatterData3DMFI();
186 displayScatterPlot3D();
187 $(window).on('resize',function() {
188 waitForFinalEvent(function() {
189 processScatterData3D();
190 displayScatterPlot3D();
191 }, 500, "resize3D");
192 });
193 }
194 });
195 }
196 });
197 };
198
199 var displayMFIBoxplot = function() {
200 $.ajax({
201 url: bpurl,
202 dataType: "json",
203 success: function(data) {
204 configbp = {
205 displaybutton : '#updateDisplaybp',
206 toggledisplayj : '#changeDisplay',
207 toggledisplay : 'changeDisplay',
208 popSelectj : '.popSelectbp',
209 plotdivj : '#plotDivbp',
210 csdata : data,
211 plotdiv : 'plotDivbp',
212 type : 'boxplot',
213 table : '#popTablebp tbody',
214 popSelect : 'popSelectbp',
215 allMarkers : [],
216 selectedMarkers: [],
217 allPopulations : [],
218 selectedPopulations : [],
219 popSelectAll : '#popSelectAllbp',
220 popSelectCheck: '.popSelectbp:checked',
221 mrkrSelectAll : '#mrkrSelectAll',
222 mrkrSelectCheck: '.mrkrSelect:checked',
223 mrkrSelect : 'mrkrSelect',
224 mtable : '#mrkrTable tbody',
225 mrkrSelectj: '.mrkrSelect',
226 displayvalues: '#displayLabels',
227 displayMFI: '#displayMFI',
228 view: 'p',
229 mrkrNames : Object.keys(data.mfi)
230 };
231 displayToolbar(configbp);
232 }
233 });
234 };
235
236 function processData(text) {
237 var data = d3.tsv.parseRows(text).map(function(row) {
238 return row.map(function(value) {
239 if (isNaN(value)) {
240 return value;
241 }
242 return +value;
243 });
244 });
245
246 this.columnHeadings = data.shift();
247 this.columnHeadings.pop();
248 var popCol = data[0].length - 1;
249 var p = data.map(function(value,index) {
250 return parseInt(value[popCol]);
251 });
252
253 var populations = {};
254 for (var i = 0; i < p.length; i++) {
255 if (populations[p[i]] === undefined) {
256 populations[p[i]] = 1;
257 } else {
258 populations[p[i]] = populations[p[i]] + 1;
259 }
260 }
261
262 this.popCol = popCol;
263 this.populations = d3.set(p).values();
264 this.populations = this.populations.map(function(value,index) {
265 return parseInt(value);
266 });
267 this.selectedPopulations = this.populations;
268 this.percent = this.populations.map(function(value,index) {
269 return Math.floor(populations[value] * 10000.0 / data.length) / 100.0;
270 });
271
272 this.data = data;
273 this.m1 = 0;
274 this.m2 = 1;
275 this.m3 = 2;
276 this.view = 1;
277 };
278
279 function processMFI(text) {
280 data = d3.tsv.parseRows(text).map(function(row) {
281 return row.map(function(value) {
282 if (isNaN(value)) {
283 return value;
284 }
285 return +value;
286 });
287 });
288
289 // Get the Headings Row, then remove the Count, Percentage and
290 // Population headings
291 this.columnHeadings = data.shift();
292 this.columnHeadings.pop();
293 this.columnHeadings.pop();
294 this.columnHeadings.pop();
295
296 var popCol = data[0].length -1;
297 var pop = data.map(function(value,index) {
298 return parseInt(value[popCol]);
299 });
300
301 var perCol = data[0].length -2;
302 var per = data.map(function(value,index) {
303 return parseFloat(value[perCol]);
304 });
305
306 var countCol = data[0].length -3;
307 var count = data.map(function(value,index) {
308 return parseInt(value[countCol]);
309 });
310
311 this.popCol = popCol;
312 this.populations = pop;
313 this.selectedPopulations = pop;
314 this.percent = per;
315 this.counts = count;
316
317 var l = data[0].length;
318 this.data = data.map(function(row) {
319 return row.splice(0,countCol);
320 });
321 this.poplist = pop;
322 this.m1 = 0;
323 this.m2 = 1;
324 this.m3 = 2;
325 };