From 87bc3e046e33acb9b9122a023042f1a542a12d7a Mon Sep 17 00:00:00 2001 From: Joe Numainville Date: Tue, 2 Apr 2024 12:42:14 -0500 Subject: [PATCH] adding title --- .../plot/express/plots/PartitionManager.py | 4 ++- .../plot/express/plots/test_layout.py | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 plugins/plotly-express/test/deephaven/plot/express/plots/test_layout.py diff --git a/plugins/plotly-express/src/deephaven/plot/express/plots/PartitionManager.py b/plugins/plotly-express/src/deephaven/plot/express/plots/PartitionManager.py index 19265fe4b..2377d0bfa 100644 --- a/plugins/plotly-express/src/deephaven/plot/express/plots/PartitionManager.py +++ b/plugins/plotly-express/src/deephaven/plot/express/plots/PartitionManager.py @@ -603,7 +603,9 @@ def default_figure(self) -> DeephavenFigure: # this is very hacky but it's needed to prevent errors when # there are no partitions until a better solution can be done # also need the px template to be set - default_fig = px.scatter(x=[0], y=[0]) + # the title can also be set here as it will never change + title = self.args.get("title") + default_fig = px.scatter(x=[0], y=[0], title=title) default_fig.update_traces(x=[], y=[]) return DeephavenFigure(default_fig) diff --git a/plugins/plotly-express/test/deephaven/plot/express/plots/test_layout.py b/plugins/plotly-express/test/deephaven/plot/express/plots/test_layout.py new file mode 100644 index 000000000..1d5ebf80e --- /dev/null +++ b/plugins/plotly-express/test/deephaven/plot/express/plots/test_layout.py @@ -0,0 +1,26 @@ +import unittest + +from ..BaseTest import BaseTestCase + + +class ScatterTestCase(BaseTestCase): + def setUp(self) -> None: + from deephaven import empty_table + + self.source = empty_table(0).update(["x=i", "y=i*Math.random()*i", "z=i%5"]) + + def test_empty_title(self): + import src.deephaven.plot.express as dx + + chart = dx.line( + self.source, x="x", y="y", by=["z"], title="Hello World0" + ).to_dict(self.exporter) + plotly, deephaven = chart["plotly"], chart["deephaven"] + + expected_title = {"text": "Hello World0"} + + self.assertEqual(plotly["layout"]["title"], expected_title) + + +if __name__ == "__main__": + unittest.main()