Skip to content

Commit 067ff0e

Browse files
author
Matthew Matz
committed
Graphing improvements, initial addition of series legends
1 parent 11d484f commit 067ff0e

File tree

6 files changed

+121
-14
lines changed

6 files changed

+121
-14
lines changed

src/main/webapp/cdn/blockly/generators/propc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ Blockly.propc.finish = function (code) {
403403
var setup = '';
404404
if (Blockly.propc.serial_terminal_) {
405405
setup += "/* SERIAL_TERMINAL USED */\n";
406-
}
407-
if (Blockly.propc.serial_graphing_) {
406+
} else if (Blockly.propc.serial_graphing_) {
408407
setup += "/* SERIAL_GRAPHING USED */\n";
409408
}
410409
if (Blockly.mainWorkspace.getAllBlocks().length === 0) {

src/main/webapp/cdn/blockly/generators/propc/communicate.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3172,11 +3172,13 @@ Blockly.Blocks.graph_output = {
31723172
this.appendValueInput('PRINTa')
31733173
.setAlign(Blockly.ALIGN_RIGHT)
31743174
.setCheck('Number')
3175+
.appendField(new Blockly.FieldTextInput(''), 'GRAPH_LABELa')
31753176
.appendField('value');
31763177
this.setPreviousStatement(true);
31773178
this.setNextStatement(true);
31783179
this.setMutator(new Blockly.Mutator(['graph_dec']));
31793180
this.optionList_ = ['dec'];
3181+
this.graph_labels_ = [];
31803182
},
31813183
mutationToDom: function (workspace) {
31823184
// Create XML to represent menu options.
@@ -3191,6 +3193,7 @@ Blockly.Blocks.graph_output = {
31913193
for (var i = 0; i < this.optionList_.length; i++) {
31923194
this.appendValueInput('PRINT' + i)
31933195
.setAlign(Blockly.ALIGN_RIGHT)
3196+
.appendField(new Blockly.FieldTextInput(''), 'GRAPH_LABEL' + i)
31943197
.appendField('value');
31953198
}
31963199
},
@@ -3204,6 +3207,13 @@ Blockly.Blocks.graph_output = {
32043207
connection.connect(optionBlock.previousConnection);
32053208
connection = optionBlock.nextConnection;
32063209
}
3210+
var i = 0;
3211+
this.graph_labels_ = null;
3212+
this.graph_labels_ = [];
3213+
while (this.getFieldValue('GRAPH_LABEL' + i)) {
3214+
this.graph_labels_.push(this.getFieldValue('GRAPH_LABEL' + i));
3215+
i++;
3216+
}
32073217
return containerBlock;
32083218

32093219
},
@@ -3214,7 +3224,6 @@ Blockly.Blocks.graph_output = {
32143224
this.removeInput('PRINT' + i);
32153225
i++;
32163226
}
3217-
32183227
i = 0;
32193228
this.optionList_.length = 0;
32203229
// Rebuild the block's optional inputs.
@@ -3225,6 +3234,7 @@ Blockly.Blocks.graph_output = {
32253234
var printInput = this.appendValueInput('PRINT' + i)
32263235
.setAlign(Blockly.ALIGN_RIGHT)
32273236
.setCheck('Number')
3237+
.appendField(new Blockly.FieldTextInput('label'), 'GRAPH_LABEL' + i)
32283238
.appendField('value');
32293239

32303240
if (clauseBlock.valueConnection_) {
@@ -3235,6 +3245,11 @@ Blockly.Blocks.graph_output = {
32353245
clauseBlock = clauseBlock.nextConnection &&
32363246
clauseBlock.nextConnection.targetBlock();
32373247
}
3248+
i = this.graph_labels_.length;
3249+
for (i = 0; i < this.graph_labels_.length; i++) {
3250+
if (this.getFieldValue('GRAPH_LABEL' + i))
3251+
this.setFieldValue(this.graph_labels_[i], 'GRAPH_LABEL' + i);
3252+
}
32383253
},
32393254
saveConnections: function (containerBlock) {
32403255
// Store a pointer to any connected child blocks.
@@ -3250,6 +3265,14 @@ Blockly.Blocks.graph_output = {
32503265
clauseBlock = clauseBlock.nextConnection &&
32513266
clauseBlock.nextConnection.targetBlock();
32523267
}
3268+
var i = 0;
3269+
this.graph_labels_ = null;
3270+
this.graph_labels_ = [];
3271+
while (this.getFieldValue('GRAPH_LABEL' + i)) {
3272+
this.graph_labels_.push(this.getFieldValue('GRAPH_LABEL' + i));
3273+
i++;
3274+
}
3275+
32533276
},
32543277
onchange: function () {
32553278
if (this.workspace && this.optionList_.length < 1) {
@@ -3294,18 +3317,23 @@ Blockly.propc.graph_output = function () {
32943317

32953318
var code = 'print("%u';
32963319
var varList = '';
3320+
var labelList = '';
32973321
var i = 0;
32983322
var orIt = '';
32993323
while (Blockly.propc.valueToCode(this, 'PRINT' + i, Blockly.propc.ORDER_NONE)) {
33003324
code += ',%d';
33013325
varList += ', ' + Blockly.propc.valueToCode(this, 'PRINT' + i, Blockly.propc.NONE || '0');
3326+
labelList += this.getFieldValue("GRAPH_LABEL" + i);
3327+
if (Blockly.propc.valueToCode(this, 'PRINT' + (i + 1), Blockly.propc.ORDER_NONE) && i < 9)
3328+
labelList += ',';
33023329
i++;
33033330
if (i > 10)
33043331
break;
33053332
}
33063333
code += '\\r", (CNT >> 16)' + varList + ');\n';
33073334

33083335
Blockly.propc.serial_graphing_ = true;
3336+
Blockly.propc.definitions_['graphing_labels'] = '// GRAPH_LABELS_START:' + labelList + ':GRAPH_LABELS_END //';
33093337

33103338
return code;
33113339
};

src/main/webapp/cdn/blocklyc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var graph_temp_string = new String;
2626
var graph_time_multiplier = 0;
2727
var graph_interval_id = null;
2828
var fullCycleTime = 4294967296 / 80000000;
29+
var graph_labels = null;
2930

3031
var console_header_arrived = false;
3132
var console_header = null;
@@ -373,6 +374,13 @@ function graphing_console() {
373374

374375
// GRAPH_SETTINGS:rate,x_axis_val,x_axis_type,y_min,y_max:GRAPH_SETTINGS_END //
375376

377+
var graph_labels_start = propcCode.indexOf("// GRAPH_LABELS_START:");
378+
if (graph_labels_start > -1) {
379+
var graph_labels_end = propcCode.indexOf(":GRAPH_LABELS_END //") + 20;
380+
var graph_labels_temp = propcCode.substring(graph_labels_start, graph_labels_end).split(':');
381+
graph_labels = graph_labels_temp[1].split(',');
382+
}
383+
376384
graph_options.refreshRate = Number(graph_settings_str[0]);
377385

378386
if (graph_settings_str[3] === '0' && graph_settings_str[4] === '0')
@@ -425,8 +433,10 @@ function graphing_console() {
425433
};
426434

427435
if (newGraph || graph !== null) {
436+
graph_new_labels();
428437
graph_interval_id = setInterval(function () {
429438
graph.update(graph_data);
439+
graph_update_labels();
430440
}, graph_options.refreshRate);
431441
}
432442

@@ -623,7 +633,9 @@ function graph_reset() {
623633
graph_temp_string = '';
624634
graph_timestamp_start = null;
625635
graph_data_ready = false;
636+
// graph_labels = null;
626637
$("#serial_graphing").html('');
638+
//$("#serial_graphing_labels").html('');
627639
}
628640

629641
function graph_redraw() {
@@ -683,4 +695,21 @@ function downloadGraph() {
683695
saveData(svgxml, value + '.svg');
684696
}
685697
});
698+
}
699+
700+
function graph_new_labels() {
701+
var labelsvg = '<svg width="60" height="300">';
702+
for (var t = 0; t < graph_labels.length; t++) {
703+
labelsvg += '<g id="labelgroup' + (t+1) + '" transform="translate(0,' + (t*25+35) + ')">';
704+
labelsvg += '<path id="label' + (t+1) + '" class="ct-marker-' + (t+1);
705+
labelsvg += '" d="M0,6 L5,0 58,0 59,1 60,2 60,10 59,11 58,12 5,12 Z"/>';
706+
labelsvg += '<text id="label' + (t+1) + 'text" x="6" y="10" style="font-family:';
707+
labelsvg += 'Arial;font-size: 10px;fill:#fff; font-weight:bold;">' + graph_labels[t] + '</text></g>';
708+
}
709+
labelsvg += '</svg>';
710+
$('#serial_graphing_labels').html(labelsvg);
711+
}
712+
713+
function graph_update_labels() {
714+
686715
}

src/main/webapp/cdn/blocklypropclient.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ var check_com_ports_interval = null;
2828
version_as_number = function (rawVersion) {
2929
var tempVersion = rawVersion.toString().split(".");
3030
tempVersion.push('0');
31-
32-
if(tempVersion.length < 3) {
33-
bootbox.alert("BlocklyProp is unable to determine what version of " +
31+
32+
if (tempVersion.length < 3) {
33+
bootbox.alert("BlocklyProp is unable to determine what version of " +
3434
"BlocklyPropClient is installed on your computer.\nYou may need to install" +
3535
"or reinstall the BlocklyPropClient.");
36-
if(tempVersion.length === 1) tempVersion = '0.0.0';
36+
if (tempVersion.length === 1)
37+
tempVersion = '0.0.0';
3738
else
38-
tempVersion.unshift('0');
39+
tempVersion.unshift('0');
3940
}
40-
41+
4142
// Allow for any of the three numbers to be between 0 and 1023.
4243
// Equivalent to: (Major * 104856) + (Minor * 1024) + Revision.
4344
return (Number(tempVersion[0]) << 20 | Number(tempVersion[1]) << 10 | Number(tempVersion[2]));

src/main/webapp/cdn/style-editor.css

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,12 @@ nav .nav > li > a:first-child {
424424

425425
.ct-series-g .ct-line {
426426
stroke-width: 1px;
427-
stroke: #c0c;
427+
stroke: #d09;
428428
}
429429

430430
.ct-series-h .ct-line {
431431
stroke-width: 1px;
432-
stroke: #000;
432+
stroke: #90d;
433433
}
434434

435435
.ct-series-i .ct-line {
@@ -439,4 +439,45 @@ nav .nav > li > a:first-child {
439439

440440
.ct-series-j .ct-line {
441441
stroke-width: 1px;
442+
stroke: #000
443+
}
444+
445+
.ct-marker-1 {
446+
fill: #00f;
447+
}
448+
449+
.ct-marker-2 {
450+
fill: #0bb;
451+
}
452+
453+
.ct-marker-3 {
454+
fill: #0d0;
455+
}
456+
457+
.ct-marker-4 {
458+
fill: #dd0;
459+
}
460+
461+
.ct-marker-5 {
462+
fill: #f90;
463+
}
464+
465+
.ct-marker-6 {
466+
fill: #f00;
467+
}
468+
469+
.ct-marker-7 {
470+
fill: #d09;
471+
}
472+
473+
.ct-marker-8 {
474+
fill: #90d;
475+
}
476+
477+
.ct-marker-9 {
478+
fill: #777;
479+
}
480+
481+
.ct-marker-10 {
482+
fill: #000
442483
}

src/main/webapp/editor/blocklyc.jsp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,17 @@
136136
<h4 class="modal-title" id="graphing-dialog-title"><fmt:message key="editor.title.graphing" /></h4>
137137
</div>
138138
<div class="modal-body" style="height: 430px;">
139-
<div id="serial_graphing" class="ct-chart ct-perfect-fourth"></div>
140-
<div id="graph_x-axis_label" align="center">Time (seconds)</div>
139+
<table>
140+
<tr>
141+
<td>
142+
<div id="serial_graphing" class="ct-chart ct-perfect-fourth"></div>
143+
<div id="graph_x-axis_label" align="center">Time (seconds)</div>
144+
</td>
145+
<td valign="top">
146+
<div id="serial_graphing_labels"></div>
147+
</td>
148+
</tr>
149+
</table>
141150
</div>
142151
<div class="modal-footer clearfix">
143152
<button type="button" id="btn-graph-play" class="btn btn-primary btn-circle pull-left" onclick="graph_play();"><i class="glyphicon glyphicon-pause"></i></button>&nbsp;
@@ -153,7 +162,7 @@
153162
<script src="<url:getCdnUrl url="/lib/bootstrap/core/js/bootstrap.min.js"/>"></script>
154163
<script src="<url:getCdnUrl url="/lib/bootstrap/plugins/bootbox.min.js"/>"></script>
155164
<script>
156-
var type = 'PROPC';
165+
var type = 'PROPC';
157166
</script>
158167
</body>
159168
</html>

0 commit comments

Comments
 (0)