From b7f1248e8f697e24fc7f7c310b94273023deaa1f Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Thu, 24 Aug 2017 14:41:21 +0200 Subject: [PATCH] DASH: sparkline value tooltip precision --- python_suite/dashboard/dashboard.py | 4 +++- python_suite/dashboard/static/js/sparkline.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/python_suite/dashboard/dashboard.py b/python_suite/dashboard/dashboard.py index fca0c8d..4b906f4 100755 --- a/python_suite/dashboard/dashboard.py +++ b/python_suite/dashboard/dashboard.py @@ -136,7 +136,9 @@ def api_history(name): history.append([time.time(), history[-1][1]]) for row in history: row[0] *= 1000. - return {'history': history} + pv_index = CONFIG['PV_lookup'][name] + precision = CONFIG['PVs'][pv_index]['precision'] + return {'history': history, 'precision': precision} @route('/static/') def static_content(path): diff --git a/python_suite/dashboard/static/js/sparkline.js b/python_suite/dashboard/static/js/sparkline.js index 1194774..1b4bc62 100644 --- a/python_suite/dashboard/static/js/sparkline.js +++ b/python_suite/dashboard/static/js/sparkline.js @@ -10,6 +10,7 @@ function sparkline() { // defaults var width = 200; var height = 40; + var precision = null; var dataSource = ''; var dataSourceType = ''; var selector = 'body'; @@ -28,6 +29,12 @@ function sparkline() { return chart; }; + chart.precision = function(value) { + if (!arguments.length) return precision; + precision = value; + return chart; + }; + chart.dataSource = function(value) { if (!arguments.length) return dataSource; dataSource = value; @@ -108,6 +115,7 @@ function sparkline() { } else { d3.json(chart.dataSource(), function(error, json) { if (error) return drawChart(error, json); + chart.precision(json.precision); drawChart(error, json.history); }); } @@ -184,7 +192,10 @@ function sparkline() { //console.log(x(d[0])); //console.log(y(d[1])); focus.attr("transform", "translate(" + x(d[0]) + "," + y(d[1]) + ")"); - tooltip_val.text(d[1]); + var val = d[1]; + if (precision != null) + val = val.toFixed(precision); + tooltip_val.text(val); var iso_date = d[0].toISOString(); tooltip_ts.text(iso_date.slice(11, 11+10)); } -- 2.43.0