Skip to content

Commit

Permalink
docs(maps): jupyter notebook now auto-updates docs site (apache#27003)
Browse files Browse the repository at this point in the history
  • Loading branch information
rusackas authored and qleroy committed Apr 28, 2024
1 parent 6717137 commit 469037f
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 106 deletions.
1 change: 1 addition & 0 deletions .github/workflows/superset-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
102 changes: 102 additions & 0 deletions docs/data/countries.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
103 changes: 7 additions & 96 deletions docs/docs/configuration/country-map-tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
<ul style={{columns: 3}}>
{countriesData.countries.map((country, index) => (
<li key={index}>{country}</li>
))}
</ul>

## Adding a New Country

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 469037f

Please sign in to comment.