Project

General

Profile

1 38716 eri.katsar
<!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
if(!isset($_GET['persistent'])){
21
22
     $persistent="true";
23
}
24
else
25
{
26
$persistent="false";
27
}
28
$selectedData = json_encode($_GET['data']);
29
$resp = $controller->makeQuery('chart',$persistent);
30
31
//echo "selected ".json_encode($_GET['data'],JSON_NUMERIC_CHECK);
32
//each filter to be included get its data and build the json object for the javascript
33
//echo "will include ".count($_GET['data']['incfilters'])." filters";
34
35
$myData = json_decode($_GET['data']);
36
37
if(isset($myData->incfilters))
38
	$myfilters = $myData->incfilters;
39
else
40
	$myfilters = array();
41
42
43
for($i=0;$i<count($myfilters);$i++){
44
	if(isset($myfilters[$i]->values) && $myfilters[$i]->values=='all'){
45
		$temp = $controller->getFilterData($myData->table,$myfilters[$i]->name);
46
		if(!is_array($temp)){
47
			$temp = json_decode($temp);
48
		}
49
		//print_r($temp->data);
50
		$myfilters[$i]->values = $temp->data;
51
	}
52
}
53
54
?>
55
<head>
56
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
57
<title>chart</title>
58
<!-- Include JQuery Core-->
59
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
60
<script type="text/javascript" src="./js/jquery-ui-1.9.1.custom/js/jquery-ui-1.9.1.custom.js"></script>
61
62
<!-- HighCharts -->
63
<script src="./js/Highcharts-4.0.1/js/highcharts.js" type="text/javascript"></script>
64
<script src="./js/Highcharts-4.0.1/js/modules/exporting.js" type="text/javascript"></script>
65
66
67
68
<script src="./js/themes9.js" type="text/javascript"></script>
69
<!--Styles-->
70
<link rel="stylesheet" href="//code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
71
<link type="text/css" href="./js/jquery/css/start/jquery-ui-1.8.20.custom.css" />
72
<link type="text/css" href="./js/highcharts.css" rel="stylesheet" />
73
<link rel="stylesheet" href="js/filters.css" />
74
75
<!--
76
<script src="http://code.highcharts.com/highcharts.js"></script>
77
<script src="http://code.highcharts.com/modules/data.js"></script>
78
<script src="http://code.highcharts.com/modules/exporting.js"></script>
79
-->
80
81
82
<script type='text/javascript'>
83
var chart;
84
var chart2;
85
var chartData;
86
var chartData2;
87
var chartDataFromServer;
88
var selectedData;
89
var filterData;
90
var myFilter;
91
//----------------- inits --------------------//
92
var wflag = <?php if(isset($_GET['w']) && $_GET['w']!='' && $_GET['w'][strlen($_GET['w'])-1] == '%'){ echo "true"; }
93
               	  else{ echo "false"; }?>
94
95
var mywidth =  <?php if(isset($_GET['w']) && $_GET['w']!=''){
96
			if($_GET['w'][strlen($_GET['w'])-1] == '%'){
97
				echo substr($_GET['w'],0,strlen($_GET['w'])-1);
98
99
			}else{
100
				if($_GET['w'][strlen($_GET['w'])-1] == 'x'){
101
					echo substr($_GET['w'],0,strlen($_GET['w'])-2);
102
				}else echo $_GET['w'];
103
			}
104
		    }else echo '700'; ?>;
105
106
var hflag = <?php if(isset($_GET['h']) && $_GET['h']!='' && $_GET['h'][strlen($_GET['h'])-1] == '%'){ echo "true"; }
107
                  else{ echo "false"; }?>
108
109
var myheight =  <?php if(isset($_GET['h']) && $_GET['h']!=''){
110
                        if($_GET['h'][strlen($_GET['h'])-1] == '%'){
111
                                echo substr($_GET['h'],0,strlen($_GET['h'])-1);
112
			}else{
113
                                if($_GET['w'][strlen($_GET['h'])-1] == 'x'){
114
                                        echo substr($_GET['h'],0,strlen($_GET['h'])-2);
115
                                } else echo $_GET['h'];
116
                        }
117
                      }else echo '500'; ?>;
118
119
//----------------- document ready --------------------//
120
$('document').ready(function(){
121
	chartDataFromServer = <?php echo $resp ?>;
122
	selectedData = $.parseJSON(<?php echo $selectedData;?>);
123
	filterData = <?php echo json_encode($myfilters);?>;
124
125
	renderChart();
126
	renderfilters();
127
	controlsforfilters();
128
});
129
130
function renderChart(){
131
132
	if(selectedData['in'] != undefined && selectedData['in'].length>0){
133
		if(chartDataFromServer[0].plotOptions != undefined && chartDataFromServer[0].plotOptions.series != undefined){
134
	 	       chartDataFromServer[0].plotOptions.series.events = new Object();
135
		       chartDataFromServer[0].plotOptions.series.events.checkboxClick = function(event){if(event.checked == true) this.show(); else this.hide();};
136
		}
137
		if(chartDataFromServer[1].plotOptions != undefined && chartDataFromServer[1].plotOptions.series != undefined){
138
		        chartDataFromServer[1].plotOptions.series.events = new Object();
139
	        	chartDataFromServer[1].plotOptions.series.events.checkboxClick = function(event){if(event.checked == true) this.show(); else this.hide();};
140
		}
141
		chartData = chartDataFromServer[0];
142
		chartData2 = chartDataFromServer[1];
143
		setSelections();
144
	}
145
	else{
146
		if(chartDataFromServer.plotOptions != undefined && chartDataFromServer.plotOptions.series != undefined){
147
		        chartDataFromServer.plotOptions.series.events = new Object();
148
			chartDataFromServer.plotOptions.series.events.checkboxClick = function(event){if(event.checked == true) this.show(); else this.hide();};
149
		}
150
		chartData = chartDataFromServer;
151
	}
152
	var formatter = chartData.xAxis.labels.formatter;
153
	if(selectedData['emp'] == undefined)
154
		selectedData['emp'] = new Array();
155
	else{
156
			chartData.xAxis.plotLines = new Array();
157
		for(var e=0;e<selectedData['emp'].length;e++){
158
			var line = new Object();
159
			line.value = chartData['xAxis']['categories'].indexOf(selectedData['emp'][e]);
160
			line.width = 1;
161
			line.color = 'red';
162
			line.dashStyle = 'dash';
163
			line.zIndex = 100;
164
			chartData.xAxis.plotLines.push(line);
165
		}
166
	}
167
168
	if(selectedData['bands'] != undefined){
169
		chartData['xAxis']['plotBands'] = new Array();
170
		for(var b=0;b<selectedData['bands'].length;b++){
171
			var band = new Object();
172
			band.color = '#FCFFC5';
173
			var from = chartData.xAxis.categories.indexOf(selectedData['bands'][b][0]);
174
			var to = chartData.xAxis.categories.indexOf(selectedData['bands'][b][1]);
175
			band.from = from;
176
			band.to = (to==-1)? chartData.xAxis.categories.length:to;
177
			band.zIndex = -100;
178
			chartData.xAxis.plotBands.push(band);
179
		}
180
	}
181
182
	if(selectedData['xStyle'] != undefined){
183
		chartData.xAxis.labels = labelsforx(selectedData['xStyle'],selectedData['emp']);
184
	}
185
	else{
186
		var temp = new Object(); temp['r'] = '-'; temp['s'] = '-'; temp['l'] = '-';
187
		chartData.xAxis.labels = labelsforx(temp,selectedDatap['emp']);
188
	}
189
190
	//headers!!!!
191
	if(typeof selectedData['title'] != 'undefined'  && selectedData['title']!=''){
192
		chartData.title = new Object();
193
		chartData.title.text = selectedData['title'];
194
		chartData.title.align = 'center';
195
	}
196
	else{
197
		chartData.title.text = null;
198
	}
199
	if(selectedData['subtitle']!=''){
200
		chartData.subtitle = new Object();
201
		chartData.subtitle.text = selectedData['subtitle'];
202
	}
203
	else{
204
		chartData.subtitle = null;
205
	}
206
207
208
	if(selectedData['fields'].length == 1 && selectedData['fields'][0]['type'] == 'pie'){
209
		chartData.xAxis.title.text = null;
210
		chartData.yAxis[0].title.text = null;
211
		$("#zoommessage").hide();
212
	}
213
214
	//chartData.xAxis.title.text = selectedData['xaxis']['name'];
215
	var today = new Date();
216
	var dd = today.getDate();
217
	var mm = today.getMonth()+1; //January is 0!
218
219
	var yyyy = today.getFullYear();
220
	chartData.credits.text = "from OpenAIRE via HighCharts (date: " + dd + "/" + mm + "/" + yyyy +")";
221
222
	if(selectedData['stacking']!=undefined){
223
                chartData['plotOptions']['column']['stacking'] = selectedData['stacking'];
224
                chartData['plotOptions']['area']['stacking'] = selectedData['stacking'];
225
                chartData['plotOptions']['areaspline']['stacking'] = selectedData['stacking'];
226
        }
227
228
	chartData.plotOptions['pie']['dataLabels']['formatter'] = function() {
229
		return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 2) +' %';
230
	};
231
232
	if(chartData.series.length > 4){
233
		chartData.legend.layout = 'horizontal';
234
		chartData.legend.align = 'center';
235
		chartData.legend.verticalAlign = 'bottom';
236
		chartData.legend.x = null;
237
		chartData.legend.y = null;
238
		chartData.legend.floating = false;
239
		//chartData.legend.itemStyle = new Object();
240
		//chartData.legend.itemStyle.margin = "4px";
241
	}
242
243
	if(selectedData['type'] == 'scatter'){
244
		if(selectedData['color'] == 'yes')
245
			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 ;};
246
		else if(selectedData['group'] != '')
247
			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 ;};
248
		else
249
			chartData.tooltip.formatter = function() { return chartData['xAxis']['title']['text']+ ': '+ this.x +'<br/>'+ chartData['yAxis'][0]['title']['text']+': '+ this.y ;};
250
		chartData['chart']['type'] = 'scatter';
251
	}
252
	else {
253
			chartData.tooltip.percentageDecimals = 1;
254
			chartData.tooltip.valueDecimals = 1;
255
			 if(selectedData['fields'][0]['type'] != 'pie'){
256
                                //chartData.tooltip.headerFormat = '<span style="font-size:10px">{point.key}</span><table>';
257
                                //chartData.tooltip.pointFormat = '<tr><td style="color:{series.color};padding:0">{series.name}:</td>'+'<td style="padding:0"><b>{point.y}</b></td></tr>';
258
                                //chartData.tooltip.footerFormat = '</table>';
259
                                chartData.tooltip.shared = true;
260
                                chartData.tooltip.useHTML = true;
261
                        }
262
                        //else
263
			chartData.tooltip.formatter = function() {
264
				if(selectedData['fields'][0]['type']!='pie'){
265
					/*//var ind = chart.xAxis[0].categories.indexOf(this.x);
266
					var str = '';
267
					if(this.point.config.name)
268
						str += '<b>'+ this.point.co/docu/nfig.name +'</b><br/>';
269
					//str += this.x + '<br />';
270
					//var myseries = chart.series;
271
					//for(var i=0;i<myseries.length;i++){
272
					//	str += myseries[i].name + ":" + numberWithCommas(myseries[i].data[ind].y) + "<br />";
273
					//}
274
					str += this.series.name + ': '+ '<b>' + numberWithCommas(this.y) + '</b><br/>';
275
					str += chart.xAxis[0].axisTitle.textStr + ": <b>" + this.x + '</b>';
276
					return str;*/
277
					var s = '<b>'+ this.x +'</b>';
278
279
                			$.each(this.points, function(i, point) {
280
                    				s += '<br/><span style="color:'+point.series.color+'">'+ point.series.name +'</span>: '+
281
                        			numberWithCommas(point.y);
282
                			});
283
284
                			return s;
285
				}
286
				else{
287
					var name;
288
					if(selectedData['fieldsheaders'].length >0)
289
						name = selectedData['fieldsheaders'][0];
290
					else if(selectedData['yaxisheaders'].length>0)
291
						name = selectedData['yaxisheaders'][0];
292
					else
293
						name = "number";
294
					return '<b>'+ this.point.config.name +'</b>: ' + Highcharts.numberFormat(this.percentage, 2) +' %<br/>(' + name + ": " + numberWithCommas(this.y) +")";
295
				}
296
			};
297
		if(selectedData['fields'].length==1)
298
			chartData['chart']['type'] = selectedData['fields'][0]['type'];
299
300
	}
301
	if('theme' in selectedData){
302
		highchartsOptions = Highcharts.setOptions(themes[selectedData['theme']][1]);
303
	}
304
	else
305
		highchartsOptions = Highcharts.setOptions(themes[0][1]);
306
307
308
//    alert('document width ' + $(document).width()  + 'and height ' + $(document).height()  ' and chart width' + chartData.chart.width);
309
310
	if(mywidth>0){
311
		if(wflag)
312
			chartData.chart.width = mywidth * $(document).width() /100;
313
		else
314
			chartData.chart.width = mywidth;
315
	}
316
	else
317
		chartData.chart.width = 90 * $(document).width() / 100;
318
	if(myheight>0){
319
                if(hflag)
320
                        chartData.chart.height = myheight * $(document).height() /100;
321
                else
322
                        chartData.chart.height = myheight;
323
        }
324
	else
325
		chartData.chart.height = 80 * $(document).height() /100;
326
327
	chartData.exporting = JSON.parse( '{ "url" : "<?php echo $export_server ?>" }');
328
329
	chart = new Highcharts.Chart(chartData, function(chart){
330
		var series = chart.series;
331
		var i=0;
332
		for(; i<series.length; i++){
333
			if( series[i].legendItem && series[i].checkbox) {
334
        			series[i].checkbox.style.marginLeft = '18px';
335
    			}
336
		}
337
	});
338
339
340
	//chart.setSize(mywidth, myheight, false);
341
	//alert(JSON.stringify(chartData));
342
	if(selectedData['in'] != undefined && selectedData['in'].length>0){
343
		if(chartData.xAxis.labels != undefined) chartData2.xAxis.labels = chartData.xAxis.labels
344
		if(chartData.title != undefined) {chartData2.title = new Object(); chartData2.title.text = chartData.title.text;}
345
		if(chartData.subtitle != undefined) {chartData2.subtitle = new Object(); chartData2.subtitle.text = chartData.subtitle.text;}
346
		chartData2.xAxis.title.text = chartData.xAxis.title.text;
347
		chartData2.yAxis[0].title.text = chartData.yAxis[0].title.text;
348
		chartData2.credits.text = chartData.credits.text;
349
		chartData2.plotOptions['pie']['dataLabels']['formatter'] = chartData.plotOptions['pie']['dataLabels']['formatter'];
350
		chartData2.tooltip = chartData.tooltip;
351
		chartData2['chart']['type'] = chartData['chart']['type'];
352
		chartData2['chart']['renderTo'] = 'chart2';
353
		chartData2['xAxis']['plotLines'] = chartData['xAxis']['plotLines'];
354
		chartData2['xAxis']['plotBands'] = chartData['xAxis']['plotBands'];
355
		if(chartData['chart']['height'] != undefined)
356
			chartData2['chart']['height'] = chartData['chart']['height'];
357
		if(chartData['chart']['width'] != undefined)
358
			chartData2['chart']['width'] = chartData['chart']['width'];
359
		if(selectedData['xStyle'] != undefined){
360
		        chartData2.xAxis.labels = labelsforx(selectedData['xStyle'],selectedData['emp']);
361
		}
362
		else{
363
		        var temp = new Object(); temp['r'] = '-'; temp['s'] = '-'; temp['l'] = '-';
364
		        chartData2.xAxis.labels = labelsforx(temp,selectedData['emp']);
365
		}
366
		if(selectedData['stacking']!=undefined){
367
		        chartData2['plotOptions']['column']['stacking'] = selectedData['stacking'];
368
		        chartData2['plotOptions']['area']['stacking'] = selectedData['stacking'];
369
		        chartData2['plotOptions']['areaspline']['stacking'] = selectedData['stacking'];
370
		}
371
372
		if(chartData2.series.length > 4)
373
                	chartData2.legend = chartData.legend;
374
		//chartData.plotOptions.column.pointWidth = 30;
375
		//chartData2.plotOptions.column.pointWidth = 30;
376
		chart2 = new Highcharts.Chart(chartData2, function(chart2){
377
	        	var series = chart2.series;
378
	        	var i=0;
379
	        	for(; i<series.length; i++){
380
	        	        if( series[i].legendItem && series[i].checkbox) {
381
	        	                series[i].checkbox.style.marginLeft = '18px';
382
	        	        }
383
	        	}
384
		});
385
386
	}
387
//exporting: { enabled: false }
388
389
//chartData['plotOptions']['exporting']['enabled']='false';
390
391
	credits();
392
}
393
394
395
function setSelections(){
396
	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" ;
397
	$("#selections").empty().append(str);
398
399
	$("input[name='sel']").live("click",function(){
400
		if($(this).val() == "cumulate"){
401
			$("#chart").hide();
402
			$("#chart2").show();
403
		}
404
		else{
405
			$("#chart2").hide();
406
			$("#chart").show();
407
		}
408
	});
409
}
410
411
function controlsforfilters(){
412
	$("a.all").live("click",function(){
413
		$(this).siblings('.filterForm').find('input').attr("checked","checked");
414
		newValues($(this).siblings('.filterForm').find('input')[0]);
415
		return false;
416
	});
417
418
	$("a.none").live("click",function(){
419
                $(this).siblings('.filterForm').find('input').removeAttr("checked");
420
		newValues($(this).siblings('.filterForm').find('input')[0]);
421
		return false;
422
        });
423
424
	$(".formContainer input").live("click",function(){
425
		newValues(this);
426
	});
427
}
428
429
function newValues(obj){
430
	var field = $(obj).parent().attr('id');
431
	var myfilters = selectedData['filters'];
432
	var thisfilter;
433
	for(var i=0;i<selectedData['incfilters'].length;i++){
434
		if(selectedData['incfilters'][i]['name'] == field){
435
			thisfilter = selectedData['incfilters'][i];
436
			break;
437
		}
438
	}
439
440
	//change the url params
441
	//if is it checked
442
	if($(obj).is(":checked")){
443
		$(obj).parents(".filter").find("a.none").show();
444
		var flag = false;
445
		var i;
446
		for(i=0;i<myfilters.length;i++){
447
			if(myfilters[i]['name'] == field){
448
				flag=true;
449
				break;
450
			}
451
		}
452
		//if there is already such a filter delete all values and insert all the checked
453
		if(flag){
454
			myfilters[i].values = new Array();
455
			$(obj).parent().find("input:checked").each(function(){
456
				myfilters[i].values.push($(this).val());
457
			});
458
			//myfilters[i].values.push($(obj).val());
459
		}
460
		//if there is no such filter
461
		else{
462
			//create one
463
			var newfilter = new Object();
464
			newfilter.name = field;
465
			newfilter.values = new Array();
466
			var ch = $(obj).parent().find("input:checked");
467
			$(ch).each(function(){
468
				newfilter.values.push($(this).val());
469
			});
470
			//newfilter.values[0] = $(obj).val();
471
			myfilters.push(newfilter);
472
		}
473
	}
474
	//if it was unchecked
475
	else{
476
		//there should be already such a filter
477
		var flag = false;
478
                var i;
479
                for(i=0;i<myfilters.length;i++){
480
                        if(myfilters[i]['name'] == field){
481
                                flag=true;
482
                                break;
483
                        }
484
                }
485
		//remove the value
486
                if($(obj).parent().find("input:checked").length == 0){
487
                        $(obj).parents(".filter").find("a.none").hide();
488
                        myfilters[i].values = new Array();
489
                }
490
                else{
491
                        var j;
492
                        for(j=0;j<myfilters[i].values.length;j++){
493
                                if(myfilters[i].values[j] == $(obj).val()){
494
                                        myfilters[i].values.splice(j,1);
495
                                        break;
496
                                }
497
                        }
498
                }
499
500
501
		//if no more values, add the values in the incfilter list and if it is all remove the filter
502
		if(myfilters[i].values.length == 0){
503
			if(thisfilter.values[0]=="all")
504
				myfilters.splice(i,1);
505
			else
506
				myfilters[i].values = thisfilter.values;
507
		}
508
	}
509
	//ajax call to get the new data
510
	$.ajax({
511
	   type: "GET",
512
	   url: "ajaxRouter9.php",
513
	   data: "com=query&type=chart&data="+encodeURIComponent(JSON.stringify(selectedData)),
514
	   success: function(resp){
515
		 // we have the response
516
		chartDataFromServer = JSON.parse(resp);
517
		renderChart();
518
		},
519
	   error: function(e){
520
		 alert('Error: ' + e);
521
	   }
522
	});
523
524
}
525
526
527
function labelsforx(style, emp){
528
	var st = Object();
529
	st.justify = null;
530
	st.style = Array();
531
	st.style['font-size'] = '8px';
532
	st.formatter = null;
533
534
	if(style['r'] != null && style['r'] != "-"){
535
		st.rotation = style['r'];
536
		st.y =25;
537
	}
538
	if(style['s'] != null && style['s'] != "-")
539
		st.step = style['s'];
540
	if(style['l'] != null && style['l'] != "-")
541
		st.staggerLines = style['l'];
542
543
	if(style['ft'] != null && style['ft'] != "-"){
544
		if(style['wt'] != null && style['wt'] != "-")
545
			st.formatter = function(){
546
				eflag = false;
547
				for(var e=0;e<emp.length;e++){
548
                                	if(this.value == emp[e]){
549
                                        	eflag = true;
550
                                                break;
551
                                        }
552
                                }
553
554
				if (typeof this.value == 'string' || this.value instanceof String){
555
					var ar = this.value.split(" ");
556
					var str = '';
557
					if(ar.length == 1){
558
						if(eflag) return '<span style="fill:red;">' + this.value.substr(0,selectedData['xStyle']['ft']) + '</span>';
559
						else return this.value.substr(0,selectedData['xStyle']['ft']);
560
					}
561
					for(var i=0;i<ar.length;i++) {
562
						str +=ar[i].substr(0,selectedData['xStyle']['wt'])+' ';
563
					}
564
					if(eflag) return '<span style="fill:red;">' + str.substr(0,selectedData['xStyle']['ft']) + '</span>';
565
					else return str.substr(0,selectedData['xStyle']['ft']);
566
				}
567
				else
568
					if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
569
			};
570
		else
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
580
				if (typeof this.value == 'string' || this.value instanceof String){
581
					if(this.value.length>selectedData['xStyle']['ft'])
582
						if(eflag) return '<span style="fill:red;">' + this.value.substr(0,selectedData['xStyle']['ft']) + "..." + '</span>';
583
						else return this.value.substr(0,selectedData['xStyle']['ft']) + "...";
584
					else
585
						if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
586
						else return this.value;
587
				}
588
				else return this.value;
589
			};
590
	}
591
	else if(style['wt'] != null && style['wt'] != "-")
592
		st.formatter = function(){
593
				eflag = false;
594
                                for(var e=0;e<emp.length;e++){
595
                                        if(this.value == emp[e]){
596
                                                eflag = true;
597
                                                break;
598
                                        }
599
                                }
600
				if (typeof this.value == 'string' || this.value instanceof String){
601
					var ar = this.value.split(" ");
602
					var str = '';
603
					if(ar.length == 1)
604
						if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
605
 						else return this.value;
606
					for(var i=0;i<ar.length;i++) {
607
						str +=ar[i].substr(0,selectedData['xStyle']['wt'])+' ';
608
					}
609
					if(eflag) return '<span style="fill:red;">' + str + '</span>';
610
					else return str
611
				}
612
				else
613
					if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
614
			};
615
	else{
616
		st.formatter = function(){
617
                	for(var e=0;e<emp.length;e++){
618
                        	if(this.value == emp[e]){
619
					return '<span style="fill:red;">' + this.value + '</span>';
620
                                }
621
                        }
622
			return this.value;
623
		};
624
	}
625
	return st;
626
}
627
628
function isInt(n) {
629
   return typeof n === 'number' && n % 1 == 0;
630
}
631
632
function numberWithCommas(num){
633
	if(isInt(num)){
634
		var array = num.toString().split('');
635
		var index = -3;
636
		var len = array.length;
637
		while((len + index) > 0){
638
			array.splice(index, 0 , ',');
639
			index -= 4;
640
		}
641
		return array.join('');
642
	}
643
	else
644
		return Math.round(num*100)/100;
645
}
646
647
function credits(){
648
	var today = new Date();
649
	var dd = today.getDate();
650
	var mm = today.getMonth()+1; //January is 0!
651
	var yyyy = today.getFullYear();
652
	var cr = document.getElementById("credits");
653
	cr.innerHTML = "from OpenAIRE via HighCharts (date: " + dd + "/" + mm + "/" + yyyy +")";
654
}
655
656
function renderfilters(){
657
	var container = document.getElementById("filters");
658
	if(filterData!=null){
659
		var len = filterData.length;
660
		for(var i=0;i<len;i++){
661
			//checkboxes
662
			if(filterData[i].values != undefined){
663
				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'>";
664
				for(var v=0;v<filterData[i].values.length;v++){
665
					str+="<input type='checkbox' value='"+filterData[i].values[v]+"' name='form"+filterData[i].name+"'>"+filterData[i].values[v]+"<br>";
666
				}
667
				str +=	"</form></div></div></div>";
668
				$(container).append(str);
669
			}
670
			//slider
671
			else{
672
				var str = "<div class='filter'><div class='filterHeader'><p>"+filterData[i].showname+"</p><input type='hidden' value='"+filterData[i].name+"' class='filtername'/></div>";
673
				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>";
674
675
				str += "<span class='price-tip slider-user-min'><span id='userMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
676
				str += "<span class='price-tip slider-user-max'><span id='userMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
677
				str += "<span class='min' style='display:none'><span id='productMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
678
				str += "<span class='max' style='display:none'><span id='productMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
679
				str += "</div></div>";
680
				$(container).append(str);
681
				myFilter = filterData[i];
682
				$(function(){
683
					$("#slider"+myFilter.name).slider({
684
						step: 1,
685
						range: true,
686
						min: parseInt(myFilter['min']),
687
						max: parseInt(myFilter['max']),
688
						values: [parseInt(myFilter['min']), parseInt(myFilter['max'])],
689
						change: function(event, ui){
690
							$(this).parent().parent().find('.slider-user-min').find('span').html(ui.values[0]);
691
							$(this).parent().parent().find('.slider-user-max').find('span').html(ui.values[1]);
692
							slidermove(myFilter.name,ui.values[0],ui.values[1]);
693
						}
694
					});
695
				});
696
			}
697
		}
698
	}
699
	else{
700
		$(container).css("width","0px");
701
	}
702
}
703
704
function slidermove(field,min,max){
705
	var myfilters = selectedData['filters'];
706
	var len = myfilters.length;
707
	for(var i=0;i<len;i++){
708
		if(myfilters[i]['name'] == field){
709
			myfilters[i]['min'] = min;
710
			myfilters[i]['max'] = max;
711
			break;
712
		}
713
	}
714
715
716
	//ajax call to get the new data
717
	$.ajax({
718
	   type: "GET",
719
	   url: "ajaxRouter9.php",
720
	   data: "com=query&type=chart&data="+encodeURIComponent(JSON.stringify(selectedData)),
721
	   success: function(resp){
722
		 // we have the response
723
		chartDataFromServer = JSON.parse(resp);
724
		renderChart();
725
		},
726
	   error: function(e){
727
		 alert('Error: ' + e);
728
	   }
729
	});
730
}
731
</script>
732
</head>
733
<body>
734
<div id="filters"></div>
735
<div id="charts-main" style="margin-right:10px;float:left">
736
	<div id='chart' style="width:95%;height:95%;margin:auto;"></div>
737
	<div id='chart2' style="width:95%;height:95%;margin:auto;display:none;"><!-- SECTION FOR THE GRAPHIC --></div>
738
739
	<div id="selections" style="width:95%;height:5%;margin:auto;text-align:center;font-family:Verdana;font-size:small;color:#000"></div>
740
	<div id='credits'></div>
741
	<div id='zoommessage'>select an area to zoom in</div>
742
</div>
743
</body>
744
</html>