/[pdpsoft]/trunk/nl.nikhef.ndpf.tools/network-stats-mashup/index.php
ViewVC logotype

Contents of /trunk/nl.nikhef.ndpf.tools/network-stats-mashup/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1278 - (show annotations) (download) (as text)
Fri Dec 11 17:00:37 2009 UTC (12 years, 8 months ago) by aramv
File MIME type: text/x-php
File size: 4136 byte(s)
Reworked version with constituent parts
1 <?php
2 $title = "Grid network summary";
3 include('includes/class.cricket_spider.php');
4 include('includes/class.trunk.php');
5 include('includes/ui_code.php');
6 ?>
7 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
8 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
9 <head>
10 <title><?=$title?></title>
11 <link rel="stylesheet" href="stylesheets/style.css" type="text/css" media="screen" charset="utf-8"/>
12 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
13 <script type="text/javascript" src="javascripts/wz_jsgraphics.js"></script>
14 <script type="text/javascript" src="javascripts/mapper.js"></script>
15 <script type="text/javascript" src="javascripts/mapper_hacks.js"></script>
16 <script type="text/javascript">
17 /* associative arrays.
18 daily_images_by_url : url -> image_link
19 daily_images_pre_cache : url -> image object
20
21 weekly_images_by_url : url -> image_link
22 weekly_images_pre_cache : url -> image object
23
24 names_by_url : url -> name
25 */
26 var snippets_by_url = Array();
27 var images_pre_cache = Array();
28 var images = Array();
29
30 <?php
31 $cs = new CricketSpider('image_map.html');
32 //print_r($cs->trunks);
33 foreach($cs->trunks as $index => $trunk){
34 ?>
35 snippets_by_url["<?=$trunk->trunk_page_url?>"] = '<?=$trunk->to_html()?>';
36 <?php
37 if($trunk->weekly_image_url){
38 ?>
39 images.push('<?=$trunk->weekly_image_url() ?>');
40 images.push('<?=$trunk->daily_image_url() ?>');
41 <?php
42 }
43 }
44 ?>
45
46 /* pre-loads all the graphs into an array that we can use to splice them back into the DOM */
47 function pre_cache_images(){
48 for(id in images){
49 images_pre_cache[id] = new Image();
50 images_pre_cache[id].src = images[id];
51 }
52 }
53
54 /* callback for onmouseover event of areas */
55 function show_graph(url){
56 snippet = document.getElementById('graph_div');
57 snippet.innerHTML = snippets_by_url[url];
58 }
59
60 </script>
61 </head>
62 <body>
63 <div id="wrapper">
64 <div class="header">
65 <h1><?=$title?></h1>
66 </div>
67 <div class="image_div">
68 <p>
69 <?php
70 /* read in GIMP output and set class attributes to enable fancy javascript features */
71 $image_map = preg_replace('/<img (.+) border="0" (.+)\/>/', '<img \1 \2 id="network_graph" class="mapper noborder" alt="" />', file_get_contents('image_map.html'));
72 /* xhtml fix - map needs an id attribute but GIMP can't edit imagemaps that have it */
73 $image_map = preg_replace('/<map(.*)>/','<map\1 id="map">', $image_map);
74 /* add some more info to the areas, based on their status */
75 /* I tried referencing the mathces[2] twice to get a prober alt tag using the name_from_url() function. However, this doesn't seem to work :( */
76 $image_map = preg_replace_callback('/<area (.+) href="(.+)" \/>/', create_function('$matches', 'return "<area ". $matches[1] . " href=\"" . $matches[2] . "\" alt=\"\" onmouseover=\"show_graph(this.href);\" class=\"icolor" . highlight_color($matches[1]) . " iborder" . border_color($matches[1]) . "\" />";'), $image_map);
77 echo $image_map;
78 ?>
79 </p>
80 </div>
81 <div class="info_div">
82 <noscript>
83 <p>
84 Please enable javascript to see graphs when hovering over trunks.
85 </p>
86 </noscript>
87 <div id="graph_div">
88 </div>
89 </div>
90 <div class="clear">&nbsp;</div>
91 <div class="links_div">
92 <h4>Trunks listed: </h4>
93 <ul>
94 <?php
95 foreach($cs->trunks as $index => $trunk){
96 ?>
97 <li><a href="<?=$trunk->trunk_page_url?>"><?=$trunk->name?></a></li>
98 <?php
99 }
100 ?>
101 </ul>
102 </div>
103 </div>
104 <script type="text/javascript">
105 pre_cache_images();
106 <?php
107 /* make double clicks work as clicks for mobile browsers and disable regular clicks*/
108 if(is_mobile()){
109 ?>
110 var loader_chain = window.onload;
111 window.onload = function(){
112 var areas = document.getElementsByTagName('area');
113 for(idx in areas){
114 areas[idx].onclick = new Function('return false;');
115 areas[idx].ondblclick = new Function('window.location = "' + areas[idx].href+'";');
116 }
117 loader_chain();
118 }
119 <?php
120 }
121 ?>
122 </script>
123 </body>
124 </html>

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28