I want to build a generalisable function, to test if a plotly plot is empty or not.
Context: I recieve the plot data from some API. I want to test if it is empty or not. I have no access to the input dataframes, and I want to automate the tests such that I don't have to plot the graph, look at it, then conclude it's either empty, or not-empty.
Here is what I've have so far;
def check_plot_data_empty(plot_data):
if 'data' in plot_data:
for trace in plot_data['data']:
data_keys = ['x', 'y', 'z', 'values', 'text', 'marker']
for key in data_keys:
if key in trace:
if key == 'marker':
if 'size' in trace['marker'] and len(trace['marker']['size']) > 0:
return False
if 'color' in trace['marker'] and len(trace['marker']['color']) > 0:
return False
else:
if isinstance(trace[key], list) and len(trace[key]) > 0:
return False
if key == 'text' and isinstance(trace[key], str) and trace[key].strip():
return False
return True
This works pretty well for the 5-6 examples I've run. However, I need a more robust way to test if this will work for all types of plotly plots. Are there plotly testing frameworks, or other approaches I can take to fully test this function.
And I would welcome any counter-examples that shows this does not work, with the approach used to come up with it, which will help me test further.
Thanks!