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