Merge pull request #1235 from pyqtgraph/revert-391-plotitem2
Revert "changed structure to redefine axis via plotitem.setAxes"
This commit is contained in:
commit
ba6f6512a9
@ -45,8 +45,11 @@ class AxisItem(GraphicsWidget):
|
|||||||
GraphicsWidget.__init__(self, parent)
|
GraphicsWidget.__init__(self, parent)
|
||||||
self.label = QtGui.QGraphicsTextItem(self)
|
self.label = QtGui.QGraphicsTextItem(self)
|
||||||
self.picture = None
|
self.picture = None
|
||||||
self.orientation = None
|
self.orientation = orientation
|
||||||
self.setOrientation(orientation)
|
if orientation not in ['left', 'right', 'top', 'bottom']:
|
||||||
|
raise Exception("Orientation argument must be one of 'left', 'right', 'top', or 'bottom'.")
|
||||||
|
if orientation in ['left', 'right']:
|
||||||
|
self.label.rotate(-90)
|
||||||
|
|
||||||
self.style = {
|
self.style = {
|
||||||
'tickTextOffset': [5, 2], ## (horizontal, vertical) spacing between text and axis
|
'tickTextOffset': [5, 2], ## (horizontal, vertical) spacing between text and axis
|
||||||
@ -108,27 +111,6 @@ class AxisItem(GraphicsWidget):
|
|||||||
self.grid = False
|
self.grid = False
|
||||||
#self.setCacheMode(self.DeviceCoordinateCache)
|
#self.setCacheMode(self.DeviceCoordinateCache)
|
||||||
|
|
||||||
def setOrientation(self, orientation):
|
|
||||||
"""
|
|
||||||
orientation = 'left', 'right', 'top', 'bottom'
|
|
||||||
"""
|
|
||||||
if orientation != self.orientation:
|
|
||||||
if orientation not in ['left', 'right', 'top', 'bottom']:
|
|
||||||
raise Exception("Orientation argument must be one of 'left', 'right', 'top', or 'bottom'.")
|
|
||||||
#rotate absolute allows to change orientation multiple times:
|
|
||||||
if orientation in ['left', 'right']:
|
|
||||||
self.label.setRotation(-90)
|
|
||||||
if self.orientation:
|
|
||||||
self._updateWidth()
|
|
||||||
self.setMaximumHeight(16777215)
|
|
||||||
else:
|
|
||||||
self.label.setRotation(0)
|
|
||||||
if self.orientation:
|
|
||||||
self._updateHeight()
|
|
||||||
self.setMaximumWidth(16777215)
|
|
||||||
self.orientation = orientation
|
|
||||||
|
|
||||||
|
|
||||||
def setStyle(self, **kwds):
|
def setStyle(self, **kwds):
|
||||||
"""
|
"""
|
||||||
Set various style options.
|
Set various style options.
|
||||||
@ -532,7 +514,6 @@ class AxisItem(GraphicsWidget):
|
|||||||
self.unlinkFromView()
|
self.unlinkFromView()
|
||||||
|
|
||||||
self._linkedView = weakref.ref(view)
|
self._linkedView = weakref.ref(view)
|
||||||
|
|
||||||
if self.orientation in ['right', 'left']:
|
if self.orientation in ['right', 'left']:
|
||||||
view.sigYRangeChanged.connect(self.linkedViewChanged)
|
view.sigYRangeChanged.connect(self.linkedViewChanged)
|
||||||
else:
|
else:
|
||||||
|
@ -153,9 +153,9 @@ class PlotItem(GraphicsWidget):
|
|||||||
|
|
||||||
self.legend = None
|
self.legend = None
|
||||||
|
|
||||||
## Create and place axis items
|
# Initialize axis items
|
||||||
self.axes = {}
|
self.axes = {}
|
||||||
self.setAxes(axisItems)
|
self.setAxisItems(axisItems)
|
||||||
|
|
||||||
self.titleLabel = LabelItem('', size='11pt', parent=self)
|
self.titleLabel = LabelItem('', size='11pt', parent=self)
|
||||||
self.layout.addItem(self.titleLabel, 0, 1)
|
self.layout.addItem(self.titleLabel, 0, 1)
|
||||||
@ -260,43 +260,6 @@ class PlotItem(GraphicsWidget):
|
|||||||
if len(kargs) > 0:
|
if len(kargs) > 0:
|
||||||
self.plot(**kargs)
|
self.plot(**kargs)
|
||||||
|
|
||||||
def setAxes(self, axisItems):
|
|
||||||
"""
|
|
||||||
Create and place axis items
|
|
||||||
For valid values for axisItems see __init__
|
|
||||||
"""
|
|
||||||
for v in self.axes.values():
|
|
||||||
item = v['item']
|
|
||||||
self.layout.removeItem(item)
|
|
||||||
self.vb.removeItem(item)
|
|
||||||
|
|
||||||
self.axes = {}
|
|
||||||
if axisItems is None:
|
|
||||||
axisItems = {}
|
|
||||||
for k, pos in (('top', (1,1)), ('bottom', (3,1)), ('left', (2,0)), ('right', (2,2))):
|
|
||||||
axis = axisItems.get(k, None)
|
|
||||||
if axis:
|
|
||||||
axis.setOrientation(k)
|
|
||||||
else:
|
|
||||||
axis = AxisItem(orientation=k)
|
|
||||||
axis.linkToView(self.vb)
|
|
||||||
self.axes[k] = {'item': axis, 'pos': pos}
|
|
||||||
self.layout.addItem(axis, *pos)
|
|
||||||
axis.setZValue(-1000)
|
|
||||||
axis.setFlag(axis.ItemNegativeZStacksBehindParent)
|
|
||||||
#show/hide axes:
|
|
||||||
all_dir = ['left', 'bottom', 'right', 'top']
|
|
||||||
if axisItems:
|
|
||||||
to_show = list(axisItems.keys())
|
|
||||||
to_hide = [a for a in all_dir if a not in to_show]
|
|
||||||
else:
|
|
||||||
to_show = all_dir[:2]
|
|
||||||
to_hide = all_dir[2:]
|
|
||||||
for a in to_hide:
|
|
||||||
self.hideAxis(a)
|
|
||||||
for a in to_show:
|
|
||||||
self.showAxis(a)
|
|
||||||
|
|
||||||
def implements(self, interface=None):
|
def implements(self, interface=None):
|
||||||
return interface in ['ViewBoxWrapper']
|
return interface in ['ViewBoxWrapper']
|
||||||
|
|
||||||
@ -1162,8 +1125,8 @@ class PlotItem(GraphicsWidget):
|
|||||||
Show or hide one of the plot's axes.
|
Show or hide one of the plot's axes.
|
||||||
axis must be one of 'left', 'bottom', 'right', or 'top'
|
axis must be one of 'left', 'bottom', 'right', or 'top'
|
||||||
"""
|
"""
|
||||||
s = self.getAxis(axis)
|
s = self.getScale(axis)
|
||||||
#p = self.axes[axis]['pos']
|
p = self.axes[axis]['pos']
|
||||||
if show:
|
if show:
|
||||||
s.show()
|
s.show()
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user