diff --git a/app.py b/app.py index 28da9e0..d9a6a97 100644 --- a/app.py +++ b/app.py @@ -87,7 +87,10 @@ def recipe(): @socketio.on('new client') def handle_new_client(): updateState() - socketio.emit('sensor history', sensors.get_history()) + +@socketio.on('get sensors history') +def send_sensors_history(elements=1000): + socketio.emit('sensor history', sensors.get_history(elements)) @socketio.on('manual response') def handle_manual_response(response): diff --git a/dist/server.js b/dist/server.js index 9a8c08a..5049c98 100644 --- a/dist/server.js +++ b/dist/server.js @@ -63,6 +63,26 @@ function applyState(newstate) { var enable_draw = true; var plot_data = {}; +function toggle_update_plot() { + enable_draw = !enable_draw; +} +function pause_plotting() {enable_draw = false;} +function resume_plotting() {enable_draw = true;} +function set_plot_points(value) { + let current = localstate.maxpoints; + if (value === undefined) { + value = parseInt(document.getElementById('point-number').value); + } + localstate.maxpoints = value; + if (value <= current) { + // we alredy have all the points we want just set it and let other + // function discard extra points + return; + } + // Ask for more data + socket.emit('get sensors history', value); +} + function add_plot_data(newpoints, render=true) { for (var i = 0; i < newpoints.length; ++i) { let point = newpoints[i] @@ -77,6 +97,8 @@ function add_plot_data(newpoints, render=true) { } plot_data[key].x.push(point[1]); plot_data[key].y.push(point[2]); + // This is different since we want maxpoints to be the absolute max, not + // for each variable, but good enough for now (or the opposite?) while (plot_data[key].x.length > localstate.maxpoints) { plot_data[key].x.shift(); plot_data[key].y.shift(); @@ -85,28 +107,19 @@ function add_plot_data(newpoints, render=true) { if (render) render_plot(); } -// function set_plot_points(maxpoints) { -// let more = localstate.maxpoints > maxpoints; -// localstate.maxpoints = maxpoints; -// if (more) { -// for (key in plot_data.keys()) -// } -// } - function render_plot() { if (enable_draw && document.getElementById("data-plot") !== null) { Plotly.newPlot('data-plot', Object.values(plot_data)); } } - function render_actuators(data) { let html = document.getElementById("actuator-list"); if (data === undefined || html === null) return; let template = `