From: Philipp Klaus Date: Tue, 12 Sep 2017 16:09:21 +0000 (+0200) Subject: DASH: sparklines y-axis extent now depends on HOPR/LOPR X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=f02c0da89117aa0cd2061d5b9c37babdd26c34eb;p=mvd_epics.git DASH: sparklines y-axis extent now depends on HOPR/LOPR --- diff --git a/python_suite/dashboard/static/js/sparkline.js b/python_suite/dashboard/static/js/sparkline.js index e17f7d1..4d6ba3c 100644 --- a/python_suite/dashboard/static/js/sparkline.js +++ b/python_suite/dashboard/static/js/sparkline.js @@ -11,6 +11,9 @@ function sparkline() { var width = 200; var height = 40; var precision = null; + var y_extent = null; + var upper_disp_limit = null; + var lower_disp_limit = null; var dataSource = ''; var dataSourceType = ''; var selector = 'body'; @@ -36,6 +39,24 @@ function sparkline() { return chart; }; + chart.y_extent = function(value) { + if (!arguments.length) return y_extent; + y_extent = value; + return chart; + }; + + chart.upper_disp_limit = function(value) { + if (!arguments.length) return upper_disp_limit; + upper_disp_limit = value; + return chart; + }; + + chart.lower_disp_limit = function(value) { + if (!arguments.length) return lower_disp_limit; + lower_disp_limit = value; + return chart; + }; + chart.dataSource = function(value) { if (!arguments.length) return dataSource; dataSource = value; @@ -117,10 +138,22 @@ function sparkline() { d3.json(chart.dataSource(), function(error, json) { if (error) return drawChart(error, json); chart.precision(json.precision); + chart.upper_disp_limit(json.upper_disp_limit); + chart.lower_disp_limit(json.lower_disp_limit); + calculateExtent(json.history); drawChart(error, json.history); }); } + function calculateExtent(data) { + if ((upper_disp_limit !== null) && (lower_disp_limit !== null)) + y_extent = [lower_disp_limit, upper_disp_limit]; + else { + y_extent = d3.extent(data, function (d) { return d[1]; }); + if (y_extent[0] == y_extent[1]) y_extent = [ y_extent[0]-.5, y_extent[0]+.5]; + } + } + /* * formats chart data and appends the sparkline */ @@ -134,9 +167,7 @@ function sparkline() { // Scale the range of the data x.domain(d3.extent(data, function (d) { return d[0]; })); - var extent = d3.extent(data, function (d) { return d[1]; }); - if (extent[0] == extent[1]) extent = [ extent[0]-.5, extent[0]+.5]; - y.domain(extent); + y.domain(y_extent); // Add the valueline path.