summaryrefslogtreecommitdiff
path: root/views/script/form.js
blob: 22502ea777baa66dae65f962089ab3169dcd87e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var socket = io();

socket.on("plotData",function(data){
	var keys = Object.keys(data);
	var traceObj = {};
	var traces = [];
	


	$('webtronics_plot_keys').innerHTML = "Available keys: " + Object.keys(data);
		
	//Dynamically creating traces
	for(var i=0; i<keys.length; i++){
		if(keys[i]=='x-axis'){
		continue;
		}
 		else{
			var trace = {
				x: data['x-axis'],
				y: data[keys[i]],
				name:keys[i],
				type: 'scatter'
			};
			traceObj[keys[i]] = trace;
		}
	}

	var traceKey = Object.keys(traceObj);
	for (var i=0;i<traceKey.length;i++) {
 		var value = traceObj[traceKey[i]];
  		traces.push(value);
	}
	
			
	var dataForPlotly = traces;

	var layout = {
		title:'Simulation Output',
		yaxis: { title: "Voltage(Volts) / Current(Amp)"},      // set the y axis title
		xaxis: {
			title:"time(Sec) / Frequency(Hz)",
			showgrid: true                 // remove the x-axis grid lines
		},
    	margin: {                           // update the left, bottom, right, top margin
    		l: 60, b: 35, r: 10, t: 25
    	}
    };

    Plotly.newPlot(document.getElementById('webtronics_graph_display'), dataForPlotly, layout);


	jQuery("#plot_graph").click(function(){
		var traceObj = {};
		var traces = [];
		var abscissa, ordinate;
		abscissa = $('abscissa_value').value;
		ordinate = $('ordinate_value').value;
		if(abscissa == "" || ordinate == ""){
			alert("PLease enter values to plot graph");
		}
		else{
			var flag = 0;
			for(var i=0; i<keys.length; i++){
				if(keys[i]==ordinate){
					flag=1;
					var trace = {
						x: data[abscissa],
						y: data[keys[i]],
						name: keys[i],
						type: 'scatter'
					};
					traceObj[keys[i]] = trace;
				}
		
			}

			if(flag == 0){
			alert("Invalid inputs");
			}
			else{
				var traceKey = Object.keys(traceObj);

				for (var i=0;i<traceKey.length;i++) {
  					var value = traceObj[traceKey[i]];
  					traces.push(value);
				}
	
				console.log("traces :"+traces);
				var dataForPlotly = traces;

				var layout = {
					title:'Simulation Output',
					yaxis: { title: "Voltage(Volts) / Current(Amp)"},      // set the y axis title
					xaxis: {
						title:"time(Sec) / Frequency(Hz)",
						showgrid: true                 // remove the x-axis grid lines
					},
    				margin: {                           // update the left, bottom, right, top margin
    					l: 60, b: 35, r: 10, t: 25
    				}
  				};
  	 			Plotly.newPlot(document.getElementById('webtronics_graph_display'), dataForPlotly, layout);
			}
		}
	
	});
	
})