Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 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
 
15
App::uses('AppHelper', 'View/Helper');
16
App::uses('HtmlHelper', 'View/Helper');
17
 
18
/**
19
 * Class SimpleGraphHelper
20
 *
21
 * Allows creation and display of extremely simple graphing elements
22
 *
23
 * @since         DebugKit 1.0
24
 */
25
class SimpleGraphHelper extends AppHelper {
26
 
27
/**
28
 * Helpers
29
 *
30
 * @var array
31
 */
32
	public $helpers = array('Html');
33
 
34
/**
35
 * Default settings to be applied to each Simple Graph
36
 *
37
 * Allowed options:
38
 *
39
 * - max => (int) Maximum value in the graphs
40
 * - width => (int)
41
 * - valueType => string (value, percentage)
42
 * - style => array
43
 *
44
 * @var array
45
 */
46
	protected $_defaultSettings = array(
47
		'max' => 100,
48
		'width' => 350,
49
		'valueType' => 'value',
50
	);
51
 
52
/**
53
 * bar method
54
 *
55
 * @param $value Value to be graphed
56
 * @param $offset how much indentation
57
 * @param array|\Graph $options Graph options
58
 * @return string Html graph
59
 */
60
	public function bar($value, $offset, $options = array()) {
61
		$settings = array_merge($this->_defaultSettings, $options);
62
		extract($settings);
63
 
64
		$graphValue = ($value / $max) * $width;
65
		$graphValue = max(round($graphValue), 1);
66
 
67
		if ($valueType === 'percentage') {
68
			$graphOffset = 0;
69
		} else {
70
			$graphOffset = ($offset / $max) * $width;
71
			$graphOffset = round($graphOffset);
72
		}
73
		return $this->Html->div(
74
			'debug-kit-graph-bar',
75
				$this->Html->div(
76
					'debug-kit-graph-bar-value',
77
					' ',
78
					array(
79
						'style' => "margin-left: {$graphOffset}px; width: {$graphValue}px",
80
						'title' => __d('debug_kit', "Starting %sms into the request, taking %sms", $offset, $value),
81
					)
82
				),
83
			array('style' => "width: {$width}px;"),
84
			false
85
		);
86
	}
87
 
88
}