forked from egi/Gudang-Data-Indonesia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.php
71 lines (61 loc) · 1.58 KB
/
graph.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
<?php
if(isset($_GET['q']))
{
$default_data = 'propinsi';
$default_output = 'graph';
$q = ucwords(str_replace("_", " ", $_GET['q']));
$gdi = new gdi();
$data = (isset($_GET['q']) && file_exists(DATA_DIR.$_GET['q'].'.txt')) ? $_GET['q'] : $default_data;
$output = (isset($_GET['o']) && class_exists($_GET['o'])) ? $_GET['o'] : $default_output;
$columns = explode(";", (isset($_GET['cols']) && file_exists(DATA_DIR.$_GET['q'].'.txt')) ? $_GET['cols'] : "");
if(sizeof($columns) == 1 and empty($columns[0]))
$columns = "";
$result = $gdi->get_data($data, $output);
$o = new $output;
if($output == 'graph')
{
$apiData = $o->out($result);
$first_key = "";
foreach($apiData as $index=>$data)
{
$counter = 0;
foreach($data as $i=>$d)
{
if($counter == sizeof($data))
$counter = 0;
if($first_key == "") $first_key = $i;
if($i == $first_key)
$ticks[] = $d;
else
{
if(is_array($columns))
{
if(in_array($counter, $columns))
{
$plot_data[$i][$data[$first_key]] = $d;
$series[$i] = "{label:'".$i."'}";
}
}
else
{
$plot_data[$i][$data[$first_key]] = $d;
$series[$i] = "{label:'".$i."'}";
}
}
$counter++;
}
}
$ticks_str = "['".(implode("','", $ticks))."']";
$data_strs = array();
$data_str = "[";
foreach($plot_data as $index=>$data)
{
$data_strs[] .= "[".implode(",", $data)."]";
}
$data_str .= implode(",", $data_strs);
$data_str .= "]";
$series_str = "[".implode(",", $series)."]";
$width = 30 * sizeof($ticks);
if ($width > 800) $width = 800;
}
}