Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Sparkline.php « ViewDataTable « modules - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd051f4732eb44eba004b92636fe32c67f619a80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
class Piwik_ViewDataTable_Sparkline extends Piwik_ViewDataTable
{
	
	function init($currentControllerName,
						$currentControllerAction, 
						$moduleNameAndMethod )
	{
		parent::init($currentControllerName, 
						$currentControllerAction, 
						$moduleNameAndMethod );
	}
	public function main()
	{
		if($this->mainAlreadyExecuted)
		{
			return;
		}
		$this->mainAlreadyExecuted = true;
	
		// we load the data with the filters applied
		$this->loadDataTableFromAPI();
		
		$this->dataAvailable = $this->dataTable->getRowsCount() != 0;
		
		if(!$this->dataAvailable)
		{
			$this->view->title("No data for this graph", '{font-size: 25px;}');
		}
		else
		{
			$data = $this->generateDataFromDataTableArray($this->dataTable);
			
			$graph = new Piwik_Sparkline_Graph;
			$graph->setData($data);
			$graph->main();
//			var_dump($data);
			$this->view = $graph;
		}
	}
	
}

require_once 'sparkline/lib/Sparkline_Line.php';

class Piwik_Sparkline_Graph
{
	function setData($data)
	{
		$this->data = $data;
	}
	
	function main()
	{
		$data = $this->data;
		$sparkline = new Sparkline_Line();
		
//		$sparkline->SetColorHtml('lineColor', '000000');
		$sparkline->SetColor('lineColor', 22,44,74); // dark blue
//		$sparkline->SetColor('lineColor', 0,119,204);
		$sparkline->SetColorHtml('red', '#FF7F7F');
		$sparkline->SetColorHtml('blue', '#55AAFF');
		$sparkline->SetColorHtml('green', '#75BF7C');
//		$sparkline->SetDebugLevel(DEBUG_NONE);
//		$sparkline->SetDebugLevel(DEBUG_ERROR | DEBUG_WARNING | DEBUG_STATS | DEBUG_CALLS | DEBUG_DRAW, 'log.txt');
		
		$data = array_reverse($data);
		$min = $max= $last = null;
		$i = 0;
		foreach($this->data as $row)
		{
		
			$value = $row['value'];
			$sparkline->SetData($i, $value);
			if(	null == $min || $value <= $min[1]) 
			{
				$min = array($i, $value);
			}
		
			if(null == $max || $value >= $max[1]) 
			{
				$max = array($i, $value);
			}
		
			$last = array($i, $value);
			
			$i++;			
		}
//		echo imagefontwidth(FONT_2);exit;
		// set y-bound, min and max extent lines
		//
		$sparkline->SetYMin(0);
		$sparkline->SetPadding(2); // setpadding is additive
		$sparkline->SetPadding(13,//font height 
					3,//4 * (strlen("$last[1]")), 
					0, //imagefontheight(FONT_2), 
					0);
		$font = FONT_2;
		$sparkline->SetFeaturePoint($min[0]-1,$min[1]+2,'red', 5, $min[1], TEXT_TOP,$font);
		$sparkline->SetFeaturePoint($max[0]-1,$max[1],  'green', 5, $max[1], TEXT_TOP,$font);
		$sparkline->SetFeaturePoint($last[0]-1, $last[1], 'blue',5);//, " $last[1]", TEXT_RIGHT,$font);
		
		$sparkline->SetLineSize(3); // for renderresampled, linesize is on virtual image
		$sparkline->RenderResampled(100, 30, 'lineColor');
		
		$this->sparkline = $sparkline;
	}
	
	function render()
	{
		$this->sparkline->Output();
	}
}

?>