Add and update y-sticky labels on new price data
							parent
							
								
									363d4cf609
								
							
						
					
					
						commit
						7a245ddda4
					
				| 
						 | 
					@ -15,7 +15,8 @@ from ._axes import (
 | 
				
			||||||
    PriceAxis,
 | 
					    PriceAxis,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
from ._graphics import CrossHair, BarItems
 | 
					from ._graphics import CrossHair, BarItems
 | 
				
			||||||
from ._style import _xaxis_at, _min_points_to_show
 | 
					from ._axes import YSticky
 | 
				
			||||||
 | 
					from ._style import _xaxis_at, _min_points_to_show, hcolor
 | 
				
			||||||
from ._source import Symbol
 | 
					from ._source import Symbol
 | 
				
			||||||
from .. import brokers
 | 
					from .. import brokers
 | 
				
			||||||
from .. import data
 | 
					from .. import data
 | 
				
			||||||
| 
						 | 
					@ -225,7 +226,6 @@ class LinkedSplitCharts(QtGui.QWidget):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cpw.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
 | 
					        cpw.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
 | 
				
			||||||
        cpw.getPlotItem().setContentsMargins(*CHART_MARGINS)
 | 
					        cpw.getPlotItem().setContentsMargins(*CHART_MARGINS)
 | 
				
			||||||
        # self.splitter.addWidget(cpw)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # link chart x-axis to main quotes chart
 | 
					        # link chart x-axis to main quotes chart
 | 
				
			||||||
        cpw.setXLink(self.chart)
 | 
					        cpw.setXLink(self.chart)
 | 
				
			||||||
| 
						 | 
					@ -246,6 +246,9 @@ class LinkedSplitCharts(QtGui.QWidget):
 | 
				
			||||||
            # scale split regions
 | 
					            # scale split regions
 | 
				
			||||||
            self.set_split_sizes()
 | 
					            self.set_split_sizes()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # XXX: we need this right?
 | 
				
			||||||
 | 
					            # self.splitter.addWidget(cpw)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return cpw
 | 
					        return cpw
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -282,6 +285,7 @@ class ChartPlotWidget(pg.PlotWidget):
 | 
				
			||||||
        self._array = array  # readonly view of data
 | 
					        self._array = array  # readonly view of data
 | 
				
			||||||
        self._graphics = {}  # registry of underlying graphics
 | 
					        self._graphics = {}  # registry of underlying graphics
 | 
				
			||||||
        self._labels = {}  # registry of underlying graphics
 | 
					        self._labels = {}  # registry of underlying graphics
 | 
				
			||||||
 | 
					        self._ysticks = {}  # registry of underlying graphics
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # show only right side axes
 | 
					        # show only right side axes
 | 
				
			||||||
        self.hideAxis('left')
 | 
					        self.hideAxis('left')
 | 
				
			||||||
| 
						 | 
					@ -350,6 +354,7 @@ class ChartPlotWidget(pg.PlotWidget):
 | 
				
			||||||
        self._graphics[name] = graphics
 | 
					        self._graphics[name] = graphics
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # XXX: How to stack labels vertically?
 | 
					        # XXX: How to stack labels vertically?
 | 
				
			||||||
 | 
					        # Ogi says: "
 | 
				
			||||||
        label = pg.LabelItem(
 | 
					        label = pg.LabelItem(
 | 
				
			||||||
            justify='left',
 | 
					            justify='left',
 | 
				
			||||||
            size='5pt',
 | 
					            size='5pt',
 | 
				
			||||||
| 
						 | 
					@ -373,6 +378,8 @@ class ChartPlotWidget(pg.PlotWidget):
 | 
				
			||||||
        # show last 50 points on startup
 | 
					        # show last 50 points on startup
 | 
				
			||||||
        self.plotItem.vb.setXRange(xlast - 50, xlast + 50)
 | 
					        self.plotItem.vb.setXRange(xlast - 50, xlast + 50)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self._add_sticky(name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return graphics
 | 
					        return graphics
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def draw_curve(
 | 
					    def draw_curve(
 | 
				
			||||||
| 
						 | 
					@ -421,6 +428,21 @@ class ChartPlotWidget(pg.PlotWidget):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return curve
 | 
					        return curve
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _add_sticky(
 | 
				
			||||||
 | 
					        self,
 | 
				
			||||||
 | 
					        name: str,
 | 
				
			||||||
 | 
					        # retreive: Callable[None, np.ndarray],
 | 
				
			||||||
 | 
					    ) -> YSticky:
 | 
				
			||||||
 | 
					        # add y-axis "last" value label
 | 
				
			||||||
 | 
					        last = self._ysticks['last'] = YSticky(
 | 
				
			||||||
 | 
					            chart=self,
 | 
				
			||||||
 | 
					            parent=self.getAxis('right'),
 | 
				
			||||||
 | 
					            # digits=0,
 | 
				
			||||||
 | 
					            opacity=1,
 | 
				
			||||||
 | 
					            color=pg.mkPen(hcolor('gray'))
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        return last
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def update_from_array(
 | 
					    def update_from_array(
 | 
				
			||||||
        self,
 | 
					        self,
 | 
				
			||||||
        name: str,
 | 
					        name: str,
 | 
				
			||||||
| 
						 | 
					@ -636,6 +658,10 @@ async def _async_main(
 | 
				
			||||||
            loglevel,
 | 
					            loglevel,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # update last price sticky
 | 
				
			||||||
 | 
					        last = chart._ysticks['last']
 | 
				
			||||||
 | 
					        last.update_from_data(*chart._array[-1][['index', 'close']])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # graphics update loop
 | 
					        # graphics update loop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        async with data.open_feed(
 | 
					        async with data.open_feed(
 | 
				
			||||||
| 
						 | 
					@ -646,7 +672,7 @@ async def _async_main(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # wait for a first quote before we start any update tasks
 | 
					            # wait for a first quote before we start any update tasks
 | 
				
			||||||
            quote = await stream.__anext__()
 | 
					            quote = await stream.__anext__()
 | 
				
			||||||
            print(f'RECEIVED FIRST QUOTE {quote}')
 | 
					            log.info(f'RECEIVED FIRST QUOTE {quote}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # start graphics tasks after receiving first live quote
 | 
					            # start graphics tasks after receiving first live quote
 | 
				
			||||||
            n.start_soon(add_new_bars, delay, linked_charts)
 | 
					            n.start_soon(add_new_bars, delay, linked_charts)
 | 
				
			||||||
| 
						 | 
					@ -675,6 +701,10 @@ async def _async_main(
 | 
				
			||||||
                                chart.name,
 | 
					                                chart.name,
 | 
				
			||||||
                                chart._array,
 | 
					                                chart._array,
 | 
				
			||||||
                            )
 | 
					                            )
 | 
				
			||||||
 | 
					                            # update sticky(s)
 | 
				
			||||||
 | 
					                            last = chart._ysticks['last']
 | 
				
			||||||
 | 
					                            last.update_from_data(
 | 
				
			||||||
 | 
					                                *chart._array[-1][['index', 'close']])
 | 
				
			||||||
                            chart._set_yrange()
 | 
					                            chart._set_yrange()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue