-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgr_byplace.php
84 lines (68 loc) · 2.16 KB
/
gr_byplace.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
<?php
defined('IN_SCRIPT') || define('IN_SCRIPT', 1);
include_once('global.php');
if ($TryToChangeMemoryAndTimeLimits) @ini_set('memory_limit', -1);
include_once($jpgraphlocation.'jpgraph.php');
include_once($jpgraphlocation.'jpgraph_bar.php');
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 suppliername,COUNT(*) AS count FROM $DVD_TABLE LEFT JOIN $DVD_SUPPLIER_TABLE ON purchaseplace=sid "
."WHERE collectiontype='owned' AND suppliername!='Unknown' $placespecialcondition GROUP BY suppliername";
$result = $db->sql_query($sql) or die($db->sql_error());
$places = array();
$maxcount = 0;
while ($row = $db->sql_fetch_array($result)) {
$place = $row['suppliername'];
$places[$place] = $row['count'];
if ($row['count'] > $maxcount)
$maxcount = $row['count'];
}
$threshold = $maxcount*$placesmin;
// Remove suppliers with < $threshold and add into others
$others = 0;
$name = '';
foreach ($places as $key => $val) {
if ($places[$key] < $threshold) {
$others += $places[$key];
if ($name != '') $name .= "\n";
$name .= "$key ($places[$key])";
}
}
$places[' '.$lang['OTHER']] = $others;
uksort($places, 'cmp');
$data = array();
$leg = array();
foreach ($places as $key => $val) {
if ($places[$key] >= $threshold) {
$data[] = $places[$key];
$leg[] = "$key ";
}
}
$graph = new Graph($graphx, $graphy, 'auto');
$graph->SetScale('textint');
$graph->img->SetMargin(50, 30, 50, 120);
$graph->title->Set(html_entity_decode($lang['GRAPHS']['PP']));
$graph->xaxis->SetTickLabels($leg);
$graph->xaxis->SetFont(FF_ARIAL);
$graph->xaxis->SetLabelAngle(45);
$graph->xaxis->HideTicks();
$graph->yaxis->scale->SetGrace($jpgrace);
$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->SetValuePos('center');
$bplot->SetShadow();
$graph->Add($bplot);
$graph->Stroke();