"""\
Copyright (c) 2023, Flagstaff Solutions, LLC
All rights reserved.
"""
import inspect
import sys
import plotly.graph_objects as go
from gofigr.backends import GoFigrBackend, get_all_function_arguments
[docs]
class PlotlyBackend(GoFigrBackend):
"""Plotly backend for GoFigr"""
[docs]
def get_backend_name(self):
return "plotly"
[docs]
def is_compatible(self, fig):
return isinstance(fig, go.Figure)
[docs]
def is_interactive(self, fig):
return True
# pylint: disable=useless-return
[docs]
def get_title(self, fig):
title_text = None
try:
title = fig.layout.title
if isinstance(title, go.layout.Title):
title_text = title.text
elif isinstance(title, str):
title_text = title
except Exception: # pylint: disable=broad-exception-caught
title_text = None
return title_text
[docs]
def add_interactive_watermark(self, fig, rev, watermark):
# pylint: disable=use-dict-literal
orig_height = getattr(fig.layout, "height")
if orig_height is None:
orig_height = 450 # Plotly default
margin = 100
new_height = 2 * margin + orig_height
wfig = go.Figure(fig)
wfig.update_layout(margin=dict(l=0, r=0, t=margin, b=margin))
wfig.update_layout(height=new_height)
wfig.add_annotation(dict(font=dict(color='black', size=15),
x=0,
y=0,
yshift=-margin,
showarrow=False,
text=f"<a href='{rev.revision_url}'>{rev.revision_url}</a>",
textangle=0,
xanchor='left',
xref="paper",
yref="paper"))
return wfig
[docs]
def close(self, fig):
pass