|
|
<!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="lib/bubbletree/lib/jquery-1.5.2.min.js"></script> |
<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/jquery.history.js"></script> |
<script type="text/javascript" src="lib/bubbletree/lib/raphael.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/vis4.js"></script> |
<script type="text/javascript" src="lib/bubbletree/lib/Tween.js"></script> |
<script type="text/javascript" src="lib/bubbletree/lib/Tween.js"></script> |
<script type="text/javascript" src="lib/bubbletree/build/bubbletree.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" /> |
<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" src="lib/bubbletree/styles/cofog.js"></script> |
|
|
|
|
<script type="text/javascript"> |
<script type="text/javascript"> |
|
|
$(function() { |
$(function() { |
<?php |
<?php |
include_once ("lib/common.inc.php"); |
include_once ("lib/common.inc.php"); |
|
|
include("lib/Color.php"); |
include("lib/Color.php"); |
$color = new Lux_Color(); |
$color = new Lux_Color(); |
|
|
|
|
$unspscresult= $conn->prepare('select * from "UNSPSCcategories";'); |
$unspscresult= $conn->prepare('select * from "UNSPSCcategories";'); |
$unspscresult->execute(); |
$unspscresult->execute(); |
foreach ($unspscresult->fetchAll() as $row) { |
foreach ($unspscresult->fetchAll() as $row) { |
$unspsc[$row['UNSPSC']] = $row['Title']; |
$unspsc[$row['UNSPSC']] = $row['Title']; |
|
|
} |
} |
$total = 0; |
$total = 0; |
|
|
$catsresult = $conn->prepare('SELECT distinct substr( "categoryUNSPSC"::text, 0, 2 ) as cat |
$catsresult = $conn->prepare('SELECT distinct substr( "categoryUNSPSC"::text, 0, 2 ) as cat |
FROM contractnotice WHERE "categoryUNSPSC" IS NOT NULL group by "categoryUNSPSC";;'); |
FROM contractnotice WHERE "categoryUNSPSC" IS NOT NULL group by "categoryUNSPSC";;'); |
$catsresult->execute(); |
$catsresult->execute(); |
foreach ($catsresult->fetchAll() as $row) { |
foreach ($catsresult->fetchAll() as $row) { |
$cats[] = $row['cat']; |
$cats[] = $row['cat']; |
} |
} |
$cattwosresult = $conn->prepare('SELECT distinct substr( "categoryUNSPSC"::text, 0, 3 ) as cat |
$cattwosresult = $conn->prepare('SELECT distinct substr( "categoryUNSPSC"::text, 0, 3 ) as cat |
FROM contractnotice |
FROM contractnotice |
WHERE "categoryUNSPSC" IS NOT NULL |
WHERE "categoryUNSPSC" IS NOT NULL |
GROUP BY "categoryUNSPSC" order by cat ;'); |
GROUP BY "categoryUNSPSC" order by cat ;'); |
$cattwosresult->execute(); |
$cattwosresult->execute(); |
foreach ($cattwosresult->fetchAll() as $tworow) { |
foreach ($cattwosresult->fetchAll() as $tworow) { |
$cattwos[substr($tworow['cat'],0,1)][] = $tworow['cat']; |
$cattwos[substr($tworow['cat'],0,1)][] = $tworow['cat']; |
} |
} |
|
|
|
|
|
|
$catthreesresult = $conn->prepare('SELECT substr( "categoryUNSPSC"::text, 0, 4 ) as cat , SUM( "value" ) as value |
$catthreesresult = $conn->prepare('SELECT substr( "categoryUNSPSC"::text, 0, 4 ) as cat , SUM( "value" ) as value |
FROM contractnotice |
FROM contractnotice |
WHERE "childCN" = 0 and "categoryUNSPSC" IS NOT NULL |
WHERE "childCN" = 0 and "categoryUNSPSC" IS NOT NULL |
GROUP BY cat order by cat ;'); |
GROUP BY cat order by cat ;'); |
$catthreesresult->execute(); |
$catthreesresult->execute(); |
foreach ($catthreesresult->fetchAll() as $threerow) { |
foreach ($catthreesresult->fetchAll() as $threerow) { |
$catthrees[substr($threerow['cat'],0,2)][] = $threerow; |
$catthrees[substr($threerow['cat'],0,2)][] = $threerow; |
} |
} |
$nodes = Array(); |
$nodes = Array(); |
foreach ($cats as $catNum) { |
foreach ($cats as $catNum) { |
$catColor = $color->hsl2hex(Array($catNum/10, .7, .5)); |
$catColor = $color->hsv2hex(Array($catNum/10, .7, abs(($catNum*(1/10))-.5) + .5)); |
$catName = $unspsc[$catNum . "0000000"] . $catNum; |
$catName = $unspsc[$catNum . "0000000"] . $catNum; |
$subnodes = Array(); |
$subnodes = Array(); |
$catValue = 0; |
$catValue = 0; |
foreach ($cattwos[$catNum] as $twoCatNum) { |
foreach ($cattwos[$catNum] as $twoCatNum) { |
$subcatName = $unspsc[$twoCatNum. "000000"] .$twoCatNum; |
$subcatName = $unspsc[$twoCatNum. "000000"] .$twoCatNum; |
$subsubnodes = Array(); |
$subsubnodes = Array(); |
$subCatValue = 0; |
$subCatValue = 0; |
$subCatColor = $color->hsl2hex(Array($catNum/10, rand(1,10)/10, .5)); |
$subCatColor = $color->hsv2hex(Array($catNum/10, rand(1,10)/10, abs(($catNum*(1/10))-.5) + .5)); |
foreach ($catthrees[$twoCatNum] as $threerow) { |
foreach ($catthrees[$twoCatNum] as $threerow) { |
$subsubcatName = $unspsc[$threerow['cat'] . "00000"] . $threerow['cat']; |
$subsubcatName = $unspsc[$threerow['cat'] . "00000"] . $threerow['cat']; |
$subsubnodes[] = Array( |
$subsubnodes[] = Array( |
"label" => $subsubcatName, |
"label" => $subsubcatName, |
"amount" => $threerow['value'], |
"amount" => $threerow['value'], |
"color" => "#".$subCatColor |
//"color" => "#".$subCatColor |
); |
); |
$subCatValue += $threerow['value']; |
$subCatValue += $threerow['value']; |
} |
} |
$subnodes[] = Array( |
$subnodes[] = Array( |
"label" => $subcatName, |
"label" => $subcatName, |
"amount" => $subCatValue, |
"amount" => $subCatValue, |
"color" => "#".$subCatColor, |
"color" => "#".$subCatColor, |
"children" => $subsubnodes |
"children" => $subsubnodes |
); |
); |
$catValue += $subCatValue; |
$catValue += $subCatValue; |
} |
} |
$nodes[] = Array( |
$nodes[] = Array( |
"label" => $catName, |
"label" => $catName, |
"amount" => $catValue, |
"amount" => $catValue, |
"color" => "#".$catColor, |
"color" => "#".$catColor, |
"children" => $subnodes |
"children" => $subnodes |
); |
); |
$total += $catValue; |
$total += $catValue; |
} |
} |
$data = Array( |
$data = Array( |
"label" => "Australian Federal Government Contract Spending", |
"label" => "Australian Federal Government Contract Spending", |
"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> |
|
|