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
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.config.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

    
311

    
312
if(mywidth>0)
313
{
314
		if(wflag)
315
			chartData.chart.width = mywidth * $(document).width() /100;
316
		else
317
			chartData.chart.width = mywidth;
318
	}
319
else{
320
	 chartData.chart.width = 90 * $(document).width() / 100;
321
	
322
}
323
 
324
      if(myheight>0){
325
                if(hflag)
326
                        chartData.chart.height = myheight * $(document).height() /100;
327
                else
328
                        chartData.chart.height = myheight;
329
       }
330
	else
331
	{chartData.chart.height = 80 * $(document).height() /100;
332
}
333

    
334

    
335
	chartData.exporting = JSON.parse( '{ "url" : "<?php echo $export_server ?>" }');
336
	
337
	chart = new Highcharts.Chart(chartData, function(chart){
338
		var series = chart.series;
339
		var i=0;
340
		for(; i<series.length; i++){
341
			if( series[i].legendItem && series[i].checkbox) {
342
        			series[i].checkbox.style.marginLeft = '18px';
343
    			}
344
		}
345
	});
346

    
347

    
348
	//chart.setSize(mywidth, myheight, false);
349
	//alert(JSON.stringify(chartData));
350
	if(selectedData['in'] != undefined && selectedData['in'].length>0){
351
		if(chartData.xAxis.labels != undefined) chartData2.xAxis.labels = chartData.xAxis.labels
352
		if(chartData.title != undefined) {chartData2.title = new Object(); chartData2.title.text = chartData.title.text;}
353
		if(chartData.subtitle != undefined) {chartData2.subtitle = new Object(); chartData2.subtitle.text = chartData.subtitle.text;}
354
		chartData2.xAxis.title.text = chartData.xAxis.title.text;
355
		chartData2.yAxis[0].title.text = chartData.yAxis[0].title.text;
356
		chartData2.credits.text = chartData.credits.text;
357
		chartData2.plotOptions['pie']['dataLabels']['formatter'] = chartData.plotOptions['pie']['dataLabels']['formatter'];
358
		chartData2.tooltip = chartData.tooltip;
359
		chartData2['chart']['type'] = chartData['chart']['type'];
360
		chartData2['chart']['renderTo'] = 'chart2';
361
		chartData2['xAxis']['plotLines'] = chartData['xAxis']['plotLines'];
362
		chartData2['xAxis']['plotBands'] = chartData['xAxis']['plotBands'];
363
		if(chartData['chart']['height'] != undefined)
364
			chartData2['chart']['height'] = chartData['chart']['height'];
365
		if(chartData['chart']['width'] != undefined)
366
			chartData2['chart']['width'] = chartData['chart']['width'];
367
		if(selectedData['xStyle'] != undefined){
368
		        chartData2.xAxis.labels = labelsforx(selectedData['xStyle'],selectedData['emp']);
369
		}
370
		else{
371
		        var temp = new Object(); temp['r'] = '-'; temp['s'] = '-'; temp['l'] = '-';
372
		        chartData2.xAxis.labels = labelsforx(temp,selectedData['emp']);
373
		}
374
		if(selectedData['stacking']!=undefined){
375
		        chartData2['plotOptions']['column']['stacking'] = selectedData['stacking'];
376
		        chartData2['plotOptions']['area']['stacking'] = selectedData['stacking'];
377
		        chartData2['plotOptions']['areaspline']['stacking'] = selectedData['stacking'];
378
		}
379

    
380
		if(chartData2.series.length > 4)
381
                         chartData2.legend = chartData.legend;
382
//chartData2.plotOptions.column.pointWidth = 30;
383
		chart2 = new Highcharts.Chart(chartData2, function(chart2){
384
	        	var series = chart2.series;
385
	        	var i=0;
386
	        	for(; i<series.length; i++){
387
	        	        if( series[i].legendItem && series[i].checkbox) {
388
	        	                series[i].checkbox.style.marginLeft = '18px';
389
	        	        }
390
	        	}
391
		});
392

    
393
	}
394
//exporting: { enabled: false }
395

    
396
//chartData['plotOptions']['exporting']['enabled']='false';
397

    
398
	credits();
399
}
400

    
401

    
402
function setSelections(){
403
	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" ;
404
	$("#selections").empty().append(str);
405

    
406
	$("input[name='sel']").live("click",function(){
407
		if($(this).val() == "cumulate"){
408
		$("#chart").hide();		
409
			$("#chart2").show();
410
		}
411
		else{
412
			$("#chart2").hide();
413
			$("#chart").show();
414
		}
415
	});
416
}
417

    
418
function controlsforfilters(){
419
	$("a.all").live("click",function(){
420
		$(this).siblings('.filterForm').find('input').attr("checked","checked");
421
		newValues($(this).siblings('.filterForm').find('input')[0]);
422
		return false;
423
	});
424

    
425
	$("a.none").live("click",function(){
426
                $(this).siblings('.filterForm').find('input').removeAttr("checked");
427
		newValues($(this).siblings('.filterForm').find('input')[0]);
428
		return false;
429
        });
430

    
431
	$(".formContainer input").live("click",function(){
432
		newValues(this);
433
	});
434
}
435

    
436
function newValues(obj){
437
	var field = $(obj).parent().attr('id');
438
	var myfilters = selectedData['filters'];
439
	var thisfilter;
440
	for(var i=0;i<selectedData['incfilters'].length;i++){
441
		if(selectedData['incfilters'][i]['name'] == field){
442
			thisfilter = selectedData['incfilters'][i];
443
			break;
444
		}
445
	}
446

    
447
	//change the url params
448
	//if is it checked
449
	if($(obj).is(":checked")){
450
		$(obj).parents(".filter").find("a.none").show();
451
		var flag = false;
452
		var i;
453
		for(i=0;i<myfilters.length;i++){
454
			if(myfilters[i]['name'] == field){
455
				flag=true;
456
				break;
457
			}
458
		}
459
		//if there is already such a filter delete all values and insert all the checked
460
		if(flag){
461
			myfilters[i].values = new Array();
462
			$(obj).parent().find("input:checked").each(function(){
463
				myfilters[i].values.push($(this).val());
464
			});
465
			//myfilters[i].values.push($(obj).val());
466
		}
467
		//if there is no such filter
468
		else{
469
			//create one
470
			var newfilter = new Object();
471
			newfilter.name = field;
472
			newfilter.values = new Array();
473
			var ch = $(obj).parent().find("input:checked");
474
			$(ch).each(function(){
475
				newfilter.values.push($(this).val());
476
			});
477
			//newfilter.values[0] = $(obj).val();
478
			myfilters.push(newfilter);
479
		}
480
	}
481
	//if it was unchecked
482
	else{
483
		//there should be already such a filter
484
		var flag = false;
485
                var i;
486
                for(i=0;i<myfilters.length;i++){
487
                        if(myfilters[i]['name'] == field){
488
                                flag=true;
489
                                break;
490
                        }
491
                }
492
		//remove the value
493
                if($(obj).parent().find("input:checked").length == 0){
494
                        $(obj).parents(".filter").find("a.none").hide();
495
                        myfilters[i].values = new Array();
496
                }
497
                else{
498
                        var j;
499
                        for(j=0;j<myfilters[i].values.length;j++){
500
                                if(myfilters[i].values[j] == $(obj).val()){
501
                                        myfilters[i].values.splice(j,1);
502
                                        break;
503
                                }
504
                        }
505
                }
506

    
507

    
508
		//if no more values, add the values in the incfilter list and if it is all remove the filter
509
		if(myfilters[i].values.length == 0){
510
			if(thisfilter.values[0]=="all")
511
				myfilters.splice(i,1);
512
			else
513
				myfilters[i].values = thisfilter.values;
514
		}
515
	}
516
	//ajax call to get the new data
517
	$.ajax({
518
	   type: "GET",
519
	   url: "ajaxRouter9.php",
520
	   data: "com=query&type=chart&data="+encodeURIComponent(JSON.stringify(selectedData)),  
521
	   success: function(resp){
522
		 // we have the response
523
		chartDataFromServer = JSON.parse(resp);
524
		renderChart();
525
		},
526
	   error: function(e){
527
		 alert('Error: ' + e);
528
	   }
529
	});
530

    
531
}
532

    
533

    
534
function labelsforx(style, emp){
535
	var st = Object();
536
	st.justify = null;
537
	st.style = Array();
538
	st.style['font-size'] = '8px';
539
	st.formatter = null;
540

    
541
	if(style['r'] != null && style['r'] != "-"){
542
		st.rotation = style['r'];
543
		st.y =25;
544
	}
545
	if(style['s'] != null && style['s'] != "-")
546
		st.step = style['s'];
547
	if(style['l'] != null && style['l'] != "-")
548
		st.staggerLines = style['l'];
549

    
550
	if(style['ft'] != null && style['ft'] != "-"){
551
		if(style['wt'] != null && style['wt'] != "-")
552
			st.formatter = function(){
553
				eflag = false;
554
				for(var e=0;e<emp.length;e++){
555
                                	if(this.value == emp[e]){
556
                                        	eflag = true;
557
                                                break;
558
                                        }
559
                                }
560

    
561
				if (typeof this.value == 'string' || this.value instanceof String){
562
					var ar = this.value.split(" ");
563
					var str = '';
564
					if(ar.length == 1){
565
						if(eflag) return '<span style="fill:red;">' + this.value.substr(0,selectedData['xStyle']['ft']) + '</span>';
566
						else return this.value.substr(0,selectedData['xStyle']['ft']);
567
					}
568
					for(var i=0;i<ar.length;i++) {
569
						str +=ar[i].substr(0,selectedData['xStyle']['wt'])+' ';
570
					}
571
					if(eflag) return '<span style="fill:red;">' + str.substr(0,selectedData['xStyle']['ft']) + '</span>';
572
					else return str.substr(0,selectedData['xStyle']['ft']);
573
				}
574
				else
575
					if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
576
			};
577
		else
578
			st.formatter = function(){
579
				eflag = false;
580
                                for(var e=0;e<emp.length;e++){
581
                                        if(this.value == emp[e]){
582
                                                eflag = true;
583
                                                break;
584
                                        }
585
                                }
586

    
587
				if (typeof this.value == 'string' || this.value instanceof String){
588
					if(this.value.length>selectedData['xStyle']['ft'])
589
						if(eflag) return '<span style="fill:red;">' + this.value.substr(0,selectedData['xStyle']['ft']) + "..." + '</span>';
590
						else return this.value.substr(0,selectedData['xStyle']['ft']) + "...";
591
					else
592
						if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
593
						else return this.value;
594
				}
595
				else return this.value;
596
			};
597
	}
598
	else if(style['wt'] != null && style['wt'] != "-")
599
		st.formatter = function(){
600
				eflag = false;
601
                                for(var e=0;e<emp.length;e++){
602
                                        if(this.value == emp[e]){
603
                                                eflag = true;
604
                                                break;
605
                                        }
606
                                }
607
				if (typeof this.value == 'string' || this.value instanceof String){
608
					var ar = this.value.split(" ");
609
					var str = '';
610
					if(ar.length == 1)
611
						if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
612
 						else return this.value;
613
					for(var i=0;i<ar.length;i++) {
614
						str +=ar[i].substr(0,selectedData['xStyle']['wt'])+' ';
615
					}
616
					if(eflag) return '<span style="fill:red;">' + str + '</span>';
617
					else return str
618
				}
619
				else
620
					if(eflag) return '<span style="fill:red;">' + this.value + '</span>';
621
			};
622
	else{
623
		st.formatter = function(){
624
                	for(var e=0;e<emp.length;e++){
625
                        	if(this.value == emp[e]){
626
					return '<span style="fill:red;">' + this.value + '</span>';
627
                                }
628
                        }
629
			return this.value;
630
		};
631
	}
632
	return st;
633
}
634

    
635
function isInt(n) {
636
   return typeof n === 'number' && n % 1 == 0;
637
}
638

    
639
function numberWithCommas(num){
640
	if(isInt(num)){
641
		var array = num.toString().split('');
642
		var index = -3;
643
		var len = array.length;
644
		while((len + index) > 0){
645
			array.splice(index, 0 , ',');
646
			index -= 4;
647
		}
648
		return array.join('');
649
	}
650
	else
651
		return Math.round(num*100)/100;
652
}
653

    
654
function credits(){
655
	var today = new Date();
656
	var dd = today.getDate();
657
	var mm = today.getMonth()+1; //January is 0!
658
	var yyyy = today.getFullYear();
659
	var cr = document.getElementById("credits");
660
	cr.innerHTML = "from OpenAIRE via HighCharts (date: " + dd + "/" + mm + "/" + yyyy +")";
661
}
662

    
663
function renderfilters(){
664
	var container = document.getElementById("filters");
665
	if(filterData!=null){
666
		var len = filterData.length;
667
		for(var i=0;i<len;i++){
668
			//checkboxes
669
			if(filterData[i].values != undefined){
670
				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'>";
671
				for(var v=0;v<filterData[i].values.length;v++){
672
					str+="<input type='checkbox' value='"+filterData[i].values[v]+"' name='form"+filterData[i].name+"'>"+filterData[i].values[v]+"<br>";
673
				}
674
				str +=	"</form></div></div></div>";
675
				$(container).append(str);
676
			}
677
			//slider
678
			else{
679
				var str = "<div class='filter'><div class='filterHeader'><p>"+filterData[i].showname+"</p><input type='hidden' value='"+filterData[i].name+"' class='filtername'/></div>";
680
				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>";
681

    
682
				str += "<span class='price-tip slider-user-min'><span id='userMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
683
				str += "<span class='price-tip slider-user-max'><span id='userMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
684
				str += "<span class='min' style='display:none'><span id='productMin"+filterData[i].name+"'>"+filterData[i]['min']+"</span></span>";
685
				str += "<span class='max' style='display:none'><span id='productMax"+filterData[i].name+"'>"+filterData[i]['max']+"</span></span>";
686
				str += "</div></div>";
687
				$(container).append(str);
688
				myFilter = filterData[i];
689
				$(function(){
690
					$("#slider"+myFilter.name).slider({
691
						step: 1,
692
						range: true,
693
						min: parseInt(myFilter['min']),
694
						max: parseInt(myFilter['max']),
695
						values: [parseInt(myFilter['min']), parseInt(myFilter['max'])],
696
						change: function(event, ui){
697
							$(this).parent().parent().find('.slider-user-min').find('span').html(ui.values[0]);
698
							$(this).parent().parent().find('.slider-user-max').find('span').html(ui.values[1]);
699
							slidermove(myFilter.name,ui.values[0],ui.values[1]);
700
						}
701
					});
702
				});
703
			}
704
		}
705
	}
706
	else{
707
		$(container).css("width","0px");
708
	}
709
}
710

    
711
function slidermove(field,min,max){
712
	var myfilters = selectedData['filters'];
713
	var len = myfilters.length;
714
	for(var i=0;i<len;i++){
715
		if(myfilters[i]['name'] == field){
716
			myfilters[i]['min'] = min;
717
			myfilters[i]['max'] = max;
718
			break;
719
		}
720
	}	
721

    
722

    
723
	//ajax call to get the new data
724
	$.ajax({  
725
	   type: "GET",  
726
	   url: "ajaxRouter9.php",
727
	   data: "com=query&type=chart&data="+encodeURIComponent(JSON.stringify(selectedData)),  
728
	   success: function(resp){  
729
		 // we have the response 
730
		chartDataFromServer = JSON.parse(resp);
731
		renderChart();
732
		},  
733
	   error: function(e){  
734
		 alert('Error: ' + e);  
735
	   }
736
	});
737
}
738
</script>
739
</head>
740
<body>
741
<div id="filters"></div>
742
<div id="charts-main" style="margin-right:10px;float:left">
743
	<div id='chart' style="width:95%;height:95%;margin:auto;"></div>
744
	<div id='chart2' style="width:95%;height:95%;margin:auto;display:none;"><!-- SECTION FOR THE GRAPHIC --></div>
745

    
746
	<div id="selections" style="width:95%;height:5%;margin:auto;text-align:center;font-family:Verdana;font-size:small;color:#000"></div>
747
	<div id='credits'></div>
748
	<div id='zoommessage'>select an area to zoom in</div>
749
</div>
750
</body>
751
</html>
752

    
(5-5/30)