Skip to content

Commit

Permalink
allow scale width adjustment in style
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGoldfarb committed Jun 14, 2023
1 parent 624d161 commit 0b53c79
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
17 changes: 11 additions & 6 deletions examples/scratch_pad/issues/issue#241_loop_all_styles.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/mplfinance/_styledata/tradingview.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'alpha' : 1.0,
'volume_alpha': 0.65,
},
#scale_width_adjustment = { 'volume': 0.8 },
mavcolors = ['#2962ff','#2962ff',],
y_on_right = True,
gridcolor = None,
Expand Down
35 changes: 20 additions & 15 deletions src/mplfinance/_widths.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ def _valid_update_width_kwargs():

return vkwargs

def _scale_width_config(scale,width_config):
if scale['volume'] is not None:
width_config['volume_width'] *= scale['volume']
if scale['ohlc'] is not None:
width_config['ohlc_ticksize'] *= scale['ohlc']
if scale['candle'] is not None:
width_config['candle_width'] *= scale['candle']
if scale['lines'] is not None:
width_config['line_width'] *= scale['lines']
if scale['volume_linewidth'] is not None:
width_config['volume_linewidth'] *= scale['volume_linewidth']
if scale['ohlc_linewidth'] is not None:
width_config['ohlc_linewidth' ] *= scale['ohlc_linewidth']
if scale['candle_linewidth'] is not None:
width_config['candle_linewidth'] *= scale['candle_linewidth']

def _determine_width_config( xdates, config ):
'''
Expand Down Expand Up @@ -138,23 +153,13 @@ def _determine_width_config( xdates, config ):
width_config['candle_linewidth'] = _dfinterpolate(_widths,datalen,'clw')
width_config['line_width' ] = _dfinterpolate(_widths,datalen,'lw')

if config['scale_width_adjustment'] is not None:
if 'scale_width_adjustment' in config['style']:
scale = _process_kwargs(config['style']['scale_width_adjustment'],_valid_scale_width_kwargs())
_scale_width_config(scale,width_config)

if config['scale_width_adjustment'] is not None:
scale = _process_kwargs(config['scale_width_adjustment'],_valid_scale_width_kwargs())
if scale['volume'] is not None:
width_config['volume_width'] *= scale['volume']
if scale['ohlc'] is not None:
width_config['ohlc_ticksize'] *= scale['ohlc']
if scale['candle'] is not None:
width_config['candle_width'] *= scale['candle']
if scale['lines'] is not None:
width_config['line_width'] *= scale['lines']
if scale['volume_linewidth'] is not None:
width_config['volume_linewidth'] *= scale['volume_linewidth']
if scale['ohlc_linewidth'] is not None:
width_config['ohlc_linewidth' ] *= scale['ohlc_linewidth']
if scale['candle_linewidth'] is not None:
width_config['candle_linewidth'] *= scale['candle_linewidth']
_scale_width_config(scale,width_config)

if config['update_width_config'] is not None:

Expand Down

0 comments on commit 0b53c79

Please sign in to comment.