Skip to content

Commit 3c7049b

Browse files
authored
Merge pull request #1045 from MatzElectronics/demo
2 parents d69863e + 1be6cd6 commit 3c7049b

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

src/main/webapp/WEB-INF/includes/pageparts/editor-menu.jsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<a onclick="serial_console()" data-toggle="tooltip" title="Open Serial Terminal" data-placement="bottom" class="btn btn-primary btn-circle"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="15"><rect x="1" y="1" width="12" height="13" rx="1" ry="1" style="stroke:#fff;stroke-width:2;fill:none;"/><path d="M3,4.5 L10,4.5 M3,6.5 L6,6.5 M3,8.5 L8,8.5" style="stroke:#fff;stroke-width:1;fill:none;"/></svg></a>
5252
<c:choose>
5353
<c:when test="${experimental == true}">
54-
<a onclick="graphing_console()" data-toggle="tooltip" title="Open Graphing Output" data-placement="bottom" class="btn btn-primary btn-circle"><svg xmlns="http://www.w3.org/2000/svg" width="13" height="14">
54+
<a onclick="graphing_console()" data-toggle="tooltip" title="Open Graphing Output" data-placement="bottom" class="btn btn-primary btn-circle" id="open-graph-output"><svg xmlns="http://www.w3.org/2000/svg" width="13" height="14">
5555
<path d="M.5,0 L.5,13.5 L12.5,13.5 M3.5,0 L3.5,13.5 M6.5,0 L6.5,13.5 M9.5,0 L9.5,13.5 M12.5,0 L12.5,13.5 M.5,3.5 L12.5,3.5 M.5,7 L12.5,7 M.5,10.5 L12.5,10.5 M.5,.5 L12.5,.5" style="stroke:rgba(255,255,255,.6);stroke-width:1;fill:none;"/>
5656
<path d="M0,13 L6,5 L9,8 L14,2" style="stroke:#fff;stroke-width:2;fill:none;"/>
5757
</svg></a>

src/main/webapp/cdn/blocklyc.js

+54-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var graph_time_multiplier = 0;
2727
var graph_interval_id = null;
2828
var fullCycleTime = 4294967296 / 80000000;
2929
var graph_labels = null;
30+
var graph_csv_data = new Array;
3031

3132
var console_header_arrived = false;
3233
var console_header = null;
@@ -581,16 +582,21 @@ function graph_new_data(stream) {
581582
} else {
582583
graph_temp_data[row].unshift(ts + graph_time_multiplier -
583584
graph_timestamp_start + graph_timestamp_restart);
584-
for (j = 2; j < graph_temp_data[row].length; j++) {
585+
var graph_csv_temp = (Math.round(graph_temp_data[row][0] * 10000) / 10000) + ',';
586+
for (var j = 2; j < graph_temp_data[row].length; j++) {
587+
graph_csv_temp += graph_temp_data[row][j] + ',';
585588
graph_data.series[j - 2].push({
586589
x: graph_temp_data[row][0],
587590
y: graph_temp_data[row][j] || null
588591
});
589592
if (graph_temp_data[row][0] > graph_options.sampleTotal)
590593
graph_data.series[j - 2].shift();
591594
}
595+
graph_csv_data.push(graph_csv_temp.slice(0, -1).split(','));
592596
}
593597

598+
599+
594600
/*
595601
var read_serial_to_div = '';
596602
for (var l = 0; l < graph_temp_data[row].length; l++)
@@ -616,6 +622,8 @@ function graph_reset() {
616622
graph_interval_id = null;
617623
graph_temp_data = null;
618624
graph_temp_data = new Array;
625+
graph_csv_data = null;
626+
graph_csv_data = new Array;
619627
graph_data = {
620628
series: [// add more here for more possible lines...
621629
[],
@@ -697,19 +705,58 @@ function downloadGraph() {
697705
});
698706
}
699707

708+
function downloadCSV() {
709+
utils.prompt("Download Graph data as CSV - Filename:", 'graph_data' + idProject, function (value) {
710+
if (value) {
711+
712+
// put all of the pieces together into a downloadable file
713+
var saveData = (function () {
714+
var a = document.createElement("a");
715+
document.body.appendChild(a);
716+
a.style = "display: none";
717+
return function (data, fileName) {
718+
var blob = new Blob([data], {type: "octet/stream"});
719+
var url = window.URL.createObjectURL(blob);
720+
a.href = url;
721+
a.download = fileName;
722+
a.click();
723+
window.URL.revokeObjectURL(url);
724+
};
725+
}());
726+
var graph_csv_temp = graph_csv_data.join('\n');
727+
var idx1 = graph_csv_temp.indexOf('\n') + 1;
728+
var idx2 = graph_csv_temp.indexOf('\n', idx1 + 1);
729+
saveData(graph_csv_temp.substring(0, idx1) + graph_csv_temp.substring(idx2 + 1, graph_csv_temp.length - 1), value + '.csv');
730+
}
731+
});
732+
}
733+
700734
function graph_new_labels() {
735+
var graph_csv_temp = '';
701736
var labelsvg = '<svg width="60" height="300">';
737+
graph_csv_temp += '"time",';
702738
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>';
739+
labelsvg += '<g id="labelgroup' + (t + 1) + '" transform="translate(0,' + (t * 30 + 25) + ')">';
740+
labelsvg += '<rect x="0" y = "0" width="60" height="26" rx="3" ry="3" id="label' + (t + 1) + '" ';
741+
labelsvg += 'style="stroke:1px;stroke-color:blue;" class="ct-marker-' + (t + 1) + '"/><rect x="3" y = "12"';
742+
labelsvg += 'width="54" height="11" rx="3" ry="3" id="value' + (t + 1) + 'bkg" style="fill:rgba';
743+
labelsvg += '(255,255,255,.7);stroke:none;"/><text id="label' + (t + 1) + 'text" x="3" ';
744+
labelsvg += 'y="9" style="font-family:Arial;font-size: 9px;fill:#fff;font-weight:bold;">' + graph_labels[t];
745+
labelsvg += '</text><text id="gValue' + (t + 1) + '" x="5" y="21" style="align:right;';
746+
labelsvg += 'font-family:Arial;font-size: 10px;fill:#000;"></text></g>';
747+
graph_csv_temp += '"' + graph_labels[t].replace(/"/g, '_') + '",';
708748
}
709749
labelsvg += '</svg>';
750+
graph_csv_data.push(graph_csv_temp.slice(0, -1));
710751
$('#serial_graphing_labels').html(labelsvg);
711752
}
712753

713754
function graph_update_labels() {
714-
755+
var row = graph_temp_data.length - 1;
756+
if (graph_temp_data[row]) {
757+
var col = graph_temp_data[row].length;
758+
for (var w = 2; w < col; w++) {
759+
document.getElementById('gValue' + (w - 1).toString(10)).textContent = graph_temp_data[row][w];
760+
}
761+
}
715762
}

src/main/webapp/cdn/editor.js

+2
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ loadProject = function () {
144144
}
145145
if (projectData['board'] === 's3' && type === 'PROPC') {
146146
$('#load-ram-button').addClass('hidden');
147+
$('#open-graph-output').addClass('hidden');
147148
document.getElementById('client-available').innerHTML = document.getElementById('client-available-short').innerHTML;
148149
} else {
149150
$('#load-ram-button').removeClass('hidden');
151+
$('#open-graph-output').removeClass('hidden');
150152
document.getElementById('client-available').innerHTML = document.getElementById('client-available-long').innerHTML;
151153
}
152154
};

src/main/webapp/editor/blocklyc.jsp

+3-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@
149149
</table>
150150
</div>
151151
<div class="modal-footer clearfix">
152-
<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-
<button type="button" id="btn-graph-snapshot" class="btn btn-success btn-circle pull-left" onclick="downloadGraph();"><i class="glyphicon glyphicon-camera"></i></button>
152+
<button type="button" id="btn-graph-play" data-toggle="tooltip" title="Pause/Resume the graph" data-placement="bottom" class="btn btn-primary btn-circle pull-left" onclick="graph_play();"><i class="glyphicon glyphicon-pause"></i></button>&nbsp;
153+
<button type="button" id="btn-graph-snapshot" data-toggle="tooltip" title="Download a snapshot of the graph" data-placement="bottom" class="btn btn-success btn-circle pull-left" onclick="downloadGraph();"><i class="glyphicon glyphicon-camera"></i></button>&nbsp;
154+
<button type="button" id="btn-graph-csv" data-toggle="tooltip" title="Download graph data as CSV" data-placement="bottom" class="btn btn-success btn-circle pull-left" onclick="downloadCSV();"><i class="glyphicon glyphicon-file"></i></button>
154155
<button type="button" class="btn btn-default" data-dismiss="modal"><fmt:message key="editor.button.close" /></button>
155156
</div>
156157
</div><!-- /.modal-content -->

0 commit comments

Comments
 (0)