(fig, validate)
| 6 | |
| 7 | |
| 8 | def validate_coerce_fig_to_dict(fig, validate): |
| 9 | from plotly.basedatatypes import BaseFigure |
| 10 | |
| 11 | if isinstance(fig, BaseFigure): |
| 12 | fig_dict = fig.to_dict() |
| 13 | elif isinstance(fig, dict): |
| 14 | if validate: |
| 15 | # This will raise an exception if fig is not a valid plotly figure |
| 16 | fig_dict = plotly.graph_objs.Figure(fig).to_plotly_json() |
| 17 | else: |
| 18 | fig_dict = fig |
| 19 | elif hasattr(fig, "to_plotly_json"): |
| 20 | fig_dict = fig.to_plotly_json() |
| 21 | else: |
| 22 | raise ValueError( |
| 23 | """ |
| 24 | The fig parameter must be a dict or Figure. |
| 25 | Received value of type {typ}: {v}""".format(typ=type(fig), v=fig) |
| 26 | ) |
| 27 | return fig_dict |
| 28 | |
| 29 | |
| 30 | def validate_coerce_output_type(output_type): |
no test coverage detected