You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2022/08/23 16:22:30 UTC

[superset] 01/02: Add example ECharts Dashboard

This is an automated email from the ASF dual-hosted git repository.

diegopucci pushed a commit to branch chore/e2e-tests-drilltodetail-modal
in repository https://gitbox.apache.org/repos/asf/superset.git

commit dfaaa1b4b1cf02fbc9e7731a1da3bf9967c42446
Author: geido <di...@gmail.com>
AuthorDate: Mon Aug 22 20:59:22 2022 +0300

    Add example ECharts Dashboard
---
 superset/cli/examples.py               |   3 +
 superset/examples/data_loading.py      |   1 +
 superset/examples/echarts_dashboard.py | 161 +++++++++++++++++++++++++++++++++
 3 files changed, 165 insertions(+)

diff --git a/superset/cli/examples.py b/superset/cli/examples.py
index cad87da9d3..cdee3747a8 100755
--- a/superset/cli/examples.py
+++ b/superset/cli/examples.py
@@ -54,6 +54,9 @@ def load_examples_run(
     if load_test_data:
         print("Loading [Tabbed dashboard]")
         examples.load_tabbed_dashboard(only_metadata)
+
+        print("Loading [ECharts Dashboard]")
+        examples.load_echarts_dashboard()
     else:
         print("Loading [Random long/lat data]")
         examples.load_long_lat_data(only_metadata, force)
diff --git a/superset/examples/data_loading.py b/superset/examples/data_loading.py
index 6eae82a799..6b1346623e 100644
--- a/superset/examples/data_loading.py
+++ b/superset/examples/data_loading.py
@@ -33,3 +33,4 @@ from .sf_population_polygons import load_sf_population_polygons
 from .tabbed_dashboard import load_tabbed_dashboard
 from .utils import load_examples_from_configs
 from .world_bank import load_world_bank_health_n_pop
+from .echarts_dashboard import load_echarts_dashboard
\ No newline at end of file
diff --git a/superset/examples/echarts_dashboard.py b/superset/examples/echarts_dashboard.py
new file mode 100644
index 0000000000..25d6b0e112
--- /dev/null
+++ b/superset/examples/echarts_dashboard.py
@@ -0,0 +1,161 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import json
+import textwrap
+
+from superset import db
+from superset.models.dashboard import Dashboard
+
+from .helpers import update_slice_ids
+
+DASH_SLUG = "echarts_dash"
+
+
+def load_echarts_dashboard() -> None:
+    """Loading a dashboard featuring EChart charts"""
+
+    print("Creating the dashboard")
+    db.session.expunge_all()
+    dash = db.session.query(Dashboard).filter_by(slug=DASH_SLUG).first()
+
+    if not dash:
+        dash = Dashboard()
+    js = textwrap.dedent(
+        """\
+{
+    "CHART-dxV7Il74hH": {
+      "children": [],
+      "id": "CHART-dxV7Il74hH",
+      "meta": {
+        "chartId": 597,
+        "height": 50,
+        "sliceName": "Box plot",
+        "width": 6
+      },
+      "type": "CHART"
+    },
+    "CHART-YyHWQacdcj": {
+      "children": [],
+      "id": "CHART-YyHWQacdcj",
+      "meta": {
+          "chartId": 15,
+          "height": 50,
+          "sliceName": "Participants",
+          "width": 6
+      },
+      "type": "CHART"
+    },
+    "CHART-oWKBOJ6Ydh": {
+      "children": [],
+      "id": "CHART-oWKBOJ6Ydh",
+      "meta":{
+          "chartId": 16,
+          "height": 50,
+          "sliceName": "Genders",
+          "width": 6
+        },
+      "type": "CHART"
+    },
+    "CHART-06Kg-rUggO": {
+      "children": [],
+      "id": "CHART-06Kg-rUggO",
+      "meta": {
+        "chartId": 617,
+        "height": 50,
+        "sliceName": "Number of Girls",
+        "width": 6
+      },
+      "type": "CHART"
+    },
+    "CHART--wEhS-MDSg": {
+      "children": [],
+      "id": "CHART--wEhS-MDS",
+      "meta": {
+        "chartId": 2,
+        "height": 50,
+        "sliceName": "Energy Force Layout",
+        "width": 6
+      },
+      "type": "CHART"
+    },
+    "GRID_ID": {
+        "children": [
+            "ROW-SytNzNA4X",
+            "ROW-HkFFEzVRVm",
+            "ROW-BytNzNA4Y"
+        ],
+        "id": "GRID_ID",
+        "type": "GRID"
+    },
+    "HEADER_ID": {
+        "id": "HEADER_ID",
+        "meta": {
+            "text": "ECharts Charts"
+        },
+        "type": "HEADER"
+    },
+    "ROOT_ID": {
+        "children": [
+            "GRID_ID"
+        ],
+        "id": "ROOT_ID",
+        "type": "ROOT"
+    },
+    "ROW-HkFFEzVRVm": {
+        "children": [
+            "CHART-dxV7Il74hH",
+            "CHART-oWKBOJ6Ydh"
+        ],
+        "id": "ROW-HkFFEzVRVm",
+        "meta": {
+            "background": "BACKGROUND_TRANSPARENT"
+        },
+        "type": "ROW"
+    },
+    "ROW-SytNzNA4X": {
+        "children": [
+            "CHART-06Kg-rUggO",
+            "CHART-YyHWQacdcj"
+        ],
+        "id": "ROW-SytNzNA4X",
+        "meta": {
+            "background": "BACKGROUND_TRANSPARENT"
+        },
+        "type": "ROW"
+    },
+    "ROW-BytNzNA4Y": {
+        "children": [
+            "CHART--wEhS-MDSg"
+        ],
+        "id": "ROW-BytNzNA4Y",
+        "meta": {
+            "background": "BACKGROUND_TRANSPARENT"
+        },
+        "type": "ROW"
+    },
+    "DASHBOARD_VERSION_KEY": "v2"
+}
+    """
+    )
+    pos = json.loads(js)
+    slices = update_slice_ids(pos)
+    dash.dashboard_title = "ECharts Dashboard"
+    dash.position_json = json.dumps(pos, indent=4)
+    dash.slug = DASH_SLUG
+    dash.slices = slices
+    db.session.merge(dash)
+    db.session.commit()