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
		return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 2) +' %';
213
	};
214

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

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

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

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

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

    
290

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

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

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

    
322

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

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

    
369
	}
370
	credits();
371
}
372

    
373

    
374
function setSelections(){
375
	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" ;
376
	$("#selections").empty().append(str);
377

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

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

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

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

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

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

    
479

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

    
503
}
504

    
505

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

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

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

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

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

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

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

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

    
635
function renderfilters(){
636
	var container = document.getElementById("filters");
637
	if(filterData!=null){
638
		var len = filterData.length;
639
		for(var i=0;i<len;i++){
640
			//checkboxes
641
			if(filterData[i].values != undefined){
642
				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'>";
643
				for(var v=0;v<filterData[i].values.length;v++){
644
					str+="<input type='checkbox' value='"+filterData[i].values[v]+"' name='form"+filterData[i].name+"'>"+filterData[i].values[v]+"<br>";
645
				}
646
				str +=	"</form></div></div></div>";
647
				$(container).append(str);
648
			}
649
			//slider
650
			else{
651
				var str = "<div class='filter'><div class='filterHeader'><p>"+filterData[i].showname+"</p><input type='hidden' value='"+filterData[i].name+"' class='filtername'/></div>";
652
				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>";
653

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

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

    
694

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

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

    
(5-5/29)