webplot: Make pressing 's' save the plot to disk
It looks like right now pressing 's' doesn't really do anything but
tell the user that the touch logs were saved. I would really like it
if pressing 's' actually saved a png of the plot to disk.
This CL adds that functionality.
BUG=chromium:473322
TEST=tested on Android and ChromeOS, pressing 's' in the browser
sends the png data over the websocket and saves it to disk.
Change-Id: I453872f3ddc994ae3ccab4ffa47bbfd99794351c
Signed-off-by: Charlie Mooney <charliemooney@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/263780
diff --git a/webplot/webplot.js b/webplot/webplot.js
index d89a0e4..55673b1 100644
--- a/webplot/webplot.js
+++ b/webplot/webplot.js
@@ -296,7 +296,7 @@
// Capture the image before clearing the canvas and send it to the server,
// and notify the server that this client quits.
- window.ws.send('quit:' + webplot.captureCanvasImage());
+ window.ws.send('quit');
canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
if (closed_by_server) {
@@ -307,6 +307,9 @@
startX, startY, font);
}
+function save() {
+ window.ws.send('save:' + webplot.captureCanvasImage());
+}
/**
* A handler for keyup events to handle user hot keys.
@@ -353,15 +356,15 @@
webplot.updateCanvasDimension();
break;
- // 'q': Quit the server
+ // 'q': Quit the server (and save the plot and logs first)
case 'q':
+ save();
quit(false);
break;
- // 's': save the touch events in a specified file name.
- // default: /tmp/webplot.dat
+ // 's': Tell the server to save the touch events and a png of the plot
case 's':
- window.ws.send('save:' + webplot.saved_file);
+ save();
break;
}
}
@@ -382,6 +385,7 @@
ws = new WebSocket(websocket);
ws.addEventListener("message", function(event) {
if (event.data == 'quit') {
+ save();
quit(true);
} else {
var snapshot = JSON.parse(event.data);