Autoscale the y-range for all linked charts

py3.10_support
Tyler Goodlet 2021-09-28 16:37:55 -04:00
parent 51def5484e
commit 51373789fe
1 changed files with 18 additions and 33 deletions

View File

@ -972,7 +972,11 @@ class ChartPlotWidget(pg.PlotWidget):
yrange: Optional[tuple[float, float]] = None, yrange: Optional[tuple[float, float]] = None,
range_margin: float = 0.06, range_margin: float = 0.06,
bars_range: Optional[tuple[int, int, int, int]] = None bars_range: Optional[tuple[int, int, int, int]] = None,
# flag to prevent triggering sibling charts from the same linked
# set from recursion errors.
autoscale_linked_plots: bool = True,
) -> None: ) -> None:
'''Set the viewable y-range based on embedded data. '''Set the viewable y-range based on embedded data.
@ -999,52 +1003,33 @@ class ChartPlotWidget(pg.PlotWidget):
l, lbar, rbar, r = bars_range or self.bars_range() l, lbar, rbar, r = bars_range or self.bars_range()
# TODO: we need a loop for auto-scaled subplots to all if autoscale_linked_plots:
# be triggered by one another # avoid recursion by sibling plots
if self.name != 'volume': linked = self.linked
vlm_chart = self.linked.subplots.get('volume') plots = list(linked.subplots.copy().values())
if vlm_chart: main = linked.chart
vlm_chart._set_yrange(bars_range=(l, lbar, rbar, r)) if main:
# curve = vlm_chart._graphics['volume'] plots.append(main)
# if rbar - lbar < 1500:
# # print('small range')
# curve._fill = True
# else:
# curve._fill = False
# figure out x-range in view such that user can scroll "off" for chart in plots:
# the data set up to the point where ``_min_points_to_show`` if chart and not chart._static_yrange:
# are left. chart._set_yrange(
# view_len = r - l bars_range=(l, lbar, rbar, r),
autoscale_linked_plots=False,
)
# TODO: logic to check if end of bars in view # TODO: logic to check if end of bars in view
# extra = view_len - _min_points_to_show # extra = view_len - _min_points_to_show
# begin = self._arrays['ohlc'][0]['index'] - extra # begin = self._arrays['ohlc'][0]['index'] - extra
# # end = len(self._arrays['ohlc']) - 1 + extra # # end = len(self._arrays['ohlc']) - 1 + extra
# end = self._arrays['ohlc'][-1]['index'] - 1 + extra # end = self._arrays['ohlc'][-1]['index'] - 1 + extra
# XXX: test code for only rendering lines for the bars in view.
# This turns out to be very very poor perf when scaling out to
# many bars (think > 1k) on screen.
# name = self.name
# bars = self._graphics[self.name]
# bars.draw_lines(
# istart=max(lbar, l), iend=min(rbar, r), just_history=True)
# bars_len = rbar - lbar # bars_len = rbar - lbar
# log.debug( # log.debug(
# f"\nl: {l}, lbar: {lbar}, rbar: {rbar}, r: {r}\n" # f"\nl: {l}, lbar: {lbar}, rbar: {rbar}, r: {r}\n"
# f"view_len: {view_len}, bars_len: {bars_len}\n" # f"view_len: {view_len}, bars_len: {bars_len}\n"
# f"begin: {begin}, end: {end}, extra: {extra}" # f"begin: {begin}, end: {end}, extra: {extra}"
# ) # )
# self._set_xlimits(begin, end)
# TODO: this should be some kind of numpy view api
# bars = self._arrays['ohlc'][lbar:rbar]
a = self._arrays['ohlc'] a = self._arrays['ohlc']
ifirst = a[0]['index'] ifirst = a[0]['index']