Fixes for examples\customPlot.py (#1448)
* Fix examples\customPlot.py: Not object-oriented Copy-paste error: I referenced a specific object instead of self. Fixed. * Fix examples\customPlot.py: Allow calling setTicks more than once This fixes a bug where TickSliderItem is expected to return ticks.keys() but while it returns ticks.items(). Also: Minor code correction. * Fix examples\customPlot.py: Avoid scaling differences Consider padding of TickSliderItem for link between ViewBox and ticks Co-authored-by: 2xB <2xB@users.noreply.github.com>
This commit is contained in:
parent
6c14204682
commit
5adb1b9a5b
@ -39,29 +39,36 @@ class CustomTickSliderItem(pg.TickSliderItem):
|
|||||||
self._range = [0,1]
|
self._range = [0,1]
|
||||||
|
|
||||||
def setTicks(self, ticks):
|
def setTicks(self, ticks):
|
||||||
for tick in tickViewer.listTicks():
|
for tick, pos in self.listTicks():
|
||||||
self.removeTick(tick)
|
self.removeTick(tick)
|
||||||
self.visible_ticks = {}
|
self.visible_ticks = {}
|
||||||
|
|
||||||
self.all_ticks = ticks
|
self.all_ticks = ticks
|
||||||
|
|
||||||
self.updateRange(None, self._range)
|
self.updateRange(None, self._range)
|
||||||
|
|
||||||
def updateRange(self, vb, viewRange):
|
def updateRange(self, vb, viewRange):
|
||||||
|
origin = self.tickSize/2.
|
||||||
|
length = self.length
|
||||||
|
|
||||||
|
lengthIncludingPadding = length + self.tickSize + 2
|
||||||
|
|
||||||
self._range = viewRange
|
self._range = viewRange
|
||||||
|
|
||||||
for pos in self.all_ticks:
|
for pos in self.all_ticks:
|
||||||
visible = pos >= viewRange[0] and pos <= viewRange[1]
|
|
||||||
|
if pos not in self.visible_ticks:
|
||||||
|
self.visible_ticks[pos] = self.addTick(pos, movable=False, color="333333")
|
||||||
|
|
||||||
|
tick = self.visible_ticks[pos]
|
||||||
|
|
||||||
|
tickValueIncludingPadding = (pos - viewRange[0]) / (viewRange[1] - viewRange[0])
|
||||||
|
tickValue = (tickValueIncludingPadding*lengthIncludingPadding - origin) / length
|
||||||
|
|
||||||
|
visible = tickValue >= 0 and tickValue <= 1
|
||||||
|
|
||||||
if visible:
|
if visible:
|
||||||
if pos not in self.visible_ticks:
|
|
||||||
self.visible_ticks[pos] = self.addTick(pos, movable=False, color="333333")
|
|
||||||
|
|
||||||
tick = self.visible_ticks[pos]
|
|
||||||
|
|
||||||
tickValue = (pos - viewRange[0]) / (viewRange[1] - viewRange[0])
|
|
||||||
self.setTickValue(tick, tickValue)
|
self.setTickValue(tick, tickValue)
|
||||||
|
|
||||||
elif pos in self.visible_ticks:
|
elif pos in self.visible_ticks:
|
||||||
self.removeTick(self.visible_ticks[pos])
|
self.removeTick(self.visible_ticks[pos])
|
||||||
del self.visible_ticks[pos]
|
del self.visible_ticks[pos]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user