# HG changeset patch # User Nicholas Jillings # Date 1456320972 0 # Node ID a08957badf33048cf428763bfc21eaf0109b39e4 # Parent f88e611cd3c7cbb95d79f02a3be7dfe8e7b443c8 Analysis: Added dynamic data sorting diff -r f88e611cd3c7 -r a08957badf33 analysis/analysis.js --- a/analysis/analysis.js Wed Feb 24 13:03:08 2016 +0000 +++ b/analysis/analysis.js Wed Feb 24 13:36:12 2016 +0000 @@ -115,16 +115,89 @@ this.data = new google.visualization.DataTable(); this.options = {}; this.print = document.createElement("button"); + this.sortDataButton = document.createElement("button"); + this.sortDataButton.textContent = "Sort by Data"; + this.sortDataButton.addEventListener("click",this); + this.sortDataButton.setAttribute("name","sort-data"); + this.sortNameButton = document.createElement("button"); + this.sortNameButton.textContent = "Sort by Name"; + this.sortNameButton.addEventListener("click",this); + this.sortNameButton.setAttribute("name","sort-name"); + this.draw = function() { + if (this.chart == undefined) {return;} + this.tableDOM.innerHTML = null; + this.latexDOM.innerHTML = null; + this.buildTable(); + this.writeLatex(); + this.chart.draw(this.data,this.options); + } + this.sortData = function() { + + var map = this.data.Jf.map(function(el,i){ + return {index: i, value: el.c[1].v}; + }); + + map.sort(function(a,b){ + if (a.value > b.value) {return -1;} + if (a.value < b.value) {return 1;} + return 0; + }) + + var Jf = []; + var cc = []; + for (var i=0; i b.value) {return 1;} + return 0; + }) + + var Jf = []; + var cc = []; + for (var i=0; iDownload'; + switch(event.currentTarget.getAttribute("name")) + { + case "download": + window.open(this.chart.getImageURI()); + break; + case "sort-data": + this.sortData(); + this.draw(); + break; + case "sort-name": + this.sortName(); + this.draw(); + break; + } } this.root.appendChild(this.chartDOM); this.root.appendChild(this.tableDOM); this.root.appendChild(this.latexDOM); + this.root.appendChild(this.sortDataButton); + this.root.appendChild(this.sortNameButton); this.root.appendChild(this.print); this.print.textContent = "Download"; + this.print.setAttribute("name","download"); this.print.addEventListener("click",this); this.root.appendChild(this.downloadDOM); this.buildTable = function() { @@ -155,6 +228,7 @@ for (var i=0; i