Add bubbletree
[disclosr.git] / bubbletree.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
 
<!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="http://code.jquery.com/jquery-1.7.2.js"></script> 
        <script type="text/javascript" src="javascripts/bubbletree/lib/jquery.history.js"></script> 
        <script type="text/javascript" src="javascripts/bubbletree/lib/raphael.js"></script> 
        <script type="text/javascript" src="javascripts/bubbletree/lib/vis4.js"></script> 
        <script type="text/javascript" src="javascripts/bubbletree/lib/Tween.js"></script> 
        <script type="text/javascript" src="javascripts/bubbletree/build/bubbletree.js"></script> 
        <link rel="stylesheet" type="text/css" href="javascripts/bubbletree/build/bubbletree.css" /> 
        <script type="text/javascript" src="javascripts/bubbletree/styles/cofog.js"></script> 
        
        
        <script type="text/javascript"> 
       
                $(function() {
                <?php
include_once('include/common.inc.php');
 
include("lib/Color.php");
$color = new Lux_Color();
 
$portfolios = Array();
 
$db = $server->get_db('disclosr-agencies');
try {
    $rows = $db->get_view("app", "byDeptStateName", null, true)->rows;
    foreach ($rows as $row) {
        $portfolios[trim(str_replace(Array("Department of","Department","the","'","`"),"",$row->key))] = $row->value;
    }
} catch (SetteeRestClientException $e) {
    setteErrorHandler($e);
}
 
$agencies = Array();
try {
    $rows = $db->get_view("app", "byCanonicalName", null, true)->rows;
//print_r($rows);
    foreach ($rows as $row) {
        $employees = 0;
        $portfolioid = 0;
        if ($row->value->employees) $employees = $row->value->employees;
        if (isset($row->value->statistics->employees)) {
$agencyEmployeesArray = object_to_array($row->value->statistics->employees);
 $employees = $agencyEmployeesArray["2010-2011"]["value"];
}
if (!($employees > 0)) $employees =0;
        if (isset($row->value->parentOrg)) $portfolioid = $row->value->parentOrg;
        if (isset($row->value->orgType) && $row->value->orgType == "FMA-DepartmentOfState") $portfolioid = $row->id;
        $agencies[$portfolioid][$row->value->name] = $employees;
    }
} catch (SetteeRestClientException $e) {
    setteErrorHandler($e);
}
//print_r($portfolios);
//print_r($agencies);
$i = 0;
foreach ($portfolios as $portfolioName => $portfolioID) {
$i++;
$portfolioColor = $color->hsv2hex(Array($i/10, .7, abs(($i*(1/10))-.5) + .5));
        $subnodes = Array();
        $portfolioEmployees = 0;
        foreach ($agencies[$portfolioID] as $agencyName => $agencyEmployees) {
                $agencyColor = $color->hsv2hex(Array($i/10, rand(1,10)/10, abs(($i*(1/10))-.5) + .5));
                $subnodes[] = Array(
                        "label" => str_replace(Array("'","`"),"",$agencyName),
                        "amount" => $agencyEmployees,
                        "color" => "#".$agencyColor
                );
                $portfolioEmployees += $agencyEmployees;
        }
        $nodes[] = Array(
                "label" => $portfolioName,
                "amount" => $portfolioEmployees,
                "color" => "#".$portfolioColor,
                "children" => $subnodes
        );
        $total += $portfolioEmployees;
}
$data = Array(
        "label" => "Australian Federal Government",
        "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>