Base for a static organization website

SimpleGraphHelper.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @since DebugKit 1.0
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. App::uses('AppHelper', 'View/Helper');
  15. App::uses('HtmlHelper', 'View/Helper');
  16. /**
  17. * Class SimpleGraphHelper
  18. *
  19. * Allows creation and display of extremely simple graphing elements
  20. *
  21. * @since DebugKit 1.0
  22. */
  23. class SimpleGraphHelper extends AppHelper {
  24. /**
  25. * Helpers
  26. *
  27. * @var array
  28. */
  29. public $helpers = array('Html');
  30. /**
  31. * Default settings to be applied to each Simple Graph
  32. *
  33. * Allowed options:
  34. *
  35. * - max => (int) Maximum value in the graphs
  36. * - width => (int)
  37. * - valueType => string (value, percentage)
  38. * - style => array
  39. *
  40. * @var array
  41. */
  42. protected $_defaultSettings = array(
  43. 'max' => 100,
  44. 'width' => 350,
  45. 'valueType' => 'value',
  46. );
  47. /**
  48. * bar method
  49. *
  50. * @param $value Value to be graphed
  51. * @param $offset how much indentation
  52. * @param array|\Graph $options Graph options
  53. * @return string Html graph
  54. */
  55. public function bar($value, $offset, $options = array()) {
  56. $settings = array_merge($this->_defaultSettings, $options);
  57. extract($settings);
  58. $graphValue = ($value / $max) * $width;
  59. $graphValue = max(round($graphValue), 1);
  60. if ($valueType === 'percentage') {
  61. $graphOffset = 0;
  62. } else {
  63. $graphOffset = ($offset / $max) * $width;
  64. $graphOffset = round($graphOffset);
  65. }
  66. return $this->Html->div(
  67. 'debug-kit-graph-bar',
  68. $this->Html->div(
  69. 'debug-kit-graph-bar-value',
  70. ' ',
  71. array(
  72. 'style' => "margin-left: {$graphOffset}px; width: {$graphValue}px",
  73. 'title' => __d('debug_kit', "Starting %sms into the request, taking %sms", $offset, $value),
  74. )
  75. ),
  76. array('style' => "width: {$width}px;"),
  77. false
  78. );
  79. }
  80. }