From 469037f83338a47ed409ca2b58f23458103f12e7 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Sat, 27 Apr 2024 14:33:12 -0600 Subject: [PATCH] docs(maps): jupyter notebook now auto-updates docs site (#27003) --- .github/workflows/superset-frontend.yml | 1 + docs/data/countries.json | 102 +++++++++++++++++ docs/docs/configuration/country-map-tools.mdx | 103 ++---------------- .../Country Map GeoJSON Generator.ipynb | 44 ++++++-- 4 files changed, 144 insertions(+), 106 deletions(-) create mode 100644 docs/data/countries.json diff --git a/.github/workflows/superset-frontend.yml b/.github/workflows/superset-frontend.yml index 20add61f7ee7b..016c082a605a2 100644 --- a/.github/workflows/superset-frontend.yml +++ b/.github/workflows/superset-frontend.yml @@ -20,6 +20,7 @@ jobs: - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" uses: actions/checkout@v4 with: + fetch-depth: 0 # Fetch all history persist-credentials: false submodules: recursive - name: Check npm lock file version diff --git a/docs/data/countries.json b/docs/data/countries.json new file mode 100644 index 0000000000000..a0807a9a12d18 --- /dev/null +++ b/docs/data/countries.json @@ -0,0 +1,102 @@ +{ + "countries": [ + "Afghanistan", + "Albania", + "Algeria", + "Argentina", + "Australia", + "Austria", + "Belgium", + "Bolivia", + "Brazil", + "Bulgaria", + "Burundi", + "Canada", + "Chile", + "China", + "Colombia", + "Costa Rica", + "Cuba", + "Cyprus", + "Czech Republic", + "Denmark", + "Dominican Republic", + "Ecuador", + "Egypt", + "El Salvador", + "Estonia", + "Ethiopia", + "France", + "France (regions)", + "Finland", + "Germany", + "Guatemala", + "Haiti", + "Honduras", + "Iceland", + "India", + "Indonesia", + "Iran", + "Italy", + "Italy (regions)", + "Japan", + "Jordan", + "Kazakhstan", + "Kenya", + "Korea", + "Kuwait", + "Kyrgyzstan", + "Latvia", + "Liechtenstein", + "Lithuania", + "Malaysia", + "Mexico", + "Morocco", + "Myanmar", + "Netherlands", + "Nicaragua", + "Nigeria", + "Norway", + "Oman", + "Pakistan", + "Panama", + "Papua New Guinea", + "Paraguay", + "Peru", + "Philippines", + "Philippines (regions)", + "Portugal", + "Poland", + "Puerto Rico", + "Qatar", + "Russia", + "Rwanda", + "Saint Barthelemy", + "Saint Martin", + "Saudi Arabia", + "Singapore", + "Slovenia", + "Spain", + "Sri Lanka", + "Sweden", + "Switzerland", + "Syria", + "Tajikistan", + "Tanzania", + "Thailand", + "Timorleste", + "Turkey", + "Turkey (regions)", + "Turkmenistan", + "Uganda", + "UK", + "Ukraine", + "United Arab Emirates", + "Uruguay", + "USA", + "Uzbekistan", + "Venezuela", + "Vietnam", + "Zambia" + ] +} diff --git a/docs/docs/configuration/country-map-tools.mdx b/docs/docs/configuration/country-map-tools.mdx index 9795f973f1bd1..691f1fa1dbb9b 100644 --- a/docs/docs/configuration/country-map-tools.mdx +++ b/docs/docs/configuration/country-map-tools.mdx @@ -5,6 +5,8 @@ sidebar_position: 10 version: 1 --- +import countriesData from '../../data/countries.json'; + ## The Country Map Visualization The Country Map visualization allows you to plot lightweight choropleth maps of @@ -21,102 +23,11 @@ The current list of countries can be found in the src The Country Maps visualization already ships with the maps for the following countries: -- Afghanistan -- Albania -- Algeria -- Argentina -- Australia -- Austria -- Belgium -- Bolivia -- Brazil -- Bulgaria -- Burundi -- Canada -- Chile -- China -- Colombia -- Costa Rica -- Cuba -- Cyprus -- Denmark -- Dominican Republic -- Ecuador -- Egypt -- El_salvador -- Estonia -- Ethiopia -- France -- France Regions -- Finland -- Germany -- Guatemala -- Haiti -- Honduras -- Iceland -- India -- Indonesia -- Iran -- Italy -- Italy Regions -- Japan -- Jordan -- Kazakhstan -- Kenya -- Korea -- Kuwait -- Kyrgyzstan -- Latvia -- Liechtenstein -- Lithuania -- Malaysia -- Mexico -- Morocco -- Myanmar -- Netherlands -- Nicaragua -- Nigeria -- Norway -- Oman -- Pakistan -- Panama -- Papua New Guinea -- Paraguay -- Peru -- Philippines -- Portugal -- Poland -- Puerto_rico -- Qatar -- Russia -- Rwanda -- Saint Barthelemy -- Saint Martin -- Saudi Arabia -- Singapore -- Slovenia -- Spain -- Sri Lanka -- Sweden -- Switzerland -- Syria -- Tajikistan -- Tanzania -- Thailand -- Timorleste -- Turkey -- Turkey Regions -- Turkmenistan -- Uganda -- Uk -- Ukraine -- United Arab Emirates -- Uruguay -- USA -- Uzbekistan -- Venezuela -- Vietnam -- Zambia + ## Adding a New Country diff --git a/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb b/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb index 248414309aae0..adef756f13fd7 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb +++ b/superset-frontend/plugins/legacy-plugin-chart-country-map/scripts/Country Map GeoJSON Generator.ipynb @@ -51,13 +51,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 77, "metadata": {}, "outputs": [], "source": [ "# Dependencies\n", "\n", "import os\n", + "import json\n", "import requests\n", "import geopandas as gpd\n", "import matplotlib.pyplot as plt\n", @@ -2590,28 +2591,26 @@ "id": "Fb58eGlIt1LW" }, "source": [ - "## Output Typescript" + "## Output Typescript & JSON for Docs Site" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 80, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "TypeScript code written to src/countries.ts\n" + "TypeScript code written to src/countries.ts\n", + "JSON written to docs/data/countries.json\n" ] } ], "source": [ + "\n", + "\n", "# Function to convert country name to a valid JavaScript identifier\n", "def to_js_identifier(name):\n", " return name.replace(' ', '_').replace('-', '_')\n", @@ -2677,8 +2676,33 @@ "with open(\"../src/countries.ts\", \"w\") as file:\n", " file.write(typescript_code)\n", "\n", - "print(\"TypeScript code written to src/countries.ts\")" + "print(\"TypeScript code written to src/countries.ts\")\n", + "\n", + "# DOCS JSON:\n", + "# Replace underscores with spaces and title-case each country name\n", + "formatted_countries = [country.replace(\"_\", \" \") for country in countries]\n", + "formatted_countries = [country.upper() if country in {\"usa\", \"uk\"} else country.title() for country in formatted_countries]\n", + "formatted_countries = [country.replace(\" Regions\",\" (regions)\") for country in formatted_countries]\n", + "\n", + "\n", + "# Create a dictionary in the desired format\n", + "data = {\"countries\": formatted_countries}\n", + "# Convert the dictionary to a JSON string with proper formatting\n", + "json_data = json.dumps(data, indent=2) + \"\\n\"\n", + "\n", + "# Write to a file\n", + "with open(\"../../../../docs/data/countries.json\", \"w\") as file:\n", + " file.write(json_data)\n", + "\n", + "print(\"JSON written to docs/data/countries.json\")" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {