فهرست منبع

Backport: chart none data (#2539)

* Backport: chart none data
resolves #2537

* fix test

---------

Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
Fred Lefévère-Laoide 1 ماه پیش
والد
کامیت
1d90658586
3فایلهای تغییر یافته به همراه32 افزوده شده و 1 حذف شده
  1. 1 1
      taipy/gui/utils/chart_config_builder.py
  2. 17 0
      tests/gui/builder/control/test_chart.py
  3. 14 0
      tests/gui/control/test_chart.py

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

@@ -113,7 +113,7 @@ def __get_col_from_indexed(col_name: str, idx: int) -> t.Optional[str]:
 
 
 
 
 def _build_chart_config(gui: "Gui", attributes: t.Dict[str, t.Any], col_types: t.Dict[str, str]):  # noqa: C901
 def _build_chart_config(gui: "Gui", attributes: t.Dict[str, t.Any], col_types: t.Dict[str, str]):  # noqa: C901
-    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": []}
         return {"traces": []}
     default_type = attributes.get("_default_type", "scatter")
     default_type = attributes.get("_default_type", "scatter")
     default_mode = attributes.get("_default_mode", "lines+markers")
     default_mode = attributes.get("_default_mode", "lines+markers")

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

@@ -258,3 +258,20 @@ def test_chart_indexed_properties_with_arrays_builder(gui: Gui, helpers):
         "&quot;lines&quot;: [null, &#x7B;&quot;dash&quot;: &quot;dashdot&quot;&#x7D;, &#x7B;&quot;dash&quot;: &quot;dash&quot;&#x7D;, null, &#x7B;&quot;dash&quot;: &quot;dashdot&quot;&#x7D;, &#x7B;&quot;dash&quot;: &quot;dash&quot;&#x7D;]",  # noqa: E501
         "&quot;lines&quot;: [null, &#x7B;&quot;dash&quot;: &quot;dashdot&quot;&#x7D;, &#x7B;&quot;dash&quot;: &quot;dash&quot;&#x7D;, null, &#x7B;&quot;dash&quot;: &quot;dashdot&quot;&#x7D;, &#x7B;&quot;dash&quot;: &quot;dash&quot;&#x7D;]",  # noqa: E501
     ]
     ]
     helpers.test_control_builder(gui, page, expected_list)
     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}",
+        '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)

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

@@ -218,3 +218,17 @@ def test_chart_indexed_properties_with_arrays(gui: Gui, helpers):
         "&quot;lines&quot;: [null, &#x7B;&quot;dash&quot;: &quot;dashdot&quot;&#x7D;, &#x7B;&quot;dash&quot;: &quot;dash&quot;&#x7D;, null, &#x7B;&quot;dash&quot;: &quot;dashdot&quot;&#x7D;, &#x7B;&quot;dash&quot;: &quot;dash&quot;&#x7D;]",  # noqa: E501
         "&quot;lines&quot;: [null, &#x7B;&quot;dash&quot;: &quot;dashdot&quot;&#x7D;, &#x7B;&quot;dash&quot;: &quot;dash&quot;&#x7D;, null, &#x7B;&quot;dash&quot;: &quot;dashdot&quot;&#x7D;, &#x7B;&quot;dash&quot;: &quot;dash&quot;&#x7D;]",  # noqa: E501
     ]
     ]
     helpers.test_control_md(gui, md, expected_list)
     helpers.test_control_md(gui, md, 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}",
+        '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)