From 260d87764ffd5e2f41544aa2a96bf6fa1ae7d920 Mon Sep 17 00:00:00 2001 From: Matthew Matz Date: Fri, 12 May 2017 19:22:56 -0700 Subject: [PATCH 1/4] disable show graph button in s3 type --- .../WEB-INF/includes/pageparts/editor-menu.jsp | 2 +- src/main/webapp/cdn/blocklyc.js | 13 ++++++++----- src/main/webapp/cdn/editor.js | 2 ++ src/main/webapp/editor/blocklyc.jsp | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/webapp/WEB-INF/includes/pageparts/editor-menu.jsp b/src/main/webapp/WEB-INF/includes/pageparts/editor-menu.jsp index 7c7b729d..5bb28dbb 100644 --- a/src/main/webapp/WEB-INF/includes/pageparts/editor-menu.jsp +++ b/src/main/webapp/WEB-INF/includes/pageparts/editor-menu.jsp @@ -51,7 +51,7 @@ - + diff --git a/src/main/webapp/cdn/blocklyc.js b/src/main/webapp/cdn/blocklyc.js index 157a2863..920507ad 100644 --- a/src/main/webapp/cdn/blocklyc.js +++ b/src/main/webapp/cdn/blocklyc.js @@ -700,11 +700,14 @@ function downloadGraph() { function graph_new_labels() { var labelsvg = ''; for (var t = 0; t < graph_labels.length; t++) { - labelsvg += ''; - labelsvg += ''; - labelsvg += '' + graph_labels[t] + ''; + labelsvg += ''; + labelsvg += ''; } labelsvg += ''; $('#serial_graphing_labels').html(labelsvg); diff --git a/src/main/webapp/cdn/editor.js b/src/main/webapp/cdn/editor.js index 5e326fa3..d3dfbf04 100644 --- a/src/main/webapp/cdn/editor.js +++ b/src/main/webapp/cdn/editor.js @@ -144,9 +144,11 @@ loadProject = function () { } if (projectData['board'] === 's3' && type === 'PROPC') { $('#load-ram-button').addClass('hidden'); + $('#open-graph-output').addClass('hidden'); document.getElementById('client-available').innerHTML = document.getElementById('client-available-short').innerHTML; } else { $('#load-ram-button').removeClass('hidden'); + $('#open-graph-output').removeClass('hidden'); document.getElementById('client-available').innerHTML = document.getElementById('client-available-long').innerHTML; } }; diff --git a/src/main/webapp/editor/blocklyc.jsp b/src/main/webapp/editor/blocklyc.jsp index e8fb5e04..e2b1dcac 100644 --- a/src/main/webapp/editor/blocklyc.jsp +++ b/src/main/webapp/editor/blocklyc.jsp @@ -149,8 +149,8 @@ From 559cf543a0bcab75283b9f1fb45edad082d6ec27 Mon Sep 17 00:00:00 2001 From: Matthew Matz Date: Fri, 12 May 2017 20:51:27 -0700 Subject: [PATCH 2/4] add live values to graph labels --- src/main/webapp/cdn/blocklyc.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/cdn/blocklyc.js b/src/main/webapp/cdn/blocklyc.js index 920507ad..7dac2cf8 100644 --- a/src/main/webapp/cdn/blocklyc.js +++ b/src/main/webapp/cdn/blocklyc.js @@ -706,7 +706,7 @@ function graph_new_labels() { labelsvg += 'width="54" height="11" rx="3" ry="3" id="value' + (t+1) + 'bkg" style="fill:rgba'; labelsvg += '(255,255,255,.7);stroke:none;"/>'; } labelsvg += ''; @@ -714,5 +714,9 @@ function graph_new_labels() { } function graph_update_labels() { - + var row = graph_temp_data.length - 1; + var col = graph_temp_data[row].length; + for(var w = 2; w < col; w++) { + document.getElementById('gValue' + (w-1).toString(10)).textContent = graph_temp_data[row][w]; + } } \ No newline at end of file From 4c42275eeacc9d4f7a6e0fb39790da76b74c99a5 Mon Sep 17 00:00:00 2001 From: Matthew Matz Date: Sat, 13 May 2017 01:10:06 -0700 Subject: [PATCH 3/4] add CSV download button and functions --- src/main/webapp/cdn/blocklyc.js | 60 ++++++++++++++++++++++++----- src/main/webapp/editor/blocklyc.jsp | 3 +- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/main/webapp/cdn/blocklyc.js b/src/main/webapp/cdn/blocklyc.js index 7dac2cf8..11d88060 100644 --- a/src/main/webapp/cdn/blocklyc.js +++ b/src/main/webapp/cdn/blocklyc.js @@ -27,6 +27,7 @@ var graph_time_multiplier = 0; var graph_interval_id = null; var fullCycleTime = 4294967296 / 80000000; var graph_labels = null; +var graph_csv_data = new Array; var console_header_arrived = false; var console_header = null; @@ -581,7 +582,9 @@ function graph_new_data(stream) { } else { graph_temp_data[row].unshift(ts + graph_time_multiplier - graph_timestamp_start + graph_timestamp_restart); - for (j = 2; j < graph_temp_data[row].length; j++) { + var graph_csv_temp = graph_temp_data[row][0] + ','; + for (var j = 2; j < graph_temp_data[row].length; j++) { + graph_csv_temp += graph_temp_data[row][j] + ','; graph_data.series[j - 2].push({ x: graph_temp_data[row][0], y: graph_temp_data[row][j] || null @@ -589,8 +592,11 @@ function graph_new_data(stream) { if (graph_temp_data[row][0] > graph_options.sampleTotal) graph_data.series[j - 2].shift(); } + graph_csv_data.push(graph_csv_temp.slice(0, -1).split(',')); } + + /* var read_serial_to_div = ''; for (var l = 0; l < graph_temp_data[row].length; l++) @@ -616,6 +622,8 @@ function graph_reset() { graph_interval_id = null; graph_temp_data = null; graph_temp_data = new Array; + graph_csv_data = null; + graph_csv_data = new Array; graph_data = { series: [// add more here for more possible lines... [], @@ -697,26 +705,58 @@ function downloadGraph() { }); } +function downloadCSV() { + utils.prompt("Download Graph data as CSV - Filename:", 'graph_data' + idProject, function (value) { + if (value) { + + // put all of the pieces together into a downloadable file + var saveData = (function () { + var a = document.createElement("a"); + document.body.appendChild(a); + a.style = "display: none"; + return function (data, fileName) { + var blob = new Blob([data], {type: "octet/stream"}); + var url = window.URL.createObjectURL(blob); + a.href = url; + a.download = fileName; + a.click(); + window.URL.revokeObjectURL(url); + }; + }()); + var graph_csv_temp = graph_csv_data.join('\n'); + var idx1 = graph_csv_temp.indexOf('\n') + 1; + var idx2 = graph_csv_temp.indexOf('\n', idx1 + 1); + saveData(graph_csv_temp.substring(0, idx1) + graph_csv_temp.substring(idx2 + 1, graph_csv_temp.length - 1), value + '.csv'); + } + }); +} + function graph_new_labels() { + var graph_csv_temp = ''; var labelsvg = ''; + graph_csv_temp += '"time",'; for (var t = 0; t < graph_labels.length; t++) { - labelsvg += ''; - labelsvg += ''; + labelsvg += ''; + graph_csv_temp += '"' + graph_labels[t].replace(/"/g, '_') + '",'; } labelsvg += ''; + graph_csv_data.push(graph_csv_temp.slice(0, -1)); $('#serial_graphing_labels').html(labelsvg); } function graph_update_labels() { var row = graph_temp_data.length - 1; - var col = graph_temp_data[row].length; - for(var w = 2; w < col; w++) { - document.getElementById('gValue' + (w-1).toString(10)).textContent = graph_temp_data[row][w]; + if (graph_temp_data[row]) { + var col = graph_temp_data[row].length; + for (var w = 2; w < col; w++) { + document.getElementById('gValue' + (w - 1).toString(10)).textContent = graph_temp_data[row][w]; + } } } \ No newline at end of file diff --git a/src/main/webapp/editor/blocklyc.jsp b/src/main/webapp/editor/blocklyc.jsp index e2b1dcac..012dfebc 100644 --- a/src/main/webapp/editor/blocklyc.jsp +++ b/src/main/webapp/editor/blocklyc.jsp @@ -150,7 +150,8 @@ From 1be6cd6691be369cea413526c5d624eab98d8cd2 Mon Sep 17 00:00:00 2001 From: Matthew Matz Date: Sat, 13 May 2017 01:23:46 -0700 Subject: [PATCH 4/4] Round timestamp in CSV export --- src/main/webapp/cdn/blocklyc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/cdn/blocklyc.js b/src/main/webapp/cdn/blocklyc.js index 11d88060..3cd01f9e 100644 --- a/src/main/webapp/cdn/blocklyc.js +++ b/src/main/webapp/cdn/blocklyc.js @@ -582,7 +582,7 @@ function graph_new_data(stream) { } else { graph_temp_data[row].unshift(ts + graph_time_multiplier - graph_timestamp_start + graph_timestamp_restart); - var graph_csv_temp = graph_temp_data[row][0] + ','; + var graph_csv_temp = (Math.round(graph_temp_data[row][0] * 10000) / 10000) + ','; for (var j = 2; j < graph_temp_data[row].length; j++) { graph_csv_temp += graph_temp_data[row][j] + ','; graph_data.series[j - 2].push({