Add bubbletree
[contractdashboard.git] / displayBubbletree.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
 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
        <meta charset="UTF-8"/> 
        <title>Minimal BubbleTree Demo</title> 
        <script type="text/javascript" src="lib/bubbletree/lib/jquery-1.5.2.min.js"></script> 
        <script type="text/javascript" src="lib/bubbletree/lib/jquery.history.js"></script> 
        <script type="text/javascript" src="lib/bubbletree/lib/raphael.js"></script> 
        <script type="text/javascript" src="lib/bubbletree/lib/vis4.js"></script> 
        <script type="text/javascript" src="lib/bubbletree/lib/Tween.js"></script> 
        <script type="text/javascript" src="lib/bubbletree/build/bubbletree.js"></script> 
        <link rel="stylesheet" type="text/css" href="lib/bubbletree/build/bubbletree.css" /> 
        <script type="text/javascript" src="lib/bubbletree/styles/cofog.js"></script> 
        
        
        <script type="text/javascript"> 
       
                $(function() {
                <?php
include_once ("lib/common.inc.php");
$unspscresult = mysql_query("select * from UNSPSCcategories;");
while ($row = mysql_fetch_assoc($unspscresult)) {
        $unspsc[$row['UNSPSC']] = $row['Title'];
}
$total = 0;
$catsresult = mysql_query("SELECT LEFT( categoryUNSPSC, 1 ) as cat ,
SUM( value ) as value
FROM `contractnotice`
WHERE childCN = 0
GROUP BY cat ;");
$nodes = Array();
while ($row = mysql_fetch_assoc($catsresult)) {
        $catName = $unspsc[$row['cat'] . "0000000"] . $row['cat'];
        if ($row['cat'] == "") $catName = "null";
        $subnodes = Array();
        $cattwosresult = mysql_query("SELECT LEFT( categoryUNSPSC, 2 ) as cat ,
SUM( value ) as value
FROM `contractnotice`
WHERE childCN = 0 and LEFT( categoryUNSPSC, 1 ) = '{$row['cat']}'
GROUP BY cat ;");
        while ($tworow = mysql_fetch_assoc($cattwosresult)) {
                $subcatName = $unspsc[$tworow['cat'] . "000000"] . $tworow['cat'];
                if ($tworow['cat'] == "") $subcatName = "null";
                $subsubnodes = Array();
                $catthreesresult = mysql_query("SELECT LEFT( categoryUNSPSC, 3 ) as cat ,
SUM( value ) as value
FROM `contractnotice`
WHERE childCN = 0 and LEFT( categoryUNSPSC, 2 ) = '{$tworow['cat']}'
GROUP BY cat ;");
                while ($threerow = mysql_fetch_assoc($catthreesresult)) {
                        $subsubcatName = $unspsc[$threerow['cat'] . "00000"] . $threerow['cat'];
                        if ($threerow['cat'] == "") $subsubcatName = "null";
                        $subsubnodes[] = Array(
                                "label" => $subsubcatName,
                                "amount" => $threerow['value'],
                                "color" => "#000000"
                        );
                }
                $subnodes[] = Array(
                        "label" => $subcatName,
                        "amount" => $tworow['value'],
                        "color" => "#000000",
                        "children" => $subsubnodes
                );
        }
        $nodes[] = Array(
                "label" => $catName,
                "amount" => $row['value'],
                "color" => "#000000",
                "children" => $subnodes
        );
        $total+= $row['value'];
}
$data = Array(
        "label" => "Australian Federal Government Contract Spending",
        "amount" => $total,
        "color" => "#000000",
        "children" => $nodes
);
echo "var data =eval('('+'" . json_encode($data) . "'+')');";
?>
 
                        new BubbleTree({
                                data: data,
                                container: '.bubbletree'
                        });
                
                        
                });
     
        </script> 
</head> 
<body> 
        <div class="bubbletree-wrapper"> 
                <div class="bubbletree"></div> 
        </div> 
</body> 
</html>