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