Skip to content

Commit 61e9178

Browse files
committed
Convert base64 in validate_coerce_fig_to_dict instead of validate_coerce
Converting to base64 in validate_coerce_fig_to_dict offers the same performance improvements without changing the output of the data field of the Figure object.
1 parent 6364d4e commit 61e9178

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/python/plotly/_plotly_utils/basevalidators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def validate_coerce(self, v):
503503
elif has_skipped_key(self.parent_name):
504504
v = to_scalar_or_list(v)
505505
elif is_homogeneous_array(v):
506-
v = to_typed_array_spec(v)
506+
v = copy_to_readonly_numpy_array(v)
507507
elif is_simple_array(v):
508508
v = to_scalar_or_list(v)
509509
else:

packages/python/plotly/plotly/io/_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _plotly_utils.basevalidators import is_homogeneous_array, to_typed_array_spec
12
import plotly
23
import plotly.graph_objs as go
34
from plotly.offline import get_plotlyjs_version
@@ -24,6 +25,14 @@ def validate_coerce_fig_to_dict(fig, validate):
2425
typ=type(fig), v=fig
2526
)
2627
)
28+
29+
# Add base64 conversion before sending to the front-end
30+
for trace in fig_dict["data"]:
31+
for key, value in trace.items():
32+
if is_homogeneous_array(value):
33+
print("to typed array: key:", key, "value:", value)
34+
trace[key] = to_typed_array_spec(value)
35+
2736
return fig_dict
2837

2938

0 commit comments

Comments
 (0)