1 <?php
2 if(file_exists('example04.cache.php')) {
3 include('example04.cache.php');
4 exit();
5 }
6 ?><html>
7 <head>
8 <title>Legal acts by directory code</title>
9 <script type="text/javascript" src="https://www.google.com/jsapi"></script>
10 <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
11 <script type="text/javascript">
12 google.load("visualization", "1", {packages:["treemap"]});
13 google.setOnLoadCallback(drawChart);
14
15 function drawChart() {
16
17 var data = new google.visualization.DataTable(),
18 tree = new google.visualization.TreeMap(document.getElementById('visualization'));
19
20 data.addColumn('string', 'Directory code');
21 data.addColumn('string', 'Top level directory code');
22 data.addColumn('number', 'Number of acts (size)');
23 data.addColumn('number', 'Number of acts (color)');
24 data.addRows([ ["All acts",null,0,0] ]);
25 <?php
26 function getChilds($url, $parent, $level) {
27 if ($level-- < 1)
28 return;
29 $data = json_decode(file_get_contents($url));
30 $i = 0;
31 $out = '';
32 foreach($data as $item) {
33 if ($item->name == 'Unknown')
34 continue;
35 $name = addslashes($item->name).' ('.$item->directory_code.')';
36 if (getChilds($item->url, $name, $level) > 1) {
37 $out .= " data.addRows([ ['".$name."', '".$parent."', 0,".$item->number_of_documents."] ]);\n";
38 } else {
39 $out .= " data.addRows([ ['".$name."', '".$parent."', ".$item->number_of_documents.",".$item->number_of_documents."] ]);\n";
40 }
41 $i++;
42 }
43 if ($i > 2) {
44 echo $out;
45 }
46 return $i;
47 }
48
49 $url = 'http://api.epdb.eu/eurlex/directory_code/browse.php?key=YOUR_API_KEY';
50 getChilds($url, "All acts", 4);
51 ?>
52
53 tree.draw(data, {
54 minColor: '#990',
55 midColor: '#099',
56 maxColor: '#909',
57 maxColorValue: 8000,
58 minColorValue: 500,
59 headerHeight: 15,
60 fontColor: 'black',
61 showScale: true
62 });
63 }
64 </script>
65 <style type="text/css">
66 body { background-color:#193F4F; text-align:center;font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px }
67 a {color:#fff; }
68 #chart_div { background-color:#fff;color:#333;}
69 #container { background-color:#fff;padding:10px; }
70 #content { width: 1020px;margin-left:auto;margin-right:auto; }
71 </style>
72 </head>
73 <body>
74 <div id='content'>
75 <div id='container'>
76 <div id="visualization" style="width: 1000px; height: 500px;"></div>
77 </div>
78 </div>
79 <div style="color:#fff;margin-top:40px;">
80 Left-click to zoom in on a directory code, right-click to zoom out.<br />
81 This example uses the <a href="http://code.google.com/apis/chart/">Google Chart Tools</a>.<br />
82 Data is taken from the <a href="http://api.epdb.eu">API for European Union legislation</a> by <a href="http://www.buhlrasmussen.eu">Buhl & Rasmussen</a> 2011.
83 The original data source is <a href="http://eur-lex.europa.eu/">EUR-Lex</a>.<br />
84 You can see the <a href="example04.php.html">PHP source-code</a> used to generate this example, and
85 you can find more <a href="/#examples">examples here</a>.
86 </div>
87 </body>
88 </html>