]> jspc29.x-matter.uni-frankfurt.de Git - mvd_epics.git/commitdiff
DASH: sparkline value tooltip precision
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 24 Aug 2017 12:41:21 +0000 (14:41 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 24 Aug 2017 12:41:21 +0000 (14:41 +0200)
python_suite/dashboard/dashboard.py
python_suite/dashboard/static/js/sparkline.js

index fca0c8d22540687362b5634a9d01cc6d4a6c842a..4b906f46d6098903377f59bba30df39097226b11 100755 (executable)
@@ -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/<path:path>')
 def static_content(path):
index 11947743b9f4713f67443b27afc16d160f19c53f..1b4bc62d75dd6c913d01260cd00b9f3af2db9497 100644 (file)
@@ -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));
       }