Don't scroll right after max zoom

bar_select
Tyler Goodlet 2020-06-15 11:40:41 -04:00
parent 6fa173a1c1
commit 507368a13a
1 changed files with 16 additions and 11 deletions

View File

@ -19,9 +19,6 @@ from .quantdom.const import ChartType
from .quantdom.portfolio import Order, Portfolio from .quantdom.portfolio import Order, Portfolio
# white background (for tinas like our pal xb)
# pg.setConfigOption('background', 'w')
# margins # margins
CHART_MARGINS = (0, 0, 10, 3) CHART_MARGINS = (0, 0, 10, 3)
@ -135,7 +132,10 @@ class SplitterChart(QtGui.QWidget):
self.splitter.setSizes(sizes) # , int(self.height()*0.2) self.splitter.setSizes(sizes) # , int(self.height()*0.2)
def plot(self, symbol): def plot(self, symbol):
"""Start up and show price chart and all registered indicators.
"""
self.digits = symbol.digits self.digits = symbol.digits
self.chart = ChartPlotWidget( self.chart = ChartPlotWidget(
split_charts=self, split_charts=self,
parent=self.splitter, parent=self.splitter,
@ -145,7 +145,7 @@ class SplitterChart(QtGui.QWidget):
) )
# TODO: ``pyqtgraph`` doesn't pass through a parent to the # TODO: ``pyqtgraph`` doesn't pass through a parent to the
# ``PlotItem`` by default; maybe we should PR this in? # ``PlotItem`` by default; maybe we should PR this in?
self.chart.plotItem.parent = self self.chart.plotItem.vb.splitter_widget = self
self.chart.getPlotItem().setContentsMargins(*CHART_MARGINS) self.chart.getPlotItem().setContentsMargins(*CHART_MARGINS)
self.chart.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain) self.chart.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
@ -161,7 +161,7 @@ class SplitterChart(QtGui.QWidget):
# axisItems={'top': self.xaxis_ind, 'right': PriceAxis()}, # axisItems={'top': self.xaxis_ind, 'right': PriceAxis()},
viewBox=ChartView, viewBox=ChartView,
) )
ind.plotItem.parent = self self.chart.plotItem.vb.splitter_widget = self
ind.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain) ind.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
ind.getPlotItem().setContentsMargins(*CHART_MARGINS) ind.getPlotItem().setContentsMargins(*CHART_MARGINS)
@ -241,6 +241,10 @@ class SplitterChart(QtGui.QWidget):
self.signals_visible = True self.signals_visible = True
_min_points_to_show = 20
_min_bars_in_view = 10
# TODO: This is a sub-class of ``GracphicView`` which can # TODO: This is a sub-class of ``GracphicView`` which can
# take a ``background`` color setting. # take a ``background`` color setting.
class ChartPlotWidget(pg.PlotWidget): class ChartPlotWidget(pg.PlotWidget):
@ -286,14 +290,12 @@ class ChartPlotWidget(pg.PlotWidget):
self.setCursor(QtCore.Qt.CrossCursor) self.setCursor(QtCore.Qt.CrossCursor)
# set panning limits # set panning limits
min_points_to_show = 20 max_lookahead = _min_points_to_show - _min_bars_in_view
min_bars_in_view = 10
max_lookahead = min_points_to_show - min_bars_in_view
last = Quotes[-1].id last = Quotes[-1].id
self.setLimits( self.setLimits(
xMin=Quotes[0].id, xMin=Quotes[0].id,
xMax=last + max_lookahead, xMax=last + max_lookahead,
minXRange=min_points_to_show, minXRange=_min_points_to_show,
# maxYRange=highest-lowest, # maxYRange=highest-lowest,
yMin=Quotes.low.min() * 0.98, yMin=Quotes.low.min() * 0.98,
yMax=Quotes.high.max() * 1.02, yMax=Quotes.high.max() * 1.02,
@ -402,8 +404,6 @@ class ChartView(pg.ViewBox):
# invertY=False, # invertY=False,
): ):
super().__init__(parent=parent, **kwargs) super().__init__(parent=parent, **kwargs)
self.chart = parent
# disable vertical scrolling # disable vertical scrolling
self.setMouseEnabled(x=True, y=False) self.setMouseEnabled(x=True, y=False)
@ -422,6 +422,11 @@ class ChartView(pg.ViewBox):
else: else:
mask = self.state['mouseEnabled'][:] mask = self.state['mouseEnabled'][:]
lbar, rbar = self.splitter_widget.chart.bars_range()
if ev.delta() >= 0 and rbar - lbar <= _min_points_to_show:
# don't zoom more then the min points setting
return
# actual scaling factor # actual scaling factor
s = 1.02 ** (ev.delta() * self.state['wheelScaleFactor']) s = 1.02 ** (ev.delta() * self.state['wheelScaleFactor'])
s = [(None if m is False else s) for m in mask] s = [(None if m is False else s) for m in mask]