dynamic sizing (size=s,m,l) and height ratio

This commit is contained in:
David Brazda
2024-06-12 11:00:41 +02:00
parent e9cf847a9a
commit d1c78719eb
2 changed files with 81 additions and 76 deletions

View File

@ -10,7 +10,7 @@ class Panel:
self.histogram = histogram if histogram is not None else [] self.histogram = histogram if histogram is not None else []
self.title = title self.title = title
def chart(panes: list[Panel], sync=False, title=''): def chart(panes: list[Panel], sync=False, title='', size="m"):
"""Function to fast render a chart with multiple panes. """Function to fast render a chart with multiple panes.
Args: Args:
@ -47,15 +47,20 @@ def chart(panes: list[Panel], sync=False, title=''):
``` ```
""" """
numpanes = len(panes) size_to_dimensions = {
's': (800, 400),
'm': (1000, 600),
'l': (1300, 800)}
width, height = size_to_dimensions.get(size, (1000, 600))
height_ratio = 1 / len(panes)
main_title_set = False main_title_set = False
for index, pane in enumerate(panes): for index, pane in enumerate(panes):
subchartX = None subchartX = None
if index == 0: if index == 0:
chartX = JupyterChart(width=1000, height=600, inner_width=1, inner_height=0.5, leftScale=bool(pane.left)) chartX = JupyterChart(width=width, height=height, inner_width=1, inner_height=height_ratio, leftScale=bool(pane.left))
active_chart = chartX active_chart = chartX
else: else:
subchartX = chartX.create_subchart(position='right', width=1, height=0.5, sync=sync, leftScale=bool(pane.left)) subchartX = chartX.create_subchart(position='right', width=1, height=height_ratio, sync=sync, leftScale=bool(pane.left))
active_chart = subchartX active_chart = subchartX
if pane.ohlcv is not None: if pane.ohlcv is not None:

View File

@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as f:
setup( setup(
name='lightweight_charts', name='lightweight_charts',
version='2.0.11', version='2.0.12',
packages=find_packages(), packages=find_packages(),
python_requires='>=3.8', python_requires='>=3.8',
install_requires=[ install_requires=[