Skip to content

Commit

Permalink
refactor: Minor reduction in AltairPlotDirective.run
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Aug 16, 2024
1 parent ec1a982 commit 07d9a8f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions sphinxext_altair/altairplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ def run(self) -> list[nodes.Element]:

if not hasattr(env, "_altair_namespaces"):
env._altair_namespaces = {}
namespace_id = self.options.get("namespace", "default")
namespace = env._altair_namespaces.setdefault(env.docname, {}).setdefault(
namespace_id, {}
self.options.get("namespace", "default"), {}
)

# Show code
Expand Down Expand Up @@ -281,9 +280,9 @@ def html_visit_altair_plot(self: altair_plot, node: nodes.Element) -> None: # n
node.append(repr_literal)
elif output == "plot":
if isinstance(chart, alt.TopLevelMixin):
# Last line should be a chart; convert to spec dict
# Last line should be a chart; convert to JSON string
try:
spec = chart.to_dict()
spec = chart.to_json(indent=None, sort_keys=False)
except SchemaValidationError as err:
msg = f"Invalid chart: {node['code']}"
raise ValueError(msg) from err
Expand All @@ -292,7 +291,7 @@ def html_visit_altair_plot(self: altair_plot, node: nodes.Element) -> None: # n
html = VGL_TEMPLATE.render(
div_id=node["div_id"],
div_class=node["div_class"],
spec=json.dumps(spec),
spec=spec,
mode="vega-lite",
renderer="canvas",
actions=json.dumps(node["links"]),
Expand Down

0 comments on commit 07d9a8f

Please sign in to comment.