From 12e4f1e553a3549449144ac08e7da5e7cecb67ec Mon Sep 17 00:00:00 2001 From: Mike Dye Date: Fri, 10 Mar 2023 01:04:25 -0700 Subject: [PATCH 1/2] Trim whitespace from beginning and end of string returned from rails before inserting them in to inline generated JSON. This prevents the possibility of breaking the JSON by unintentionally including characters that require being escaped, such as tabs. --- .../instruments/_multivariable_graph_chart.html.haml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/instruments/_multivariable_graph_chart.html.haml b/app/views/instruments/_multivariable_graph_chart.html.haml index 654e7a6f..2d415743 100644 --- a/app/views/instruments/_multivariable_graph_chart.html.haml +++ b/app/views/instruments/_multivariable_graph_chart.html.haml @@ -65,13 +65,13 @@ var y_axis_js_part = ''; y_axis_js_part += '{\n'; y_axis_js_part += ' "labels": {\n'; - y_axis_js_part += ' "format": "{value} ' + v.units + '"' + ',\n'; - y_axis_js_part += ' "style": { "color": "' + highcharts_color + '" }\n'; + y_axis_js_part += ' "format": "{value} ' + $.trim(v.units) + '"' + ',\n'; + y_axis_js_part += ' "style": { "color": "' + $.trim(highcharts_color) + '" }\n'; y_axis_js_part += ' },\n'; y_axis_js_part += ' "title": {\n '; - y_axis_js_part += ' "text": "' + v.name + ' (' + v.units + ')",\n'; - y_axis_js_part += ' "style": { "color": "' + highcharts_color + '" }\n'; + y_axis_js_part += ' "text": "' + $.trim(v.name) + ' (' + $.trim(v.units) + ')",\n'; + y_axis_js_part += ' "style": { "color": "' + $.trim(highcharts_color) + '" }\n'; y_axis_js_part += ' },\n'; y_axis_js_part += ' "opposite": false,\n'; From 2120f5108465644f25c88ba87fc47d3a3b85a801 Mon Sep 17 00:00:00 2001 From: Mike Dye Date: Fri, 10 Mar 2023 01:38:16 -0700 Subject: [PATCH 2/2] In javascript highcharts updating functions (both initial and live) check to make sure that there were returned points to graph before attempting to add them to the graph. --- .../instruments/_multivariable_graph_chart.html.haml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/views/instruments/_multivariable_graph_chart.html.haml b/app/views/instruments/_multivariable_graph_chart.html.haml index 2d415743..fc2a3159 100644 --- a/app/views/instruments/_multivariable_graph_chart.html.haml +++ b/app/views/instruments/_multivariable_graph_chart.html.haml @@ -141,7 +141,9 @@ live_chart.series[i].setData(points); // update last times array for current variable - live_last_times[i] = points[points.length - 1][0]; + if (points.length > 0) { + live_last_times[i] = points[points.length - 1][0]; + } } live_chart.redraw(); } @@ -165,7 +167,9 @@ } // update last times array for current variable - live_last_times[i] = points[points.length - 1][0]; + if (points.length > 0) { + live_last_times[i] = points[points.length - 1][0]; + } } live_chart.redraw(); } @@ -192,7 +196,9 @@ live_chart.redraw(); // update last times array for specific variable - live_last_times[series_index] = points[points.length - 1][0]; + if (points.length > 0) { + live_last_times[series_index] = points[points.length - 1][0]; + } } ////////////////////////////////////////////////////////////////