summaryrefslogtreecommitdiff
path: root/views/script/form.js
blob: 2198a5097511d8cd5bd885e585c017c66026ac44 (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
var socket = io();

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

	console.log(Object.keys(data));

	$('webtronics_plot_keys').innerHTML = "Available keys: " + Object.keys(data);
		
	//Dynamically creating traces
	jQuery("#plot_graph").click(function(){
		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
    				}
  				};
  				$('plot_details').style.display = "none";
  				$('webtronics_graph_display').style.display = "block";
  	 			Plotly.newPlot(document.getElementById('webtronics_graph_display'), dataForPlotly, layout);
			}
		}
	
	});
	
})