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

    
7
require_once('controller.php');
8
$controller = new Controller(false);
9

    
10
if(!isset($_GET['com'])) {
11
	echo "no command given";
12
	return;
13
}
14
if($_GET['com'] != "query"){
15
	echo "unknown command code";
16
	return;
17
}
18

    
19
//make the query
20
$selectedData = json_encode($_GET['data']);
21
$resp = $controller->makeQuery('chart');
22

    
23
//echo "selected ".json_encode($_GET['data'],JSON_NUMERIC_CHECK);
24
//each filter to be included get its data and build the json object for the javascript
25
//echo "will include ".count($_GET['data']['incfilters'])." filters";
26

    
27
$myData = json_decode($_GET['data']);
28
if(isset($myData->incfilters))
29
	$myfilters = $myData->incfilters;
30
else
31
	$myfilters = array();
32

    
33

    
34
for($i=0;$i<count($myfilters);$i++){
35
	if(isset($myfilters[$i]->values) && $myfilters[$i]->values=='all'){
36
		$temp = $controller->getFilterData($myData->table,$myfilters[$i]->name);
37
		if(!is_array($temp)){
38
			$temp = json_decode($temp);
39
		}
40
		//print_r($temp->data);
41
		$myfilters[$i]->values = $temp->data;
42
	}
43
}
44

    
45
?>
46
<head>
47
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
48
<title>chart</title>
49
<!-- Include JQuery Core-->
50
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
51
<script type="text/javascript" src="./js/jquery-ui-1.9.1.custom/js/jquery-ui-1.9.1.custom.js"></script>
52

    
53
<!-- HighCharts -->
54
<script src="./js/Highcharts-4.0.1/js/highcharts.js" type="text/javascript"></script>
55
<script src="./js/Highcharts-4.0.1/js/modules/exporting.js" type="text/javascript"></script>
56

    
57
<script src="./js/themes9.js" type="text/javascript"></script>
58
<!--Styles-->
59
<link rel="stylesheet" href="//code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
60
<link type="text/css" href="./js/jquery/css/start/jquery-ui-1.8.20.custom.css" />
61
<link type="text/css" href="./js/highcharts.css" rel="stylesheet" />
62
<link rel="stylesheet" href="js/filters.css" />
63

    
64

    
65
<script type='text/javascript'>
66
var chart;
67
var chart2;
68
var chartData;
69
var chartData2;
70
var chartDataFromServer;
71
var selectedData;
72
var filterData;
73
var myFilter;
74
//----------------- inits --------------------//
75
var wflag = <?php if(isset($_GET['w']) && $_GET['w']!='' && $_GET['w'][strlen($_GET['w'])-1] == '%'){ echo "true"; }
76
               	  else{ echo "false"; }?>
77

    
78
var mywidth =  <?php if(isset($_GET['w']) && $_GET['w']!=''){
79
			if($_GET['w'][strlen($_GET['w'])-1] == '%'){
80
				echo substr($_GET['w'],0,strlen($_GET['w'])-1);
81

    
82
			}else{
83
				if($_GET['w'][strlen($_GET['w'])-1] == 'x'){
84
					echo substr($_GET['w'],0,strlen($_GET['w'])-2);
85
				}else echo $_GET['w'];
86
			}
87
		    }else echo '700'; ?>;
88

    
89
var hflag = <?php if(isset($_GET['h']) && $_GET['h']!='' && $_GET['h'][strlen($_GET['h'])-1] == '%'){ echo "true"; }
90
                  else{ echo "false"; }?>
91

    
92
var myheight =  <?php if(isset($_GET['h']) && $_GET['h']!=''){
93
                        if($_GET['h'][strlen($_GET['h'])-1] == '%'){
94
                                echo substr($_GET['h'],0,strlen($_GET['h'])-1);
95
			}else{ 
96
                                if($_GET['w'][strlen($_GET['h'])-1] == 'x'){
97
                                        echo substr($_GET['h'],0,strlen($_GET['h'])-2);
98
                                } else echo $_GET['h'];
99
                        }
100
                      }else echo '400'; ?>;
101

    
102
//----------------- document ready --------------------//
103
$('document').ready(function(){
104
	chartDataFromServer = <?php echo $resp ?>;
105
	selectedData = $.parseJSON(<?php echo $selectedData;?>);
106
	filterData = <?php echo json_encode($myfilters);?>;
107

    
108
	renderChart();
109
	renderfilters();
110
	controlsforfilters();
111
});
112

    
113
function renderChart(){
114

    
115
	if(selectedData['in'] != undefined && selectedData['in'].length>0){
116
		if(chartDataFromServer[0].plotOptions != undefined && chartDataFromServer[0].plotOptions.series != undefined){
117
	 	       chartDataFromServer[0].plotOptions.series.events = new Object();
118
		       chartDataFromServer[0].plotOptions.series.events.checkboxClick = function(event){if(event.checked == true) this.show(); else this.hide();};
119
		}
120
		if(chartDataFromServer[1].plotOptions != undefined && chartDataFromServer[1].plotOptions.series != undefined){
121
		        chartDataFromServer[1].plotOptions.series.events = new Object();
122
	        	chartDataFromServer[1].plotOptions.series.events.checkboxClick = function(event){if(event.checked == true) this.show(); else this.hide();};
123
		}
124
		chartData = chartDataFromServer[0];
125
		chartData2 = chartDataFromServer[1];
126
		setSelections();
127
	}
128
	else{
129
		if(chartDataFromServer.plotOptions != undefined && chartDataFromServer.plotOptions.series != undefined){
130
		        chartDataFromServer.plotOptions.series.events = new Object();
131
			chartDataFromServer.plotOptions.series.events.checkboxClick = function(event){if(event.checked == true) this.show(); else this.hide();};
132
		}
133
		chartData = chartDataFromServer;
134
	}
135
	var formatter = chartData.xAxis.labels.formatter;
136
	if(selectedData['emp'] == undefined)
137
		selectedData['emp'] = new Array();
138
	else{
139
			chartData.xAxis.plotLines = new Array();
140
		for(var e=0;e<selectedData['emp'].length;e++){
141
			var line = new Object();
142
			line.value = chartData['xAxis']['categories'].indexOf(selectedData['emp'][e]);
143
			line.width = 1;
144
			line.color = 'red';
145
			line.dashStyle = 'dash';
146
			line.zIndex = 100;
147
			chartData.xAxis.plotLines.push(line);
148
		}
149
	}
150

    
151
	if(selectedData['bands'] != undefined){
152
		chartData['xAxis']['plotBands'] = new Array();
153
		for(var b=0;b<selectedData['bands'].length;b++){
154
			var band = new Object();
155
			band.color = '#FCFFC5';
156
			var from = chartData.xAxis.categories.indexOf(selectedData['bands'][b][0]);
157
			var to = chartData.xAxis.categories.indexOf(selectedData['bands'][b][1]);
158
			band.from = from;
159
			band.to = (to==-1)? chartData.xAxis.categories.length:to;
160
			band.zIndex = -100;
161
			chartData.xAxis.plotBands.push(band);
162
		}
163
	}
164

    
165
	if(selectedData['xStyle'] != undefined){
166
		chartData.xAxis.labels = labelsforx(selectedData['xStyle'],selectedData['emp']);
167
	}
168
	else{
169
		var temp = new Object(); temp['r'] = '-'; temp['s'] = '-'; temp['l'] = '-';
170
		chartData.xAxis.labels = labelsforx(temp,selectedDatap['emp']);
171
	}
172

    
173
	//headers!!!!
174
	if(typeof selectedData['title'] != 'undefined'  && selectedData['title']!=''){
175
		chartData.title = new Object();
176
		chartData.title.text = selectedData['title'];
177
		chartData.title.align = 'center';
178
	}
179
	else{
180
		chartData.title.text = null;
181
	}
182
	if(selectedData['subtitle']!=''){
183
		chartData.subtitle = new Object();
184
		chartData.subtitle.text = selectedData['subtitle'];
185
	}
186
	else{
187
		chartData.subtitle = null;
188
	}
189

    
190

    
191
	if(selectedData['fields'].length == 1 && selectedData['fields'][0]['type'] == 'pie'){
192
		chartData.xAxis.title.text = null;
193
		chartData.yAxis[0].title.text = null;
194
		$("#zoommessage").hide();
195
	}
196

    
197
	//chartData.xAxis.title.text = selectedData['xaxis']['name'];
198
	var today = new Date();
199
	var dd = today.getDate();
200
	var mm = today.getMonth()+1; //January is 0!
201

    
202
	var yyyy = today.getFullYear();
203
	chartData.credits.text = "from OpenAIRE via HighCharts (date: " + dd + "/" + mm + "/" + yyyy +")";
204

    
205
	if(selectedData['stacking']!=undefined){
206
                chartData['plotOptions']['column']['stacking'] = selectedData['stacking'];
207
                chartData['plotOptions']['area']['stacking'] = selectedData['stacking'];
208
                chartData['plotOptions']['areaspline']['stacking'] = selectedData['stacking'];
209
        }
210

    
211
	chartData.plotOptions['pie']['dataLabels']['formatter'] = function() {
212

    
213
		return '<b>'+ this.point.name +'</b>: '+ this.point.y + ' ' ;
214
	};
215

    
216
	if(chartData.series.length > 4){
217
		chartData.legend.layout = 'horizontal';
218
		chartData.legend.align = 'center';
219
		chartData.legend.verticalAlign = 'bottom';
220
		chartData.legend.x = null;
221
		chartData.legend.y = null;
222
		chartData.legend.floating = false;
223
		//chartData.legend.itemStyle = new Object();
224
		//chartData.legend.itemStyle.margin = "4px";
225
	}
226

    
227
	if(selectedData['type'] == 'scatter'){
228
		if(selectedData['color'] == 'yes')
229
			chartData.tooltip.formatter = function() { return '<b>'+ this.series.name +'</b><br/>'+ chartData['xAxis']['title']['text']+ ': '+ this.x +'<br/>'+ chartData['yAxis'][0]['title']['text']+': '+ this.y ;};
230
		else if(selectedData['group'] != '')
231
			chartData.tooltip.formatter = function() { return '<b>'+ this.point.name +'</b><br/>'+ chartData['xAxis']['title']['text']+ ': '+ this.x +'<br/>'+ chartData['yAxis'][0]['title']['text']+': '+ this.y ;};
232
		else
233
			chartData.tooltip.formatter = function() { return chartData['xAxis']['title']['text']+ ': '+ this.x +'<br/>'+ chartData['yAxis'][0]['title']['text']+': '+ this.y ;};
234
		chartData['chart']['type'] = 'scatter';
235
	}
236
	else {
237
			chartData.tooltip.percentageDecimals = 1;
238
			chartData.tooltip.valueDecimals = 1;
239
			 if(selectedData['fields'][0]['type'] != 'pie'){
240
                                //chartData.tooltip.headerFormat = '<span style="font-size:10px">{point.key}</span><table>';
241
                                //chartData.tooltip.pointFormat = '<tr><td style="color:{series.color};padding:0">{series.name}:</td>'+'<td style="padding:0"><b>{point.y}</b></td></tr>';
242
                                //chartData.tooltip.footerFormat = '</table>';
243
                                chartData.tooltip.shared = true;
244
                                chartData.tooltip.useHTML = true;
245
                        }
246
                        //else
247
			chartData.tooltip.formatter = function() {
248
				if(selectedData['fields'][0]['type']!='pie'){
249
					/*//var ind = chart.xAxis[0].categories.indexOf(this.x);
250
					var str = '';
251
					if(this.point.config.name)
252
						str += '<b>'+ this.point.config.name +'</b><br/>';
253
					//str += this.x + '<br />';
254
					//var myseries = chart.series;
255
					//for(var i=0;i<myseries.length;i++){
256
					//	str += myseries[i].name + ":" + numberWithCommas(myseries[i].data[ind].y) + "<br />";
257
					//}
258
					str += this.series.name + ': '+ '<b>' + numberWithCommas(this.y) + '</b><br/>';
259
					str += chart.xAxis[0].axisTitle.textStr + ": <b>" + this.x + '</b>';
260
					return str;*/
261
					var s = '<b>'+ this.x +'</b>';
262

    
263
                			$.each(this.points, function(i, point) {
264
                    				s += '<br/><span style="color:'+point.series.color+'">'+ point.series.name +'</span>: '+
265
                        			numberWithCommas(point.y);
266
                			});
267

    
268
                			return s;
269
				}
270
				else{
271
					var name;
272
					if(selectedData['fieldsheaders'].length >0)
273
						name = selectedData['fieldsheaders'][0];
274
					else if(selectedData['yaxisheaders'].length>0)
275
						name = selectedData['yaxisheaders'][0];
276
					else
277
						name = "number";
278
					return '<b>'+ this.point.config.name +'</b>: ' + Highcharts.numberFormat(this.percentage, 2) +' %<br/>(' + name + ": " + numberWithCommas(this.y) +")";
279
				}
280
			};
281
		if(selectedData['fields'].length==1)
282
			chartData['chart']['type'] = selectedData['fields'][0]['type'];
283

    
284
	}
285
	if('theme' in selectedData){
286
		highchartsOptions = Highcharts.setOptions(themes[selectedData['theme']][1]);
287
	}
288
	else
289
		highchartsOptions = Highcharts.setOptions(themes[0][1]);
290

    
291

    
292
	//alert('Found ' + document.getElementsByTagName('div').length + ' divs');
293

    
294
	if(mywidth>0){
295
		if(wflag)
296
			chartData.chart.width = mywidth * $(document).width() /100;
297
		else
298
			chartData.chart.width = mywidth;
299
	}
300
	else
301
		chartData.chart.width = 90 * $(document).width() / 100;
302
	if(myheight>0){
303
                if(hflag)
304
                        chartData.chart.height = myheight * $(document).height() /100;
305
                else
306
                        chartData.chart.height = myheight;
307
        }
308
	else
309
		chartData.chart.height = 80 * $(document).height() /100;
310

    
311
	chartData.exporting = JSON.parse( '{ "url" : "<?php echo $export_server ?>" }');
312
	
313
	chart = new Highcharts.Chart(chartData, function(chart){
314
		var series = chart.series;
315
		var i=0;
316
		for(; i<series.length; i++){
317
			if( series[i].legendItem && series[i].checkbox) {
318
        			series[i].checkbox.style.marginLeft = '18px';
319
    			}
320
		}
321
	});
322

    
323

    
324
	//chart.setSize(mywidth, myheight, false);
325
	//alert(JSON.stringify(chartData));
326
	if(selectedData['in'] != undefined && selectedData['in'].length>0){
327
		if(chartData.xAxis.labels != undefined) chartData2.xAxis.labels = chartData.xAxis.labels
328
		if(chartData.title != undefined) {chartData2.title = new Object(); chartData2.title.text = chartData.title.text;}
329
		if(chartData.subtitle != undefined) {chartData2.subtitle = new Object(); chartData2.subtitle.text = chartData.subtitle.text;}
330
		chartData2.xAxis.title.text = chartData.xAxis.title.text;
331
		chartData2.yAxis[0].title.text = chartData.yAxis[0].title.text;
332
		chartData2.credits.text = chartData.credits.text;
333
		chartData2.plotOptions['pie']['dataLabels']['formatter'] = chartData.plotOptions['pie']['dataLabels']['formatter'];
334
		chartData2.tooltip = chartData.tooltip;
335
		chartData2['chart']['type'] = chartData['chart']['type'];
336
		chartData2['chart']['renderTo'] = 'chart2';
337
		chartData2['xAxis']['plotLines'] = chartData['xAxis']['plotLines'];
338
		chartData2['xAxis']['plotBands'] = chartData['xAxis']['plotBands'];
339
		if(chartData['chart']['height'] != undefined)
340
			chartData2['chart']['height'] = chartData['chart']['height'];
341
		if(chartData['chart']['width'] != undefined)
342
			chartData2['chart']['width'] = chartData['chart']['width'];
343
		if(selectedData['xStyle'] != undefined){
344
		        chartData2.xAxis.labels = labelsforx(selectedData['xStyle'],selectedData['emp']);
345
		}
346
		else{
347
		        var temp = new Object(); temp['r'] = '-'; temp['s'] = '-'; temp['l'] = '-';
348
		        chartData2.xAxis.labels = labelsforx(temp,selectedData['emp']);
349
		}
350
		if(selectedData['stacking']!=undefined){
351
		        chartData2['plotOptions']['column']['stacking'] = selectedData['stacking'];
352
		        chartData2['plotOptions']['area']['stacking'] = selectedData['stacking'];
353
		        chartData2['plotOptions']['areaspline']['stacking'] = selectedData['stacking'];
354
		}
355

    
356
		if(chartData2.series.length > 4)
357
                	chartData2.legend = chartData.legend;
358
		//chartData.plotOptions.column.pointWidth = 30;
359
		//chartData2.plotOptions.column.pointWidth = 30;
360
		chart2 = new Highcharts.Chart(chartData2, function(chart2){
361
	        	var series = chart2.series;
362
	        	var i=0;
363
	        	for(; i<series.length; i++){
364
	        	        if( series[i].legendItem && series[i].checkbox) {
365
	        	                series[i].checkbox.style.marginLeft = '18px';
366
	        	        }
367
	        	}
368
		});
369

    
370
	}
371
	credits();
372
}
373

    
374

    
375
function setSelections(){
376
	var str = "<input type='radio' name='sel' checked value='not'/>"+selectedData['in'][0]['text']+"&nbsp&nbsp&nbsp<input type='radio' name='sel' value='cumulate'/>Cumulative" ;
377
	$("#selections").empty().append(str);
378

    
379
	$("input[name='sel']").live("click",function(){
380
		if($(this).val() == "cumulate"){
381
			$("#chart").hide();
382
			$("#chart2").show();
383
		}
384
		else{
385
			$("#chart2").hide();
386
			$("#chart").show();
387
		}
388
	});
389
}
390

    
391
function controlsforfilters(){
392
	$("a.all").live("click",function(){
393
		$(this).siblings('.filterForm').find('input').attr("checked","checked");
394
		newValues($(this).siblings('.filterForm').find('input')[0]);
395
		return false;
396
	});
397

    
398
	$("a.none").live("click",function(){
399
                $(this).siblings('.filterForm').find('input').removeAttr("checked");
400
		newValues($(this).siblings('.filterForm').find('input')[0]);
401
		return false;
402
        });
403

    
404
	$(".formContainer input").live("click",function(){
405
		newValues(this);
406
	});
407
}
408

    
409
function newValues(obj){
410
	var field = $(obj).parent().attr('id');
411
	var myfilters = selectedData['filters'];
412
	var thisfilter;
413
	for(var i=0;i<selectedData['incfilters'].length;i++){
414
		if(selectedData['incfilters'][i]['name'] == field){
415
			thisfilter = selectedData['incfilters'][i];
416
			break;
417
		}
418
	}
419

    
420
	//change the url params
421
	//if is it checked
422
	if($(obj).is(":checked")){
423
		$(obj).parents(".filter").find("a.none").show();
424
		var flag = false;
425
		var i;
426
		for(i=0;i<myfilters.length;i++){
427
			if(myfilters[i]['name'] == field){
428
				flag=true;
429
				break;
430
			}
431
		}
432
		//if there is already such a filter delete all values and insert all the checked
433
		if(flag){
434
			myfilters[i].values = new Array();
435
			$(obj).parent().find("input:checked").each(function(){
436
				myfilters[i].values.push($(this).val());
437
			});
438
			//myfilters[i].values.push($(obj).val());
439
		}
440
		//if there is no such filter
441
		else{
442
			//create one
443
			var newfilter = new Object();
444
			newfilter.name = field;
445
			newfilter.values = new Array();
446
			var ch = $(obj).parent().find("input:checked");
447
			$(ch).each(function(){
448
				newfilter.values.push($(this).val());
449
			});
450
			//newfilter.values[0] = $(obj).val();
451
			myfilters.push(newfilter);
452
		}
453
	}
454
	//if it was unchecked
455
	else{
456
		//there should be already such a filter
457
		var flag = false;
458
                var i;
459
                for(i=0;i<myfilters.length;i++){
460
                        if(myfilters[i]['name'] == field){
461
                                flag=true;
462
                                break;
463
                        }
464
                }
465
		//remove the value
466
                if($(obj).parent().find("input:checked").length == 0){
467
                        $(obj).parents(".filter").find("a.none").hide();
468
                        myfilters[i].values = new Array();
469
                }
470
                else{
471
                        var j;
472
                        for(j=0;j<myfilters[i].values.length;j++){
473
                                if(myfilters[i].values[j] == $(obj).val()){
474
                                        myfilters[i].values.splice(j,1);
475
                                        break;
476
                                }
477
                        }
478
                }
479

    
480

    
481
		//if no more values, add the values in the incfilter list and if it is all remove the filter
482
		if(myfilters[i].values.length == 0){
483
			if(thisfilter.values[0]=="all")
484
				myfilters.splice(i,1);
485
			else
486
				myfilters[i].values = thisfilter.values;
487
		}
488
	}
489
	//ajax call to get the new data
490
	$.ajax({
491
	   type: "GET",
492
	   url: "ajaxRouter9.php",
493
	   data: "com=query&type=chart&data="+encodeURIComponent(JSON.stringify(selectedData)),  
494
	   success: function(resp){
495
		 // we have the response
496
		chartDataFromServer = JSON.parse(resp);
497
		renderChart();
498
		},
499
	   error: function(e){
500
		 alert('Error: ' + e);
501
	   }
502
	});
503

    
504
}
505

    
506

    
507
function labelsforx(style, emp){
508
	var st = Object();
509
	st.justify = null;
510
	st.style = Array();
511
	st.style['font-size'] = '8px';
512
	st.formatter = null;
513

    
514
	if(style['r'] != null && style['r'] != "-"){
515
		st.rotation = style['r'];
516
		st.y =25;
517
	}
518
	if(style['s'] != null && style['s'] != "-")
519
		st.step = style['s'];
520
	if(style['l'] != null && style['l'] != "-")
521
		st.staggerLines = style['l'];
522

    
523
	if(style['ft'] != null && style['ft'] != "-"){
524
		if(style['wt'] != null && style['wt'] != "-")
525
			st.formatter = function(){
526
				eflag = false;
527
				for(var e=0;e<emp.length;e++){
528
                                	if(this.value == emp[e]){
529
                                        	eflag = true;
530
                                                break;
531
                                        }
532
                                }
533

    
534
				if (typeof this.value == 'string' || this.value instanceof String){
535
					var ar = this.value.split(" ");
536
					var str = '';
537
					if(ar.length == 1){
538
						if(eflag) return '<span style="fill:red;">' + this.value.substr(0,selectedData['xStyle']['ft']) + '</span>';
539
						else return this.value.substr(0,selectedData['xStyle']['ft']);
540
					}
541
					for(var i=0;i<ar.length;i++) {
542
						str +=ar[i].substr(0,selectedData['xStyle']['wt'])+' ';
543
					}
544
					if(eflag) return '<span style="fill:red;">' + str.substr(0,selectedData['xStyle']['ft']) + '</span>';
545
					else return str.substr(0,selectedData['xStyle']['ft']);
546
				}
547
				else
548
					if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
549
			};
550
		else
551
			st.formatter = function(){
552
				eflag = false;
553
                                for(var e=0;e<emp.length;e++){
554
                                        if(this.value == emp[e]){
555
                                                eflag = true;
556
                                                break;
557
                                        }
558
                                }
559

    
560
				if (typeof this.value == 'string' || this.value instanceof String){
561
					if(this.value.length>selectedData['xStyle']['ft'])
562
						if(eflag) return '<span style="fill:red;">' + this.value.substr(0,selectedData['xStyle']['ft']) + "..." + '</span>';
563
						else return this.value.substr(0,selectedData['xStyle']['ft']) + "...";
564
					else
565
						if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
566
						else return this.value;
567
				}
568
				else return this.value;
569
			};
570
	}
571
	else if(style['wt'] != null && style['wt'] != "-")
572
		st.formatter = function(){
573
				eflag = false;
574
                                for(var e=0;e<emp.length;e++){
575
                                        if(this.value == emp[e]){
576
                                                eflag = true;
577
                                                break;
578
                                        }
579
                                }
580
				if (typeof this.value == 'string' || this.value instanceof String){
581
					var ar = this.value.split(" ");
582
					var str = '';
583
					if(ar.length == 1)
584
						if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
585
 						else return this.value;
586
					for(var i=0;i<ar.length;i++) {
587
						str +=ar[i].substr(0,selectedData['xStyle']['wt'])+' ';
588
					}
589
					if(eflag) return '<span style="fill:red;">' + str + '</span>';
590
					else return str
591
				}
592
				else
593
					if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
594
			};
595
	else{
596
		st.formatter = function(){
597
                	for(var e=0;e<emp.length;e++){
598
                        	if(this.value == emp[e]){
599
					return '<span style="fill:red;">' + this.value + '</span>';
600
                                }
601
                        }
602
			return this.value;
603
		};
604
	}
605
	return st;
606
}
607

    
608
function isInt(n) {
609
   return typeof n === 'number' && n % 1 == 0;
610
}
611

    
612
function numberWithCommas(num){
613
	if(isInt(num)){
614
		var array = num.toString().split('');
615
		var index = -3;
616
		var len = array.length;
617
		while((len + index) > 0){
618
			array.splice(index, 0 , ',');
619
			index -= 4;
620
		}
621
		return array.join('');
622
	}
623
	else
624
		return Math.round(num*100)/100;
625
}
626

    
627
function credits(){
628
	var today = new Date();
629
	var dd = today.getDate();
630
	var mm = today.getMonth()+1; //January is 0!
631
	var yyyy = today.getFullYear();
632
	var cr = document.getElementById("credits");
633
	cr.innerHTML = "from OpenAIRE via HighCharts (date: " + dd + "/" + mm + "/" + yyyy +")";
634
}
635

    
636
function renderfilters(){
637
	var container = document.getElementById("filters");
638
	if(filterData!=null){
639
		var len = filterData.length;
640
		for(var i=0;i<len;i++){
641
			//checkboxes
642
			if(filterData[i].values != undefined){
643
				var str = "<div class='filter'><div class='filterHeader'><p>"+filterData[i].showname+"</p><input type='hidden' value='"+filterData[i].name+"' class='filtername'/></div><a class='all' href='#'>select all</a><a class='none' href='#' style='display:none;float:right'>clear</a><div class='filterForm'><div class='formContainer'><form id='"+filterData[i].name+"' class='filterform'>";
644
				for(var v=0;v<filterData[i].values.length;v++){
645
					str+="<input type='checkbox' value='"+filterData[i].values[v]+"' name='form"+filterData[i].name+"'>"+filterData[i].values[v]+"<br>";
646
				}
647
				str +=	"</form></div></div></div>";
648
				$(container).append(str);
649
			}
650
			//slider
651
			else{
652
				var str = "<div class='filter'><div class='filterHeader'><p>"+filterData[i].showname+"</p><input type='hidden' value='"+filterData[i].name+"' class='filtername'/></div>";
653
				str += "<div class='filter-slider'><div class='slider-container'><div id='slider"+filterData[i].name+"' class='ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all' aria-disabled='false'></div></div>";
654

    
655
				str += "<span class='price-tip slider-user-min'><span id='userMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
656
				str += "<span class='price-tip slider-user-max'><span id='userMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
657
				str += "<span class='min' style='display:none'><span id='productMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
658
				str += "<span class='max' style='display:none'><span id='productMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
659
				str += "</div></div>";
660
				$(container).append(str);
661
				myFilter = filterData[i];
662
				$(function(){
663
					$("#slider"+myFilter.name).slider({
664
						step: 1,
665
						range: true,
666
						min: parseInt(myFilter['min']),
667
						max: parseInt(myFilter['max']),
668
						values: [parseInt(myFilter['min']), parseInt(myFilter['max'])],
669
						change: function(event, ui){
670
							$(this).parent().parent().find('.slider-user-min').find('span').html(ui.values[0]);
671
							$(this).parent().parent().find('.slider-user-max').find('span').html(ui.values[1]);
672
							slidermove(myFilter.name,ui.values[0],ui.values[1]);
673
						}
674
					});
675
				});
676
			}
677
		}
678
	}
679
	else{
680
		$(container).css("width","0px");
681
	}
682
}
683

    
684
function slidermove(field,min,max){
685
	var myfilters = selectedData['filters'];
686
	var len = myfilters.length;
687
	for(var i=0;i<len;i++){
688
		if(myfilters[i]['name'] == field){
689
			myfilters[i]['min'] = min;
690
			myfilters[i]['max'] = max;
691
			break;
692
		}
693
	}	
694

    
695

    
696
	//ajax call to get the new data
697
	$.ajax({  
698
	   type: "GET",  
699
	   url: "ajaxRouter9.php",
700
	   data: "com=query&type=chart&data="+encodeURIComponent(JSON.stringify(selectedData)),  
701
	   success: function(resp){  
702
		 // we have the response 
703
		chartDataFromServer = JSON.parse(resp);
704
		renderChart();
705
		},  
706
	   error: function(e){  
707
		 alert('Error: ' + e);  
708
	   }
709
	});
710
}
711
</script>
712
</head>
713
<body>
714
<div id="filters"></div>
715
<div id="charts-main" style="margin-right:10px;float:left">
716
	<div id='chart' style="width:95%;height:95%;margin:auto;"></div>
717
	<div id='chart2' style="width:95%;height:95%;margin:auto;display:none;"><!-- SECTION FOR THE GRAPHIC --></div>
718

    
719
	<div id="selections" style="width:95%;height:5%;margin:auto;text-align:center;font-family:Verdana;font-size:small;color:#000"></div>
720
	<div id='credits'></div>
721
	<div id='zoommessage'>select an area to zoom in</div>
722
</div>
723
</body>
724
</html>
725

    
(5-5/28)