Project

General

Profile

1
<?php
2

    
3
include_once("../paths.php")
4

    
5
?>
6

    
7
/* TODO:
8

    
9
PARADOXES:
10
1) den theloume na doume sto idio diagramma pragmata apo diaforetikous facts tables
11
2) ola ta meas einai numerics
12
*/
13
var FOO = (function() {
14

    
15
var path = "<?php echo $stats_server ?>";
16
var viztype = "chart";
17
var selectedData = new Object();
18
var fieldscounter = 0;
19
var filtercounter = 0;
20
var yaxiscounter = 0;
21

    
22
var chartData = new Object();
23

    
24
var yaxislist = '';
25
var forDimsGroupsControls = "";
26
var forDimsColorsControls = "";
27
//var measaggs = "";
28
var loadFlag = true;
29

    
30
var theme = 3;
31
var thisyaxis =-1;
32

    
33
//var xAxisContainer = 'xaxis';
34
var xAxisCont = 'xaxis-list';
35
var yAxisContainer = 'addy-list';
36
var newyAxis = 'yaxis-basket';
37
var filtersContainer = "filter-list";
38
var moreContainer = "moreoptions";
39

    
40

    
41
function inits(schema,container) {
42
	var mydiv = document.getElementById(container);
43
	//create the select header
44
	var sel = document.getElementById('tableselect');
45
	//selectedData['table'] = schema[0]['name'];
46
	selectedData['nulls'] = false;
47
	$("#nulls").removeAttr("checked");
48
	for(var factnum in schema) {
49
		//local var for selected options
50
		//selectedData['fields'] = new Array();
51
		//selectedData['series'] = new Array();
52
		//selectedData['type'] = 'chart';
53
		//every fact table has an option in the FactTableSelect with its name and a div in the info space with its fields 
54
		
55
		//select option for the fact table
56
		var tableheader = document.createElement('option');
57
		if(factnum == 0) $(tableheader).attr("selected","selected");
58
		tableheader.setAttribute('id',schema[factnum]['name']);
59
		tableheader.setAttribute('value',schema[factnum]['name']);
60
		$(tableheader).html(schema[factnum]['name']);
61
		sel.appendChild(tableheader);
62
		
63
		//div in the info space
64
		var measInfoDiv = document.createElement('div'); 
65
		$(measInfoDiv).attr('id',schema[factnum]['name']+'infoDiv').addClass('infoDiv').hide();
66
		/*if(factnum > 0)
67
			$(measInfoDiv).css('display','none');
68
		*/
69
		mydiv.appendChild(measInfoDiv);
70

    
71
		//get the metadata for the measurements
72
		/*var metadata = null;
73
		$.ajax({  
74
			type: "GET",  
75
			async: false,
76
			url: "ajaxRouter9.php",  
77
			data: "com=measMetadata&table="+schema[factnum]['name'],  
78
			success: function(resp){  
79
				// we have the response 
80
				//metadata = JSON.parse(resp);
81
			},
82
			error: function(e){  
83
			alert('Error: ' + e);  
84
			}  
85
		});*/
86
		/*for(var m in schema[factnum]['meas']) {
87
			var mflag = false;
88
			var i=0;
89
			for(i in metadata){
90
				if(metadata[i]['name'] == schema[factnum]['meas'][m]['name']){
91
					mflag = true;
92
					break;
93
				}
94
			}
95
			//the info line for the measurement
96
			var infoLine = document.createElement('div');
97
			
98
			//header the name of the measurement
99
			var measHeader = document.createElement('p');
100
			$(measHeader).addClass('measHeader');
101
			if(schema[factnum]['meas'][m]['view'])
102
				$(measHeader).append("<b>"+schema[factnum]['meas'][m]['view']+"</b>");
103
			else
104
				$(measHeader).append("<b>"+schema[factnum]['meas'][m]['name']+"</b>");
105
			infoLine.appendChild(measHeader);
106
			
107
			if(metadata[i]['definition']!=''){
108
				var desc = document.createElement('p');
109
				$(desc).addClass('info');
110
				$(desc).append(metadata[i]['definition']+".");
111
				infoLine.appendChild(desc);
112
			}
113
			if(metadata[i]['source']!=''){
114
				var src = document.createElement('p');
115
				$(src).addClass('info');
116
				$(src).append("<br/><b>Source:</b><a href='"+metadata[i]['sourceUrl']+"' target='_blank'>"+metadata[i]['source']+"</a>");
117
				infoLine.appendChild(src);
118
			}
119
			measInfoDiv.appendChild(infoLine);
120
		}*/
121
	}
122
	$(mydiv).append("<button type='button' id='metadataclose'>close</button>");
123
}
124

    
125
function renderChartThemes(container) {
126
	var myDiv = document.getElementById(container);
127
	var content = '';
128
	for(var i=0;i<themes.length;i++){
129
		content +='<input type="radio" name="chartTheme" value="'+themes[i][0]+'">'+themes[i][0]+'<br>';
130
	}
131
	$(myDiv).append(content);
132
	$('input:radio[name=chartTheme]:nth('+theme+')').attr('checked',true);
133
}
134

    
135
function userselect() {
136
	/* XAXIS */
137
	$('.x-aggrs-select').unbind("click").click(function(){
138
		if($(this).hasClass('disabled')){
139
			$(this).val('none');
140
			return false;
141
		}
142
		if($(this).val()=='none')
143
			selectedData['xaxis']['agg'] = '' ;
144
		else
145
			selectedData['xaxis']['agg'] = $(this).val();
146
		reDo();
147
	});
148

    
149
	$("#xaxis").unbind("click").click(function(){
150
		if($('#xaxis-list').css('display') =='block'){
151
			//$('#close-xaxis-list').css('display','none');
152
			$('#xaxis-list').css('display','none');
153
		}
154
		else{
155
			//$('#close-xaxis-list').css('display','block');
156
			$('#xaxis-list').css('display','block');
157
		}
158
		return false;
159
	});
160
	$(".xaxis-row").live("click", function(){
161
		$('.xaxis-row').css('font-weight','normal');
162
		$(this).addClass('xaxis-selected').css('font-weight','bold');
163
		$("#xaxis-list").css('display','none');
164
		//$("#close-xaxis-list").css("display","none");
165
		$("#xaxis-name").val($(this).find('label').html());
166
		selectedData['xaxis']['name'] = $(this).find('input.val').val();
167
		$("#sort-list option[value='xaxis']").html($(this).find('label').html());
168
		reDo();
169
	});
170
	
171
	$(".xaxis-row").live("mouseover", function() {
172
			$(this).css('box-shadow', '3px 3px 1px #888888').css('background-color','#666666').css('color','#ffffff');
173
		});
174
	$(".xaxis-row").live("mouseout", function() {
175
			$(this).css('box-shadow', 'none').css('background-color','#ffffff').css('color','#666666');
176
	});
177
	
178
	$("#close-xaxis-list").click(function() {
179
		$("#xaxis-list").css('display','none');
180
		$(this).css("display","none");
181
		return false;
182
	});
183
	
184
	/*Y-AXIS*/
185
	/*add field */
186
	$('#addf').unbind("click").click(function(){
187
		$("#addy-list").css("display","block");
188
		$("#close-yaxis-list").css("display","block");
189
		$('div#axis-select').show();
190
	});
191
	/*delete*/
192
	$(".field .delete").live("click", function(){
193
		if(fieldscounter == 1)
194
			return false;
195
		var name = $(this).siblings('.yaxis-select').val();
196
		var agg = $(this).siblings('.aggrs-select').val();
197
		var ind = $(this).parent().attr('title');
198
		//delete all filters that apply to that field
199
		//and reset the field counter for all the filters that apply to following fields
200
		$('select.applyselect').each(function(){
201
			if($(this).val() == ind){
202
				//delete the filter
203
				$(this).parents('tr').remove();
204
			}
205
			else if($(this).val() > ind)
206
				$(this).val($(this).val()-1);
207
			
208
			//delete the last option
209
			$(this).find('option').last().remove();
210
		});
211
		
212
		//delete the field header
213
		var hfd = $("#fheaders > .headerdiv").has('input.fieldsheadersval[value="'+ind+'"]');
214
		$(hfd).remove(); 
215
		
216
		//if this yaxis has no other field then delete it as well
217
		if($(this).parent().siblings().length == 2){
218
			//delete the axis header
219
			var temp1 = $(this).parent().parent().find('.ycountval').val();
220
			var hd = $("#yheaders > .headerdiv").has('input.yaxisheadersval[value="'+temp1+'"]');
221
			$(hd).remove(); 
222
			yaxiscounter--;
223
			$(this).parent().parent().remove();
224
			//redo the counts
225
			if(yaxiscounter == 1){
226
				$('.ycount').empty();
227
				$(".ycountval").val(1);
228
				$("#yheaders > .headerdiv").find("p").html("yaxis (1)");
229
				$("#yheaders > .headerdiv").find("input.yaxisheadersval").val(1);
230
			}
231
			else{
232
				$('.yaxis').each(function(index){
233
					$(this).find('.ycount').empty().html("yaxis: ("+(index+1)+")")});
234
					$(this).find('.ycountval').val(index+1);
235
					var header = $("#yheaders > .headerdiv").get(index);
236
					$(header).find("p").html("yaxis ("+(index+1)+")");
237
					$(header).find("input.yaxisheadersval").val(index+1);
238
			}
239
			//delete from the select the last child
240
			$('div#axis-select select option:last-child').remove();
241
		}
242
		else{ 
243
			$(this).parent().remove();
244
		}
245
		
246
		//delete the option in sort if needed
247
		compileSortOptions();
248
		
249
		fieldscounter--;
250

    
251
		
252
		if(fieldscounter == 1)
253
			$('.field .delete').hide();
254
		else
255
			$('.field .delete').show();
256
			
257
		//redo counting the fields in field/@title and field/fieldnum/html
258
		$('.field').each(function(index){
259
			$(this).attr('title', index+1);
260
			$(this).find('.fieldnum').html(index+1);
261
			
262
			var header = $("#fheaders > .headerdiv").get(index);
263
			$(header).find("p").html("field ("+(index+1)+")");
264
			$(header).find("input.fieldsheadersval").val(index+1);
265
		});
266
		
267
		reDo();
268
	});
269
	/*change agg*/
270
	$('.aggrs-select').live("change", function(){
271
		if($(this).hasClass('disabled')){
272
			$(this).val('none');
273
			return false;
274
		}
275
		compileSortOptions();
276
		reDo();
277
	});
278
	/*change type*/
279
	$('.type-select').live("change", function(){
280
		if($(this).hasClass('disabled')){
281
			$(this).val('scatter');
282
			return false;
283
		}
284
		//find for which field the change was done
285
		var fieldId = $(this).parent().parent().attr('title');
286
		if($(this).find(":selected").attr("value") == "column"){
287
			//disable the column choise to all other axis
288
			 //$(".type-select").not(this).find("option[value='column']").attr('disabled','disabled');
289
		}
290
		var i=0;
291
		for(i=0;i<selectedData['fields'].length;i++) {
292
			if(selectedData['fields'][i]['id'] == fieldId){
293
				selectedData['fields'][i]['type'] = $(this).find(":selected").attr("value");
294
				break;
295
			}
296
		}
297
		reDo();
298
		return false;
299
	});
300
	/*change field*/
301
	$('.yaxis-select').live("change", function(){
302
		//find for which field the change was done
303
		var fieldId = $(this).parent().attr('title');
304
		var i=0;
305
		for(i=0;i<selectedData['fields'].length;i++) {
306
			if(selectedData['fields'][i]['id'] == fieldId){
307
				selectedData['fields'][i]['fld'] = $(this).find(":selected").attr("value");
308
				break;
309
			}
310
		}
311
		compileSortOptions();
312
		reDo();
313
		return false;
314
	});
315
	/*MORE OPTIONS*/
316
	/*color*/
317
	$(".controls select.color-list").live("change", function(){
318
		if($(this).hasClass('disabled')){
319
			$(this).val('none');
320
			return false;
321
		}
322
		if($(this).val() == 'none'){
323
			//remove the analyze data from selectedData
324
			if(selectedData['group'] != ''){
325
				selectedData['group'] = '';
326
				selectedData['color'] = '';
327
				reDo();
328
			}
329
			//redo chart TODO
330
			return false;
331
		}
332
		//some value was chosen
333
		//not able to group while it is colored
334
		$('.group').addClass('disabled');
335
		//get the value and add it to selected data
336
		selectedData['group'] = '';
337
		selectedData['color'] = $(this).val();
338
		//redo chart
339
		reDo();
340
		return false;
341
	});
342
	$(".control-row").live("mouseover", function() {
343
			$(this).css('box-shadow', '3px 3px 1px #888888').css('background-color','#666666').css('color','#ffffff');
344
		});
345
	$(".control-row").live("mouseout", function() {
346
			$(this).css('box-shadow', 'none').css('background-color','#ffffff').css('color','#666666');
347
	});
348
	/*group*/
349
	$('.group').live("click",function(){
350
		$(this).siblings('a').css('display','block');
351
		$(this).siblings('.list:first').css('display','block');
352
		return false;
353
	});
354

    
355
	$(".controls select.groups-list").live("change", function(){
356
		if($(this).hasClass('disabled')){
357
			$(this).val('none');
358
			return false;
359
		}
360
		if($(this).val() == 'none'){
361
			//remove the analyze data from selectedData
362
			if(selectedData['group'] != ''){
363
				selectedData['group'] = '';
364
				reDo();
365
			}
366
			return false;
367
		}
368
		//some value was chosen
369
		//not able to group while it is colored
370
		$('.color').addClass('disabled');
371
		//get the value and add it to selected data
372
		selectedData['group'] = $(this).val();
373
		//redo chart
374
		reDo();
375
		return false;
376
	});
377
	/*add y*/
378
	/*$("#addy").click(function(){
379
		if($("#addy").hasClass('disabled')){
380
			alert('sorry, you cannot add a fourth yaxis!');
381
			return false;
382
		}
383
		$("#addy-list").css("display","block");
384
		$("#close-yaxis-list").css("display","block");
385
		return false;
386
	});*/
387
	
388
	$("#close-yaxis-list").click(function() {
389
		$("#addy-list").css('display','none');
390
		$('div#axis-select select').val('1');
391
		$('div#axis-select').hide();
392
		//$('div#axis-select select').val(1);
393
		$(this).css("display","none");
394
		return false;
395
	});
396
	
397
	$(".yaxis-row").die().live("click", function(){
398
		$('.analyze').addClass('disabled');
399
		$("#addy-list").css('display','none');
400
		$("div#axis-select").hide();
401
		$("#close-yaxis-list").css("display","none");
402

    
403
		var yaxis = $("#whichyaxis").val();
404
		if(yaxis > 0)
405
			addField($(this).find('input.defaggs').attr('value'),$(this).find('input.name').attr('value'),'',yaxis);
406
		else
407
			addyAxis($(this).find('input.defaggs').attr('value'),$(this).find('input.name').attr('value'),'');
408
		//hide the measurements from x axis select
409
		//$('#xaxis option.optionMeas').attr('disabled','disabled');<------------------------------todo
410
		reDo();
411
	});
412
	$(".yaxis-row").live("mouseover", function() {
413
			$(this).css('box-shadow', '3px 3px 1px #888888').css('background-color','#666666').css('color','#ffffff');
414
		});
415
	$(".yaxis-row").live("mouseout", function() {
416
			$(this).css('box-shadow', 'none').css('background-color','#ffffff').css('color','#666666');
417
	});
418

    
419
	/*CHART THEME*/
420
	$('input:radio[name=chartTheme]').live('change',function(){
421
		selectedData['theme'] = ($('input:radio[name=chartTheme]:checked').index()+1)/2-1;
422
		reDo();
423
	});
424
	/*FILTERS*/
425
	$(".filter-row").die().live("click", function(){
426
		$("#filter-list").css('display','none');
427
		$("#close-filter-list").css("display","none");
428
		if($(this).find('input.type').attr('value') == 'meas')
429
			getFilterData(selectedData['table'],$(this).find('input.val').attr('value'),$(this).find('label').html(),'m');
430
		else
431
			getFilterData(selectedData['table'],$(this).find('input.val').attr('value'),$(this).find('label').html(),'d');
432
		filtercounter++;
433
		return false;
434
	});
435
	
436
	$(".filter-row").live("mouseover", function() {
437
			$(this).css('box-shadow', '3px 3px 1px #888888').css('background-color','#666666').css('color','#ffffff');
438
		});
439
	$(".filter-row").live("mouseout", function() {
440
			$(this).css('box-shadow', 'none').css('background-color','#ffffff').css('color','#666666');
441
	});
442
	
443
	$("#close-filter-list").click(function() {
444
		$("#filter-list").css('display','none');
445
		$(this).css("display","none");
446
		return false;
447
	});
448
	
449
	$("#addfilter").click(function(){
450
		$("#filter-list").css("display","block");
451
		$("#close-filter-list").css("display","block");
452
		return false;
453
	});
454

    
455
	$('.filter a.xsmall-button').live("click", function(){
456
		if($(this).hasClass('btactive'))
457
			return false;
458
		$(this).siblings().removeClass('btactive');
459
		$(this).addClass('btactive');
460
		if($(this).html()=="discrete"){
461
			$(this).parent().parent().find('.filter-slider').hide();
462
			$(this).parent().parent().find('.filter-form').show();
463
			$(this).parent().parent().find('.filter-having').hide();
464
		}
465
		else if($(this).html()=='slider'){
466
			$(this).parent().parent().find('.filter-slider').show();
467
			$(this).parent().parent().find('.filter-form').hide();
468
			$(this).parent().parent().find('.filter-having').hide();
469
		}
470
		else{
471
			$(this).parent().parent().find('.filter-having').show();
472
			$(this).parent().parent().find('.filter-slider').hide();
473
			$(this).parent().parent().find('.filter-form').hide();
474
		}
475
	});
476
	
477
	$(document).on("click",".removefilter",function() {
478
		$(this).parent().parent().parent().parent().remove();
479
		$('#filterTable td').css('background-color','#f6f6f6');
480
		$('#filterTable td:even').css('background-color','white');
481
		filtercounter--;
482
		//TODO: redo query
483
	});
484
}
485

    
486
function userselect2(){
487
	$("#sort-list").live("change",function(){selectedData['sort'] = $(this).val(); reDo();});
488
	
489
	$("#order-list").live("change",function(){selectedData['order'] = $(this).find('input:checked').val(); reDo();});
490
	
491
	$("#nulls").click(function(){
492
		if($(this).attr('checked') == 'checked')
493
			selectedData['nulls'] = true;
494
		else
495
			selectedData['nulls'] = false;
496
		reDo();
497
	});
498
	
499
	$(".cumulate").live("change",function(){reDo();});
500
	
501
	$(".addtochart").live("click",function(){$(this).removeClass("addtochart").addClass("delfromchart");
502
		$(this).parent().find("input").show();
503
	});
504
	
505
	$(".delfromchart").live("click",function(){$(this).removeClass("delfromchart").addClass("addtochart");
506
		$(this).parent().find("input").hide();
507
	});
508
}
509

    
510
function menueffects() {
511
	$("#i").click(function(){
512
		$("#metadata").css('display','block');
513
		$("#"+selectedData['table']+"infoDiv").css('display','block');
514
	});
515
	
516
	$('#metadataclose').live('click',function(){
517
		$('.infoDiv').css('display','none');
518
		$('#metadata').css('display','none');
519
	});
520
	
521
	$('.submit-div').hover(
522
		function(){
523
			$(this).css('border','1px solid #41b7d8');
524
		},
525
		function(){
526
			$(this).css('border','1px solid rgba(0,0,0,0.1)');
527
		}
528
	);
529

    
530
	$('.viztype-button').click(function(){
531
		//an patithike to map prepei na doume an ola einai ok
532
		/*if($(this).html()=='map'){
533
			if($('.field').length>1 || selectedData['type'] != 'chart')
534
				return false;
535
		}*/
536
		$('.viztype-button').removeClass('viztype-active');
537
		$(this).addClass('viztype-active');
538
		if($(this).html() != viztype){
539
			//an to palio viztype einai map prepei na epanaferoume ta options
540
			if(viztype=='map') restoreOptions();
541
			
542
			viztype = $(this).html();
543
			//an to neo viztype einai map prepei na apenergopoiisoume tis epiloges
544
			if(viztype=='map') mapOptions();
545
			reDo();
546
		}
547
	});
548
	
549
	//$('.contentcontaining').children('.content').hide();
550
	$('.contentcontaining > label').live('click', function(){
551
		$(this).parent().removeClass('contentcontaining').addClass('opencontentcontaining');
552
		$(this).siblings('.content').show();
553
	});
554
	$('.opencontentcontaining > label').live('click', function(){
555
		$(this).parent().removeClass('opencontentcontaining').addClass('contentcontaining');
556
		$(this).siblings('.content').hide();
557
	});
558
	
559
	
560
	$('body').click(function(){
561
		//$("#addy-list").css('display','none');
562
		//$("#close-yaxis-list").css("display","none");
563
		//$("#filter-list").css('display','none');
564
		//$("#close-filter-list").css("display","none");
565
	});
566
	
567
	$('#resultsetsize').change(function(){selectedData['size'] = $(this).val();});
568
}
569

    
570
function restoreOptions(){
571
	$('.x-aggrs-select').removeClass('disabled');
572
	//$('#xaxis').removeClass('disabled');<-------------------------------todo
573
	
574
	$('.header-select').has('.type-select').show();
575
	
576
	if(selectedData['type'] == 'scatter'){ //scatter plot
577
		$('.type-select').val('scatter').addClass('disabled');
578
		$('.color,.group').removeClass('disabled');
579
		$('.color-list,.groups-list').removeClass('disabled');
580
		
581
		$('.analyze').addClass('disabled');
582
		$('.analyze-list').val('none').addClass('disabled');
583
		selectedData['group'] = "";
584
	}
585
	else{//chart
586
		selectedData['type'] = 'chart';
587
		$('.type-select').val('column').removeClass('disabled');
588
		
589
		$('.color,.group').addClass('disabled');
590
		$('.color-list,.groups-list').val('none').addClass('disabled');
591
		
592
		$('.analyze').removeClass('disabled');
593
		$('.analyze-list').removeClass('disabled');
594
		selectedData['group'] = "";
595
		selectedData['color'] = "";
596
	}
597
}
598

    
599
function mapOptions(){
600
	$('.x-aggrs-select').val('none').addClass('disabled');
601
	selectedData['xaxis']['agg'] = '';
602
	$('.header-select').has('.type-select').hide();
603
	//$('.type-select').addClass('disabled');
604
	
605
	//$('.controls').addClass('disabled');
606
	//$('.controls').find('select').val('none').addClass('disabled');
607
	selectedData['group'] = "";
608
	selectedData['color'] = "";
609
}
610

    
611
function chartControls() {
612
	$('.analyze-list').live('change', function(){
613
		if($(this).hasClass('disabled')){
614
			$(this).val('none');
615
			return false;
616
		}
617
		//if no value was chosen
618
		if($(this).val() == 'none'){
619
			if(selectedData['group'] != ""){
620
				selectedData['group'] = '';
621
				reDo();
622
				return false;
623
			}
624
			else
625
				return false;
626
		}
627
		//some value was chosen
628
		//get the value and add it to selected data
629
		selectedData['group'] = $(this).val();
630
		//redo chart
631
		reDo();
632
	});
633
	///////////////////////////////////////
634
	$(".ui-slider").live("slide",function(event, ui){
635
			$(this).parent().parent().find('.slider-user-min').find('span').html(ui.values[0]);
636
			$(this).parent().parent().find('.slider-user-max').find('span').html(ui.values[1]);
637
		}
638
	);
639
	$("#filterok").click(function(){
640
		reDo();
641
	});
642
	
643
	$('a.all').live("click",function(){
644
		$(this).siblings('.form-container').find('input').attr('checked','checked');
645
	});
646
	
647
	$('a.none').live("click",function(){
648
		$(this).siblings('.form-container').find('input').removeAttr('checked');
649
	});
650
	///////////////////////////////////////
651
	$('#headersok').click(function(){
652
		selectedData['title'] = $('#mytitle').val();
653
		selectedData['subtitle'] = $('#mysubtitle').val();
654
		selectedData['xaxistitle'] = $('#myxaxistitle').val();
655
		reDo();
656
	});
657
	$('#sizeok').click(function(){reDo();});
658
}
659

    
660
function renderPage(schema,facttable) {
661
	selectedData['table'] = facttable;
662
	selectedData['fields'] = new Array();
663
	selectedData['type'] = 'chart';
664
	selectedData['xaxis'] = new Array();
665
	yaxiscounter = 0;
666
	fieldscounter = 0;
667
	filtercounter = 0;
668
	
669
	$('#filterTable').empty();
670
	$('.headerdiv').remove();
671
	
672
	//var xdiv = document.getElementById(xAxisContainer);
673
	var xdivlist = document.getElementById(xAxisCont);
674
	var ydiv = document.getElementById(yAxisContainer);
675
	var fdiv = document.getElementById(filtersContainer);
676
	var mdiv = document.getElementById(moreContainer);
677
	var factnum;
678
	
679
	var forfilters = ''; var forxaxis = '';
680
	var forcolors = ''; var forgroups = ''; var foranalyse = ''
681
	yaxislist = "";
682
	forcolors = "<input type='text' id='color-name' disabled></input><div id='color' class='choose'><img src='images/icon_triangle_down.gif'></img></div><a id='close-color-list' style='display:none'>close</a><div id='color-list' class='list' style='display:none'></div>";
683
	forDimsColorsControls = "<select class='color-list'><option class='color-option' value='none' selected>none</option>";
684
	forDimsGroupsControls = "<select class='groups-list'><option class='groups-option' value='none' selected>none</option>";
685
	forDimsAnalyseControls = "<select class='analyze-list'><option class='analyze-option' value='none' selected>none</option>";
686
	var xcontents = "";	var xcontente= "";	var ycontent = "";	var fcontent = "";
687
	var mscontent = "";	var mccontent = "";
688
	for(factnum=0; factnum<schema.length; factnum++) {
689
		if(schema[factnum]['name'] == facttable)
690
			break;
691
	}
692
	var meas = schema[factnum]['meas'];
693
	for(var m in meas) {
694
		if(!meas[m]['agg'] || meas[m]['agg'] == '')
695
			meas[m]['agg'] = 'avg';
696
		ycontent += "<div class='yaxis-row'><input type='hidden' class='name' value='"+meas[m]['name']+"'></input><input type='hidden' class='defaggs' name='"+meas[m]['name']+"' value='"+meas[m]['agg']+"'/><label class='yaxis-label'>";
697
		xcontente += "<option value='"+meas[m]['name']+"' class='x-axis-option optionMeas'>";
698
		forxaxis += "<div class='xaxis-row'><input type='hidden' class='type' value='meas'></input><input type='hidden' class='val' value='"+meas[m]['name']+"'></input>";
699
		forfilters += "<div class='filter-row'><input type='hidden' class='type' value='meas'></input><input type='hidden' class='val' value='"+meas[m]['name']+"'></input>";
700
		//fcontent += "<div class='filter-row'><input type='hidden' value='"+meas[m]['name']+"'></input>";
701
		yaxislist += "<option class='yaxis-option' value='"+meas[m]['name']+"'>";
702
		if(meas[m]['view']){
703
			forxaxis += "<label class='xaxis-label'>"+meas[m]['view']+" ("+meas[m]['name']+")</label></div>";
704
			forfilters += "<label class='filter-label'>"+meas[m]['view']+" ("+meas[m]['name']+")</label></div>";
705
			//fcontent += "<label class='filter-label'>"+meas[m]['view']+" ("+meas[m]['name']+")</label></div>";
706
			xcontente += meas[m]['view']+" ("+meas[m]['name']+")</option>";
707
			ycontent += meas[m]['view']+" ("+meas[m]['name']+")</label></div>";
708
			yaxislist += meas[m]['view']+" ("+meas[m]['name']+")</option>";
709
		}
710
		else{
711
			forxaxis += "<label class='xaxis-label'>"+meas[m]['name']+"</label></div>";
712
			forfilters += "<label class='filter-label'>"+meas[m]['name']+"</label></div>";
713
			//fcontent += "<label class='filter-label'>"+meas[m]['name']+"</label></div>";
714
			xcontente += meas[m]['name']+"</option>";
715
			ycontent += meas[m]['name']+"</label></div>";
716
			yaxislist += meas[m]['name']+"</option>";
717
		}
718
	}
719
	
720
	var dims = schema[factnum]['dim'];
721
	for(var d in dims) {
722
		if(dims[d]['dimtable'] == 'yes'){
723
			forfilters += "<div class='dim opencontentcontaining'><input type='hidden' class='val' value='"+dims[d]['name']+"'></input><label>"+dims[d]['name']+"</label><div class='content' style='margin-left:12px'>"+dimstree(dims[d]['attrib'],[dims[d]['name']], 'filter-row')+"</div></div>";
724
		
725
			forxaxis += "<div class='dim opencontentcontaining'><input type='hidden' class='val' value='"+dims[d]['name']+"'></input><label>"+dims[d]['name']+"</label><div class='content' style='margin-left:12px'>"+dimstree(dims[d]['attrib'],[dims[d]['name']], 'xaxis-row')+"</div></div>";
726
			
727
			xcontents += attribsOfDims(dims[d]['attrib'],[dims[d]['name']],"optionDim x-axis","option");
728
		
729
			//fcontent += attribsOfDims(dims[d]['attrib'],[dims[d]['name']],"filter","row");
730
			forDimsColorsControls += attribsOfDims(dims[d]['attrib'],[dims[d]['name']],"color","option");
731
			forDimsGroupsControls += attribsOfDims(dims[d]['attrib'],[dims[d]['name']],"groups","option");
732
			forDimsAnalyseControls += attribsOfDims(dims[d]['attrib'],[dims[d]['name']],"analyze","option");
733
		}
734
		else{
735
			forfilters += "<div class='dim filter-row'><input type='hidden' class='val' value='"+dims[d]['name']+"'></input><label class='dim-label'>"+dims[d]['name']+"</label></div>";
736
			
737
			forxaxis += "<div class='dim xaxis-row'><input type='hidden'  class='val' value='"+dims[d]['name']+"'></input><label class='dim-label'>"+dims[d]['name']+"</label></div>";
738
			
739
			xcontents += "<option class='x-axis-option optionDim' value='"+dims[d]['name']+"'>"+dims[d]['name']+"</option>";
740
			
741
			//fcontent += "<div class='filter-row'><input type='hidden' value='"+dims[d]['name']+"'></input>";
742
			//fcontent += "<label class='filter-label'>"+dims[d]['name']+"</label></div>";
743
			
744
			forDimsColorsControls += "<option class='color-option' value='"+dims[d]['name']+"'>"+dims[d]['name']+"</option>";
745
			forDimsGroupsControls += "<option class='groups-option' value='"+dims[d]['name']+"'>"+dims[d]['name']+"</option>";
746
			forDimsAnalyseControls += "<option class='analyze-option' value='"+dims[d]['name']+"'>"+dims[d]['name']+"</option>";
747
		}
748
	}
749
	
750
	//$(xdiv).empty().append(xcontents).append(xcontente);
751
	$(xdivlist).empty().append(forxaxis);
752
	//$(fdiv).empty().append(fcontent);
753
	$(fdiv).empty().append(forfilters);
754
	$(ydiv).empty().append(ycontent);
755
	forDimsColorsControls += "</select>";
756
	forDimsGroupsControls += "</select>";
757
	forDimsAnalyseControls += "</select>";
758
	$("#"+newyAxis).empty();
759
	
760
	mscontent += "<div id='scatter-controls'><div class='controls'>";
761
	mscontent += "<p class='small-header color'>Distinguish by:</p><div id='colors-list-div' class='list'>"+forDimsColorsControls+"</div></div>";
762
	
763
	mscontent += "<div class='controls'>";
764
	mscontent += "<p class='small-header group'>Group by:</p><div id='groups-list-div' class='list'>"+forDimsGroupsControls+"</div></div></div>";
765
	
766
	mccontent += "<div id='chart-controls'><div class='controls'>";
767
	mccontent += "<p class='small-header sort'>sort by:</p><div class='list'><select id='sort-list'><option class='sort-option' value='xaxis' selected></option></select></div>";
768
	mccontent += "</div>";
769
	mccontent += "<div class='controls'><p class='small-header order'>order:</p><div id='order-list' class='list'><input type='radio' name='order' value='a' checked='ckecked'>min to max</input><br/><input type='radio' name='order' value='d'>max to min</input></div></div>";
770
	
771
	mccontent += "<div class='controls'>";
772
	mccontent += "<p class='small-header analyze'>Split by:</p><div id='analyze-div' class='list'>"+forDimsAnalyseControls+"</div></div>";
773
	
774
	//mccontent += "<div class='controls'>";
775
	//mccontent += "<p class='small-header size'>Size by:</p><div id='size-div' class='list'>"+forDimsAnalyseControls+"</div></div>";
776
	mccontent += "</div>";
777
	$(mdiv).empty().append(mccontent/*+mscontent*/);
778
	
779
	selectedData['sort'] = 'xaxis';
780
	selectedData['order'] = 'a';
781
}
782

    
783
function dimstree(attribs, predecessors, classname){
784
	var contentString = "";
785
	for(var attrnum in attribs) {
786
		if(attribs[attrnum]['attrib'].length == 0){
787
			if(typeof attribs[attrnum]['analysed'] === 'undefined'){
788
				contentString += "<div class='"+classname+"'><input type='hidden' class='val' value='"+predecessors.join('-')+"-"+attribs[attrnum]['name']+"'></input>";
789
				contentString += "<label class='dim-label'>";
790
				if(attribs[attrnum]['view'])
791
					contentString+= attribs[attrnum]['view']+" ("+predecessors[predecessors.length-1]+"-"+attribs[attrnum]['name']+")</label></div>";
792
				else
793
					contentString+= predecessors[predecessors.length-1]+"-"+attribs[attrnum]['name']+"</label></div>";
794
			}
795
		}
796
		else {
797
			var temp = dimstree(attribs[attrnum]['attrib'],predecessors.concat([attribs[attrnum]['name']]), classname);
798
			if(temp!='')
799
				contentString += "<div class='dim opencontentcontaining'><input type='hidden' class='val' value='"+predecessors.join('-')+"-"+attribs[attrnum]['name']+"'></input><label>"+attribs[attrnum]['name']+"</label><div class='content' style='margin-left:12px;'>"+temp+"</div></div>";
800
		}
801
	}
802
	return contentString;
803
}
804

    
805
function attribsOfDims(attribs, predecessors, classPrefix, type) {
806
	var contentString = "";
807
	for(var attrnum in attribs) {
808
		if(type == 'row'){
809
			if(attribs[attrnum]['attrib'].length == 0) {
810
				contentString += "<div class='"+classPrefix+"-row'><input type='hidden' value='"+predecessors.join('-')+"-"+attribs[attrnum]['name']+"'></input>";
811
				contentString += "<label class='"+classPrefix+"-label'>";
812
				if(attribs[attrnum]['view'])
813
					contentString+= attribs[attrnum]['view']+" ("+predecessors[predecessors.length-1]+"-"+attribs[attrnum]['name']+")</label></div>";
814
				else
815
					contentString+= predecessors[predecessors.length-1]+"-"+attribs[attrnum]['name']+"</label></div>";
816
			}
817
			else {
818
				contentString += attribsOfDims(attribs[attrnum]['attrib'],predecessors.concat([attribs[attrnum]['name']]),classPrefix,type);
819
			}
820
		}
821
		else if(type == 'option') {
822
			if(attribs[attrnum]['attrib'].length == 0) {
823
				contentString += "<option class='"+classPrefix+"-option' value='"+predecessors.join('-')+"-"+attribs[attrnum]['name']+"'>";
824
				if(attribs[attrnum]['view'])
825
					contentString+= attribs[attrnum]['view']+" ("+predecessors[predecessors.length-1]+"-"+attribs[attrnum]['name']+")</option>";
826
				else
827
					contentString+= predecessors[predecessors.length-1]+"-"+attribs[attrnum]['name']+"</option>";
828
			}
829
			else {
830
				contentString += attribsOfDims(attribs[attrnum]['attrib'],predecessors.concat([attribs[attrnum]['name']]),classPrefix,type);
831
			}
832
		}
833
	}
834
	return contentString;
835
}
836

    
837
function reDo(){
838
	if(viztype=='chart')
839
		renderChart();
840
	else if(viztype=='table')
841
		renderTable('g');
842
	else if(viztype=='g table')
843
		renderTable('g');
844
	else if(viztype=='map')
845
		renderMap();
846
	else if(viztype=='treemap')
847
		renderTreemap();
848
	else{
849
		viztype='chart';
850
		renderChart();
851
	}
852
}
853

    
854
function renderMap(){
855
	if(selectedData['fields'].length == 0)
856
		getFields();
857
	
858
	if(filtercounter >0)
859
		getFilters();
860
	
861
	$("#chartcontainer").attr("src",path+"choromap.php?com=query&data="+encodeURIComponent(JSON.stringify(selectedData)));
862
	$("#url").html(path+'choromap.php?com=query&data='+JSON.stringify(selectedData));
863
	$("#urlencode").html(path+'choromap.php?com=query&data='+encodeURIComponent(JSON.stringify(selectedData)));
864
	selectedData['fields'] = new Array();
865
	$('.header-select').has('.type-select').hide();
866
}
867

    
868
function renderChart(){
869
	if(loadFlag)
870
		getFields();
871
	loadFlag=true;
872
	if(filtercounter > 0)
873
		getFilters();
874
	
875
	//xaxis style
876
	selectedData['xStyle'] = Object();
877
	if($("#xarotate").is(":checked")){
878
		var val = $("#rotatedegrees").val();
879
		selectedData['xStyle']['r'] = parseInt(val,10);
880
	}
881
	else
882
		selectedData['xStyle']['r'] = "-";
883
	if($("#xastep").is(":checked")){
884
		var val = $("#stepsnum").val();
885
		selectedData['xStyle']['s'] = parseInt(val,10);
886
	}
887
	else
888
		selectedData['xStyle']['s'] = "-";
889
	if($("#xalevel").is(":checked")){
890
		var val = $("#levelsnum").val();
891
		selectedData['xStyle']['l'] = parseInt(val,10);
892
	}
893
	else
894
		selectedData['xStyle']['l'] = "-";
895
	if($("#xaftrim").is(":checked")){
896
		var val = $("#ftrimnum").val();
897
		selectedData['xStyle']['ft'] = parseInt(val,10);
898
	}
899
	else
900
		selectedData['xStyle']['ft'] = "-";
901
	if($("#xawtrim").is(":checked")){
902
		var val = $("#wtrimnum").val();
903
		selectedData['xStyle']['wt'] = parseInt(val,10);
904
	}
905
	else
906
		selectedData['xStyle']['wt'] = "-";
907
		
908
	if(selectedData['type'] == 'scatter'){
909
		if(selectedData['group'] && selectedData['group']!='' && (!selectedData['color'] || selectedData['color'] == '')){
910
			$(".aggrs-select").val('avg').removeClass('disabled');
911
			$(".x-aggrs-select").val('avg').removeClass('disabled');
912
		}
913
		else{
914
			$(".aggrs-select").val('none').addClass('disabled');
915
			$(".x-aggrs-select").val('none').addClass('disabled');
916
		}
917
		$('#scatter-controls .controls').removeClass('disabled');
918
		$('#chart-controls .controls').addClass('disabled');
919
	}
920
	else{
921
		if($(".aggrs-select").hasClass('disabled'))
922
			$(".aggrs-select").val('avg').removeClass('disabled');
923
		$(".x-aggrs-select").addClass('disabled');
924
		$(".aggrs-select option").removeAttr('disabled');
925
		$('#scatter-controls .controls').addClass('disabled');
926
		$('#chart-controls .controls').removeClass('disabled');
927
	}
928
	$("#chartcontainer").attr("src",path+"chart.php?com=query&data="+encodeURIComponent(JSON.stringify(selectedData)));
929
	$("#url").html(path+'chart.php?com=query&data='+JSON.stringify(selectedData));
930
	$("#urlencode").html(path+'chart.php?com=query&data='+encodeURIComponent(JSON.stringify(selectedData)));
931
	selectedData['fields'] = new Array();
932
	$('.header-select').has('.type-select').show();
933
}
934

    
935
function renderTable(which){
936
	if(selectedData['fields'].length == 0)
937
		getFields();
938
	
939
	if(filtercounter >0)
940
		getFilters();
941
	
942
	if(selectedData['type'] == 'scatter'){
943
		if(selectedData['group'] && selectedData['group']!='' && (!selectedData['color'] || selectedData['color'] == '')){
944
			$(".aggrs-select").val('avg').removeClass('disabled');
945
			$(".x-aggrs-select").val('avg').removeClass('disabled');
946
		}
947
		else {
948
			$(".aggrs-select").val('none').addClass('disabled');
949
			$(".x-aggrs-select").val('none').addClass('disabled');
950
		}
951
		$('#scatter-controls .controls').removeClass('disabled');
952
		$('#chart-controls .controls').addClass('disabled');
953
	}
954
	else{
955
		if($(".aggrs-select").hasClass('disabled'))
956
			$(".aggrs-select").val('avg').removeClass('disabled');
957
		$(".x-aggrs-select").addClass('disabled');
958
		$(".aggrs-select option").removeAttr('disabled');
959
		$('#scatter-controls .controls').addClass('disabled');
960
		$('#chart-controls .controls').removeClass('disabled');
961
	}
962
	var location = '';
963
	if(which == '1'){
964
		$("#chartcontainer").attr("src",path+"table.php?com=query&data="+encodeURIComponent(JSON.stringify(selectedData)));
965
		$("#url").html(path+"table.php?com=query&data="+JSON.stringify(selectedData));
966
		$("#urlencode").html(path+"table.php?com=query&data="+encodeURIComponent(JSON.stringify(selectedData)));
967
	}
968
	else if(which == 'g'){
969
		$("#chartcontainer").attr("src",path+"gtable.php?com=query&data="+encodeURIComponent(JSON.stringify(selectedData)));
970
		$("#url").html(path+"gtable.php?com=query&data="+JSON.stringify(selectedData));
971
		$("#urlencode").html(path+"gtable.php?com=query&data="+encodeURIComponent(JSON.stringify(selectedData)));
972
	}
973
	selectedData['fields'] = new Array();
974
	$('.header-select').has('.type-select').hide();
975
}
976

    
977
function renderTreemap(){
978
	if(selectedData['fields'].length == 0)
979
		getFields();
980
	
981
	if(filtercounter >0)
982
		getFilters();
983
	
984
	if(selectedData['type'] == 'scatter'){
985
		if(selectedData['group'] && selectedData['group']!='' && (!selectedData['color'] || selectedData['color'] == '')){
986
			$(".aggrs-select").val('avg').removeClass('disabled');
987
			$(".x-aggrs-select").val('avg').removeClass('disabled');
988
		}
989
		else {
990
			$(".aggrs-select").val('none').addClass('disabled');
991
			$(".x-aggrs-select").val('none').addClass('disabled');
992
		}
993
		$('#scatter-controls .controls').removeClass('disabled');
994
		$('#chart-controls .controls').addClass('disabled');
995
	}
996
	else{
997
		if($(".aggrs-select").hasClass('disabled'))
998
			$(".aggrs-select").val('avg').removeClass('disabled');
999
		$(".x-aggrs-select").addClass('disabled');
1000
		$(".aggrs-select option").removeAttr('disabled');
1001
		$('#scatter-controls .controls').addClass('disabled');
1002
		$('#chart-controls .controls').removeClass('disabled');
1003
	}
1004
	$("#chartcontainer").attr("src",path+"treemap.php?com=query&data="+encodeURIComponent(JSON.stringify(selectedData)));
1005
	$("#url").html(path+"treemap.php?com=query&data="+JSON.stringify(selectedData));
1006
	$("#urlencode").html(path+"treemap.php?com=query&data="+encodeURIComponent(JSON.stringify(selectedData)));
1007
	
1008
	selectedData['fields'] = new Array();
1009
	$('.header-select').has('.type-select').hide();
1010
}
1011

    
1012
	function defaultSelections(){
1013
		//select the xAxis
1014
		//$('#xaxis').val(selectedData['xaxis']['name']);
1015
		$('#xaxis-name').val(selectedData['xaxis']['name']);
1016
		$(".xaxis-row").has("input[value='"+selectedData['xaxis']['name']+"']").addClass('xaxis-selected').css('font-weight','bold');
1017
		$("#sort-list option[value='xaxis']").html($(".xaxis-row").has("input[value='"+selectedData['xaxis']['name']+"']").find('label').html());
1018
		
1019
		
1020
		/*if($('#xaxis').find(':selected').hasClass('optionMeas')){ <-------------------------todo
1021
			selectedData['type'] = 'scatter';
1022
		}
1023
		else {
1024
			selectedData['type'] = 'chart';
1025
		}*/
1026
		//create the yaxis selection
1027
		for(var i=0; i<selectedData['fields'].length; i++){
1028
			addyAxis(selectedData['fields'][i]['agg'],selectedData['fields'][i]['fld'],selectedData['fields'][i]['type']);
1029
		}
1030
		//size
1031
		$("#resultsetsize").val(selectedData['size']);
1032
	}
1033

    
1034
	function defaultChart(table) {
1035
		return $.ajax({  
1036
			type: "GET",  
1037
			url: "ajaxRouter9.php",  
1038
			data: "com=defaultChartSelections&table="+((table==null)?"null":table),
1039
			success: function(resp){
1040
				response = JSON.parse(resp);
1041
				if(response != "empty"){
1042
					selectedData = jQuery.extend(true, {}, response);
1043
					//selecteData = response;
1044
					//alert(JSON.stringify(selectedData));
1045
					defaultSelections();
1046
					reDo();
1047
				}
1048
			},
1049
			error: function(e){  
1050
				alert('Error: ' + e);  
1051
		   }
1052
		});
1053
	}
1054

    
1055
function addField(agg,field,type,yaxis){
1056
	fieldscounter++;
1057
	
1058
	$('select.applyselect').each(function(){
1059
		$(this).append("<option value='"+fieldscounter+"'>field "+fieldscounter+"</option>");
1060
	});
1061

    
1062
	var content = "<div class='field' title='"+fieldscounter+"'>";
1063
	content += "<p class='fieldnum'>"+fieldscounter+"</p>";
1064
	content += "<select class='aggrs-select'>";
1065
	content += "<option value='none'></option>";
1066
	content += "<option value='avg'>avg of</option>";
1067
	content += "<option value='count'>count of</option>";
1068
	content += "<option value='sum'>sum of</option>";
1069
	content += "<option value='max'>max of</option>";
1070
	content += "<option value='min'>min of</option></select>";
1071
	content += "<a href='#' title='delete' class='delete'><img src='images/close_16.png' alt='delete'/></a>";
1072
	//create select
1073
	content += "<select class='yaxis-select' id='"+fieldscounter+"'>"+yaxislist+"</select>"
1074
	content += "<div class='field-options'>";
1075
	content += "<div class='header-select'><p class='small-header'>type:</p><select class='type-select'>";
1076
	content += "<option value='scatter'>scatter</option>"
1077
	content += "<option value='column'>column</option>";
1078
	content += "<option value='spline'>spline</option>";
1079
	content += "<option value='line'>line</option>";
1080
	content += "<option value='area'>area</option>";
1081
	content += "<option value='pie'>pie</option></select></div>";
1082
	content += "<p class='small-header'>cumulative</p><input type='checkbox' class='cumulate' value='cummulate'/><p class='addtochartouter'><a class='addtochart'></a><input class='vscumulate' type='text' value='not cumulative'/></p>";
1083
	
1084
	content += "</div>";
1085
	
1086
	//place the content in the yaxis
1087
	$($('.yaxis')[yaxis-1]).append(content);
1088
	
1089
	//preselected option
1090
	if(agg!='')
1091
		$(".field[title='"+fieldscounter+"'] .aggrs-select").val(agg);
1092
	else
1093
		$(".field[title='"+fieldscounter+"'] .aggrs-select").val('none');
1094
		
1095
	if(field!='')
1096
		$(".field[title='"+fieldscounter+"'] .yaxis-select").val(field);
1097

    
1098
	if(selectedData['type'] == 'scatter')
1099
		$('.type-select').val('scatter').addClass('disabled');
1100
	else{
1101
		if(type!='')
1102
			$(".field[title='"+fieldscounter+"'] .type-select").val(type);
1103
		else
1104
			$(".field[title='"+fieldscounter+"'] .type-select").val('column');
1105
	}
1106
	
1107
	if(fieldscounter>1){
1108
		$('.delete').show();
1109
	}
1110
	else
1111
		$('.delete').hide();
1112
		
1113
	//add a header input for the new field
1114
	$("#fheaders").append("<div class='headerdiv'><p class='small-header'>field ("+fieldscounter+"):</p><input type=hidden class='fieldsheadersval' value="+fieldscounter+"></input><input type=text class='fieldsheaders'></input></div>");
1115

    
1116
	compileSortOptions();
1117
}
1118

    
1119
function compileSortOptions(){
1120
	var previous = $("#sort-list").val();
1121
	$("#sort-list > option[value!='xaxis']").remove();
1122
	
1123
	$(".field").each(function(){
1124
		var agg = $(this).find('.aggrs-select').val();
1125
		var field = $(this).find('.yaxis-select').val();
1126
		if($("#sort-list > option[value='"+agg+"-"+field+"']").length == 0)
1127
			$('#sort-list').append("<option class='sort-option' value='"+agg+"-"+field+"'>"+agg+" ("+field+")"+"</option>");
1128
	})
1129
	if($("#sort-list > option[value='"+previous+"']").length > 0 ){
1130
		$("#sort-list").val(previous);
1131
		selectedData['sort'] = previous;
1132
	}
1133
	else{
1134
		$("#sort-list").val('xaxis');
1135
		selectedData['sort'] = 'xaxis';
1136
	}
1137
}
1138

    
1139
function addyAxis(agg,field,type){
1140
	yaxiscounter++;
1141
	//add it in the axis-select
1142
	var name = '';
1143
	if(yaxiscounter == 1) $('div#axis-select select').append("<option name='whichyaxis' value='1' selected>1st yaxis</option>");
1144
	else {
1145
		if(yaxiscounter == 2) name = '2nd';
1146
		else if(yaxiscounter == 3) name = '3rd';
1147
		else name = yaxiscounter+'th';
1148
		$('div#axis-select select').append("<option name='whichyaxis' value='"+yaxiscounter+"'>"+name+" yaxis</option>");
1149
	}
1150
	
1151
	var mydiv = document.getElementById(newyAxis);
1152
	
1153
	//div that has an x sign, an aggs select, a fields select, a diagram select
1154
	var content = "<div class='yaxis' id='yaxis"+yaxiscounter+"'>";
1155
	if(yaxiscounter == 1)
1156
		content += "<div class='ycount'></div><input class='ycountval' type='hidden' value='1'></input>";
1157
	else {
1158
		content += "<div class='ycount'>yaxis: ("+yaxiscounter+")</div><input class='ycountval' type='hidden' value='"+yaxiscounter+"'></input></div>";
1159
		if(yaxiscounter == 2){
1160
			$('.yaxis .ycount').html('yaxis: (1)');
1161
		}
1162
	}
1163
	//put it in the div
1164
	$(mydiv).append(content);
1165
	addField(agg,field,type,yaxiscounter);
1166
	
1167
	//add a header input for the new axis
1168
	$("#yheaders").append("<div class='headerdiv'><p class='small-header'>yaxis ("+yaxiscounter+"):</p><input type=hidden class='yaxisheadersval' value="+yaxiscounter+"></input><input type=text class='yaxisheaders'></input></div>");
1169
	
1170
}
1171

    
1172
function getFields(){
1173
	var counter = 0;
1174
	selectedData['fields'] = new Array();
1175
	selectedData['yaxisheaders'] = new Array();
1176
	selectedData['fieldsheaders'] = new Array();
1177
	$('.yaxis').each(function(index){
1178
		//gia kathe yaxis get the header and iterate over the fields
1179
		selectedData['yaxisheaders'][index] = $($("#yheaders > .headerdiv").get(index)).find(".yaxisheaders").val();
1180
		//gia kathe field ftiakse ena gia to selectedData pou tha exei fld, agg, type, yaxis 
1181
		selectedData['in'] = new Array();
1182
		$(this).find('.field').each(function(){
1183
			selectedData['fields'][counter] = new Object();
1184
			selectedData['fields'][counter]['fld'] = $(this).find('.yaxis-select').val();
1185
			if($(this).find('.aggrs-select').val() == 'none')
1186
				selectedData['fields'][counter]['agg'] = '';
1187
			else
1188
				selectedData['fields'][counter]['agg'] = $(this).find('.aggrs-select').val();
1189
			selectedData['fields'][counter]['type'] = $(this).find('.type-select').val();
1190
			selectedData['fields'][counter]['yaxis'] = index+1;
1191
			
1192
			var fname = $($("#fheaders > .headerdiv").get(counter)).find(".fieldsheaders").val();
1193

    
1194
			selectedData['fieldsheaders'][counter] = fname;
1195
			
1196
			selectedData['fields'][counter]['c'] = $(this).find('.cumulate').is(':checked');
1197
			
1198
			if($(this).find(".delfromchart").length > 0) {
1199
				var l = selectedData['in'].length;
1200
				selectedData['in'][l] = new Object;
1201
				selectedData['in'][l]['f'] = counter;
1202
				selectedData['in'][l]['text'] = $(this).find(".vscumulate").val();
1203
			}
1204
			
1205
			counter++;
1206
		});
1207
	});
1208
}
1209

    
1210
function getFilters(){
1211
	var incfilters = new Array();
1212
	var incfltcount = 0;
1213
	var filters = new Array();
1214
	var fltcount = 0;
1215
	var inchaving = new Array();
1216
	var inchavingcnt = 0;
1217
	var having = new Array();
1218
	var havingcnt = 0;
1219
	$('#filterTable tr td').each(function(index){
1220

    
1221
		//SLIDER
1222
		if($(this).find('.filter-slider').length >0 && $(this).find('.filter-slider').css('display') != 'none'){
1223
			if($(this).find('select.applyselect').val()==-2){
1224
				var flag = false;				
1225
				for(var i =0;i<incfltcount;i++){
1226
					if(incfilters[i].name == $(this).find('.filterfullname').val()){
1227
						flag=true;break;
1228
					}
1229
				}
1230
				if(!flag){
1231
					incfilters[incfltcount] = new Object();
1232
					incfilters[incfltcount].name = $(this).find('.filterfullname').val();
1233
					incfilters[incfltcount].showname = $(this).find('.filtershowname').val();
1234
					incfilters[incfltcount].max = $(this).find('.filter-slider .slider-user-max span').html();
1235
					incfilters[incfltcount].min = $(this).find('.filter-slider .slider-user-min span').html();
1236
					incfltcount++;			
1237
				}			
1238
			}
1239
			//else{			
1240

    
1241
				if($(this).find('.filter-slider .max span').html() == $(this).find('.filter-slider .slider-user-max span').html() && $(this).find('.filter-slider .slider-user-min span').html() == $(this).find('.filter-slider .min span').html())
1242
					return;
1243
				filters[fltcount] = new Object();
1244
				filters[fltcount].name = $(this).find('.filterfullname').val();
1245
				filters[fltcount].max = $(this).find('.filter-slider .slider-user-max span').html();
1246
				filters[fltcount].min = $(this).find('.filter-slider .slider-user-min span').html();
1247
				filters[fltcount]['to'] = ($(this).find('select.applyselect').val()<0)?-1:$(this).find('select.applyselect').val();
1248
				fltcount++;
1249
			//}		
1250
		}
1251
		//CHECKBOXES
1252
		else if($(this).find('.filter-form').css('display') != 'none'){
1253
			if($(this).find('select.applyselect').val()==-2){
1254
				var flag = false;				
1255
				for(var i =0;i<incfltcount;i++){
1256
					if(incfilters[i].name == $(this).find('.filterfullname').val()){
1257
						flag=true;break;
1258
					}
1259
				}
1260
				if($(this).find('.ex').is(':checked')){
1261
					flag=true;				
1262
				}
1263
				if(!flag){
1264
					incfilters[incfltcount] = new Object();
1265
					incfilters[incfltcount].name = $(this).find('.filterfullname').val();
1266
					incfilters[incfltcount].showname = $(this).find('.filtershowname').val();
1267
									
1268
					if($(this).find('form input:checked').length == 0 || $(this).find('form input:not(:checked)').length == 0){
1269
						incfilters[incfltcount].values = 'all';
1270
					}
1271
					else{
1272
						incfilters[incfltcount].values = new Array();
1273
						$(this).find('form input:checked').each(function(){
1274
							incfilters[incfltcount].values.push($(this).val());
1275
						});
1276
					}
1277
					incfltcount++;
1278
				}
1279
			}
1280
			//else{			
1281
				if($(this).find('form input:checked').length == 0 || $(this).find('form input:not(:checked)').length == 0){
1282
					return;
1283
				}
1284
				else{
1285
					filters[fltcount] = new Object();
1286
					filters[fltcount].name = $(this).find('.filterfullname').val();
1287
					if($(this).find('.ex').is(':checked')){
1288
						filters[fltcount].exvalues = new Array();
1289
						$(this).find('form input:checked').each(function(){
1290
							filters[fltcount].exvalues.push($(this).val());
1291
						});
1292
					}
1293
					else{					
1294
						filters[fltcount].values = new Array();
1295
						$(this).find('form input:checked').each(function(){
1296
							filters[fltcount].values.push($(this).val());
1297
						});
1298
					}					
1299
					filters[fltcount]['to'] = $(this).find('select.applyselect').val();
1300
					fltcount++;
1301
				}
1302
			//}
1303
		}
1304
		//HAVING
1305
		else{
1306
			if($(this).find('select.applyselect').val()==-2){
1307
				var flag = false;				
1308
				for(var i =0;i<inchavingcnt;i++){
1309
					if(inchaving[i].name == $(this).find('.filterfullname').val()){
1310
						flag=true;break;
1311
					}
1312
				}
1313
				if(!flag){
1314
					inchaving[inchavingcnt].name = $(this).find('.filterfullname').val();
1315
					inchaving[inchavingcnt].showname = $(this).find('.filtershowname').val();
1316
					inchavingcnt++;
1317
				}				
1318
			}
1319
			else{
1320
				if($(this).find('input.filter-value').val()==''){
1321
					return;
1322
				}
1323
				having[havingcnt] = new Object();
1324
				having[havingcnt].name = $(this).find('.filterfullname').val();
1325
				having[havingcnt].agg = $(this).find('.filter-aggrs-select').val();
1326
				having[havingcnt].value = $(this).find('input.filter-value').val();
1327
				having[havingcnt].fnc = $(this).find('.filter-fnc-select').val();
1328
				having[havingcnt]['to'] = $(this).find('select.applyselect').val();
1329
				havingcnt++;
1330
			}		
1331
		}
1332
		
1333
	});
1334
	selectedData['filters'] = filters;
1335
	selectedData['having'] = having;
1336
	selectedData['incfilters'] = incfilters;
1337
	selectedData['inchaving'] = inchaving;
1338
}
1339

    
1340
function getFilterData(table,field,fname,type){
1341
	$.ajax({  
1342
	   type: "GET",  
1343
	   url: "ajaxRouter9.php",  
1344
	   data: "com=filterData&table="+encodeURIComponent(table)+"&field="+encodeURIComponent(field),  
1345
	   success: function(resp){  
1346
		 // we have the response 
1347
		createFilter(fname,field,JSON.parse(resp),type);
1348
		$('#filterTable td').css('background-color','#e6e6e6');
1349
		$('#filterTable td:even').css('background-color','white');
1350
		},  
1351
	   error: function(e){  
1352
		 alert('Error: ' + e);  
1353
	   }  
1354
	});
1355
}
1356

    
1357
function createFilter(filterName,fullname,filterData,type) {
1358
	//every filter is a row in a table
1359
	var doc = document;
1360
	var row = doc.createElement('tr');
1361
	var col = doc.createElement('td'); row.appendChild(col);
1362
	$("#filterTable").append(row);
1363
	//create the div that will contain all
1364
	var container_div = doc.createElement("div");$(col).append(container_div);
1365
	$(container_div).attr("id","filter"+filtercounter).addClass('filter');
1366
	
1367
	var outer = doc.createElement('div');
1368
	
1369
	var header_p = doc.createElement("p"); 
1370
	var remove_a = doc.createElement("a"); 
1371
	container_div.appendChild(outer); $(outer).addClass('filterheader');
1372
	$(remove_a).addClass("removefilter").attr("href","#").append("<img src='images/close_16.png'/>");
1373
	//$(header_p).addClass("filtername").append("<a href='#' class='toggleFilter'>"+filterName+"</a>").append('<input type="hidden" value="'+fullname+'"></input>');
1374
	$(header_p).addClass("filtername").append("<input type='text' class='filtershowname' value='"+filterName+"'></input>").append('<input class="filterfullname" type="hidden" value="'+fullname+'">');
1375
	
1376
	outer.appendChild(remove_a);
1377
	outer.appendChild(header_p);
1378
	//create a div with the content of the filter
1379
	var filtcont = doc.createElement("div"); 
1380
	$(filtcont).addClass('filtercontent');
1381
	//apply to
1382
	var applydiv = doc.createElement('div');
1383
	var applyselect = doc.createElement('select');
1384
	$(applyselect).attr('id','apply'+filtercounter).addClass('applyselect');
1385
	$(applydiv).addClass('applyselect').append("<p class='small-header'>apply to:</p>").append(applyselect);
1386
	$(applyselect).append("<option value='-1'>whole chart</option><option value='-2'>include in chart</option>");
1387
	$('.field').each(function(index){
1388
		$(applyselect).append("<option value='"+(index+1)+"'>field "+(index+1)+"</option>");
1389
	});
1390
	$(container_div).append(applydiv);
1391
	$(container_div).append(filtcont);
1392
	if(filterData['type'] == "ordinal"){
1393
		//buttons
1394
		$(container_div).append("<br/><a class='xsmall-button slider btactive' href='#'>slider</a>");
1395
		$(container_div).append("<a class='xsmall-button discrete' href='#'>discrete</a>");
1396
		if(type=='m')
1397
			$(container_div).append("<a class='xsmall-button having' href='#'>having</a>");
1398
		//double slider
1399
		var str;
1400
		str = "<div class='filter-slider'><div class='slider-container'><div id='slider"+filtercounter+"' class='ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all' aria-disabled='false'></div></div>";
1401
		
1402
		str += "<span class='price-tip slider-user-min'><span id='userMin"+filtercounter+"'>"+filterData['min']+"</span></span>";
1403
		str += "<span class='price-tip slider-user-max'><span id='userMax"+filtercounter+"'>"+filterData['max']+"</span></span>";
1404
		str += "<span class='min' style='display:none'><span id='productMin"+filtercounter+"'>"+filterData['min']+"</span></span>";
1405
		str += "<span class='max' style='display:none'><span id='productMax"+filtercounter+"'>"+filterData['max']+"</span></span>";
1406
		str += "</div>";
1407
		$(filtcont).append(str);
1408
		$(function(){
1409
			$("#slider"+filtercounter).slider({
1410
				step: 1,
1411
				range: true,
1412
				min: filterData['min'],
1413
				max: filterData['max'],
1414
				values: [filterData['min'], filterData['max']],
1415
				slide: function(event, ui){
1416
					$(this).siblings('span').find('.slider-user-min').html(ui.values[0]);
1417
					$(this).siblings('span').find('.slider-user-max').html(ui.values[1]);
1418
				}
1419
			});
1420
		});
1421
		//str = "<div class='sel-all'><input type='checkbox'></input></div>";
1422
		//form
1423
		str = "<div class='filter-form' style='display:none'><a class='all' href='#'>all</a><span> | </span><a class='none' href='#'>none</a><span style='float:right'>exclude values</span><input style='float:right;margin:0px;' class='ex' type='checkbox' value='ex'></input>";
1424
		//checkboxes (hidden)
1425
		var wdt = 20*filterData['data'].length;
1426
		str += "<div class='form-container' style='width:100%;height:"+wdt+"px;'><form id='check"+filtercounter+"' class='filterform'>";
1427
		//$(filtcont).append("<p>choose values</p><div class='form-container'><form id='check"+filtercounter+"' class='filterform'>");
1428
		for(var i=0; i<filterData['data'].length; i++) {
1429
			str += "<input type='checkbox' name='form"+filtercounter+"' value='"+filterData['data'][i][0]+"'>"+filterData['data'][i][0]+"</input></br>";
1430
		}
1431
		str += "</form></div></div>";
1432
		$(filtcont).append(str);
1433
		//having
1434
		if(type=='m'){
1435
			str = "<div class='filter-having' style='display:none'><select id='faggr"+filtercounter+"' class='filter-aggrs-select'><option value='avg'>avg</option><option value='count'>count</option><option value='sum'>sum</option><option value='max'>max</option><option value='min'>min</option></select><select class='filter-fnc-select'><option value='='>&#61;</option><option value='!='>&#33;&#61;</option><option value='>'>&gt;</option><option value='<'>&lt;</option><option value='>='>&gt;&#61;</option><option value='<='>&lt;&#61;</option></select><input type='text' class='filter-value'></input></div>";
1436
			$(filtcont).append(str);
1437
		}
1438
	}
1439
	else if(filterData['type'] == "nominal") {
1440
		//checkboxes
1441
		var wdt = 20*filterData['data'].length;
1442
		//var str = "<div class='sel-all'><input type='checkbox'></input></div>";
1443
		var str = "<div class='filter-form'><a class='all' href='#'>all</a><span> | </span><a class='none' href='#'>none</a><span style='float:right'>exclude values</span><input style='float:right;margin:0px;' class='ex' type='checkbox' value='ex'></input>";
1444
		str += "<div class='form-container' style='width:100%;height:"+wdt+"px;'><form id='check"+filtercounter+"' class='filterform'>";
1445
		//$(filtcont).append("<p>choose values</p><div class='form-container'><form id='check"+filtercounter+"' class='filterform'>");
1446
		for(var i=0; i<filterData['data'].length; i++) {
1447
			str += "<input type='checkbox' name='form"+filtercounter+"' value='"+filterData['data'][i][0]+"'>"+filterData['data'][i][0]+"</input></br>";
1448
		}
1449
		str += "</form></div></div>";
1450
		$(filtcont).append(str);
1451
	}
1452
	else if(filterData['type'] == "quantitative") {
1453
		//will see
1454
	}
1455

    
1456
}
1457

    
1458
return {
1459
	getFullSchema: function(container){
1460
		var s = null;
1461
		$('document').css('cursor','wait');
1462
		return $.ajax({  
1463
			type: "GET",  
1464
			url: "ajaxRouter9.php",
1465
			data: "com=get_schema",
1466
			success: function(resp){
1467
			// we have the response
1468
			fs = JSON.parse(resp);
1469
			$('#dbName').html(fs.name);
1470
			s = fs.schema;
1471
			inits(s,container)
1472
			renderPage(s,s[0]['name']);
1473
			renderChartThemes('chartThemes');
1474
			menueffects();
1475
			userselect();
1476
			userselect2();
1477
			chartControls();
1478
			loadFlag = false;
1479
			defaultChart(null);
1480
			
1481
			$('#tableselect').on('change',function(){
1482
				chart = null;
1483
				selectedData['table'] = $(this).find(':selected').attr('value');
1484
				selectedData['fields'] = new Array();
1485
				//selectedData['series'] = new Array();
1486
				selectedData['xaxis'] = new Array();
1487
				selectedData['xaxis']['name'] = '';
1488
				
1489
				renderPage(s,$(this).find(':selected').attr('value'));
1490

    
1491
				//menueffects();
1492
				//userselect();
1493
				//userselect2();
1494
				chartControls();
1495
				loadFlag = false;
1496
				defaultChart($(this).find(':selected').attr('value'));
1497
			});
1498
			},  
1499
			error: function(e){  
1500
				alert('Error: ' + e);  
1501
		   }
1502
		});
1503
	}
1504
};
1505

    
1506
})();
1507
/*
1508

    
1509
function createFieldFilter(filterName,filterData,fieldcounter) {
1510
	//create the div that will contain all
1511
	var filterstr = "<div class='fieldfilter'><div class='filtercontent'>";
1512

    
1513
	if(filterData['type'] == "ordinal"){
1514
		//buttons
1515
		filterstr += "<br/><a class='xsmall-button fieldslider btactive' href='#'>slider</a>";
1516
		filterstr += "<a class='xsmall-button fielddiscrete' href='#'>discrete</a>";
1517
		filterstr += "<a class='xsmall-button fieldhaving' href='#'>having</a></br>";
1518
		//double slider
1519
		filterstr += "<div class='fieldfilter-slider'><div class='slider-container'><div id='fieldslider"+fieldcounter+"' class='ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all' aria-disabled='false'></div></div>";
1520
		
1521
		filterstr += "<span class='price-tip slider-user-min'><span id='fuserMin"+fieldcounter+"'>"+filterData['min']+"</span></span>";
1522
		filterstr += "<span class='price-tip slider-user-max'><span id='fuserMax"+fieldcounter+"'>"+filterData['max']+"</span></span>";
1523
		filterstr += "<span class='min' style='display:none'><span id='fproductMin"+fieldcounter+"'>"+filterData['min']+"</span></span>";
1524
		filterstr += "<span class='max' style='display:none'><span id='fproductMax"+fieldcounter+"'>"+filterData['max']+"</span></span>";
1525
		filterstr += "</div>";
1526
		//form
1527
		filterstr += "<div class='filter-form' style='display:none'><a class='all' href='#'>all</a><span> | </span><a class='none' href='#'>none</a>";
1528
		//checkboxes (hidden)
1529
		var wdt = 20*filterData['data'].length;
1530
		filterstr += "<div class='form-container' style='height:"+wdt+"px;'><form id='fcheck"+fieldcounter+"' class='filterform'>";
1531
		for(var i=0; i<filterData['data'].length; i++) {
1532
			str += "<input type='checkbox' name='fform"+fieldcounter+"' value='"+filterData['data'][i][0]+"'>"+filterData['data'][i][0]+"</input></br>";
1533
		}
1534
		filterstr += "</form></div></div>";
1535
		//having
1536
		filterstr += "<div class='filter-having' style='display:none'><select id='ffaggr"+fieldcounter+"' class='filter-aggrs-select'><option value='avg'>avg</option><option value='count'>count</option><option value='sum'>sum</option><option value='max'>max</option><option value='min'>min</option></select><select class='filter-fnc-select'><option value='='>&#61;</option><option value='!='>&#33;&#61;</option><option value='>'>&gt;</option><option value='<'>&lt;</option><option value='>='>&gt;&#61;</option><option value='<='>&lt;&#61;</option></select><input type='text' class='fieldfilter-value'></input></div>";
1537
	}
1538
	else if(filterData['type'] == "nominal") {
1539
		//checkboxes
1540
		var wdt = 20*filterData['data'].length;
1541
		//var str = "<div class='sel-all'><input type='checkbox'></input></div>";
1542
		var str = "<div class='filter-form'><a class='all' href='#'>all</a><span> | </span><a class='none' href='#'>none</a>";
1543
		str += "<div class='form-container' style='height:"+wdt+"px;'><form id='check"+filtercounter+"' class='filterform'>";
1544
		//$(filtcont).append("<p>choose values</p><div class='form-container'><form id='check"+filtercounter+"' class='filterform'>");
1545
		for(var i=0; i<filterData['data'].length; i++) {
1546
			str += "<input type='checkbox' name='form"+filtercounter+"' value='"+filterData['data'][i][0]+"'>"+filterData['data'][i][0]+"</input></br>";
1547
		}
1548
		str += "</form></div></div>";
1549
	}
1550
	
1551
	filterstr += "</div></div>";
1552
	return filterstr;
1553
}
1554

    
1555
*/
1556

    
1557

    
1558

    
(12-12/16)