Allow to pass Plotly-style data_config to report_table

This commit is contained in:
Alex Burlacu 2023-03-23 17:12:29 +02:00
parent f9fa303091
commit 3ee6ddf835
3 changed files with 32 additions and 4 deletions

View File

@ -615,7 +615,7 @@ class Reporter(InterfaceBase, AbstractContextManager, SetupUploadMixin, AsyncMan
nan_as_null=False,
)
def report_table(self, title, series, table, iteration, layout_config=None):
def report_table(self, title, series, table, iteration, layout_config=None, data_config=None):
"""
Report a table plot.
@ -629,8 +629,10 @@ class Reporter(InterfaceBase, AbstractContextManager, SetupUploadMixin, AsyncMan
:type iteration: int
:param layout_config: optional dictionary for layout configuration, passed directly to plotly
:type layout_config: dict or None
:param data_config: optional dictionary for data configuration, like column width, passed directly to plotly
:type data_config: dict or None
"""
table_output = create_plotly_table(table, title, series, layout_config=layout_config)
table_output = create_plotly_table(table, title, series, layout_config=layout_config, data_config=data_config)
return self.report_plot(
title=self._normalize_name(title),
series=self._normalize_name(series),

View File

@ -306,6 +306,7 @@ class Logger(object):
csv=None, # type: Optional[str]
url=None, # type: Optional[str]
extra_layout=None, # type: Optional[dict]
extra_data=None, # type: Optional[dict]
):
"""
For explicit report, report a table plot.
@ -337,7 +338,27 @@ class Logger(object):
:param url: A URL to the location of csv file.
:param extra_layout: optional dictionary for layout configuration, passed directly to plotly
See full details on the supported configuration: https://plotly.com/javascript/reference/layout/
example: extra_layout={'height': 600}
For example:
.. code block:: py
logger.report_table(
title='table example',
series='pandas DataFrame',
iteration=0,
table_plot=df,
extra_layout={'height': 600})
:param extra_data: optional dictionary for data configuration, like column width, passed directly to plotly
See full details on the supported configuration: https://plotly.com/javascript/reference/table/
For example:
.. code block:: py
logger.report_table(
title='table example',
series='pandas DataFrame',
iteration=0,
table_plot=df,
extra_data={'columnwidth': [2., 1., 1., 1.]})
"""
mutually_exclusive(
UsageError, _check_none=True,
@ -373,6 +394,7 @@ class Logger(object):
table=reporter_table,
iteration=iteration or 0,
layout_config=extra_layout,
data_config=extra_data,
)
def report_line_plot(

View File

@ -482,7 +482,7 @@ def plotly_scatter3d_layout_dict(title="Scatter", xaxis_title="X", yaxis_title="
return plotly_object
def create_plotly_table(table_plot, title, series, layout_config=None):
def create_plotly_table(table_plot, title, series, layout_config=None, data_config=None):
"""
Create a basic Plotly table json style to be sent
@ -492,6 +492,7 @@ def create_plotly_table(table_plot, title, series, layout_config=None):
:param series: Series (AKA variant)
:type series: str
:param layout_config: additional configuration layout
:param data_config: additional configuration for the data
:return: dict with plotly data.
"""
is_list = isinstance(table_plot, (list, tuple))
@ -545,4 +546,7 @@ def create_plotly_table(table_plot, title, series, layout_config=None):
if layout_config:
ret["layout"] = merge_dicts(ret["layout"], layout_config)
if data_config and len(ret["data"]) == 1:
ret["data"][0] = merge_dicts(ret["data"][0], data_config)
return ret