OLD | NEW |
(Empty) | |
| 1 google.load('visualization', '1.0', {'packages':['corechart']}); |
| 2 google.setOnLoadCallback(draw_charts); |
| 3 |
| 4 function draw_charts() { |
| 5 $.getJSON("./all_monthly_stats.json", function(data) { |
| 6 monthly = data['monthly_breakdown']; |
| 7 var colors = [['#594F4F'], ['#547980', '#45ADA8', '#9DE0AD', '#E5FCC2']]; |
| 8 var ratio_data = congregate_series( |
| 9 ['Month', 'Suspicious/Total Commits'], |
| 10 [monthly['suspicious_to_total_ratio']] |
| 11 ); |
| 12 var all_commit_data = congregate_series( |
| 13 ['Month', 'Total Commits', 'TBR no LGTM', 'No Review URL', 'Blank TBRs'], |
| 14 [ |
| 15 monthly['total_commits'], |
| 16 monthly['tbr_no_lgtm'], |
| 17 monthly['no_review_url'], |
| 18 monthly['blank_tbrs'], |
| 19 ] |
| 20 ); |
| 21 var line_charts = [ |
| 22 ['Ratio of "Suspicious" Commits to Commits per Month', ratio_data, |
| 23 'ratio_chart'], |
| 24 ['Commits per Month', all_commit_data, 'commits_chart'], |
| 25 ]; |
| 26 for (var i = 0; i < line_charts.length; i++) { |
| 27 chart_data = line_charts[i]; |
| 28 draw_line_chart(chart_data[0], chart_data[1], chart_data[2], |
| 29 colors[i]); |
| 30 } |
| 31 }); |
| 32 } |
| 33 |
| 34 function congregate_series(headers, all_series) { |
| 35 var all_data = [headers]; |
| 36 for (var data_item = 0; data_item < all_series[0].length; data_item++) { |
| 37 var data_point = [all_series[0][data_item][0]]; // date |
| 38 for (var series = 0; series < all_series.length; series++) { |
| 39 data_point = data_point.concat(all_series[series][data_item][1]); |
| 40 } all_data = all_data.concat([data_point]); |
| 41 } |
| 42 return all_data; |
| 43 } |
| 44 |
| 45 function draw_line_chart(chart_title, data, element_id, color) { |
| 46 var data = google.visualization.arrayToDataTable(data, false); |
| 47 var options = { |
| 48 colors: color, |
| 49 fontName: 'Quattrocento Sans', |
| 50 hAxis: { |
| 51 title: 'Month', |
| 52 showTextEvery: 5, |
| 53 }, |
| 54 legend: { |
| 55 position: 'right', |
| 56 alignment: 'center', |
| 57 }, |
| 58 title: chart_title, |
| 59 titleTextStyle: { |
| 60 fontSize: 20, |
| 61 }, |
| 62 vAxis: { |
| 63 title: 'Commits', |
| 64 } |
| 65 }; |
| 66 var chart = new google.visualization.LineChart( |
| 67 document.getElementById(element_id)); |
| 68 |
| 69 chart.draw(data, options); |
| 70 } |
| 71 |
| 72 function resize () { |
| 73 draw_charts(); |
| 74 } |
| 75 |
| 76 window.onload = resize(); |
| 77 window.onresize = resize; |
OLD | NEW |