Project

General

Profile

1
<!DOCTYPE html 
2
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
<html>
5
<?php
6
require_once('controller.php');
7
$controller = new Controller(false);
8

    
9
if(isset($_GET['com'])) {
10
	if($_GET['com'] == "query") {
11
		$selectedData = json_encode($_GET['data'],JSON_NUMERIC_CHECK);
12
		$resp = $controller->makeQuery('table');
13
	}
14
	else{
15
		echo "unknown command code";
16
	}
17
}
18
else {
19
	//oops error
20
	echo "no command given";
21
}
22

    
23
?>
24
  <head>
25
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
26
	<title>treemap</title>
27
	
28
	<!-- Include JQuery Core-->
29
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
30
	<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
31
	<script type="text/javascript" src="./js/themes9.js"></script>
32
	<style type="text/css">
33
		h1{
34
			text-align: center;
35
			font-family: "YanoneKaffeesatzLight","Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif;
36
			font-weight: normal;
37
			font-size:26px;
38
			color: #2B54B8;
39
			line-height: 30px;
40
		}
41

    
42
		h2{
43
			text-align: center;
44
			color: #2d72d6;
45
			font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif;
46
			font-weight: bold;
47
			font-size:medium;
48
		}
49
		
50
		#credits {
51
			color: #909090;
52
			//cursor: pointer;
53
			fill: #909090;
54
			font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif;
55
			font-size: 10px;
56
			float:right;
57
			margin-right:10%;
58
		}
59
		
60
	</style>
61
	<script type='text/javascript' src='https://www.google.com/jsapi'></script>
62
	<script type='text/javascript'>
63
	
64
	function isNumber (o) {
65
		return ! isNaN (o-0) && o !== null && o !== "" && o !== false;
66
	}
67
	
68
	var chart;
69
	var tableData;
70
	var selectedData;
71
	var headers;
72
	
73
	tableData = <?php echo $resp ?>;
74
	
75
	tableData['data'].sort(function(a,b) {
76
		return parseInt(b[1],10)-parseInt(a[1],10);
77
	});
78

    
79
	selectedData = $.parseJSON(<?php echo $selectedData;?>);
80

    
81
		google.load("visualization", "1", {packages:["treemap"]});
82
		google.setOnLoadCallback(draw);
83
		
84
		function draw() {
85
			drawTable();
86
			drawToolbar();
87
			credits();
88
		}
89
		
90
		function drawTable(){
91
			$('h1').html(selectedData['title']);
92
			$('h2').html(selectedData['subtitle']);
93
//////////////////////////////////////////////////
94
			var rows = new Array();
95
			var headerrow = new Array();
96
			var data = new google.visualization.DataTable();
97
			if(selectedData['xaxistitle'] && selectedData['xaxistitle']!=''){
98
				headerrow.push(selectedData['xaxistitle']);
99
			}
100
			else{
101
				var fld = selectedData['xaxis']['name'].split('-');
102
				if(selectedData['xaxis']['agg']!='')
103
					headerrow.push(selectedData['xaxis']['agg']+" of "+fld[fld.length-1]);
104
				else
105
					headerrow.push(fld[fld.length-1]);
106
			}
107
			headerrow.push("Parent");
108
			
109
			for(var i=0;i<selectedData['fields'].length && i<2;i++){
110
				if(selectedData['fieldsheaders'] && selectedData['fieldsheaders'][i] && selectedData['fieldsheaders'][i]!=''){
111
					headerrow.push(selectedData['fieldsheaders'][i]);
112
				}
113
				else{
114
					fld = selectedData['fields'][i]['fld'].split('-');
115
					if(selectedData['fields'][i]['agg']!='')
116
						headerrow.push(selectedData['fields'][i]['agg']+" of "+fld[fld.length-1]);
117
					else
118
						headerrow.push(fld[fld.length-1]);
119
				}
120
			}
121

    
122
			rows.push(headerrow);
123
			rows.push(new Array("All",null,0));
124
			for(var i in tableData['data']){
125
				var row = new Array();
126
				for(var j=0;j<tableData['data'][i].length && j<2;j++){
127
					if(j==0){
128
						if(isNumber(tableData['data'][i][j]))
129
							row.push(tableData['data'][i][j].toString());
130
						else
131
							row.push(tableData['data'][i][j]);
132
						row.push("All");
133
					}
134
					else
135
						row.push(tableData['data'][i][j]);
136
				}
137
				rows.push(row);//alert(JSON.stringify(tableData['data'][i]));
138
				//alert(JSON.stringify(row));
139
			}
140
			data = google.visualization.arrayToDataTable(rows);
141
//////////////////////////////////////////////
142
			var tree = new google.visualization.TreeMap(document.getElementById('tree_div'));
143
			tree.draw(data, {
144
				minColor: '#086A87',
145
				midColor: '#086A87',
146
				maxColor: '#086A87',
147
				headerHeight: 15,
148
				fontColor: 'black',
149
				showScale: false});
150

    
151
		}
152
		
153
		function drawToolbar() {
154
			var components = [
155
				{type: 'html', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>},
156
				{type: 'csv', datasource: 'datasource.php?com=query&data='+<?php echo $selectedData;?>},
157
				{type: 'htmlcode', datasource: '<?php echo $stats_server ?>/datasource.php?com=query&data='+<?php echo $selectedData;?>,
158
				style: 'width: 800px; height: 700px; border: 3px solid purple;'}
159
			];
160

    
161
			var container = document.getElementById('toolbar');
162
			google.visualization.drawToolbar(container, components);
163
		};
164
		
165
		
166
		
167
	function numberWithCommas(num){
168
		if(typeof num == "string")
169
			var array = num;
170
		else
171
			var array = num.toString().split('');
172
		var index = -3;
173
		var len = array.length;
174
		while(len + index > 0){
175
			array.splice(index, 0 , ',');
176
			index -= 4;
177
		}
178
		return array.join('');
179
	}
180
	
181
	function credits(){
182
		var cr = document.getElementById("credits");
183
		var str = signature;
184
		if(addDate){
185
			var today = new Date();
186
			var dd = today.getDate();
187
			var mm = today.getMonth()+1; //January is 0!
188
			var yyyy = today.getFullYear();
189
			str += " (" + datetext + dd + "/" + mm + "/" + yyyy +")";
190
		}
191
		cr.innerHTML = str;
192
	}
193
	</script>
194
  </head>
195

    
196
  <body>
197
  <h1 id='title'></h1>
198
  <h2 id='subtitle'></h2>
199

    
200
	<div id='tree_div' style="height:450px;width:736px;margin:auto"></div>
201
	<div id='toolbar' style="width:218px;margin:auto;"></div>
202
	<div id="credits"></div>
203
  </body>
204
</html>
(29-29/29)