diff options
author | Romain d'Alverny <rda@mageia.org> | 2012-09-04 15:28:57 +0000 |
---|---|---|
committer | Romain d'Alverny <rda@mageia.org> | 2012-09-04 15:28:57 +0000 |
commit | 13426e1a3df985b8547455b3a0257039653603f9 (patch) | |
tree | ba478ebd4e5215600302730f6e39f4f34cf9924b | |
parent | 0f078a17c32669b79ecce52142cdb52e32d57fa1 (diff) | |
download | pkgsubmit-13426e1a3df985b8547455b3a0257039653603f9.tar pkgsubmit-13426e1a3df985b8547455b3a0257039653603f9.tar.gz pkgsubmit-13426e1a3df985b8547455b3a0257039653603f9.tar.bz2 pkgsubmit-13426e1a3df985b8547455b3a0257039653603f9.tar.xz pkgsubmit-13426e1a3df985b8547455b3a0257039653603f9.zip |
try js charts
-rw-r--r-- | lib.php | 110 | ||||
-rw-r--r-- | test_index.php | 13 |
2 files changed, 123 insertions, 0 deletions
@@ -236,3 +236,113 @@ function build_stats($pkgs) $pkgs ); } + + +class mga_bs_charts +{ + + public static function js_init() + { + return <<<S +<script type="text/javascript" src="https://www.google.com/jsapi"></script> +<script type="text/javascript"> + + // Load the Visualization API and the piechart package. + google.load('visualization', '1.0', {'packages':['corechart']}); + + // Set a callback to run when the Google Visualization API is loaded. + google.setOnLoadCallback(drawChart); +</script> +S; + } + + public static function js_draw_charts() + { + return <<<S +function drawChart() { + draw_status_chart(); + draw_buildtime_chart(); + draw_buildschedule_chart(); +} +S; + } + + public static function js_draw_status_chart($stats, $id) + { + $rows = array(); + foreach ($stats as $status => $count) { + $rows[] = sprintf("['%s', %d]", $status, $count); + } + $rows = implode(', ', $rows); + $s = <<<S +function draw_status_chart() { + var data = new google.visualization.DataTable(); + data.addColumn('string', 'Status'); + data.addColumn('number', 'Packages'); + data.addRows([{$rows}]); + + var options = {'title':'Packages status', + 'width':300, + 'height':300}; + + var chart = new google.visualization.PieChart(document.getElementById('{$id}')); + chart.draw(data, options); +} +S; + return $s; + } + + public static function js_draw_buildtime_chart($data, $id) + { + $d = print_r($data, true); + $rows = array("['Duration', 'Builds']", '[1, 3]'); + foreach ($data as $duration => $count) { + $rows[] = sprintf("['%s', %d]", $duration, $count); + } + $rows = implode(', ', $rows); + return <<<S +function draw_buildtime_chart() { + /* + {$d} + */ + var data = google.visualization.arrayToDataTable([{$rows}]); + var options = { + title: 'Builds duration', + hAxis: {title: ''}, + 'width':600, + 'height':300 + }; + var chart = new google.visualization.ColumnChart(document.getElementById('{$id}')); + chart.draw(data, options); +} +S; + } + + public static function js_draw_buildschedule_chart($data, $id) + { + $d = print_r($data, true); + $rows = array("['Hour', 'Builds']", '[1, 3]'); + foreach ($data as $hour => $count) { + $rows[] = sprintf("['%s', %d]", $hour, $count); + } + $rows = implode(', ', $rows); + return <<<S +function draw_buildschedule_chart() { + /* + {$d} + */ + var data = google.visualization.arrayToDataTable([{$rows}]); + var options = { + title: 'Builds layout', + hAxis: {title: ''}, + 'width':600, + 'height':300 + }; + var chart = new google.visualization.ColumnChart(document.getElementById('{$id}')); + chart.draw(data, options); +} +S; + } + +} + diff --git a/test_index.php b/test_index.php index 232ff64..eebb7d4 100644 --- a/test_index.php +++ b/test_index.php @@ -412,6 +412,19 @@ else ?> </ul> <div class="clear"></div> + <hr> + <div id="status-chart"></div> + <div id="buildtime-chart"></div> + <div id="buildschedule-chart"></div> + <?php + echo '<script>', + mga_bs_charts::js_draw_status_chart($stats, 'status-chart'), + mga_bs_charts::js_draw_buildtime_chart($buildtime_stats, 'buildtime-chart'), + mga_bs_charts::js_draw_buildschedule_chart($build_dates, 'buildschedule-chart'), + mga_bs_charts::js_draw_charts(), + '</script>'; + echo mga_bs_charts::js_init(); + ?> <hr /> <p>Generated at <?php echo $date_gen; ?>. Code for this page is in <a href="http://svnweb.mageia.org/soft/build_system/web/">http://svnweb.mageia.org/soft/build_system/web/</a>.</p> |