From f4c38621d5dc15a126c68bafd47b02778a7a5a2b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 15 Oct 2020 15:08:56 -0400 Subject: [PATCH] Add a default "bars from right" style setting --- piker/ui/_chart.py | 15 ++++++++++++--- piker/ui/_style.py | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/piker/ui/_chart.py b/piker/ui/_chart.py index 8ee6cf25..50220174 100644 --- a/piker/ui/_chart.py +++ b/piker/ui/_chart.py @@ -18,6 +18,7 @@ from ._axes import YSticky from ._style import ( _xaxis_at, _min_points_to_show, hcolor, CHART_MARGINS, + _bars_from_right_in_follow_mode, ) from ..data._source import Symbol from .. import brokers @@ -398,7 +399,10 @@ class ChartPlotWidget(pg.PlotWidget): xlast = data[-1]['index'] # show last 50 points on startup - self.plotItem.vb.setXRange(xlast - 50, xlast + 50) + self.plotItem.vb.setXRange( + xlast - 50, + xlast + _bars_from_right_in_follow_mode + ) self._add_sticky(name) @@ -457,7 +461,10 @@ class ChartPlotWidget(pg.PlotWidget): xlast = len(data) - 1 # show last 50 points on startup - self.plotItem.vb.setXRange(xlast - 50, xlast + 50) + self.plotItem.vb.setXRange( + xlast - 50, + xlast + _bars_from_right_in_follow_mode + ) # TODO: we should instead implement a diff based # "only update with new items" on the pg.PlotDataItem @@ -774,7 +781,9 @@ async def chart_from_fsp( dtype=fsp_dtype, readonly=True, ) - assert opened + # XXX: fsp may have been opened by a duplicate chart. Error for + # now until we figure out how to wrap fsps as "feeds". + assert opened, f"A chart for {key} likely already exists?" # start fsp sub-actor portal = await n.run_in_actor( diff --git a/piker/ui/_style.py b/piker/ui/_style.py index 0378f079..d6f2adec 100644 --- a/piker/ui/_style.py +++ b/piker/ui/_style.py @@ -18,6 +18,7 @@ _xaxis_at = 'bottom' # charting config _min_points_to_show = 3 +_bars_from_right_in_follow_mode = 5 CHART_MARGINS = (0, 0, 2, 2)