forked from niyeradori/QuickSmith-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsertionLoss.html
372 lines (334 loc) · 14 KB
/
InsertionLoss.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<!-- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=6.0, minimum-scale=.25, user-scalable=yes"/>
<title>Insertion Loss</title>
<link href="img/smith.ico" rel="icon" >
<link href="css/bootstrap3.min.css" rel="stylesheet" type="text/css" media="all"/>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/bootstrap3.min.js"></script>
<script src="js/math.min.js"></script>
<script src="common.js"></script>
<script src="smith.js"></script>
<script src="sch.js"></script>
<script src="js/Chart.min.js"></script>
<script src="js/chartjs-plugin-zoom.min.js"></script>
<style>
.container {
width: 80%;
margin: 15px auto;
}
body {
-webkit-touch-callout: none;
-webkit-text-size-adjust: none;
-webkit-user-select: none;
}
table {
border-collapse: collapse;
}
td {
padding-top: .5em;
padding-bottom: .5em;
}
</style>
</head>
<body>
<!-- ********************************NAV BAR************************************************* -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- <a class="navbar-brand" href="#"><img src="img/smith.ico">QuickSmith</a> -->
<a class="navbar-brand" href="index.html">
<img src="img/smith.ico" style="display: inline-block; margin-top:-7px; width:32px; height:32px">
<span style="display: inline-block; color:blue">QuickSmith</span>
</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
</ul>
<button class="btn btn-default navbar-btn" onclick=runILsweep() >Run Sweep</button>
<ul class="nav navbar-nav navbar-right">
<li><a href="#" onclick=goBack_click() ><span class="glyphicon glyphicon-backward"></span>Back</a></li>
<li><a href="qsmithfaq.html"><span class="glyphicon glyphicon-book"></span> FAQ</a></li>
<!-- <li><a href="#" data-toggle="modal" data-target="#optionsModal" onclick ="options_click()"><span class="glyphicon glyphicon-list-alt"></span> Options</a></li> -->
</ul>
</div>
</div>
</nav>
<!-- onclick=runILsweep() -->
<!-- ********************************Chart WINDOW************************************************* -->
<div class="container-fluid">
<div class="row">
<!-- <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12" style="margin-top: 0px"> -->
<!-- <h4 style = "font-weight:bold" >Smith Chart</h4> -->
<table style="margin-left: 20px;">
<tr >
<td> <label for="START" > <font size="1"> START [MHZ]: </font> </label> </td>
<td> <input id="START" type="text" value="1" style="width: 100%" class="form-control input-sm" onchange="spin_change1(this.id)" /></td>
<td>    </td>
<td> <label for="STOP" > <font size="1"> STOP [MHZ]: </font> </label> </td>
<td> <input id="STOP" type="text" value="100" style="width: 100%" class="form-control input-sm " onchange="spin_change1(this.id)" /></td>
<td>    </td>
<td> <label for="STEP" > <font size="1"> STEP [MHZ]: </font> </label> </td>
<td> <input id="STEP" type="text" value="1" style="width: 100%" class="form-control input-sm " onchange="spin_change1(this.id)" /></td>
<td>    </td>
</tr>
<br />
<tr >
<td style="margin-top: 10px"> <label style="width: 100%"> <font size="1"></font> </label> </td>
<td> <label for="SE"><font size="1"> Sweep Variable:</label>
<select class="form-control input-sm" id="SE" style="width: 100%">
<option>Frequency</option>
<option>Element 2</option>
<option>Element 3</option>
<option>Element 4</option>
<option>Element 5</option>
<option>Element 6</option>
<option>Element 7</option>
<option>Element 8</option>
<option>Element 9</option>
<option>Element 10</option>
</select>
</td>
</tr>
</table>
</canvas><canvas id="myChart" ></canvas>
<!-- </div> -->
</div>
</div>
<script>
/*************************INSERTION LOSS CHART********************************************************************************/
$('document').ready(function () {
console.log("init")
get();
runILsweep();
})
function get() {
// Get from local storage
var item = localStorage.getItem('schDataIL');
if( item !== null)
{
var schObj1 =JSON.parse(item);
copy_schObj(schObj1);
}
else { console.log(" schDataIL local storage not set"); };
}
// // // stackoverflow 37250456 evenly distribute ticks when using maxTicksLimit
// Chart.pluginService.register({
// afterUpdate: function (chart) {
// var xScale = chart.scales['x-axis-0'];
// if (xScale.options.ticks.maxTicksLimit) {
// // store the original maxTicksLimit
// xScale.options.ticks._maxTicksLimit = xScale.options.ticks.maxTicksLimit;
// // let chart.js draw the first and last label
// xScale.options.ticks.maxTicksLimit = (xScale.ticks.length % xScale.options.ticks._maxTicksLimit === 0) ? 1 : 2;
// var originalXScaleDraw = xScale.draw
// xScale.draw = function () {
// originalXScaleDraw.apply(this, arguments);
// var xScale = chart.scales['x-axis-0'];
// if (xScale.options.ticks.maxTicksLimit) {
// var helpers = Chart.helpers;
// var tickFontColor = helpers.getValueOrDefault(xScale.options.ticks.fontColor, Chart.defaults.global.defaultFontColor);
// var tickFontSize = helpers.getValueOrDefault(xScale.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
// var tickFontStyle = helpers.getValueOrDefault(xScale.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
// var tickFontFamily = helpers.getValueOrDefault(xScale.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
// var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
// var tl = xScale.options.gridLines.tickMarkLength;
// var isRotated = xScale.labelRotation !== 0;
// var yTickStart = xScale.top;
// var yTickEnd = xScale.top + tl;
// var chartArea = chart.chartArea;
// // use the saved ticks
// var maxTicks = xScale.options.ticks._maxTicksLimit - 1;
// var ticksPerVisibleTick = xScale.ticks.length / maxTicks;
// // chart.js uses an integral skipRatio - this causes all the fractional ticks to be accounted for between the last 2 labels
// // we use a fractional skipRatio
// var ticksCovered = 0;
// helpers.each(xScale.ticks, function (label, index) {
// if (index < ticksCovered)
// return;
// ticksCovered += ticksPerVisibleTick;
// // chart.js has already drawn these 2
// if (index === 0 || index === (xScale.ticks.length - 1))
// return;
// // copy of chart.js code
// var xLineValue = this.getPixelForTick(index);
// var xLabelValue = this.getPixelForTick(index, this.options.gridLines.offsetGridLines);
// if (this.options.gridLines.display) {
// this.ctx.lineWidth = this.options.gridLines.lineWidth;
// this.ctx.strokeStyle = this.options.gridLines.color;
// xLineValue += helpers.aliasPixel(this.ctx.lineWidth);
// // Draw the label area
// this.ctx.beginPath();
// if (this.options.gridLines.drawTicks) {
// this.ctx.moveTo(xLineValue, yTickStart);
// this.ctx.lineTo(xLineValue, yTickEnd);
// }
// // Draw the chart area
// if (this.options.gridLines.drawOnChartArea) {
// this.ctx.moveTo(xLineValue, chartArea.top);
// this.ctx.lineTo(xLineValue, chartArea.bottom);
// }
// // Need to stroke in the loop because we are potentially changing line widths & colours
// this.ctx.stroke();
// }
// if (this.options.ticks.display) {
// this.ctx.save();
// this.ctx.translate(xLabelValue + this.options.ticks.labelOffset, (isRotated) ? this.top + 12 : this.options.position === "top" ? this.bottom - tl : this.top + tl);
// this.ctx.rotate(helpers.toRadians(this.labelRotation) * -1);
// this.ctx.font = tickLabelFont;
// this.ctx.textAlign = (isRotated) ? "right" : "center";
// this.ctx.textBaseline = (isRotated) ? "middle" : this.options.position === "top" ? "bottom" : "top";
// this.ctx.fillText(label, 0, 0);
// this.ctx.restore();
// }
// }, xScale);
// }
// };
// }
// },
// });
var freqPoints = [];
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
lineThickness: 1,
animation: true,
data: {
//labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S'],
labels: [],
datasets: [{
label: '',
data: [0,0],
borderColor:"rgba(0,0,255,1)",
backgroundColor: "rgba(255,255,255,0)",
borderWidth: 1
}]
},
options:{
title:{
display:true,
text:'Insertion Loss [dB]',
fontSize:25
},
legend: {
display: false
},
layout:{
padding:{
left:50,
right:50,
bottom:50,
top:0
}
},
tooltips:{
enabled:true,
// callback: function(tooltipItem) {
// return tooltipItem.yLabel;
// }
},
scales: {
xAxes: [{
position: 'top',
ticks: {
autoSkip: true,
maxTicksLimit: 10,
// min:0,
//max:1000,
},
stacked: true,
gridLines: {
lineWidth: 1,
color: "rgba(255,255,255,0)"
},
scaleLabel: {
display: true,
labelString: "Frequency [MHz]",
fontColor: "green"
}
}],
yAxes: [{
gridLines: {
color: "black",
borderDash: [2, 5],
},
scaleLabel: {
display: true,
labelString: "dB",
fontColor: "green"
},
}],
},
zoom: {
enabled: false,
mode: 'xy'
},
pan: {
enabled: false,
mode: 'xy'
},
elements: {
point: { radius: 0, hitRadius: 10, hoverRadius: 10 }
}
}
});
function runILsweep()
{
var sweepElement = document.getElementById("SE").value;
var start = document.getElementById("START").value;
var stop = document.getElementById("STOP").value;
var step = document.getElementById("STEP").value;
if( isNumeric(start) == 0 || isNumeric(stop) == 0 || isNumeric(step) == 0) {
return;
}
console.log( " Running IL")
if(sweepElement == "Frequency") sweepElement = "Element 0";
if(sweepElement == "Frequency" && start <0) start =0.000000000000001;
var points = Math.abs((stop-start)/step);
var elNum = parseInt(sweepElement.split(' ')[1]);
var oldValue;
if(schObj.ELEMENT[elNum].tune == 1) oldValue = schObj.ELEMENT[elNum].value1; else oldValue = schObj.ELEMENT[elNum].value2;
if(schObj.ELEMENT[elNum].tune == 1) schObj.ELEMENT[elNum].value1=parseFloat(start) ; else schObj.ELEMENT[elNum].value2= parseFloat(start);
console.log( "points = " +points);
myChart.data.datasets[0].data.splice(0,myChart.data.datasets[0].data.length); // clear data
myChart.data.labels = []; // lazy way to clear data, references not cleared.
//freqPoints[0] = parseFloat(start);
myChart.data.labels[0] =parseFloat(start);
var i;
for ( i=0; i <= points; i++) {
if(i!==0) {
if(schObj.ELEMENT[elNum].tune == 1) schObj.ELEMENT[elNum].value1=math.add(schObj.ELEMENT[elNum].value1,step) ;
else schObj.ELEMENT[elNum].value2=math.add(schObj.ELEMENT[elNum].value2,step);
//freqPoints[i] = math.add(points,step);
myChart.data.labels[i] = math.add(start,math.multiply(step,i));
}
resultsObj.OUTPUT[0].calculate(); // this will call Zcalsweep1(); calculate Zcalsweep1
resultsObj.OUTPUT[5].calculate(); // calculate Insertion loss
myChart.data.datasets[0].data[i] = resultsObj.OUTPUT[5].S21Mag ;
//console.log( "next value = " +schObj.ELEMENT[elNum].value1);
}
if(schObj.ELEMENT[elNum].tune == 1) schObj.ELEMENT[elNum].value1=oldValue; else schObj.ELEMENT[elNum].value2=oldValue;
myChart.update();
}
function goBack_click() {
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if (isFirefox) { // Firefox does not open the parent window why
var new_window= window.open('index.html', '_blank');
new_window.location;
}
else {
var goBack = window.open('', 'parent');
goBack.focus();
}
}
</script>
</body>
</html>