| 1 |
|
| 2 |
var colors = ['red','orange','yellow','olive','green','teal','blue','violet','purple','pink','brown','grey','black']; |
| 3 |
var recentcolor=0; |
| 4 |
|
| 5 |
var mydata = {}; |
| 6 |
var startTime = new Date(); |
| 7 |
var activePlot=null; |
| 8 |
var myplots = {} |
| 9 |
var options = {} |
| 10 |
var plotdatastack = {}; |
| 11 |
|
| 12 |
var clearPlot = function(){ |
| 13 |
plotdatastack = {}; |
| 14 |
resultplots.empty(); |
| 15 |
myplots = {}; |
| 16 |
options = {}; |
| 17 |
} |
| 18 |
|
| 19 |
function createPlots(latestCode){ |
| 20 |
mydata = {}; startTime = new Date(); |
| 21 |
if(latestCode.indexOf('plot_radar(')>=0) |
| 22 |
addPolarPlot(); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
var polarPositions = []; |
| 27 |
|
| 28 |
var addPolarPlot = function(){ |
| 29 |
polarPositions = []; |
| 30 |
|
| 31 |
resultplots.append(` |
| 32 |
<div id="polarplot" style="min-width:300px;width:100%;height:100%;position:relative;"> |
| 33 |
<!-- Grey circle --> |
| 34 |
<svg viewBox="0 0 200 200" class="circle" style="position:absolute;"> |
| 35 |
<circle cx="100" cy="100" r="100" fill="#9cb" /> |
| 36 |
</svg> |
| 37 |
|
| 38 |
<!-- Pie --> |
| 39 |
<svg class="polar" viewBox="-1 -1 2 2" style="transform: rotate(-90deg);position: absolute;"> |
| 40 |
</svg> |
| 41 |
|
| 42 |
<!-- Slice borders --> |
| 43 |
<svg viewBox="0 0 200 200" style="transform: rotate(0deg);position:absolute;" xmlns="http://www.w3.org/2000/svg"> |
| 44 |
<line x1="0" y1="300" x2="0" y2="0" stroke-width="1" stroke="#ffffff33" transform="translate(100, 0)"> |
| 45 |
</svg> |
| 46 |
|
| 47 |
<svg viewBox="0 0 200 200" style="transform: rotate(60deg);position:absolute;" xmlns="http://www.w3.org/2000/svg"> |
| 48 |
<line x1="0" y1="300" x2="0" y2="0" stroke-width="1" stroke="#ffffff33" transform="translate(100, 0)"> |
| 49 |
</svg> |
| 50 |
|
| 51 |
<svg viewBox="0 0 200 200" style="transform: rotate(-60deg);position:absolute;" xmlns="http://www.w3.org/2000/svg"> |
| 52 |
<line x1="0" y1="300" x2="0" y2="0" stroke-width="1" stroke="#ffffff33" transform="translate(100, 0)"> |
| 53 |
</svg> |
| 54 |
|
| 55 |
<svg viewBox="0 0 200 200" style="transform: rotate(30deg);position:absolute;" xmlns="http://www.w3.org/2000/svg"> |
| 56 |
<line x1="0" y1="300" x2="0" y2="0" stroke-width="1" stroke="#ffffff33" transform="translate(100, 0)"> |
| 57 |
</svg> |
| 58 |
|
| 59 |
<svg viewBox="0 0 200 200" style="transform: rotate(-30deg);position:absolute;" xmlns="http://www.w3.org/2000/svg"> |
| 60 |
<line x1="0" y1="300" x2="0" y2="0" stroke-width="1" stroke="#ffffff33" transform="translate(100, 0)"> |
| 61 |
</svg> |
| 62 |
|
| 63 |
<svg viewBox="0 0 200 200" style="transform: rotate(90deg);position:absolute;" xmlns="http://www.w3.org/2000/svg"> |
| 64 |
<line x1="0" y1="300" x2="0" y2="0" stroke-width="1" stroke="#ffffff33" transform="translate(100, 0)"> |
| 65 |
</svg> |
| 66 |
|
| 67 |
|
| 68 |
<!-- Concentric circles --> |
| 69 |
<svg viewBox="0 0 200 200" class="polar circle" style="position:absolute;"> |
| 70 |
<circle cx="100" cy="100" r="100" fill="none" stroke="white" stroke-width="1" stroke-opacity=".5" /> |
| 71 |
<circle cx="100" cy="100" r="80" fill="none" stroke="white" stroke-width="1" stroke-opacity=".5"/> |
| 72 |
<circle cx="100" cy="100" r="60" fill="none" stroke="white" stroke-width="1" stroke-opacity=".5"/> |
| 73 |
<circle cx="100" cy="100" r="40" fill="none" stroke="white" stroke-width="1" stroke-opacity=".5"/> |
| 74 |
<circle cx="100" cy="100" r="20" fill="none" stroke="white" stroke-width="1" stroke-opacity=".5"/> |
| 75 |
</svg> |
| 76 |
|
| 77 |
|
| 78 |
</div> |
| 79 |
`); |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
plt = document.querySelector('.polar.circle'); |
| 84 |
|
| 85 |
for(var i=0;i<361;i++){ |
| 86 |
dot = document.createElementNS("http://www.w3.org/2000/svg", "circle"); |
| 87 |
dot.setAttribute('cx',100); |
| 88 |
dot.setAttribute('cy',100); |
| 89 |
dot.setAttribute('r',2); |
| 90 |
dot.setAttribute('stroke','lightgreen'); |
| 91 |
dot.setAttribute('fill','green'); |
| 92 |
polarPositions.push(dot); |
| 93 |
plt.appendChild(dot); |
| 94 |
} |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
var makePlotIfUnavailable = function(plotname){ |
| 99 |
if(!(plotname in myplots)){ |
| 100 |
mydata[plotname] = []; |
| 101 |
var w = resultplots.width()<300?300:resultplots.width(); |
| 102 |
var h = resultplots.height()<300 ? 300:resultplots.height(); |
| 103 |
if(h>400)h=400; |
| 104 |
startTime = new Date(); |
| 105 |
resultplots.append($('<span style="color:red" onclick="savePlotData(\''+plotname+'\');">'+plotname+'</span><hr color="red">')); |
| 106 |
resultplots.append($('<div id="cs_'+plotname+'">').width(w).height(h)); |
| 107 |
myplots[plotname] = 0; |
| 108 |
options[plotname] = { |
| 109 |
series: { |
| 110 |
lines: { |
| 111 |
show: true, |
| 112 |
lineWidth: 2 |
| 113 |
}, |
| 114 |
points: { |
| 115 |
radius: 2, |
| 116 |
show: true, |
| 117 |
color: "red", |
| 118 |
symbol: "cross" |
| 119 |
} |
| 120 |
}, |
| 121 |
xaxis: { |
| 122 |
gridLines: true, |
| 123 |
autoScaleMargin : 0.1, |
| 124 |
autoScale: 'exact', |
| 125 |
growOnly : true |
| 126 |
}, |
| 127 |
yaxis: { |
| 128 |
gridLines: true, |
| 129 |
autoScaleMargin : 0.1, |
| 130 |
autoScale: 'exact', |
| 131 |
growOnly : true |
| 132 |
}, |
| 133 |
|
| 134 |
legend: { |
| 135 |
show: true, |
| 136 |
noColumns: 1, |
| 137 |
labelFormatter: null, |
| 138 |
container: null, |
| 139 |
position: 'ne', |
| 140 |
margin: 5, |
| 141 |
sorted: null |
| 142 |
} |
| 143 |
}; |
| 144 |
|
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
var addDataPoint = function(plotname, x){ |
| 150 |
|
| 151 |
|
| 152 |
makePlotIfUnavailable(plotname); |
| 153 |
if(myplots[plotname]==0){ |
| 154 |
startTime = new Date(); |
| 155 |
mydata[plotname].push([0,x]); |
| 156 |
}else{ |
| 157 |
mydata[plotname].push([(new Date() - startTime)/1000.,x]); |
| 158 |
} |
| 159 |
myplots[plotname] ++; |
| 160 |
options[plotname].series.lines.show = false; |
| 161 |
|
| 162 |
options[plotname].xaxes = [{ position: 'bottom', axisLabel: 'Time (S)', show: true }]; |
| 163 |
$.plot("#cs_"+plotname, [{color: "red", lines: {show: true, lineWidth: 2}, data: mydata[plotname], label: "Y data"}], options[plotname]); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
var addDataPoints = function(plotname, x){ |
| 168 |
x = myInterpreter.pseudoToNative(x); |
| 169 |
makePlotIfUnavailable(plotname); |
| 170 |
var t=0; |
| 171 |
if(myplots[plotname]==0){ |
| 172 |
startTime = new Date(); |
| 173 |
for(var i=0;i<x.length;i++){ |
| 174 |
mydata[plotname].push({ lines: {show: true, lineWidth: 1}, data: [] ,label:'Y'+(i+1) } ); |
| 175 |
} |
| 176 |
}else{ |
| 177 |
t = (new Date() - startTime)/1000.; |
| 178 |
} |
| 179 |
|
| 180 |
try{ |
| 181 |
for(var i=0;i<x.length;i++){ |
| 182 |
mydata[plotname][i].data.push([t,x[i]]); |
| 183 |
if(myplots[plotname]==20)mydata[plotname][i].points = {show:false}; |
| 184 |
} |
| 185 |
|
| 186 |
myplots[plotname] ++; |
| 187 |
|
| 188 |
|
| 189 |
options[plotname].series.lines.show = false; |
| 190 |
|
| 191 |
options[plotname].xaxes = [{ position: 'bottom', axisLabel: 'Time (S)', show: true }]; |
| 192 |
$.plot("#cs_"+plotname, mydata[plotname], options[plotname]); |
| 193 |
}catch(e){ |
| 194 |
console.log('Plot Err:'+e); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
var addDataPointXY = function(plotname, x,y){ |
| 200 |
makePlotIfUnavailable(plotname); |
| 201 |
mydata[plotname].push([x,y]); |
| 202 |
myplots[plotname] ++; |
| 203 |
options[plotname].series.lines.show = false; |
| 204 |
$.plot("#cs_"+plotname, [{color: "red", lines: {show: true, lineWidth: 2}, data: mydata[plotname], label: plotname}], options[plotname]); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
var plotArraysXYStack = function(plotname,X,Y, state){ |
| 209 |
makePlotIfUnavailable(plotname); |
| 210 |
options[plotname].series.points.show = false; |
| 211 |
if(!(plotname in plotdatastack))plotdatastack[plotname] = []; |
| 212 |
|
| 213 |
if(state)plotdatastack[plotname] = [ {color: colors[plotdatastack[plotname].length % colors.length], lines: {show: true, lineWidth: 2}, data: [], label: "Chan "+plotdatastack[plotname].length} ]; |
| 214 |
else plotdatastack[plotname].push( {color: colors[plotdatastack[plotname].length % colors.length], lines: {show: true, lineWidth: 2}, data: [], label: "Chan "+plotdatastack[plotname].length} ); |
| 215 |
|
| 216 |
nx = myInterpreter.pseudoToNative(X); |
| 217 |
ny = myInterpreter.pseudoToNative(Y); |
| 218 |
|
| 219 |
|
| 220 |
dat = plotdatastack[plotname][plotdatastack[plotname].length - 1]; |
| 221 |
for (i=0;i<nx.length;i++){ |
| 222 |
dat.data.push([nx[i],ny[i]]); |
| 223 |
} |
| 224 |
|
| 225 |
$.plot("#cs_"+plotname, plotdatastack[plotname], options[plotname]); |
| 226 |
|
| 227 |
} |
| 228 |
|
| 229 |
var plotArraysXY = function(plotname,X,Y){ |
| 230 |
makePlotIfUnavailable(plotname); |
| 231 |
options[plotname].series.points.show = false; |
| 232 |
mydata[plotname] = [ |
| 233 |
{color: "red", lines: {show: true, lineWidth: 2}, data: [], label: "Chan 1"}, |
| 234 |
]; |
| 235 |
nx = Object.values(X.a) |
| 236 |
ny = Object.values(Y.a) |
| 237 |
for (i=0;i<nx.length;i++){ |
| 238 |
mydata[plotname][0].data.push([nx[i],ny[i]]); |
| 239 |
} |
| 240 |
|
| 241 |
$.plot("#cs_"+plotname, mydata[plotname], options[plotname]); |
| 242 |
|
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
var plotArraysXYY = function(plotname, X,Y1, Y2){ |
| 247 |
makePlotIfUnavailable(plotname); |
| 248 |
options[plotname].series.points.show = false; |
| 249 |
mydata[plotname] = [ |
| 250 |
{color: "red", lines: {show: true, lineWidth: 2}, data: [], label: "Chan 1"}, |
| 251 |
{color: "blue", lines: {show: true, lineWidth: 2}, data: [], label: "Chan 2"}, |
| 252 |
]; |
| 253 |
|
| 254 |
nx = Object.values(X.a) |
| 255 |
ny1 = Object.values(Y1.a) |
| 256 |
ny2 = Object.values(Y2.a) |
| 257 |
for (i=0;i<nx.length;i++){ |
| 258 |
mydata[plotname][0].data.push([nx[i],ny1[i]]); |
| 259 |
mydata[plotname][1].data.push([nx[i],ny2[i]]); |
| 260 |
} |
| 261 |
|
| 262 |
$.plot("#cs_"+plotname, mydata[plotname] , options[plotname]); |
| 263 |
|
| 264 |
} |
| 265 |
|
| 266 |
var plotArraysXYYY = function(plotname, X,Y1, Y2, Y3){ |
| 267 |
makePlotIfUnavailable(plotname); |
| 268 |
options[plotname].series.points.show = false; |
| 269 |
mydata[plotname] = [ |
| 270 |
{color: "red", lines: {show: true, lineWidth: 2}, data: [], label: "Chan 1"}, |
| 271 |
{color: "blue", lines: {show: true, lineWidth: 2}, data: [], label: "Chan 2"}, |
| 272 |
{color: "forestgreen", lines: {show: true, lineWidth: 2}, data: [], label: "Chan 3"}, |
| 273 |
]; |
| 274 |
|
| 275 |
nx = Object.values(X.a) |
| 276 |
ny1 = Object.values(Y1.a) |
| 277 |
ny2 = Object.values(Y2.a) |
| 278 |
ny3 = Object.values(Y3.a) |
| 279 |
for (i=0;i<nx.length;i++){ |
| 280 |
mydata[plotname][0].data.push([nx[i],ny1[i]]); |
| 281 |
mydata[plotname][1].data.push([nx[i],ny2[i]]); |
| 282 |
mydata[plotname][2].data.push([nx[i],ny3[i]]); |
| 283 |
} |
| 284 |
|
| 285 |
$.plot("#cs_"+plotname, mydata[plotname] , options[plotname]); |
| 286 |
|
| 287 |
} |
| 288 |
|
| 289 |
var savePlotData = function(plotname){ |
| 290 |
if(mydata[plotname].length == 0)return; |
| 291 |
if(mydata[plotname][0].constructor == Array){ |
| 292 |
x=[]; |
| 293 |
y=[]; |
| 294 |
for (var i=0;i<mydata[plotname].length;i++){ |
| 295 |
x.push(parseFloat(mydata[plotname][i][0])); |
| 296 |
y.push(parseFloat(mydata[plotname][i][1])); |
| 297 |
} |
| 298 |
JSBridge.save_lists(plotname+".csv",JSON.stringify(x),JSON.stringify(y),"[]","[]"); |
| 299 |
alert("Saved to SEELab3 directory :"+plotname+".csv"); |
| 300 |
|
| 301 |
} |
| 302 |
else if(mydata[plotname][0].constructor == Object){ |
| 303 |
msg = '' |
| 304 |
for (var dset=0;dset<mydata[plotname].length;dset++){ |
| 305 |
x=[]; |
| 306 |
y=[]; |
| 307 |
for (var i=0;i<mydata[plotname][dset].data.length;i++){ |
| 308 |
x.push(parseFloat(mydata[plotname][dset].data[i][0])); |
| 309 |
y.push(parseFloat(mydata[plotname][dset].data[i][1])); |
| 310 |
} |
| 311 |
JSBridge.save_lists(plotname+'_'+dset+'.csv',JSON.stringify(x),JSON.stringify(y),"[]","[]"); |
| 312 |
msg+=plotname+'_'+dset+'.csv ,'; |
| 313 |
} |
| 314 |
alert("Saved to SEELab3 directory :"+msg); |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
} |
| 319 |
|
| 320 |
var addDataPointPolar = function(angle, radius, maxrad){ |
| 321 |
angle = angle%360; |
| 322 |
x = 100+100*radius*Math.cos(3.1415*angle/180)/maxrad; |
| 323 |
y = 100-100*radius*Math.sin(3.1415*angle/180)/maxrad; |
| 324 |
polarPositions[Math.round(angle)].setAttribute('cx',x) |
| 325 |
polarPositions[Math.round(angle)].setAttribute('cy',y) |
| 326 |
|
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
Blockly.Blocks['plot_datapoint'] = { |
| 333 |
init: function() { |
| 334 |
this.appendDummyInput() |
| 335 |
.appendField("PLOT Y Vs Time:"); |
| 336 |
this.appendValueInput("VALUE") |
| 337 |
.setAlign(Blockly.ALIGN_LEFT) |
| 338 |
.appendField(new Blockly.FieldTextInput("myplot"), "PLOTNAME") |
| 339 |
.appendField("Y :") |
| 340 |
this.setInputsInline(false); |
| 341 |
this.setPreviousStatement(true, null); |
| 342 |
this.setNextStatement(true, null); |
| 343 |
this.setColour(230); |
| 344 |
this.setTooltip("Plot datapoint against time"); |
| 345 |
this.setHelpUrl(""); |
| 346 |
} |
| 347 |
}; |
| 348 |
|
| 349 |
|
| 350 |
Blockly.JavaScript['plot_datapoint'] = function(block) { |
| 351 |
var value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.Python.ORDER_NONE); |
| 352 |
var name = block.getFieldValue('PLOTNAME'); |
| 353 |
var code = 'sleep(0.001);\n'+'plot(\''+name+'\','+value+');\n'; |
| 354 |
|
| 355 |
return code; |
| 356 |
}; |
| 357 |
|
| 358 |
|
| 359 |
Blockly.Python['plot_datapoint'] = function(block) { |
| 360 |
var value = Blockly.Python.valueToCode(block, 'VALUE', Blockly.Python.ORDER_NONE); |
| 361 |
var code = 'plot('+value+')\n'; |
| 362 |
|
| 363 |
return code; |
| 364 |
}; |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
Blockly.Blocks['plot_datapoints'] = { |
| 369 |
init: function() { |
| 370 |
this.appendDummyInput() |
| 371 |
.appendField("PLOT Y[] Vs Time:"); |
| 372 |
this.appendValueInput("VALUE") |
| 373 |
.setAlign(Blockly.ALIGN_LEFT) |
| 374 |
.appendField(new Blockly.FieldTextInput("myplot"), "PLOTNAME") |
| 375 |
.appendField("Y[] :") |
| 376 |
this.setInputsInline(false); |
| 377 |
this.setPreviousStatement(true, null); |
| 378 |
this.setNextStatement(true, null); |
| 379 |
this.setColour(230); |
| 380 |
this.setTooltip("Plot datapoints against time"); |
| 381 |
this.setHelpUrl(""); |
| 382 |
} |
| 383 |
}; |
| 384 |
|
| 385 |
|
| 386 |
Blockly.JavaScript['plot_datapoints'] = function(block) { |
| 387 |
var value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.Python.ORDER_NONE); |
| 388 |
var name = block.getFieldValue('PLOTNAME'); |
| 389 |
var code = 'sleep(0.001);\n'+'plot_array(\''+name+'\','+value+');\n'; |
| 390 |
|
| 391 |
return code; |
| 392 |
}; |
| 393 |
|
| 394 |
|
| 395 |
Blockly.Python['plot_datapoints'] = function(block) { |
| 396 |
var value = Blockly.Python.valueToCode(block, 'VALUE', Blockly.Python.ORDER_NONE); |
| 397 |
var code = 'plot('+value+')\n'; |
| 398 |
|
| 399 |
return code; |
| 400 |
}; |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
Blockly.Blocks['plot_scale'] = { |
| 405 |
init: function() { |
| 406 |
this.appendDummyInput() |
| 407 |
.appendField(new Blockly.FieldTextInput("myplot"), "PLOTNAME"); |
| 408 |
this.appendDummyInput() |
| 409 |
.appendField(" : Set Range"); |
| 410 |
this.appendDummyInput() |
| 411 |
.appendField("Plot X Range, Min: ") |
| 412 |
.appendField(new Blockly.FieldNumber(0), "XMIN") |
| 413 |
.appendField(" Max: ") |
| 414 |
.appendField(new Blockly.FieldNumber(10), "XMAX") |
| 415 |
.appendField(new Blockly.FieldDropdown([["fixed","none"], ["autoscale","exact"]]), "SCALEX") |
| 416 |
this.appendDummyInput() |
| 417 |
.appendField("Plot Y Range, Min: ") |
| 418 |
.appendField(new Blockly.FieldNumber(-5), "YMIN") |
| 419 |
.appendField(" Max: ") |
| 420 |
.appendField(new Blockly.FieldNumber(5), "YMAX") |
| 421 |
.appendField(new Blockly.FieldDropdown([["fixed","none"], ["autoscale","exact"]]), "SCALEY"); |
| 422 |
this.setInputsInline(false); |
| 423 |
this.setPreviousStatement(true, null); |
| 424 |
this.setNextStatement(true, null); |
| 425 |
this.setColour(230); |
| 426 |
this.setTooltip("Plot Ranges"); |
| 427 |
this.setHelpUrl(""); |
| 428 |
} |
| 429 |
}; |
| 430 |
|
| 431 |
|
| 432 |
Blockly.JavaScript['plot_scale'] = function(block) { |
| 433 |
var xmin = Number(block.getFieldValue('XMIN')); |
| 434 |
var xmax = Number(block.getFieldValue('XMAX')); |
| 435 |
var ymin = Number(block.getFieldValue('YMIN')); |
| 436 |
var ymax = Number(block.getFieldValue('YMAX')); |
| 437 |
var scalex = block.getFieldValue('SCALEX'); |
| 438 |
var scaley = block.getFieldValue('SCALEY'); |
| 439 |
var name = block.getFieldValue('PLOTNAME'); |
| 440 |
var code = 'plot_scale(\''+name+'\',\'x\','+xmin+','+xmax+',\''+scalex+'\');\n'; |
| 441 |
code += 'plot_scale(\''+name+'\',\'y\','+ymin+','+ymax+',\''+scaley+'\');\n'; |
| 442 |
|
| 443 |
return code; |
| 444 |
}; |
| 445 |
|
| 446 |
|
| 447 |
Blockly.Python['plot_scale'] = function(block) { |
| 448 |
var xmin = Number(block.getFieldValue('XMIN')); |
| 449 |
var xmax = Number(block.getFieldValue('XMAX')); |
| 450 |
var ymin = Number(block.getFieldValue('YMIN')); |
| 451 |
var ymax = Number(block.getFieldValue('YMAX')); |
| 452 |
var name = block.getFieldValue('PLOTNAME'); |
| 453 |
var code = 'plot_scale(\''+name+'\',\'x\','+xmin+','+xmax+')\n'; |
| 454 |
code += 'plot_scale(\''+name+'\',\'y\','+ymin+','+ymax+')\n'; |
| 455 |
return code; |
| 456 |
}; |
| 457 |
|
| 458 |
|
| 459 |
Blockly.Blocks['plot_scale_x'] = { |
| 460 |
init: function() { |
| 461 |
this.appendDummyInput() |
| 462 |
.appendField(new Blockly.FieldTextInput("myplot"), "PLOTNAME"); |
| 463 |
this.appendDummyInput() |
| 464 |
.appendField(" : Set X Range"); |
| 465 |
this.appendDummyInput() |
| 466 |
.appendField("Plot X Range, Min: ") |
| 467 |
.appendField(new Blockly.FieldNumber(0), "XMIN"); |
| 468 |
this.appendDummyInput() |
| 469 |
.appendField(" Max: ") |
| 470 |
.appendField(new Blockly.FieldNumber(0), "XMAX"); |
| 471 |
this.setInputsInline(true); |
| 472 |
this.setPreviousStatement(true, null); |
| 473 |
this.setNextStatement(true, null); |
| 474 |
this.setColour(230); |
| 475 |
this.setTooltip("Plot X Axis Range"); |
| 476 |
this.setHelpUrl(""); |
| 477 |
} |
| 478 |
}; |
| 479 |
|
| 480 |
|
| 481 |
Blockly.JavaScript['plot_scale_x'] = function(block) { |
| 482 |
var vmin = Number(block.getFieldValue('XMIN')); |
| 483 |
var vmax = Number(block.getFieldValue('XMAX')); |
| 484 |
var name = block.getFieldValue('PLOTNAME'); |
| 485 |
var code = 'plot_scale(\''+name+'\',\'x\','+vmin+','+vmax+');\n'; |
| 486 |
|
| 487 |
return code; |
| 488 |
}; |
| 489 |
|
| 490 |
|
| 491 |
Blockly.Python['plot_scale_x'] = function(block) { |
| 492 |
var vmin = Number(block.getFieldValue('XMIN')); |
| 493 |
var vmax = Number(block.getFieldValue('XMAX')); |
| 494 |
var code = 'plot_scale(\'x\','+vmin+','+vmax+')\n'; |
| 495 |
return code; |
| 496 |
}; |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
Blockly.Blocks['plot_scale_y'] = { |
| 501 |
init: function() { |
| 502 |
this.appendDummyInput() |
| 503 |
.appendField(new Blockly.FieldTextInput("myplot"), "PLOTNAME"); |
| 504 |
this.appendDummyInput() |
| 505 |
.appendField(" : Set Y Range"); |
| 506 |
this.appendDummyInput() |
| 507 |
.appendField("Plot Y Range, Min: ") |
| 508 |
.appendField(new Blockly.FieldNumber(0), "YMIN"); |
| 509 |
this.appendDummyInput() |
| 510 |
.appendField(" Max: ") |
| 511 |
.appendField(new Blockly.FieldNumber(0), "YMAX"); |
| 512 |
this.setInputsInline(true); |
| 513 |
this.setPreviousStatement(true, null); |
| 514 |
this.setNextStatement(true, null); |
| 515 |
this.setColour(230); |
| 516 |
this.setTooltip("Plot Y Axis Range"); |
| 517 |
this.setHelpUrl(""); |
| 518 |
} |
| 519 |
}; |
| 520 |
|
| 521 |
|
| 522 |
Blockly.JavaScript['plot_scale_y'] = function(block) { |
| 523 |
var vmin = Number(block.getFieldValue('YMIN')); |
| 524 |
var vmax = Number(block.getFieldValue('YMAX')); |
| 525 |
var name = block.getFieldValue('PLOTNAME'); |
| 526 |
var code = 'plot_scale(\''+name+'\',\'y\','+vmin+','+vmax+');\n'; |
| 527 |
|
| 528 |
return code; |
| 529 |
}; |
| 530 |
|
| 531 |
|
| 532 |
Blockly.Python['plot_scale_y'] = function(block) { |
| 533 |
var vmin = Number(block.getFieldValue('YMIN')); |
| 534 |
var vmax = Number(block.getFieldValue('YMAX')); |
| 535 |
var code = 'plot_scale(\'y\','+vmin+','+vmax+')\n'; |
| 536 |
return code; |
| 537 |
}; |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
Blockly.Blocks['plot_xyarray'] = { |
| 544 |
init: function() { |
| 545 |
this.appendValueInput("X") |
| 546 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 547 |
.appendField("PLOT ARRAY X[]:") |
| 548 |
this.appendValueInput("Y") |
| 549 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 550 |
.appendField("ARRAY Y[]:"); |
| 551 |
this.appendDummyInput() |
| 552 |
.appendField(new Blockly.FieldTextInput("myplot"), "PLOTNAME") |
| 553 |
.appendField(new Blockly.FieldCheckbox("TRUE"), "CLEAR") |
| 554 |
.appendField("Clear?"); |
| 555 |
this.setInputsInline(false); |
| 556 |
this.setPreviousStatement(true, null); |
| 557 |
this.setNextStatement(true, null); |
| 558 |
this.setColour(230); |
| 559 |
this.setTooltip("Plot X, Y arrays"); |
| 560 |
this.setHelpUrl(""); |
| 561 |
} |
| 562 |
}; |
| 563 |
|
| 564 |
|
| 565 |
Blockly.JavaScript['plot_xyarray'] = function(block) { |
| 566 |
var X = Blockly.JavaScript.valueToCode(block, 'X', Blockly.JavaScript.ORDER_NONE); |
| 567 |
var Y = Blockly.JavaScript.valueToCode(block, 'Y', Blockly.JavaScript.ORDER_NONE); |
| 568 |
var name = block.getFieldValue('PLOTNAME'); |
| 569 |
var clr = block.getFieldValue('CLEAR'); |
| 570 |
var state = (clr == "TRUE")?true:false; |
| 571 |
var code = 'sleep(0.001);\n'+'plot_xyarray(\''+name+'\','+X+','+Y+','+state+');\n'; |
| 572 |
|
| 573 |
return code; |
| 574 |
}; |
| 575 |
|
| 576 |
|
| 577 |
Blockly.Python['plot_xyarray'] = function(block) { |
| 578 |
var X = Blockly.JavaScript.valueToCode(block, 'X', Blockly.JavaScript.ORDER_NONE); |
| 579 |
var Y = Blockly.JavaScript.valueToCode(block, 'Y', Blockly.JavaScript.ORDER_NONE); |
| 580 |
var code = 'sleep(0.001);\n'+'plot_xyarray('+X+','+Y+')\n'; |
| 581 |
|
| 582 |
return code; |
| 583 |
}; |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
Blockly.Blocks['plot_xyyarray'] = { |
| 592 |
init: function() { |
| 593 |
this.appendValueInput("X") |
| 594 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 595 |
.appendField("PLOT ARRAY X[]:") |
| 596 |
this.appendValueInput("Y1") |
| 597 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 598 |
.appendField("ARRAY Y1[]:") |
| 599 |
this.appendValueInput("Y2") |
| 600 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 601 |
.appendField(new Blockly.FieldTextInput("myplot"), "PLOTNAME") |
| 602 |
.appendField("ARRAY Y2[]:") |
| 603 |
this.setInputsInline(false); |
| 604 |
this.setPreviousStatement(true, null); |
| 605 |
this.setNextStatement(true, null); |
| 606 |
this.setColour(230); |
| 607 |
this.setTooltip("Plot X, Y1, Y2 arrays"); |
| 608 |
this.setHelpUrl(""); |
| 609 |
} |
| 610 |
}; |
| 611 |
|
| 612 |
|
| 613 |
Blockly.JavaScript['plot_xyyarray'] = function(block) { |
| 614 |
var X = Blockly.JavaScript.valueToCode(block, 'X', Blockly.JavaScript.ORDER_NONE); |
| 615 |
var Y1 = Blockly.JavaScript.valueToCode(block, 'Y1', Blockly.JavaScript.ORDER_NONE); |
| 616 |
var Y2 = Blockly.JavaScript.valueToCode(block, 'Y2', Blockly.JavaScript.ORDER_NONE); |
| 617 |
var name = block.getFieldValue('PLOTNAME'); |
| 618 |
var code = 'sleep(0.001);\n'+'plot_xyyarray(\''+name+'\','+X+','+Y1+','+Y2+');\n'; |
| 619 |
|
| 620 |
return code; |
| 621 |
}; |
| 622 |
|
| 623 |
|
| 624 |
Blockly.Python['plot_xyyarray'] = function(block) { |
| 625 |
var X = Blockly.Python.valueToCode(block, 'X', Blockly.Python.ORDER_NONE); |
| 626 |
var Y1 = Blockly.Python.valueToCode(block, 'Y1', Blockly.Python.ORDER_NONE); |
| 627 |
var Y2 = Blockly.Python.valueToCode(block, 'Y2', Blockly.Python.ORDER_NONE); |
| 628 |
var code = 'plot_xyyarray('+X+','+Y1+','+Y2+')\n'; |
| 629 |
return code; |
| 630 |
}; |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
Blockly.Blocks['plot_xyyyarray'] = { |
| 637 |
init: function() { |
| 638 |
this.appendValueInput("X") |
| 639 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 640 |
.appendField("PLOT ARRAY X[]:") |
| 641 |
this.appendValueInput("Y1") |
| 642 |
.appendField(new Blockly.FieldTextInput("myplot"), "PLOTNAME") |
| 643 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 644 |
.appendField("ARRAY Y1[]:") |
| 645 |
this.appendValueInput("Y2") |
| 646 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 647 |
.appendField("ARRAY Y2[]:") |
| 648 |
this.appendValueInput("Y3") |
| 649 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 650 |
.appendField("ARRAY Y3[]:") |
| 651 |
this.setInputsInline(false); |
| 652 |
this.setPreviousStatement(true, null); |
| 653 |
this.setNextStatement(true, null); |
| 654 |
this.setColour(230); |
| 655 |
this.setTooltip("Plot X, Y1, Y2, Y3 arrays"); |
| 656 |
this.setHelpUrl(""); |
| 657 |
} |
| 658 |
}; |
| 659 |
|
| 660 |
|
| 661 |
Blockly.JavaScript['plot_xyyyarray'] = function(block) { |
| 662 |
var X = Blockly.JavaScript.valueToCode(block, 'X', Blockly.JavaScript.ORDER_NONE); |
| 663 |
var Y1 = Blockly.JavaScript.valueToCode(block, 'Y1', Blockly.JavaScript.ORDER_NONE); |
| 664 |
var Y2 = Blockly.JavaScript.valueToCode(block, 'Y2', Blockly.JavaScript.ORDER_NONE); |
| 665 |
var Y3 = Blockly.JavaScript.valueToCode(block, 'Y3', Blockly.JavaScript.ORDER_NONE); |
| 666 |
var name = block.getFieldValue('PLOTNAME'); |
| 667 |
var code = 'sleep(0.001);\n'+'plot_xyyyarray(\''+name+'\','+X+','+Y1+','+Y2+','+Y3+');\n'; |
| 668 |
|
| 669 |
return code; |
| 670 |
}; |
| 671 |
|
| 672 |
|
| 673 |
Blockly.Python['plot_xyyyarray'] = function(block) { |
| 674 |
var X = Blockly.Python.valueToCode(block, 'X', Blockly.Python.ORDER_NONE); |
| 675 |
var Y1 = Blockly.Python.valueToCode(block, 'Y1', Blockly.Python.ORDER_NONE); |
| 676 |
var Y2 = Blockly.Python.valueToCode(block, 'Y2', Blockly.Python.ORDER_NONE); |
| 677 |
var Y3 = Blockly.Python.valueToCode(block, 'Y3', Blockly.Python.ORDER_NONE); |
| 678 |
var code = 'sleep(0.001)\n'+'plot_xyyyarray('+X+','+Y1+','+Y2+','+Y3+')\n'; |
| 679 |
return code; |
| 680 |
}; |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
Blockly.Blocks['plot_xy'] = { |
| 686 |
init: function() { |
| 687 |
this.appendDummyInput() |
| 688 |
.appendField("PLOT X,Y") |
| 689 |
this.appendValueInput("X") |
| 690 |
.appendField(new Blockly.FieldTextInput("myplot"), "PLOTNAME") |
| 691 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 692 |
.appendField("X:") |
| 693 |
this.appendValueInput("Y") |
| 694 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 695 |
.appendField("Y:") |
| 696 |
this.setInputsInline(false); |
| 697 |
this.setPreviousStatement(true, null); |
| 698 |
this.setNextStatement(true, null); |
| 699 |
this.setColour(230); |
| 700 |
this.setTooltip("Plot X, Y"); |
| 701 |
this.setHelpUrl(""); |
| 702 |
} |
| 703 |
}; |
| 704 |
|
| 705 |
|
| 706 |
Blockly.JavaScript['plot_xy'] = function(block) { |
| 707 |
var name = block.getFieldValue('PLOTNAME'); |
| 708 |
var vx = Blockly.JavaScript.valueToCode(block, 'X', Blockly.JavaScript.ORDER_NONE); |
| 709 |
var vy = Blockly.JavaScript.valueToCode(block, 'Y', Blockly.JavaScript.ORDER_NONE); |
| 710 |
var code = 'sleep(0.001);\n'+'plot_xy(\''+name+'\','+vx+','+vy+')\n'; |
| 711 |
|
| 712 |
return code; |
| 713 |
}; |
| 714 |
|
| 715 |
|
| 716 |
Blockly.Python['plot_xy'] = function(block) { |
| 717 |
var vx = Blockly.JavaScript.valueToCode(block, 'X', Blockly.Python.ORDER_NONE); |
| 718 |
var vy = Blockly.JavaScript.valueToCode(block, 'Y', Blockly.Python.ORDER_NONE); |
| 719 |
var code = 'plot_xy('+vx+','+vy+')\n'; |
| 720 |
|
| 721 |
return code; |
| 722 |
}; |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
Blockly.Blocks['plot_radar'] = { |
| 731 |
init: function() { |
| 732 |
this.appendDummyInput() |
| 733 |
.appendField("Polar Plot") |
| 734 |
this.appendValueInput("MAXRADIUS") |
| 735 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 736 |
.appendField("Maximum Radius:") |
| 737 |
this.appendValueInput("RADIUS") |
| 738 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 739 |
.appendField("RADIUS:") |
| 740 |
this.appendValueInput("ANGLE") |
| 741 |
.setAlign(Blockly.ALIGN_RIGHT) |
| 742 |
.appendField("ANGLE(Deg):") |
| 743 |
this.setInputsInline(false); |
| 744 |
this.setPreviousStatement(true, null); |
| 745 |
this.setNextStatement(true, null); |
| 746 |
this.setColour(230); |
| 747 |
this.setTooltip("Plot R, Theta"); |
| 748 |
this.setHelpUrl(""); |
| 749 |
} |
| 750 |
}; |
| 751 |
|
| 752 |
|
| 753 |
Blockly.JavaScript['plot_radar'] = function(block) { |
| 754 |
var angle = Blockly.JavaScript.valueToCode(block, 'ANGLE', Blockly.JavaScript.ORDER_NONE); |
| 755 |
var radius = Blockly.JavaScript.valueToCode(block, 'RADIUS', Blockly.JavaScript.ORDER_NONE); |
| 756 |
var maxrad = Blockly.JavaScript.valueToCode(block, 'MAXRADIUS', Blockly.JavaScript.ORDER_NONE); |
| 757 |
var code = 'sleep(0.001);\n'+'plot_radar('+angle+','+radius+','+maxrad+');\n'; |
| 758 |
|
| 759 |
return code; |
| 760 |
}; |
| 761 |
|
| 762 |
|
| 763 |
Blockly.Python['plot_radar'] = function(block) { |
| 764 |
var angle = Blockly.Python.valueToCode(block, 'ANGLE', Blockly.Python.ORDER_NONE); |
| 765 |
var radius = Blockly.Python.valueToCode(block, 'RADIUS', Blockly.Python.ORDER_NONE); |
| 766 |
var maxrad = Blockly.Python.valueToCode(block, 'MAXRADIUS', Blockly.Python.ORDER_NONE); |
| 767 |
var code = 'plot_radar('+angle+','+radius+','+maxrad+')\n'; |
| 768 |
|
| 769 |
return code; |
| 770 |
}; |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
function initPlots(interpreter, scope) { |
| 777 |
|
| 778 |
|
| 779 |
interpreter.setProperty(scope, 'plot', interpreter.createNativeFunction( |
| 780 |
function(plotname, value) { |
| 781 |
return addDataPoint(plotname, value); |
| 782 |
}) |
| 783 |
); |
| 784 |
|
| 785 |
|
| 786 |
interpreter.setProperty(scope, 'plot_array', interpreter.createNativeFunction( |
| 787 |
function(plotname, values) { |
| 788 |
return addDataPoints(plotname, values); |
| 789 |
}) |
| 790 |
); |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
interpreter.setProperty(scope, 'plot_scale', interpreter.createNativeFunction( |
| 796 |
function( plotname, axis, vmin,vmax, scale) { |
| 797 |
makePlotIfUnavailable(plotname); |
| 798 |
if(axis === 'x'){options[plotname].xaxis.min = vmin; options[plotname].xaxis.max = vmax; options[plotname].xaxis.autoScale=scale;} |
| 799 |
else if(axis === 'y'){options[plotname].yaxis.min = vmin; options[plotname].yaxis.max = vmax; options[plotname].yaxis.autoScale=scale;} |
| 800 |
}) |
| 801 |
); |
| 802 |
|
| 803 |
interpreter.setProperty(scope, 'plot_xy', interpreter.createNativeFunction( |
| 804 |
function(plotname, vx,vy) { |
| 805 |
return addDataPointXY(plotname, vx,vy); |
| 806 |
}) |
| 807 |
); |
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
interpreter.setProperty(scope, 'plot_xyarray', interpreter.createNativeFunction( |
| 812 |
function(plotname, X,Y, state) { |
| 813 |
if(typeof state == 'undefined')state = false; |
| 814 |
console.log(state); |
| 815 |
return plotArraysXYStack(plotname, X,Y, state); |
| 816 |
}) |
| 817 |
); |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
interpreter.setProperty(scope, 'plot_xyyarray', interpreter.createNativeFunction( |
| 822 |
function( plotname, x,y1, y2) { |
| 823 |
return plotArraysXYY(plotname, x,y1, y2); |
| 824 |
}) |
| 825 |
); |
| 826 |
|
| 827 |
|
| 828 |
interpreter.setProperty(scope, 'plot_xyyyarray', interpreter.createNativeFunction( |
| 829 |
function( plotname, x,y1, y2, y3) { |
| 830 |
return plotArraysXYYY(plotname, x,y1, y2, y3); |
| 831 |
}) |
| 832 |
); |
| 833 |
|
| 834 |
|
| 835 |
interpreter.setProperty(scope, 'plot_radar', interpreter.createNativeFunction( |
| 836 |
function( angle,radius, maxrad) { |
| 837 |
return addDataPointPolar(angle,radius, maxrad); |
| 838 |
}) |
| 839 |
); |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
|