forked from julmud/phpDVDProfiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gr_byorigin.php
114 lines (100 loc) · 3.2 KB
/
gr_byorigin.php
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
<?php
define('IN_SCRIPT', 1);
$originsmin = 0;
$hideunknown = true;
include_once('global.php');
if ($TryToChangeMemoryAndTimeLimits) @ini_set('memory_limit', -1);
include($jpgraphlocation.'jpgraph.php');
include($jpgraphlocation.'jpgraph_bar.php');
include($jpgraphlocation.'jpgraph_log.php');
function FormatLog($val) {
return($val);
}
function cmp($a, $b) {
if (strtolower($a) == strtolower($b))
return(0);
return((strtolower($a) < strtolower($b))? -1 : 1);
}
if (!isset($graphx) || !$graphx)
$graphx = 800 - 40;
if (!isset($graphy) || !$graphy)
$graphy = 'auto';
if ($graphy == 'auto')
$graphy = ($graphx*3)/4;
$sql = "SELECT countryoforigin,countryoforigin2,countryoforigin3, sum(1) count FROM $DVD_TABLE WHERE collectiontype='owned' $originspecialcondition GROUP by countryoforigin,countryoforigin2,countryoforigin3";
$result = $db->sql_query($sql) or die($db->sql_error());
$origins = array();
$unknownkey = " $lang[UNKNOWN]";
$maxcount = 0;
while ($row = $db->sql_fetch_array($result)) {
$origin = '';
if ($row['countryoforigin'] != '') {
CountryToLang($row['countryoforigin'], $origin, $countryloc);
if (!isset($origins[$origin]))
$origins[$origin] = 0;
$origins[$origin] += $row['count'];
if ($origins[$origin] > $maxcount)
$maxcount = $origins[$origin];
}
if ($row['countryoforigin2'] != '') {
CountryToLang($row['countryoforigin2'], $origin, $countryloc);
if (!isset($origins[$origin]))
$origins[$origin] = 0;
$origins[$origin] += $row['count'];
if ($origins[$origin] > $maxcount)
$maxcount = $origins[$origin];
}
if ($row['countryoforigin3'] != '') {
CountryToLang($row['countryoforigin3'], $origin, $countryloc);
if (!isset($origins[$origin]))
$origins[$origin] = 0;
$origins[$origin] += $row['count'];
if ($origins[$origin] > $maxcount)
$maxcount = $origins[$origin];
}
if ($origin == '') {
$origin = $unknownkey;
$origins[$origin] = $row['count'];
if ($origins[$origin] > $maxcount)
$maxcount = $origins[$origin];
}
}
$db->sql_freeresult($result);
$threshold = $maxcount*$originsmin;
uksort($origins, 'cmp');
$data = array();
$leg = array();
foreach ($origins as $key => $val) {
if (!(($key == $unknownkey) && $hideunknown)) {
if ($origins[$key] >= $threshold) {
$data[] = $origins[$key];
$leg[] = "$key ";
}
}
}
$graph = new Graph($graphx, $graphy, 'auto');
$graph->SetScale('textlog');
$graph->img->SetMargin(50, 30, 50, 120);
$unkncnt = array_key_exists($unknownkey, $origins)? $origins[$unknownkey]: 0;
if ($hideunknown && $unkncnt != 0)
$graph->title->Set(html_entity_decode($lang['GRAPHS']['COO']."\n($lang[UNKNOWN] = $unkncnt)"));
else
$graph->title->Set(html_entity_decode($lang['GRAPHS']['COO']));
$graph->xaxis->SetTickLabels($leg);
$graph->xaxis->SetFont(FF_ARIAL);
$graph->xaxis->SetLabelAngle(45);
$graph->xaxis->HideTicks();
$graph->yaxis->scale->SetGrace($jpgrace);
$graph->yaxis->SetLabelFormatCallback('FormatLog');
$bplot = new BarPlot($data);
$bplot->SetFillColor('lightgreen'); // Fill color
$bplot->value->Show();
$bplot->value->SetFormat('%d');
$bplot->value->SetFont(FF_ARIAL, FS_BOLD);
$bplot->value->SetColor('black', 'navy');
$bplot->SetYBase(0.1);
$bplot->SetValuePos('center');
$bplot->SetShadow();
$graph->Add($bplot);
$graph->Stroke();
?>