function loadGoogleApi(success) { if(window.google) { // Load the Visualization API library google.charts.load('current', {'packages':['corechart','geochart','table'], callback: success} ); } else { success(); } } function json2array(json){ var result = []; var keys = Object.keys(json); keys.forEach(function(key){ result.push([key,json[key]]); }); return result; } function rand(length) { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for(var i = 0; i < length; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; } function drawGooglePieChart(data, el, subst, sort, threshold) { sort = (sort == undefined ? "byKey" : sort); var id = rand(5); el.append(""); el.append("
"); var result = []; for(var i in data) { result.push([((subst && i in subst) ? subst[i] : i)+" ("+data[i]+")", parseInt(data[i])]); } if(sort === "byKey") { result.sort(); result.reverse(); } else if(sort === "byValue") { result.sort(function(a,b) {return b[1] - a[1]}); } var array = new google.visualization.DataTable(); array.addColumn("string","Topping"); array.addColumn("number","Slices"); array.addRows(result); var options = { is3D: true, chartArea : { height:'80%',width:'95%' }, tooltip: { trigger: 'selection' }, width: 600, legend: {position: 'right',labeledValueText: 'both'}, pieSliceText: 'none', height: 450, sliceVisibilityThreshold: threshold }; var container = document.getElementById(id); var chart = new google.visualization.PieChart(document.getElementById(id)); chart.draw(array,options); } // helper method in string for replacement String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp("^"+search+"$", 'g'), replacement); }; function replaceAll(str, map){ for(key in map){ str = str.replaceAll(key, map[key]); } return str; } function drawGoogleGermanyMap(data, el) { var id = rand(5); el.append(""); el.append(""); var result = []; var mapTextToCode = { "Baden-Wurttemberg": "DE-BW", "Bayern": "DE-BY", "Berlin": "DE-BE", "Brandenburg": "DE-BB", "Bremen": "DE-HB", "Hamburg": "DE-HH", "Hessen": "DE-HE", "Mecklenburg-Vorpommern": "DE-MV", "Niedersachsen":"DE-NI", "Nordrhein-Westfalen": "DE-NW", "Rheinland-Pfalz": "DE-RP", "Saarland":"DE-SL", "Sachsen":"DE-SN", "Sachsen-Anhalt":"DE-ST", "Schleswig-Holstein":"DE-SH", "Thuringen":"DE-TH" }; var mapTextToEnglish = { "Baden-Wurttemberg": "Baden-Württemberg", "Bayern": "Bavaria", "Hessen": "Hesse", "Niedersachsen":"Lower Saxony", "Nordrhein-Westfalen": "North Rhine-Westphalia", "Rheinland-Pfalz": "Rhineland-Palatinate", "Sachsen":"Saxony", "Sachsen-Anhalt":"Saxony-Anhalt", "Thuringen":"Thuringia" }; for(var i in data) { result.push([replaceAll(i, mapTextToCode), data [i], replaceAll(i, mapTextToEnglish)+": "+data[i]]); } var array = new google.visualization.DataTable(); array.addColumn("string","Country"); array.addColumn("number","Installations"); array.addColumn({type: 'string', role: 'tooltip', p:{'html': true}}); array.addRows(result); var options = { region: 'DE', colorAxis: {colors: ['#A7E7A7', '#278727']}, resolution: "provinces", backgroundColor : 'lightblue', tooltip: {isHtml: true}, width:800 }; var chart = new google.visualization.GeoChart(document.getElementById(id)); chart.draw(array,options); } function drawGoogleWorldMap(data, el) { var id = rand(5); el.append(""); el.append(""); var result = []; for(var i in data) { result.push([i, data[i].count, data[i].name+": "+data[i].count]); } var array = new google.visualization.DataTable(); array.addColumn("string","Country"); array.addColumn("number","Installations"); array.addColumn({type: 'string', role: 'tooltip', p:{'html': true}}); array.addRows(result); var options = { colorAxis: {colors: ['#A7E7A7', '#A7E7A7']}, backgroundColor : 'lightblue', tooltip: {isHtml: true}, legend: 'none', width: 800 }; var chart = new google.visualization.GeoChart(document.getElementById(id)); chart.draw(array,options); } function drawGoogleEuroMap(data, el) { var id = rand(5); el.append(""); el.append(""); var result = []; for(var i in data) { result.push([i, data[i].count, data[i].name+": "+data[i].count]); } var array = new google.visualization.DataTable(); array.addColumn("string","Country"); array.addColumn("number","Installations"); array.addColumn({type: 'string', role: 'tooltip'}); array.addRows(result); var options = { region: '150', colorAxis: {colors: ['#A7E7A7', '#A7E7A7']}, backgroundColor : 'lightblue', legend: 'none', width:800 }; var chart = new google.visualization.GeoChart(document.getElementById(id)); chart.draw(array,options); } function createModulTable(modules,models,table) { var tbody = table.children("tbody"); $.each(modules, function(module, moduleData) { if(moduleData.installations > 1) { var addon = ""; if(module in models) { addon = ""+ Object.keys(models[module]).length+""; } else { addon = "-"; } tbody.append("Model | # of installations | # of definitions |
---|---|---|
'+convertHtmlEntities(arr[0])+' | '+arr[1].installations+' | '+arr[1].definitions+" |
"+convertHtmlEntities(jqXHR.responseText)+""); } $("div#loading").hide(0); } // start the JSON request $(function() { $.ajax({ dataType: "json", url: "statistics2.cgi?type=json", success: onSuccess, error: onError, timeout: 30000 }); })