Skip to content

Commit 4e9d64e

Browse files
committed
Use to_json_plotly in html and orca logic
1 parent 0a51020 commit 4e9d64e

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

packages/python/plotly/plotly/io/_html.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def to_html(
128128
str
129129
Representation of figure as an HTML div string
130130
"""
131+
from plotly.io.json import to_json_plotly
131132

132133
# ## Validate figure ##
133134
fig_dict = validate_coerce_fig_to_dict(fig, validate)
@@ -136,15 +137,11 @@ def to_html(
136137
plotdivid = str(uuid.uuid4())
137138

138139
# ## Serialize figure ##
139-
jdata = _json.dumps(
140-
fig_dict.get("data", []), cls=utils.PlotlyJSONEncoder, sort_keys=True
141-
)
142-
jlayout = _json.dumps(
143-
fig_dict.get("layout", {}), cls=utils.PlotlyJSONEncoder, sort_keys=True
144-
)
140+
jdata = to_json_plotly(fig_dict.get("data", []))
141+
jlayout = to_json_plotly(fig_dict.get("layout", {}))
145142

146143
if fig_dict.get("frames", None):
147-
jframes = _json.dumps(fig_dict.get("frames", []), cls=utils.PlotlyJSONEncoder)
144+
jframes = to_json_plotly(fig_dict.get("frames", []))
148145
else:
149146
jframes = None
150147

packages/python/plotly/plotly/io/_orca.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ def request_image_with_retrying(**kwargs):
14581458
with retrying logic.
14591459
"""
14601460
from requests import post
1461+
from plotly.io.json import to_json_plotly
14611462

14621463
if config.server_url:
14631464
server_url = config.server_url
@@ -1467,7 +1468,7 @@ def request_image_with_retrying(**kwargs):
14671468
)
14681469

14691470
request_params = {k: v for k, v, in kwargs.items() if v is not None}
1470-
json_str = json.dumps(request_params, cls=_plotly_utils.utils.PlotlyJSONEncoder)
1471+
json_str = to_json_plotly(request_params)
14711472
response = post(server_url + "/", data=json_str)
14721473

14731474
if response.status_code == 522:

packages/python/plotly/templategen/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from plotly.utils import PlotlyJSONEncoder
2-
import json
1+
from plotly.io.json import to_json_plotly
32
import os
43
from templategen.definitions import builders
54

@@ -20,4 +19,4 @@
2019
),
2120
"w",
2221
) as f:
23-
plotly_schema = json.dump(template, f, cls=PlotlyJSONEncoder)
22+
f.write(to_json_plotly(template))

0 commit comments

Comments
 (0)