prod-monitor-performance.tpl.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @file
  4. * Template that renders a google graph. Feel free to override it if you prefer
  5. * another graphing mechanism by placing it in your themes folder.
  6. *
  7. * Available variables:
  8. * $data contains raw data fetched from the prod_monitor_performance table.
  9. * $graphs contains preprocessed data to allow (more) easy output.
  10. *
  11. * TODO: add preloader element to the Graphs div so the users see something is
  12. * loading.
  13. */
  14. // Output all graphs.
  15. $scripts = '';
  16. foreach ($graphs as $module => $data) {
  17. ?>
  18. <h2><?php print $data['title'] ?></h2>
  19. <?php
  20. unset($data['title']);
  21. if (isset($data['message'])) {
  22. print $data['message'];
  23. }
  24. else {
  25. foreach ($data as $unit => $numbers) {
  26. $unit = strtolower($unit);
  27. ?>
  28. <div id="<?php print $module . (!empty($unit) ? '-' . $unit : ''); ?>" style="width: 960px; height: 300px; text-align: center;" class="performance-data"><img style="padding-top: 140px;" src="<?php print base_path() . drupal_get_path('module', 'prod_monitor'); ?>/images/spinner.gif" width="20" height="20" /></div>
  29. <?php
  30. $scripts .= ' Drupal.behaviors.prod_monitor_performance.' . $module . (!empty($unit) ? '_' . $unit : '') . " = function() {\n";
  31. $scripts .= ' var data = new google.visualization.DataTable();'."\n";
  32. $scripts .= " data.addColumn('datetime', 'Date');\n";
  33. // Add columns.
  34. foreach ($numbers['cols'] as $col) {
  35. $scripts .= " data.addColumn('number', '$col');\n";
  36. }
  37. // Add column data.
  38. $scripts .= ' data.addRows(['."\n";
  39. foreach ($numbers['rows'] as $time => $row) {
  40. $scripts .= ' [new Date(' . date('Y, n, j, G, i, s', $time) . '), ' . implode(', ', $row ) . "],\n";
  41. }
  42. $scripts .= " ]);\n\n";
  43. $scripts .= " var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('". $module . (!empty($unit) ? '-' . $unit : '') . "'));\n";
  44. $scripts .= ' chart.draw(data, {displayAnnotations: false});'."\n";
  45. $scripts .= " }\n\n";
  46. ?>
  47. <p>&nbsp;</p>
  48. <?php
  49. }
  50. }
  51. }
  52. // Actually add the JS files to the page. Order is important!
  53. drupal_add_js(drupal_get_path('module', 'prod_monitor') . '/js/prod-monitor.performance.js', array('type' => 'file', 'weight' => 1));
  54. drupal_add_js($scripts, array('type' => 'inline', 'weight' => 2));
  55. ?>