Added code for inverting X axis
This commit is contained in:
parent
255b2405d1
commit
c6f2e9c2a9
@ -48,6 +48,7 @@ pyqtgraph-0.9.9 [unreleased]
|
||||
- Added AxisItem.setStyle()
|
||||
- Added configurable formatting for TableWidget
|
||||
- Added 'stepMode' argument to PlotDataItem()
|
||||
- Added ViewBox.invertX()
|
||||
|
||||
Bugfixes:
|
||||
- PlotCurveItem now has correct clicking behavior--clicks within a few px
|
||||
|
@ -454,6 +454,9 @@ class AxisItem(GraphicsWidget):
|
||||
else:
|
||||
if newRange is None:
|
||||
newRange = view.viewRange()[0]
|
||||
if view.xInverted():
|
||||
self.setRange(*newRange[::-1])
|
||||
else:
|
||||
self.setRange(*newRange)
|
||||
|
||||
def boundingRect(self):
|
||||
|
@ -78,6 +78,7 @@ class PlotItem(GraphicsWidget):
|
||||
:func:`disableAutoRange <pyqtgraph.ViewBox.disableAutoRange>`,
|
||||
:func:`setAspectLocked <pyqtgraph.ViewBox.setAspectLocked>`,
|
||||
:func:`invertY <pyqtgraph.ViewBox.invertY>`,
|
||||
:func:`invertX <pyqtgraph.ViewBox.invertX>`,
|
||||
:func:`register <pyqtgraph.ViewBox.register>`,
|
||||
:func:`unregister <pyqtgraph.ViewBox.unregister>`
|
||||
|
||||
@ -299,7 +300,7 @@ class PlotItem(GraphicsWidget):
|
||||
for m in ['setXRange', 'setYRange', 'setXLink', 'setYLink', 'setAutoPan', # NOTE:
|
||||
'setAutoVisible', 'setRange', 'autoRange', 'viewRect', 'viewRange', # If you update this list, please
|
||||
'setMouseEnabled', 'setLimits', 'enableAutoRange', 'disableAutoRange', # update the class docstring
|
||||
'setAspectLocked', 'invertY', 'register', 'unregister']: # as well.
|
||||
'setAspectLocked', 'invertY', 'invertX', 'register', 'unregister']: # as well.
|
||||
|
||||
def _create_method(name):
|
||||
def method(self, *args, **kwargs):
|
||||
|
@ -104,7 +104,7 @@ class ViewBox(GraphicsWidget):
|
||||
NamedViews = weakref.WeakValueDictionary() # name: ViewBox
|
||||
AllViews = weakref.WeakKeyDictionary() # ViewBox: None
|
||||
|
||||
def __init__(self, parent=None, border=None, lockAspect=False, enableMouse=True, invertY=False, enableMenu=True, name=None):
|
||||
def __init__(self, parent=None, border=None, lockAspect=False, enableMouse=True, invertY=False, enableMenu=True, name=None, invertX=False):
|
||||
"""
|
||||
============== =============================================================
|
||||
**Arguments:**
|
||||
@ -115,6 +115,7 @@ class ViewBox(GraphicsWidget):
|
||||
coorinates to. (or False to allow the ratio to change)
|
||||
*enableMouse* (bool) Whether mouse can be used to scale/pan the view
|
||||
*invertY* (bool) See :func:`invertY <pyqtgraph.ViewBox.invertY>`
|
||||
*invertX* (bool) See :func:`invertX <pyqtgraph.ViewBox.invertX>`
|
||||
============== =============================================================
|
||||
"""
|
||||
|
||||
@ -139,6 +140,7 @@ class ViewBox(GraphicsWidget):
|
||||
'viewRange': [[0,1], [0,1]], ## actual range viewed
|
||||
|
||||
'yInverted': invertY,
|
||||
'xInverted': invertX,
|
||||
'aspectLocked': False, ## False if aspect is unlocked, otherwise float specifies the locked ratio.
|
||||
'autoRange': [True, True], ## False if auto range is disabled,
|
||||
## otherwise float gives the fraction of data that is visible
|
||||
@ -996,6 +998,9 @@ class ViewBox(GraphicsWidget):
|
||||
x2 = vr.right()
|
||||
else: ## views overlap; line them up
|
||||
upp = float(vr.width()) / vg.width()
|
||||
if self.xInverted():
|
||||
x1 = vr.left() + (sg.right()-vg.right()) * upp
|
||||
else:
|
||||
x1 = vr.left() + (sg.x()-vg.x()) * upp
|
||||
x2 = x1 + sg.width() * upp
|
||||
self.enableAutoRange(ViewBox.XAxis, False)
|
||||
@ -1054,10 +1059,27 @@ class ViewBox(GraphicsWidget):
|
||||
#self.updateMatrix(changed=(False, True))
|
||||
self.updateViewRange()
|
||||
self.sigStateChanged.emit(self)
|
||||
self.sigYRangeChanged.emit(self, tuple(self.state['viewRange'][1]))
|
||||
|
||||
def yInverted(self):
|
||||
return self.state['yInverted']
|
||||
|
||||
def invertX(self, b=True):
|
||||
"""
|
||||
By default, the positive x-axis points rightward on the screen. Use invertX(True) to reverse the x-axis.
|
||||
"""
|
||||
if self.state['xInverted'] == b:
|
||||
return
|
||||
|
||||
self.state['xInverted'] = b
|
||||
#self.updateMatrix(changed=(False, True))
|
||||
self.updateViewRange()
|
||||
self.sigStateChanged.emit(self)
|
||||
self.sigXRangeChanged.emit(self, tuple(self.state['viewRange'][0]))
|
||||
|
||||
def xInverted(self):
|
||||
return self.state['xInverted']
|
||||
|
||||
def setAspectLocked(self, lock=True, ratio=1):
|
||||
"""
|
||||
If the aspect ratio is locked, view scaling must always preserve the aspect ratio.
|
||||
@ -1555,6 +1577,7 @@ class ViewBox(GraphicsWidget):
|
||||
if link is not None:
|
||||
link.linkedViewChanged(self, ax)
|
||||
|
||||
self.update()
|
||||
self._matrixNeedsUpdate = True
|
||||
|
||||
def updateMatrix(self, changed=None):
|
||||
@ -1567,6 +1590,8 @@ class ViewBox(GraphicsWidget):
|
||||
scale = Point(bounds.width()/vr.width(), bounds.height()/vr.height())
|
||||
if not self.state['yInverted']:
|
||||
scale = scale * Point(1, -1)
|
||||
if self.state['xInverted']:
|
||||
scale = scale * Point(-1, 1)
|
||||
m = QtGui.QTransform()
|
||||
|
||||
## First center the viewport at 0
|
||||
|
@ -56,7 +56,7 @@ class ViewBoxMenu(QtGui.QMenu):
|
||||
for sig, fn in connects:
|
||||
sig.connect(getattr(self, axis.lower()+fn))
|
||||
|
||||
self.ctrl[0].invertCheck.hide() ## no invert for x-axis
|
||||
self.ctrl[0].invertCheck.toggled.connect(self.xInvertToggled)
|
||||
self.ctrl[1].invertCheck.toggled.connect(self.yInvertToggled)
|
||||
## exporting is handled by GraphicsScene now
|
||||
#self.export = QtGui.QMenu("Export")
|
||||
@ -139,8 +139,9 @@ class ViewBoxMenu(QtGui.QMenu):
|
||||
|
||||
self.ctrl[i].autoPanCheck.setChecked(state['autoPan'][i])
|
||||
self.ctrl[i].visibleOnlyCheck.setChecked(state['autoVisibleOnly'][i])
|
||||
xy = ['x', 'y'][i]
|
||||
self.ctrl[i].invertCheck.setChecked(state.get(xy+'Inverted', False))
|
||||
|
||||
self.ctrl[1].invertCheck.setChecked(state['yInverted'])
|
||||
self.valid = True
|
||||
|
||||
def popup(self, *args):
|
||||
@ -217,19 +218,19 @@ class ViewBoxMenu(QtGui.QMenu):
|
||||
def yInvertToggled(self, b):
|
||||
self.view().invertY(b)
|
||||
|
||||
def xInvertToggled(self, b):
|
||||
self.view().invertX(b)
|
||||
|
||||
def exportMethod(self):
|
||||
act = self.sender()
|
||||
self.exportMethods[str(act.text())]()
|
||||
|
||||
|
||||
def set3ButtonMode(self):
|
||||
self.view().setLeftButtonAction('pan')
|
||||
|
||||
def set1ButtonMode(self):
|
||||
self.view().setLeftButtonAction('rect')
|
||||
|
||||
|
||||
def setViewList(self, views):
|
||||
names = ['']
|
||||
self.viewMap.clear()
|
||||
|
Loading…
Reference in New Issue
Block a user