visualize.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. (function($) {
  2. // TODO this is entire thing sucks
  3. $(function() {
  4. var searchMap = (function() {
  5. var searchSplit, searchMap = {};
  6. if ( !location.search ){
  7. return searchMap;
  8. }
  9. searchSplit = location.search.replace(/^\?/, "").split( /&|;/ );
  10. for( var i = 0; i < searchSplit.length; i++ ) {
  11. var kv = searchSplit[i].split(/=/);
  12. searchMap[ kv[0] ] = kv[1];
  13. }
  14. return searchMap;
  15. })();
  16. $.get("../", searchMap, function(data) {
  17. $.each(data, function( i, avg ) {
  18. var tablename = avg.point + " " + avg.agent + " " + avg.agent_version + " " + avg.pathname,
  19. $table = $( "table > caption:contains(" + tablename + ")").parent();
  20. if( !$table.length ) {
  21. $table = $( "<table></table>", {
  22. "data-pathname": avg.pathname,
  23. "data-point": avg.point,
  24. "data-agent": avg.agent,
  25. "data-agent-version": avg.agent_version
  26. });
  27. $table.append( "<caption>" + tablename + "</caption>");
  28. $table.append( "<thead><tr></tr></thead>" );
  29. $table.append( "<tbody><tr></tr></tbody>" );
  30. }
  31. // TODO assume time ordering in the data set
  32. var $heading = $table.find("thead > tr > th:contains(" + avg.day + ")");
  33. if( !$heading.length ) {
  34. $heading = $("<th></th>", {
  35. text: avg.day,
  36. scope: "column"
  37. });
  38. $table.find("thead > tr").append($heading);
  39. }
  40. var $rowHeading = $table.find("tbody > tr > th:contains(" + avg.point + ")" ),
  41. $row = $table.find( "tbody > tr" );
  42. if( !$rowHeading.length ) {
  43. $rowHeading = $("<th></th>", {
  44. text: avg.point,
  45. scope: "row"
  46. });
  47. $row.append( $rowHeading );
  48. }
  49. $row.append( "<td>" + avg.avg_value + "</td>" );
  50. $("#tables").append($table);
  51. });
  52. $("#tables table").visualize({ type: "bar", width: 400, height: 400 }).appendTo("#graphs");
  53. });
  54. });
  55. })(jQuery);