Remove bubbletree colors
Remove bubbletree colors


Former-commit-id: 91129056b556973816d6200d698809bba6c57d9c

   
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<title>Minimal BubbleTree Demo</title> <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="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/jquery.history.js"></script>
<script type="text/javascript" src="javascripts/bubbletree/lib/raphael.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/vis4.js"></script>
<script type="text/javascript" src="javascripts/bubbletree/lib/Tween.js"></script> <script type="text/javascript" src="javascripts/bubbletree/lib/Tween.js"></script>
<script type="text/javascript" src="javascripts/bubbletree/build/bubbletree.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" /> <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" src="javascripts/bubbletree/styles/cofog.js"></script>
   
   
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
<?php <?php
include_once('include/common.inc.php'); include_once('include/common.inc.php');
   
include("lib/Color.php"); include("lib/Color.php");
$color = new Lux_Color(); $color = new Lux_Color();
   
$portfolios = Array(); $portfolios = Array();
$total = 0; $total = 0;
$db = $server->get_db('disclosr-agencies'); $db = $server->get_db('disclosr-agencies');
try { try {
$rows = $db->get_view("app", "byDeptStateName", null, true)->rows; $rows = $db->get_view("app", "byDeptStateName", null, true)->rows;
foreach ($rows as $row) { foreach ($rows as $row) {
$portfolios[trim(str_replace(Array("Department of","Department","the","'","`"),"",$row->key))] = $row->value; $portfolios[trim(str_replace(Array("Department of", "Department", "the", "'", "`"), "", $row->key))] = $row->value;
} }
} catch (SetteeRestClientException $e) { } catch (SetteeRestClientException $e) {
setteErrorHandler($e); setteErrorHandler($e);
} }
   
$agencies = Array(); $agencies = Array();
try { try {
$rows = $db->get_view("app", "byCanonicalName", null, true)->rows; $rows = $db->get_view("app", "byCanonicalName", null, true)->rows;
//print_r($rows); //print_r($rows);
foreach ($rows as $row) { foreach ($rows as $row) {
$employees = 0; $employees = 0;
$portfolioid = 0; $portfolioid = 0;
if (isset($row->value->employees)) $employees = $row->value->employees; if (isset($row->value->employees)) {
if (isset($row->value->statistics->employees)) { $employees = $row->value->employees;
$agencyEmployeesArray = object_to_array($row->value->statistics->employees); }
if (isset($agencyEmployeesArray["2010-2011"]["value"])) { if (isset($row->value->statistics->employees)) {
$employees = $agencyEmployeesArray["2010-2011"]["value"]; $agencyEmployeesArray = object_to_array($row->value->statistics->employees);
} else { if (isset($agencyEmployeesArray["2010-2011"]["value"])) {
// get last year that is recorded? throw error? $employees = $agencyEmployeesArray["2010-2011"]["value"];
continue; } else {
} // bailout for agencies that are closed for business
} continue;
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; if (!($employees > 0)) {
$agencies[$portfolioid][$row->value->name] = $employees; $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) { } catch (SetteeRestClientException $e) {
setteErrorHandler($e); setteErrorHandler($e);
} }
//print_r($portfolios); //print_r($portfolios);
//print_r($agencies); //print_r($agencies);
$i = 0;  
  // http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
  $golden_ratio_conjugate = 0.618033988749895;
  $h = 0.00+rand(0,10)/10; # use random start value
foreach ($portfolios as $portfolioName => $portfolioID) { foreach ($portfolios as $portfolioName => $portfolioID) {
$i++; $h += $golden_ratio_conjugate;
$portfolioColor = $color->hsv2hex(Array($i/10, .7, abs(($i*(1/10))-.5) + .5));  
$subnodes = Array(); $h = fmod($h,1);
$portfolioEmployees = 0; $portfolioColor = $color->hsv2hex(Array($h, .3, .99));
foreach ($agencies[$portfolioID] as $agencyName => $agencyEmployees) { $subnodes = Array();
$agencyColor = $color->hsv2hex(Array($i/10, rand(1,10)/10, abs(($i*(1/10))-.5) + .5)); $portfolioEmployees = 0;
$subnodes[] = Array( foreach ($agencies[$portfolioID] as $agencyName => $agencyEmployees) {
"label" => str_replace(Array("'","`"),"",$agencyName), $agencyColor = $color->hsv2hex(Array($h / 10, rand(1, 10) / 10, abs(($h * (1 / 10)) - .5) + .5));
"amount" => $agencyEmployees, $subnodes[] = Array(
"color" => "#".$agencyColor "label" => str_replace(Array("'", "`"), "", $agencyName),
); "amount" => $agencyEmployees,
$portfolioEmployees += $agencyEmployees; //"color" => "#" . $agencyColor
} );
$nodes[] = Array( $portfolioEmployees += $agencyEmployees;
"label" => $portfolioName, }
"amount" => $portfolioEmployees, $nodes[] = Array(
"color" => "#".$portfolioColor, "label" => $portfolioName,
"children" => $subnodes "amount" => $portfolioEmployees,
); //"color" => "#" . $portfolioColor,
$total += $portfolioEmployees; "children" => $subnodes
  );
  $total += $portfolioEmployees;
} }
$data = Array( $data = Array(
"label" => "Australian Federal Government", "label" => "Australian Federal Government",
"amount" => $total, "amount" => $total,
"color" => "#000000", //"color" => "#000000",
"children" => $nodes "children" => $nodes
); );
echo "var data =eval('('+'" . json_encode($data) . "'+')');"; echo "var data =eval('('+'" . json_encode($data) . "'+')');";
?> ?>
   
new BubbleTree({ new BubbleTree({
data: data, data: data,
container: '.bubbletree' container: '.bubbletree'
}); });
}); });
</script> </script>
</head> </head>
<body> <body>
<div class="bubbletree-wrapper"> <div class="bubbletree-wrapper">
<div class="bubbletree"></div> <div class="bubbletree"></div>
</div> </div>
</body> </body>
</html> </html>