Skip to content

Commit d543727

Browse files
committed
Don't set chart if it is None
1 parent 68a4546 commit d543727

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

chartlets.py/chartlets/components/plot.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ class Plot(Component):
1212
[Vega Altair](https://altair-viz.github.io/) chart."""
1313

1414
theme: str | None = None
15-
"""A [Vega theme name](https://vega.github.io/vega-themes/)."""
15+
"""The name of a [Vega theme](https://vega.github.io/vega-themes/)."""
1616

1717
chart: alt.Chart | None = None
18-
"""The Vega Altair
19-
[chart object](https://altair-viz.github.io/user_guide/generated/toplevel/altair.Chart.html)."""
18+
"""The [Vega Altair chart](https://altair-viz.github.io/gallery/index.html)."""
2019

2120
def to_dict(self) -> dict[str, Any]:
2221
d = super().to_dict()
2322
if self.chart is not None:
2423
d.update(chart=self.chart.to_dict())
25-
else:
26-
d.update(chart=None)
2724
return d

chartlets.py/tests/components/plot_test.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import json
2-
import unittest
3-
41
import pandas as pd
52
import altair as alt
63

@@ -12,7 +9,7 @@
129

1310
class PlotTest(make_base(Plot)):
1411

15-
def test_is_json_serializable(self):
12+
def test_with_chart(self):
1613
source = pd.DataFrame(
1714
{"x": ["A", "B", "C", "D", "E"], "a": [28, 55, 43, 91, 81]}
1815
)
@@ -28,6 +25,8 @@ def test_is_json_serializable(self):
2825
self.assert_is_json_serializable(
2926
self.cls(id="plot", theme="dark", chart=self.chart),
3027
{
28+
"type": "Plot",
29+
"id": "plot",
3130
"theme": "dark",
3231
"chart": {
3332
"$schema": "https://vega.github.io/schema/vega-lite/v5.20.1.json",
@@ -50,7 +49,11 @@ def test_is_json_serializable(self):
5049
},
5150
"mark": {"type": "bar"},
5251
},
53-
"id": "plot",
54-
"type": "Plot",
5552
},
5653
)
54+
55+
def test_without_chart(self):
56+
self.assert_is_json_serializable(
57+
self.cls(id="plot", style={"width": 100}),
58+
{"type": "Plot", "id": "plot", "style": {"width": 100}},
59+
)

0 commit comments

Comments
 (0)