(function ($) { function inArray(needle, haystack) { var length = haystack.length; for (var i = 0; i < length; i++) { if (haystack[i] == needle) return true; } return false; } $.test = function (target, json, options) { datasets = new Array(); test= new Array(); testnames = new Array(); systems =['Smarty','Twig']; colors = ['red', 'blue']; if (json == null) { return true; } testresult = jQuery.parseJSON(json); if (options == 'db') { //test = $.test.databases(testresult); } if (options == 'test') { // test = $.test.systems(testresult); } test=testresult; for (tests = 0; tests < test.length; tests++) { datasets.push(test[tests]); } setup = { // The "seriesDefaults" option is an options object that will // be applied to all series in the chart. seriesColors: colors, seriesDefaults: { renderer: $.jqplot.BarRenderer, rendererOptions: {fillToZero: true} }, series: testnames, // Show the legend and put it outside the grid, but inside the // plot container, shrinking the grid to accomodate the legend. // A value of "outside" would not shrink the grid and allow // the legend to overflow the container. legend: { show:true, placement: 'insideGrid' }, axes: { // Use a category axis on the x axis and use our custom ticks. xaxis: { renderer: $.jqplot.CategoryAxisRenderer, ticks: systems, }, // Pad the y axis just a little so bars can get close to, but // not touch, the grid boundaries. 1.2 is the default padding. yaxis: { pad: 1.05, min: 0 } } }; if (datasets.length > 0) { $.jqplot(target, datasets, setup); } }; $.test.databases = function (testresult) { test = new Array(); systems = new Array(); testnames = new Array(); colors = ['red', 'blue', 'green', 'orange']; for (var schlussel in testresult) { systems.push(schlussel); //alert(testresult[schlussel]); var testarray = testresult[schlussel]; anzahl = testarray.length; for (i = 0; i < anzahl; i++) { var element = testarray[i]; for (var testname in element) { if (test[i] == null) { test[i] = new Array(); } test[i].push(element[testname] * 1000); var label = {label: testname} testnames.push(label); } } } return test; } $.test.systems = function (testresult) { test = new Array(); colors = new Array(); systems = new Array(); testnames = new Array(); var cicolors = {'SolrDatabase': 'orange', 'MySQL': 'red', 'MongoDatabase': 'green', 'Postgres': 'blue', 'PDOMySQL': 'magenta', 'PDOPostgres': 'navy'}; index = 0; for (var schlussel in testresult) { var label = {label: schlussel} testnames.push(label); colors.push(cicolors[schlussel]) //alert(cicolors[schlussel]+'vs'+schlussel); var testarray = testresult[schlussel]; anzahl = testarray.length; for (i = 0; i < anzahl; i++) { var element = testarray[i]; for (var testname in element) { if (test[index] == null) { test[index] = new Array(); } test[index].push(element[testname] * 1000); if (inArray(testname, systems) == false) { systems.push(testname); } } } index++; } return test; } })(jQuery);