Quellcode durchsuchen

chart none data (#2538)

resolves #2537

Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
Fred Lefévère-Laoide vor 1 Monat
Ursprung
Commit
758909168a

+ 1 - 1
taipy/gui/utils/chart_config_builder.py

@@ -115,7 +115,7 @@ def __get_col_from_indexed(col_name: str, idx: int) -> t.Optional[str]:
 def _build_chart_config(  # noqa: C901
     gui: "Gui", attributes: t.Dict[str, t.Any], cols_descriptions_list: t.List[t.Dict[str, t.Dict[str, str]]]
 ):
-    if "data" not in attributes and "figure" in attributes:
+    if ("data" not in attributes and "figure" in attributes) or (attributes.get("data") is None):
         return {"traces": []}
     default_type = attributes.get("_default_type", "scatter")
     default_mode = attributes.get("_default_mode", "lines+markers")

+ 18 - 0
tests/gui/builder/control/test_chart.py

@@ -276,3 +276,21 @@ def test_chart_multi_data(gui: Gui, helpers, csvdata):
     ]
     gui._set_frame(inspect.currentframe())
     helpers.test_control_builder(gui, page, expected_list)
+
+
+def test_chart_none_data(gui: Gui, helpers):
+    data=None  # noqa: F841
+    with tgb.Page(frame=None) as page:
+        tgb.chart(  # type: ignore[attr-defined]
+            data="{data}",
+        )
+    expected_list = [
+        "<Chart",
+        "data={_TpD_tpec_TpExPr_data_TPMDL_0}",
+        'dataVarNames=""',
+        'defaultConfig="{&quot;traces&quot;: []}"',
+        'libClassName="taipy-chart"',
+        'updateVarName="_TpD_tpec_TpExPr_data_TPMDL_0"',
+    ]
+    gui._set_frame(inspect.currentframe())
+    helpers.test_control_builder(gui, page, expected_list)

+ 16 - 0
tests/gui/control/test_chart.py

@@ -219,6 +219,7 @@ def test_chart_indexed_properties_with_arrays(gui: Gui, helpers):
     ]
     helpers.test_control_md(gui, md, expected_list)
 
+
 def test_chart_multi_data(gui: Gui, helpers, csvdata):
     md_string = "<|{csvdata}|chart|x=Day|y=Daily hospital occupancy|data[1]={csvdata}|>"
     expected_list = [
@@ -230,3 +231,18 @@ def test_chart_multi_data(gui: Gui, helpers, csvdata):
     ]
     gui._set_frame(inspect.currentframe())
     helpers.test_control_md(gui, md_string, expected_list)
+
+
+def test_chart_none_data(gui: Gui, helpers):
+    data = None  # noqa: F841
+    md_string = "<|{data}|chart|>"
+    expected_list = [
+        "<Chart",
+        "data={_TpD_tpec_TpExPr_data_TPMDL_0}",
+        'dataVarNames=""',
+        'defaultConfig="{&quot;traces&quot;: []}"',
+        'libClassName="taipy-chart"',
+        'updateVarName="_TpD_tpec_TpExPr_data_TPMDL_0"',
+    ]
+    gui._set_frame(inspect.currentframe())
+    helpers.test_control_md(gui, md_string, expected_list)