n@566: /* n@566: * Analysis script for WAET n@566: */ n@566: n@566: var chartContext; n@566: window.onload = function() { n@566: // Load the Visualization API and the corechart package. n@566: google.charts.load('current', {'packages':['corechart']}); n@566: chartContext = new Chart(); n@566: } n@566: n@566: function Chart() { n@569: this.valueData = null; n@569: this.commentData = null; n@569: this.loadStatus = 0; n@566: n@569: var XMLHttp = new XMLHttpRequest(); n@569: XMLHttp.parent = this; n@569: XMLHttp.open("GET","../scripts/score_parser.php?format=JSON",true); n@569: XMLHttp.onload = function() { n@569: // Now we have the JSON data, extract n@569: this.parent.valueData = JSON.parse(this.responseText); n@569: this.parent.loadStatus++; n@566: } n@569: XMLHttp.send(); n@569: var XMLHttp2 = new XMLHttpRequest(); n@569: XMLHttp2.parent = this; n@569: XMLHttp2.open("GET","../scripts/comment_parser.php?format=JSON",true); n@569: XMLHttp2.onload = function() { n@569: // Now we have the JSON data, extract n@569: this.parent.commentData = JSON.parse(this.responseText); n@569: this.parent.loadStatus++; n@569: } n@569: XMLHttp2.send(); n@566: n@566: this.drawMean = function() { n@566: // First we must get the value data n@569: if (this.valueData == null) { n@569: console.log("Error - Data not loaded"); n@569: return; n@569: } n@569: // We create one plot per page n@569: for (var page of this.valueData.pages) { n@569: // First, create the chart resulting point n@569: var inject = document.createElement("div"); n@569: document.getElementById("test-pages").appendChild(inject); n@569: n@569: // Create the data table n@569: var data = new google.visualization.DataTable(); n@569: data.addColumn('string','id'); n@569: // Get axis labels n@569: for (var axis of page.elements[0].axis) { n@569: data.addColumn('number',axis.name); n@569: } n@569: var rows = []; // Rows is an array of tuples [col1, col2, col3 ... colN]; n@569: for (var element of page.elements) { n@569: var entry = [element.id]; n@569: for (var i=0; i