Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var buildGraphs = {
- init: function(){
- self = this;
- $.ajax({
- url: "pollscript.php",
- cache: false
- }).done(function(data) {
- console.log(data);
- console.log("hi");
- var statsJSON = jQuery.parseJSON(data);
- console.log(statsJSON);
- self.statsJSON = statsJSON;
- self.hardscores = self.methods.buildScoreArr(self.data.categories.cathard);
- self.softscores = self.methods.buildScoreArr(self.data.categories.catsoft);
- self.expscores = self.methods.buildScoreArr(self.data.categories.catexp);
- self.totscores = self.methods.totalScore();
- self.hardsimple = self.methods.simpleScore(self.hardscores);
- self.softsimple = self.methods.simpleScore(self.softscores);
- self.expsimple = self.methods.simpleScore(self.expscores);
- self.totsimple = self.methods.simpleScore(self.totscores);
- self.hardbars = self.methods.graphSizes(self.hardsimple);
- self.softbars = self.methods.graphSizes(self.softsimple);
- self.expbars = self.methods.graphSizes(self.expsimple);
- self.totbars = self.methods.graphSizes(self.totsimple);
- console.log(buildGraphs.hardbars);
- console.log(buildGraphs.softbars);
- console.log(buildGraphs.expbars);
- console.log(buildGraphs.totbars);
- self.methods.addTotMarkup();
- self.methods.addCatMarkup();
- });
- },
- data: {
- categories: {
- cathard: ["consoleunit","motioncap","otherinter"],
- catsoft: ["games","ng_apps","media_int","marketplace"],
- catexp: ["onlineplay","service","interface"]
- },
- barsizeratio: 2.66,
- barlength: 216
- },
- methods: {
- buildScoreArr: function(arr){
- usearray = arr;
- jsonObj = buildGraphs.statsJSON;
- thiscatscore = [0,0,0,0];
- for (i=0; i<usearray.length; i++){
- for (ii=0; ii<4; ii++){
- thiscatscore[ii] += jsonObj[usearray[i]][ii];
- }
- }
- for (i=0;i<4;i++){
- thiscatscore[i] = thiscatscore[i]/usearray.length;
- result = Math.round(thiscatscore[i]);
- thiscatscore[i] = result;
- }
- return thiscatscore;
- },
- totalScore: function(){
- totalscore = [0,0,0,0];
- for (i=0;i<4;i++){
- totalscore[i] += buildGraphs.hardscores[i];
- totalscore[i] += buildGraphs.softscores[i];
- totalscore[i] += buildGraphs.expscores[i];
- totalscore[i] = Math.round(totalscore[i]/3);
- }
- return totalscore;
- },
- simpleScore: function(arr){
- usearray = arr;
- thisScoreSimple = [0,0];
- thisScoreSimple[0] = Math.round((usearray[0]+usearray[2])/2);
- thisScoreSimple[1] = 100-thisScoreSimple[0];
- console.log(thisScoreSimple);
- return thisScoreSimple;
- },
- graphSizes: function(arr){
- usearray = arr;
- thisbarsizeshort = [0,0];
- thisbarsizeshort[0] = Math.round((usearray[0]/100)*buildGraphs.data.barlength);
- thisbarsizeshort[1] = buildGraphs.data.barlength-thisbarsizeshort[0];
- return thisbarsizeshort;
- },
- addCatMarkup: function(){
- $wrapCats = $("<div></div>").attr("id","wrapCats");
- $paraHard = $("<p></p>").text("Hardware").addClass("catTitle");
- $paraSoft = $("<p></p>").text("Software").addClass("catTitle");
- $paraExp = $("<p></p>").text("Experience").addClass("catTitle");
- $barWrapperCat = $("<div></div>").addClass("barWrapperCat");
- $barPS3 = $("<div></div>").addClass("scorebar0").addClass("ps3").css("width",buildGraphs.hardbars[1]).text("PS3 (" + buildGraphs.hardsimple[1] + "%)");
- $barXBOX = $("<div></div>").addClass("scorebar1").addClass("xbox").css("width",buildGraphs.hardbars[0]).text("XBOX (" + buildGraphs.hardsimple[0] + "%)");
- $barWrapperCat.append($paraHard).append($barPS3).append($barXBOX);
- $wrapCats.append($barWrapperCat);
- $barWrapperCat = $("<div></div>").addClass("barWrapperCat");
- $barPS3 = $("<div></div>").addClass("scorebar0").addClass("ps3").css("width",buildGraphs.softbars[1]).text("PS3 (" + buildGraphs.softsimple[1] + "%)");
- $barXBOX = $("<div></div>").addClass("scorebar1").addClass("xbox").css("width",buildGraphs.softbars[0]).text("XBOX (" + buildGraphs.softsimple[0] + "%)");
- $barWrapperCat.append($paraSoft).append($barPS3).append($barXBOX);
- $wrapCats.append($barWrapperCat);
- $barWrapperCat = $("<div></div>").addClass("barWrapperCat");
- $barPS3 = $("<div></div>").addClass("scorebar0").addClass("ps3").css("width",buildGraphs.expbars[1]).text("PS3 (" + buildGraphs.expsimple[1] + "%)");
- $barXBOX = $("<div></div>").addClass("scorebar1").addClass("xbox").css("width",buildGraphs.expbars[0]).text("XBOX (" + buildGraphs.expsimple[0] + "%)");
- $barWrapperCat.append($paraExp).append($barPS3).append($barXBOX);
- $wrapCats.append($barWrapperCat);
- $("#graphWrapper").append($wrapCats);
- },
- addTotMarkup: function(){
- totWidth0 = Math.round((buildGraphs.totsimple[0]/100)*778);
- totWidth1 = 778-totWidth0;
- $paraTot = $("<p></p>").text("Overall Score").addClass("catTitle");
- $barWrapperTot = $("<div></div>").attr("id","wrapTot");
- $barPS3 = $("<div></div>").addClass("scorebar0").addClass("ps3").css("width",totWidth1).text("PS3 (" + buildGraphs.totsimple[1] + "%)");
- $barXBOX = $("<div></div>").addClass("scorebar1").addClass("xbox").css("width",totWidth0).text("XBOX (" + buildGraphs.totsimple[0] + "%)");
- $barWrapperTot.append($paraTot).append($barPS3).append($barXBOX);
- $("#graphWrapper").append($barWrapperTot);
- }
- }
- }
- $(document).ready(function(){
- buildGraphs.init();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement