Ensure we update the volume array, not graphics
Ugh, turns out the wacky `ChartView.maxmin` callback stuff we did (for determining y-range sizings) currently requires that the volume array has a "bars in view" result.. so let's make that keep working without rendering the graphics for the curve (since we're disabling them once $vlm comes up).only_draw_iv_for_ohlc
							parent
							
								
									8e6fda0049
								
							
						
					
					
						commit
						f9d2e45836
					
				| 
						 | 
					@ -75,6 +75,7 @@ _tick_groups = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def chart_maxmin(
 | 
					def chart_maxmin(
 | 
				
			||||||
    chart: ChartPlotWidget,
 | 
					    chart: ChartPlotWidget,
 | 
				
			||||||
 | 
					    ohlcv_shm: ShmArray,
 | 
				
			||||||
    vlm_chart: Optional[ChartPlotWidget] = None,
 | 
					    vlm_chart: Optional[ChartPlotWidget] = None,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
) -> tuple[
 | 
					) -> tuple[
 | 
				
			||||||
| 
						 | 
					@ -91,7 +92,8 @@ def chart_maxmin(
 | 
				
			||||||
    # https://arxiv.org/abs/cs/0610046
 | 
					    # https://arxiv.org/abs/cs/0610046
 | 
				
			||||||
    # https://github.com/lemire/pythonmaxmin
 | 
					    # https://github.com/lemire/pythonmaxmin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    array = chart._arrays[chart.name]
 | 
					    # array = chart._arrays[chart.name]
 | 
				
			||||||
 | 
					    array = ohlcv_shm.array
 | 
				
			||||||
    ifirst = array[0]['index']
 | 
					    ifirst = array[0]['index']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    last_bars_range = chart.bars_range()
 | 
					    last_bars_range = chart.bars_range()
 | 
				
			||||||
| 
						 | 
					@ -183,7 +185,12 @@ async def graphics_update_loop(
 | 
				
			||||||
    if vlm_chart:
 | 
					    if vlm_chart:
 | 
				
			||||||
        vlm_sticky = vlm_chart._ysticks['volume']
 | 
					        vlm_sticky = vlm_chart._ysticks['volume']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    maxmin = partial(chart_maxmin, chart, vlm_chart)
 | 
					    maxmin = partial(
 | 
				
			||||||
 | 
					        chart_maxmin,
 | 
				
			||||||
 | 
					        chart,
 | 
				
			||||||
 | 
					        ohlcv,
 | 
				
			||||||
 | 
					        vlm_chart,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
    last_bars_range: tuple[float, float]
 | 
					    last_bars_range: tuple[float, float]
 | 
				
			||||||
    (
 | 
					    (
 | 
				
			||||||
        last_bars_range,
 | 
					        last_bars_range,
 | 
				
			||||||
| 
						 | 
					@ -325,7 +332,13 @@ def graphics_update_cycle(
 | 
				
			||||||
    update_uppx = 5
 | 
					    update_uppx = 5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for sym, quote in ds.quotes.items():
 | 
					    for sym, quote in ds.quotes.items():
 | 
				
			||||||
        brange, mx_in_view, mn_in_view, mx_vlm_in_view = ds.maxmin()
 | 
					        (
 | 
				
			||||||
 | 
					            brange,
 | 
				
			||||||
 | 
					            mx_in_view,
 | 
				
			||||||
 | 
					            mn_in_view,
 | 
				
			||||||
 | 
					            mx_vlm_in_view,
 | 
				
			||||||
 | 
					        ) = ds.maxmin()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        l, lbar, rbar, r = brange
 | 
					        l, lbar, rbar, r = brange
 | 
				
			||||||
        mx = mx_in_view + tick_margin
 | 
					        mx = mx_in_view + tick_margin
 | 
				
			||||||
        mn = mn_in_view - tick_margin
 | 
					        mn = mn_in_view - tick_margin
 | 
				
			||||||
| 
						 | 
					@ -333,6 +346,7 @@ def graphics_update_cycle(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # compute the first available graphic's x-units-per-pixel
 | 
					        # compute the first available graphic's x-units-per-pixel
 | 
				
			||||||
        xpx = vlm_chart.view.xs_in_px()
 | 
					        xpx = vlm_chart.view.xs_in_px()
 | 
				
			||||||
 | 
					        # print(f'vlm xpx {xpx}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        in_view = chart.in_view(ohlcv.array)
 | 
					        in_view = chart.in_view(ohlcv.array)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -424,15 +438,32 @@ def graphics_update_cycle(
 | 
				
			||||||
            ):
 | 
					            ):
 | 
				
			||||||
                # TODO: make it so this doesn't have to be called
 | 
					                # TODO: make it so this doesn't have to be called
 | 
				
			||||||
                # once the $vlm is up?
 | 
					                # once the $vlm is up?
 | 
				
			||||||
                vlm_chart.update_graphics_from_array('volume', array)
 | 
					                vlm_chart.update_graphics_from_array(
 | 
				
			||||||
 | 
					                    'volume',
 | 
				
			||||||
 | 
					                    array,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    # UGGGh, see ``maxmin()`` impl in `._fsp` for
 | 
				
			||||||
 | 
					                    # the overlayed plotitems... we need a better
 | 
				
			||||||
 | 
					                    # bay to invoke a maxmin per overlay..
 | 
				
			||||||
 | 
					                    render=False,
 | 
				
			||||||
 | 
					                    # XXX: ^^^^ THIS IS SUPER IMPORTANT! ^^^^
 | 
				
			||||||
 | 
					                    # without this, since we disable the
 | 
				
			||||||
 | 
					                    # 'volume' (units) chart after the $vlm starts
 | 
				
			||||||
 | 
					                    # up we need to be sure to enable this
 | 
				
			||||||
 | 
					                    # auto-ranging otherwise there will be no handler
 | 
				
			||||||
 | 
					                    # connected to update accompanying overlay
 | 
				
			||||||
 | 
					                    # graphics..
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                last_mx_vlm = vars['last_mx_vlm']
 | 
				
			||||||
                if (
 | 
					                if (
 | 
				
			||||||
                    mx_vlm_in_view != vars['last_mx_vlm']
 | 
					                    mx_vlm_in_view != last_mx_vlm
 | 
				
			||||||
                    or mx_vlm_in_view > vars['last_mx_vlm']
 | 
					                    or mx_vlm_in_view > last_mx_vlm
 | 
				
			||||||
                ):
 | 
					                ):
 | 
				
			||||||
                    # print(f'mx vlm: {last_mx_vlm} -> {mx_vlm_in_view}')
 | 
					                    # print(f'mx vlm: {last_mx_vlm} -> {mx_vlm_in_view}')
 | 
				
			||||||
                    vlm_chart.view._set_yrange(
 | 
					 | 
				
			||||||
                    yrange = (0, mx_vlm_in_view * 1.375)
 | 
					                    yrange = (0, mx_vlm_in_view * 1.375)
 | 
				
			||||||
 | 
					                    vlm_chart.view._set_yrange(
 | 
				
			||||||
 | 
					                        yrange=yrange,
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                    vars['last_mx_vlm'] = mx_vlm_in_view
 | 
					                    vars['last_mx_vlm'] = mx_vlm_in_view
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -444,7 +475,10 @@ def graphics_update_cycle(
 | 
				
			||||||
                        array_key=curve_name,
 | 
					                        array_key=curve_name,
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                    # is this even doing anything?
 | 
					                    # is this even doing anything?
 | 
				
			||||||
                    flow.plot.vb._set_yrange(
 | 
					                    # (pretty sure it's the real-time
 | 
				
			||||||
 | 
					                    # resizing from last quote?)
 | 
				
			||||||
 | 
					                    fvb = flow.plot.vb
 | 
				
			||||||
 | 
					                    fvb._set_yrange(
 | 
				
			||||||
                        autoscale_linked_plots=False,
 | 
					                        autoscale_linked_plots=False,
 | 
				
			||||||
                        name=curve_name,
 | 
					                        name=curve_name,
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
| 
						 | 
					@ -590,6 +624,9 @@ def graphics_update_cycle(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # run synchronous update on all derived fsp subplots
 | 
					        # run synchronous update on all derived fsp subplots
 | 
				
			||||||
        for name, subchart in ds.linked.subplots.items():
 | 
					        for name, subchart in ds.linked.subplots.items():
 | 
				
			||||||
 | 
					            if name == 'volume':
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            update_fsp_chart(
 | 
					            update_fsp_chart(
 | 
				
			||||||
                subchart,
 | 
					                subchart,
 | 
				
			||||||
                subchart._shm,
 | 
					                subchart._shm,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue