Mercurial > hg > webaudioevaluationtool
comparison analysis/analysis.js @ 1228:a08957badf33
Analysis: Added dynamic data sorting
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Wed, 24 Feb 2016 13:36:12 +0000 |
parents | f88e611cd3c7 |
children | 9dcfd654abad 83b439322229 |
comparison
equal
deleted
inserted
replaced
1227:f88e611cd3c7 | 1228:a08957badf33 |
---|---|
113 this.downloadDOM = document.createElement("div"); | 113 this.downloadDOM = document.createElement("div"); |
114 this.chart = undefined; | 114 this.chart = undefined; |
115 this.data = new google.visualization.DataTable(); | 115 this.data = new google.visualization.DataTable(); |
116 this.options = {}; | 116 this.options = {}; |
117 this.print = document.createElement("button"); | 117 this.print = document.createElement("button"); |
118 this.sortDataButton = document.createElement("button"); | |
119 this.sortDataButton.textContent = "Sort by Data"; | |
120 this.sortDataButton.addEventListener("click",this); | |
121 this.sortDataButton.setAttribute("name","sort-data"); | |
122 this.sortNameButton = document.createElement("button"); | |
123 this.sortNameButton.textContent = "Sort by Name"; | |
124 this.sortNameButton.addEventListener("click",this); | |
125 this.sortNameButton.setAttribute("name","sort-name"); | |
126 this.draw = function() { | |
127 if (this.chart == undefined) {return;} | |
128 this.tableDOM.innerHTML = null; | |
129 this.latexDOM.innerHTML = null; | |
130 this.buildTable(); | |
131 this.writeLatex(); | |
132 this.chart.draw(this.data,this.options); | |
133 } | |
134 this.sortData = function() { | |
135 | |
136 var map = this.data.Jf.map(function(el,i){ | |
137 return {index: i, value: el.c[1].v}; | |
138 }); | |
139 | |
140 map.sort(function(a,b){ | |
141 if (a.value > b.value) {return -1;} | |
142 if (a.value < b.value) {return 1;} | |
143 return 0; | |
144 }) | |
145 | |
146 var Jf = []; | |
147 var cc = []; | |
148 for (var i=0; i<map.length; i++) { | |
149 Jf.push(this.data.Jf[map[i].index]); | |
150 cc.push(this.data.cc[map[i].index]); | |
151 } | |
152 this.data.Jf = Jf; | |
153 this.data.cc = cc; | |
154 } | |
155 this.sortName = function() { | |
156 var map = this.data.Jf.map(function(el,i){ | |
157 return {index: i, value: el.c[0].v}; | |
158 }); | |
159 | |
160 map.sort(function(a,b){ | |
161 if (a.value < b.value) {return -1;} | |
162 if (a.value > b.value) {return 1;} | |
163 return 0; | |
164 }) | |
165 | |
166 var Jf = []; | |
167 var cc = []; | |
168 for (var i=0; i<map.length; i++) { | |
169 Jf.push(this.data.Jf[map[i].index]); | |
170 cc.push(this.data.cc[map[i].index]); | |
171 } | |
172 this.data.Jf = Jf; | |
173 this.data.cc = cc; | |
174 } | |
118 this.handleEvent = function() { | 175 this.handleEvent = function() { |
119 // Only used to handle the chart.event.addListener(this,'ready') callback | 176 // Only used to handle the chart.event.addListener(this,'ready') callback |
120 this.downloadDOM.innerHTML = '<a href="' + this.chart.getImageURI() + '">Download</a>'; | 177 switch(event.currentTarget.getAttribute("name")) |
178 { | |
179 case "download": | |
180 window.open(this.chart.getImageURI()); | |
181 break; | |
182 case "sort-data": | |
183 this.sortData(); | |
184 this.draw(); | |
185 break; | |
186 case "sort-name": | |
187 this.sortName(); | |
188 this.draw(); | |
189 break; | |
190 } | |
121 } | 191 } |
122 | 192 |
123 this.root.appendChild(this.chartDOM); | 193 this.root.appendChild(this.chartDOM); |
124 this.root.appendChild(this.tableDOM); | 194 this.root.appendChild(this.tableDOM); |
125 this.root.appendChild(this.latexDOM); | 195 this.root.appendChild(this.latexDOM); |
196 this.root.appendChild(this.sortDataButton); | |
197 this.root.appendChild(this.sortNameButton); | |
126 this.root.appendChild(this.print); | 198 this.root.appendChild(this.print); |
127 this.print.textContent = "Download"; | 199 this.print.textContent = "Download"; |
200 this.print.setAttribute("name","download"); | |
128 this.print.addEventListener("click",this); | 201 this.print.addEventListener("click",this); |
129 this.root.appendChild(this.downloadDOM); | 202 this.root.appendChild(this.downloadDOM); |
130 this.buildTable = function() { | 203 this.buildTable = function() { |
131 var table = document.createElement("table"); | 204 var table = document.createElement("table"); |
132 table.border = "1"; | 205 table.border = "1"; |
153 start.textContent = "\\" + "begin{tabular}{|l|"; | 226 start.textContent = "\\" + "begin{tabular}{|l|"; |
154 holder.appendChild(start); | 227 holder.appendChild(start); |
155 for (var i=0; i<this.data.cc.length; i++) { | 228 for (var i=0; i<this.data.cc.length; i++) { |
156 start.textContent = start.textContent+"c|"; | 229 start.textContent = start.textContent+"c|"; |
157 } | 230 } |
231 start.textContent = start.textContent.concat("}"); | |
158 // Now write the rows: | 232 // Now write the rows: |
159 for (var rIndex=0; rIndex<this.data.If.length; rIndex++) { | 233 for (var rIndex=0; rIndex<this.data.If.length; rIndex++) { |
160 var row = document.createElement("p"); | 234 var row = document.createElement("p"); |
161 row.textContent = this.data.If[rIndex].label.concat(" & "); | 235 row.textContent = this.data.If[rIndex].label.concat(" & "); |
162 for (var cIndex=0; cIndex<this.data.cc.length; cIndex++) { | 236 for (var cIndex=0; cIndex<this.data.cc.length; cIndex++) { |