Use overlay api to access multi-axes by name
							parent
							
								
									f5eb34c4d7
								
							
						
					
					
						commit
						7f4546b71f
					
				|  | @ -479,14 +479,20 @@ class LinkedSplits(QWidget): | ||||||
|             axisItems=axes, |             axisItems=axes, | ||||||
|             **cpw_kwargs, |             **cpw_kwargs, | ||||||
|         ) |         ) | ||||||
|  |         cpw.hideAxis('left') | ||||||
|  |         cpw.hideAxis('bottom') | ||||||
| 
 | 
 | ||||||
|         if self.xaxis_chart: |         if self.xaxis_chart: | ||||||
|  |             self.xaxis_chart.hideAxis('bottom') | ||||||
|  | 
 | ||||||
|             # presuming we only want it at the true bottom of all charts. |             # presuming we only want it at the true bottom of all charts. | ||||||
|             # XXX: uses new api from our ``pyqtgraph`` fork. |             # XXX: uses new api from our ``pyqtgraph`` fork. | ||||||
|             # https://github.com/pikers/pyqtgraph/tree/plotitemoverlay_onto_pg_master |             # https://github.com/pikers/pyqtgraph/tree/plotitemoverlay_onto_pg_master | ||||||
|             _ = self.xaxis_chart.removeAxis('bottom', unlink=False) |             # _ = self.xaxis_chart.removeAxis('bottom', unlink=False) | ||||||
|             assert 'bottom' not in self.xaxis_chart.plotItem.axes |             # assert 'bottom' not in self.xaxis_chart.plotItem.axes | ||||||
|  | 
 | ||||||
|             self.xaxis_chart = cpw |             self.xaxis_chart = cpw | ||||||
|  |             cpw.showAxis('bottom') | ||||||
| 
 | 
 | ||||||
|         if self.xaxis_chart is None: |         if self.xaxis_chart is None: | ||||||
|             self.xaxis_chart = cpw |             self.xaxis_chart = cpw | ||||||
|  | @ -726,11 +732,6 @@ class ChartPlotWidget(pg.PlotWidget): | ||||||
|         self._static_yrange = static_yrange  # for "known y-range style" |         self._static_yrange = static_yrange  # for "known y-range style" | ||||||
|         self._view_mode: str = 'follow' |         self._view_mode: str = 'follow' | ||||||
| 
 | 
 | ||||||
|         # show only right side axes |  | ||||||
|         self.hideAxis('left') |  | ||||||
|         self.showAxis('right') |  | ||||||
|         # self.showAxis('left') |  | ||||||
| 
 |  | ||||||
|         # show background grid |         # show background grid | ||||||
|         self.showGrid(x=False, y=True, alpha=0.3) |         self.showGrid(x=False, y=True, alpha=0.3) | ||||||
| 
 | 
 | ||||||
|  | @ -862,55 +863,58 @@ class ChartPlotWidget(pg.PlotWidget): | ||||||
|     def overlay_plotitem( |     def overlay_plotitem( | ||||||
|         self, |         self, | ||||||
|         name: str, |         name: str, | ||||||
|  |         index: Optional[int] = None, | ||||||
|  |         axis_title: Optional[str] = None, | ||||||
|  |         axis_side: str = 'right', | ||||||
|         axis_kwargs: dict = {}, |         axis_kwargs: dict = {}, | ||||||
| 
 | 
 | ||||||
|     ) -> pg.PlotItem: |     ) -> pg.PlotItem: | ||||||
|  | 
 | ||||||
|         # Custom viewbox impl |         # Custom viewbox impl | ||||||
|         cv = self.mk_vb(name) |         cv = self.mk_vb(name) | ||||||
|         cv.chart = self |         cv.chart = self | ||||||
| 
 | 
 | ||||||
|         # xaxis = DynamicDateAxis( |         allowed_sides = {'left', 'right'} | ||||||
|         #     orientation='bottom', |         if axis_side not in allowed_sides: | ||||||
|         #     linkedsplits=self.linked, |             raise ValueError(f'``axis_side``` must be in {allowed_sides}') | ||||||
|         # ) |  | ||||||
|         yaxis = PriceAxis( |         yaxis = PriceAxis( | ||||||
|             orientation='right', |             orientation=axis_side, | ||||||
|             linkedsplits=self.linked, |             linkedsplits=self.linked, | ||||||
|             **axis_kwargs, |             **axis_kwargs, | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         plotitem = pg.PlotItem( |         pi = pg.PlotItem( | ||||||
|             parent=self.plotItem, |             parent=self.plotItem, | ||||||
|             name=name, |             name=name, | ||||||
|             enableMenu=False, |             enableMenu=False, | ||||||
|             viewBox=cv, |             viewBox=cv, | ||||||
|             axisItems={ |             axisItems={ | ||||||
|                 # 'bottom': xaxis, |                 # 'bottom': xaxis, | ||||||
|                 'right': yaxis, |                 axis_side: yaxis, | ||||||
|             }, |             }, | ||||||
|             default_axes=[], |             default_axes=[], | ||||||
|         ) |         ) | ||||||
|         # plotitem.setAxisItems( |         pi.hideButtons() | ||||||
|         #     add_to_layout=False, | 
 | ||||||
|         #     axisItems={ |  | ||||||
|         #         'bottom': xaxis, |  | ||||||
|         #         'right': yaxis, |  | ||||||
|         #     }, |  | ||||||
|         # ) |  | ||||||
|         # plotite.hideAxis('right') |  | ||||||
|         # plotite.hideAxis('bottom') |  | ||||||
|         # plotitem.addItem(curve) |  | ||||||
|         cv.enable_auto_yrange() |         cv.enable_auto_yrange() | ||||||
| 
 | 
 | ||||||
|         # plotitem.enableAutoRange(axis='y') |         # compose this new plot's graphics with the current chart's | ||||||
|         plotitem.hideButtons() |         # existing one but with separate axes as neede and specified. | ||||||
| 
 |  | ||||||
|         self.pi_overlay.add_plotitem( |         self.pi_overlay.add_plotitem( | ||||||
|             plotitem, |             pi, | ||||||
|  |             index=index, | ||||||
|  | 
 | ||||||
|             # only link x-axes, |             # only link x-axes, | ||||||
|             link_axes=(0,), |             link_axes=(0,), | ||||||
|         ) |         ) | ||||||
|         return plotitem | 
 | ||||||
|  |         # add axis title | ||||||
|  |         # TODO: do we want this API to still work? | ||||||
|  |         # raxis = pi.getAxis('right') | ||||||
|  |         axis = self.pi_overlay.get_axis(pi, axis_side) | ||||||
|  |         axis.set_title(axis_title or name, view=pi.getViewBox()) | ||||||
|  | 
 | ||||||
|  |         return pi | ||||||
| 
 | 
 | ||||||
|     def draw_curve( |     def draw_curve( | ||||||
|         self, |         self, | ||||||
|  | @ -1016,7 +1020,8 @@ class ChartPlotWidget(pg.PlotWidget): | ||||||
|         # add y-axis "last" value label |         # add y-axis "last" value label | ||||||
|         last = self._ysticks[name] = YAxisLabel( |         last = self._ysticks[name] = YAxisLabel( | ||||||
|             chart=self, |             chart=self, | ||||||
|             parent=self.getAxis('right'), |             # parent=self.getAxis('right'), | ||||||
|  |             parent=self.pi_overlay.get_axis(self.plotItem, 'right'), | ||||||
|             # TODO: pass this from symbol data |             # TODO: pass this from symbol data | ||||||
|             digits=digits, |             digits=digits, | ||||||
|             opacity=1, |             opacity=1, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue