geovizpy 0.1.7__tar.gz → 0.1.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {geovizpy-0.1.7 → geovizpy-0.1.8}/PKG-INFO +112 -118
  2. geovizpy-0.1.8/docs/source/conf.py +32 -0
  3. geovizpy-0.1.8/examples/advanced_plots.py +82 -0
  4. geovizpy-0.1.8/examples/bubble.py +46 -0
  5. geovizpy-0.1.8/examples/choropleth.py +45 -0
  6. geovizpy-0.1.8/examples/choropleth_effect.py +62 -0
  7. geovizpy-0.1.8/examples/json_export.py +37 -0
  8. geovizpy-0.1.8/examples/labels.py +43 -0
  9. geovizpy-0.1.8/examples/layer_control.py +70 -0
  10. geovizpy-0.1.8/examples/lines.py +74 -0
  11. geovizpy-0.1.8/examples/reactive.py +37 -0
  12. geovizpy-0.1.8/examples/simple.py +38 -0
  13. geovizpy-0.1.8/examples/tiles.py +47 -0
  14. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy/controls.py +20 -0
  15. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy/geoviz.py +2 -3
  16. geovizpy-0.1.8/geovizpy/insets.py +0 -0
  17. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy/renderer.py +131 -17
  18. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy.egg-info/PKG-INFO +112 -118
  19. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy.egg-info/SOURCES.txt +13 -0
  20. geovizpy-0.1.8/geovizpy.egg-info/top_level.txt +4 -0
  21. geovizpy-0.1.8/pyproject.toml +26 -0
  22. {geovizpy-0.1.7 → geovizpy-0.1.8}/setup.cfg +4 -4
  23. {geovizpy-0.1.7 → geovizpy-0.1.8}/setup.py +1 -1
  24. geovizpy-0.1.7/geovizpy/insets.py +0 -20
  25. geovizpy-0.1.7/geovizpy.egg-info/top_level.txt +0 -1
  26. {geovizpy-0.1.7 → geovizpy-0.1.8}/README.md +0 -0
  27. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy/__init__.py +0 -0
  28. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy/effects.py +0 -0
  29. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy/legends.py +0 -0
  30. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy/marks.py +0 -0
  31. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy/plots.py +0 -0
  32. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy.egg-info/dependency_links.txt +0 -0
  33. {geovizpy-0.1.7 → geovizpy-0.1.8}/geovizpy.egg-info/requires.txt +0 -0
@@ -1,118 +1,112 @@
1
- Metadata-Version: 2.4
2
- Name: geovizpy
3
- Version: 0.1.7
4
- Summary: A Python wrapper for the geoviz JavaScript library
5
- Author: fbxyz
6
- Project-URL: Source, https://codeberg.org/fbxyz/geovizpy
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Requires-Python: >=3.6
11
- Description-Content-Type: text/markdown
12
- Provides-Extra: export
13
- Requires-Dist: playwright; extra == "export"
14
- Dynamic: author
15
- Dynamic: classifier
16
- Dynamic: description
17
- Dynamic: description-content-type
18
- Dynamic: project-url
19
- Dynamic: provides-extra
20
- Dynamic: requires-python
21
- Dynamic: summary
22
-
23
- # geovizpy
24
-
25
- **geovizpy** is a Python wrapper for the `geoviz` JavaScript library, designed to bring the power of D3.js-based thematic mapping to Python. It allows you to create high-quality, interactive maps directly from Python scripts or Jupyter notebooks.
26
-
27
- This library is a wrapper around the `geoviz` library. For detailed information on the underlying mapping logic, please refer to the [original geoviz documentation](https://github.com/neocarto/geoviz).
28
-
29
- ![Choropleth Map Example](https://codeberg.org/fbxyz/geovizpy/raw/branch/main/docs/source/_static/choropleth.png)
30
-
31
- ## Features
32
-
33
- - **Simple, chainable API**: Build complex maps by chaining intuitive methods.
34
- - **Variety of Map Types**: Create choropleth, proportional symbol, typology, and other thematic maps.
35
- - **Interactive Controls**: Add hover-to-expand controls for toggling layer visibility and exporting the map as SVG or PNG.
36
- - **Customizable**: Extensive options to customize colors, legends, strokes, and more.
37
- - **Standalone HTML**: Renders self-contained HTML files with no server required.
38
- - **Image Export**: Save maps directly to PNG or SVG from Python (requires optional dependencies).
39
-
40
- ## Installation
41
-
42
- ### Standard Installation
43
-
44
- You can install the core library using pip:
45
-
46
- ```bash
47
- pip install geovizpy
48
- ```
49
-
50
- Or install directly from the source repository:
51
-
52
- ```bash
53
- pip install git+https://codeberg.org/fbxyz/geovizpy.git
54
- ```
55
-
56
- ### For Image Export
57
-
58
- To save maps as PNG or SVG files directly from Python, you need to install the optional `export` dependencies:
59
-
60
- 1. **Install the extra dependencies:**
61
-
62
- ```bash
63
- pip install "geovizpy[export]"
64
- ```
65
-
66
- 2. **Install Playwright's browser binaries:**
67
-
68
- ```bash
69
- playwright install
70
- ```
71
-
72
- On Linux, you may also need to install host dependencies:
73
-
74
- ```bash
75
- sudo playwright install-deps
76
- ```
77
-
78
- ## Quick Start
79
-
80
- Here is a simple example of how to create a choropleth map:
81
-
82
- ```python
83
- from geovizpy import Geoviz
84
- import json
85
-
86
- # Load your GeoJSON data
87
- # (Assuming 'world.json' is in a 'data' subdirectory)
88
- with open("data/world.json") as f:
89
- world_data = json.load(f)
90
-
91
- # Initialize the map
92
- viz = Geoviz(projection="EqualEarth", width=800)
93
-
94
- # Add layers
95
- viz.outline()
96
- viz.graticule()
97
-
98
- # Add a choropleth layer
99
- viz.choro(
100
- data=world_data,
101
- var="gdppc",
102
- colors="Blues",
103
- legend=True,
104
- leg_title="GDP per Capita"
105
- )
106
-
107
- # Add interactive controls
108
- viz.add_layer_control(layers=["choropleth_gdp"])
109
- viz.add_export_control()
110
-
111
- # Save the map
112
- viz.save("my_map.html") # Renders an interactive HTML file
113
- # viz.save("my_map.png") # Renders a static PNG image (requires export dependencies)
114
- ```
115
-
116
- ## Documentation
117
-
118
- For more detailed information on all available methods and parameters, please see the [full documentation](https://geovizpy.readthedocs.io/en/latest/).
1
+ Metadata-Version: 2.4
2
+ Name: geovizpy
3
+ Version: 0.1.8
4
+ Summary: A Python wrapper for the geoviz JavaScript library
5
+ Author: fbxyz
6
+ License: MIT
7
+ Project-URL: Source, https://codeberg.org/fbxyz/geovizpy
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Provides-Extra: export
14
+ Requires-Dist: playwright; extra == "export"
15
+ Dynamic: requires-python
16
+
17
+ # geovizpy
18
+
19
+ **geovizpy** is a Python wrapper for the `geoviz` JavaScript library, designed to bring the power of D3.js-based thematic mapping to Python. It allows you to create high-quality, interactive maps directly from Python scripts or Jupyter notebooks.
20
+
21
+ This library is a wrapper around the `geoviz` library. For detailed information on the underlying mapping logic, please refer to the [original geoviz documentation](https://github.com/neocarto/geoviz).
22
+
23
+ ![Choropleth Map Example](https://codeberg.org/fbxyz/geovizpy/raw/branch/main/docs/source/_static/choropleth.png)
24
+
25
+ ## Features
26
+
27
+ - **Simple, chainable API**: Build complex maps by chaining intuitive methods.
28
+ - **Variety of Map Types**: Create choropleth, proportional symbol, typology, and other thematic maps.
29
+ - **Interactive Controls**: Add hover-to-expand controls for toggling layer visibility and exporting the map as SVG or PNG.
30
+ - **Customizable**: Extensive options to customize colors, legends, strokes, and more.
31
+ - **Standalone HTML**: Renders self-contained HTML files with no server required.
32
+ - **Image Export**: Save maps directly to PNG or SVG from Python (requires optional dependencies).
33
+
34
+ ## Installation
35
+
36
+ ### Standard Installation
37
+
38
+ You can install the core library using pip:
39
+
40
+ ```bash
41
+ pip install geovizpy
42
+ ```
43
+
44
+ Or install directly from the source repository:
45
+
46
+ ```bash
47
+ pip install git+https://codeberg.org/fbxyz/geovizpy.git
48
+ ```
49
+
50
+ ### For Image Export
51
+
52
+ To save maps as PNG or SVG files directly from Python, you need to install the optional `export` dependencies:
53
+
54
+ 1. **Install the extra dependencies:**
55
+
56
+ ```bash
57
+ pip install "geovizpy[export]"
58
+ ```
59
+
60
+ 2. **Install Playwright's browser binaries:**
61
+
62
+ ```bash
63
+ playwright install
64
+ ```
65
+
66
+ On Linux, you may also need to install host dependencies:
67
+
68
+ ```bash
69
+ sudo playwright install-deps
70
+ ```
71
+
72
+ ## Quick Start
73
+
74
+ Here is a simple example of how to create a choropleth map:
75
+
76
+ ```python
77
+ from geovizpy import Geoviz
78
+ import json
79
+
80
+ # Load your GeoJSON data
81
+ # (Assuming 'world.json' is in a 'data' subdirectory)
82
+ with open("data/world.json") as f:
83
+ world_data = json.load(f)
84
+
85
+ # Initialize the map
86
+ viz = Geoviz(projection="EqualEarth", width=800)
87
+
88
+ # Add layers
89
+ viz.outline()
90
+ viz.graticule()
91
+
92
+ # Add a choropleth layer
93
+ viz.choro(
94
+ data=world_data,
95
+ var="gdppc",
96
+ colors="Blues",
97
+ legend=True,
98
+ leg_title="GDP per Capita"
99
+ )
100
+
101
+ # Add interactive controls
102
+ viz.add_layer_control(layers=["choropleth_gdp"])
103
+ viz.add_export_control()
104
+
105
+ # Save the map
106
+ viz.save("my_map.html") # Renders an interactive HTML file
107
+ # viz.save("my_map.png") # Renders a static PNG image (requires export dependencies)
108
+ ```
109
+
110
+ ## Documentation
111
+
112
+ For more detailed information on all available methods and parameters, please see the [full documentation](https://geovizpy.readthedocs.io/en/latest/).
@@ -0,0 +1,32 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ import os
3
+ import sys
4
+ sys.path.insert(0, os.path.abspath('../../'))
5
+
6
+ project = 'geovizpy'
7
+ copyright = '2026, fbxyz'
8
+ author = 'fbxyz'
9
+ release = '0.1.3'
10
+
11
+ # -- General configuration ---------------------------------------------------
12
+ extensions = [
13
+ 'sphinx.ext.autodoc',
14
+ 'sphinx.ext.napoleon',
15
+ 'sphinx.ext.viewcode',
16
+ 'sphinx.ext.githubpages',
17
+ ]
18
+
19
+ templates_path = ['_templates']
20
+ exclude_patterns = []
21
+
22
+ # -- Options for HTML output -------------------------------------------------
23
+ try:
24
+ import sphinx_rtd_theme
25
+ html_theme = 'sphinx_rtd_theme'
26
+ except ImportError:
27
+ html_theme = 'alabaster'
28
+
29
+ html_static_path = ['_static']
30
+
31
+ # -- Options for autodoc -----------------------------------------------------
32
+ autodoc_member_order = 'bysource'
@@ -0,0 +1,82 @@
1
+ """Example script demonstrating advanced plot types."""
2
+
3
+ import json
4
+ import os
5
+ import random
6
+ from geovizpy import Geoviz
7
+
8
+ # Define output directory
9
+ output_dir = os.path.join(os.path.dirname(__file__), "html")
10
+ os.makedirs(output_dir, exist_ok=True)
11
+
12
+ data_path = os.path.join(os.path.dirname(__file__), "data", "world.json")
13
+ try:
14
+ with open(data_path) as f:
15
+ world_data = json.load(f)
16
+ except FileNotFoundError:
17
+ print(f"{data_path} not found.")
18
+ world_data = {}
19
+
20
+ continents = ["Africa", "Asia", "Europe", "North America", "South America", "Oceania"]
21
+ symbols_list = ["star", "circle", "cross", "diamond", "square", "triangle"]
22
+
23
+ for f in world_data.get("features", []):
24
+ f["properties"]["random_continent"] = random.choice(continents)
25
+ f["properties"]["random_symbol"] = random.choice(symbols_list)
26
+
27
+ # 1. Typology Map
28
+ viz1 = Geoviz(projection="EqualEarth", width=800)
29
+ viz1.outline()
30
+ viz1.graticule(stroke="white", strokeWidth=0.4)
31
+
32
+ viz1.typo(
33
+ data=world_data,
34
+ var="random_continent",
35
+ colors="Pastel",
36
+ strokeWidth=0.5,
37
+ leg_title="Random Continent",
38
+ leg_pos=[10, 200]
39
+ )
40
+ viz1.header(text="Typology Map (Random Data)", fontSize=20)
41
+ viz1.render_html(os.path.join(output_dir, "advanced_typo.html"))
42
+
43
+ # 2. Proportional Symbols with Typology
44
+ viz2 = Geoviz(projection="EqualEarth", width=800)
45
+ viz2.outline()
46
+ viz2.graticule()
47
+ viz2.path(datum=world_data, fill="#eee")
48
+
49
+ viz2.proptypo(
50
+ data=world_data,
51
+ var1="pop",
52
+ var2="random_continent",
53
+ k=50,
54
+ colors="Set1",
55
+ leg1_title="Population",
56
+ leg2_title="Continent",
57
+ leg1_pos=[10, 300],
58
+ leg2_pos=[10, 150]
59
+ )
60
+ viz2.header(text="Proportional Symbols + Typology", fontSize=20)
61
+ viz2.render_html(os.path.join(output_dir, "advanced_proptypo.html"))
62
+
63
+ # 3. Symbol Map
64
+ viz3 = Geoviz(projection="EqualEarth", width=800)
65
+ viz3.outline()
66
+ viz3.graticule()
67
+ viz3.path(datum=world_data, fill="#ddd")
68
+
69
+ viz3.picto(
70
+ data=world_data,
71
+ var="random_symbol",
72
+ symbols=["star", "circle", "cross", "diamond", "square", "triangle"],
73
+ colors="black",
74
+ fill="red",
75
+ stroke="white",
76
+ strokeWidth=1,
77
+ k=15,
78
+ leg_title="Random Symbols",
79
+ leg_pos=[10, 200]
80
+ )
81
+ viz3.header(text="Symbol Map (Picto)", fontSize=20)
82
+ viz3.render_html(os.path.join(output_dir, "advanced_symbol.html"))
@@ -0,0 +1,46 @@
1
+ """Example script for creating a proportional symbol map (bubble map)."""
2
+
3
+ import json
4
+ import os
5
+ from geovizpy import Geoviz
6
+
7
+ # Define output directory
8
+ output_dir = os.path.join(os.path.dirname(__file__), "html")
9
+ os.makedirs(output_dir, exist_ok=True)
10
+
11
+ data_path = os.path.join(os.path.dirname(__file__), "data", "world.json")
12
+ try:
13
+ with open(data_path) as f:
14
+ world_data = json.load(f)
15
+ except FileNotFoundError:
16
+ print(f"{data_path} not found.")
17
+ world_data = {}
18
+
19
+ viz = Geoviz(projection="EqualEarth", zoomable=True)
20
+ viz.outline()
21
+ viz.graticule(stroke="white", strokeWidth=0.4)
22
+ viz.path(datum=world_data, fill="white", fillOpacity=0.4)
23
+
24
+ # Use viz.prop instead of viz.circle to get automatic legend handling
25
+ viz.prop(
26
+ data=world_data,
27
+ var="pop", # 'var' is used instead of 'r' in viz.prop
28
+ fill="#f07d75",
29
+ tip="(d) => `${d.properties.NAMEen}\n${d.properties.pop / 1000} thousands inh.`",
30
+ leg_type="separate",
31
+ leg_title="Population",
32
+ leg_pos=[30, 30], # Added position to make sure it's visible
33
+ leg_title_fontSize=15
34
+ )
35
+
36
+ pops = [f["properties"]["pop"] for f in world_data.get("features", []) if "pop" in f["properties"]]
37
+
38
+ viz.header(
39
+ fontSize=30,
40
+ text="A World Map With Bubbles",
41
+ fill="#267A8A",
42
+ fontWeight="bold",
43
+ fontFamily="Tangerine"
44
+ )
45
+
46
+ viz.render_html(os.path.join(output_dir, "bubble.html"))
@@ -0,0 +1,45 @@
1
+ """Example script for a choropleth map."""
2
+
3
+ import json
4
+ import os
5
+ from geovizpy import Geoviz
6
+
7
+ # Define output directory
8
+ output_dir = os.path.join(os.path.dirname(__file__), "html")
9
+ os.makedirs(output_dir, exist_ok=True)
10
+
11
+ data_path = os.path.join(os.path.dirname(__file__), "data", "world.json")
12
+ try:
13
+ with open(data_path) as f:
14
+ world_data = json.load(f)
15
+ except FileNotFoundError:
16
+ print(f"{data_path} not found.")
17
+ world_data = {}
18
+
19
+ viz = Geoviz(projection="EqualEarth")
20
+ viz.outline()
21
+ viz.graticule(stroke="white", step=30, strokeWidth=1.2)
22
+
23
+ viz.choro(
24
+ data=world_data,
25
+ var="gdppc",
26
+ strokeWidth=0.3,
27
+ tip=True,
28
+ leg_type="horizontal",
29
+ leg_title="GDP per capita",
30
+ leg_subtitle="($ per inh.)",
31
+ leg_note="Source: worldbank, 2020",
32
+ leg_pos=[410, 370],
33
+ leg_values_round=0,
34
+ leg_missing_text="Missing values"
35
+ )
36
+
37
+ viz.header(
38
+ fontSize=30,
39
+ text="A Choropleth World Map",
40
+ fill="#267A8A",
41
+ fontWeight="bold",
42
+ fontFamily="Tangerine"
43
+ )
44
+
45
+ viz.render_html(os.path.join(output_dir, "choropleth.html"))
@@ -0,0 +1,62 @@
1
+ """Example script demonstrating visual effects (shadow)."""
2
+
3
+ import json
4
+ import os
5
+ from geovizpy import Geoviz
6
+
7
+ # Define output directory
8
+ output_dir = os.path.join(os.path.dirname(__file__), "html")
9
+ os.makedirs(output_dir, exist_ok=True)
10
+
11
+ data_path = os.path.join(os.path.dirname(__file__), "data", "world.json")
12
+ try:
13
+ with open(data_path) as f:
14
+ world_data = json.load(f)
15
+ except FileNotFoundError:
16
+ print(f"{data_path} not found.")
17
+ world_data = {}
18
+
19
+ brazil = {
20
+ "type": "FeatureCollection",
21
+ "features": [f for f in world_data.get("features", []) if f["properties"].get("NAMEen") == "Brazil"]
22
+ }
23
+
24
+ viz = Geoviz(projection="EqualEarth")
25
+
26
+ viz.effect_shadow(id="myshadow", dx=10, dy=10, opacity=0.5)
27
+
28
+ viz.outline()
29
+ viz.graticule(stroke="white", step=30, strokeWidth=1.2)
30
+
31
+ viz.choro(
32
+ data=world_data,
33
+ var="gdppc",
34
+ strokeWidth=0.3,
35
+ tip=True,
36
+ leg_type="horizontal",
37
+ leg_title="GDP per capita",
38
+ leg_subtitle="($ per inh.)",
39
+ leg_note="Source: worldbank, 2020",
40
+ leg_pos=[410, 370],
41
+ leg_values_round=0,
42
+ leg_missing_text="Missing values"
43
+ )
44
+
45
+ if brazil["features"]:
46
+ viz.path(
47
+ data=brazil,
48
+ fill="none",
49
+ stroke="red",
50
+ strokeWidth=2,
51
+ filter="url(#myshadow)"
52
+ )
53
+
54
+ viz.header(
55
+ fontSize=30,
56
+ text="Choropleth with Shadow Effect on Brazil",
57
+ fill="#267A8A",
58
+ fontWeight="bold",
59
+ fontFamily="Tangerine"
60
+ )
61
+
62
+ viz.render_html(os.path.join(output_dir, "choropleth_effect.html"))
@@ -0,0 +1,37 @@
1
+ """Example script for exporting the map configuration to JSON."""
2
+
3
+ import json
4
+ import os
5
+ from geovizpy import Geoviz
6
+
7
+ # Define output directory
8
+ output_dir = os.path.join(os.path.dirname(__file__), "html")
9
+ os.makedirs(output_dir, exist_ok=True)
10
+
11
+ data_path = os.path.join(os.path.dirname(__file__), "data", "world.json")
12
+ try:
13
+ with open(data_path) as f:
14
+ world_data = json.load(f)
15
+ except FileNotFoundError:
16
+ print(f"{data_path} not found.")
17
+ world_data = {}
18
+
19
+ viz = Geoviz(projection="EqualEarth")
20
+ viz.outline()
21
+ viz.graticule(stroke="white", strokeWidth=0.4)
22
+ viz.choro(
23
+ data=world_data,
24
+ var="gdppc",
25
+ strokeWidth=0.3,
26
+ tip=True,
27
+ leg_title="GDP per capita"
28
+ )
29
+ viz.header(text="Map from JSON Config", fontSize=30)
30
+
31
+ config_json = viz.to_json()
32
+ print("Configuration JSON (first 500 chars):")
33
+ print(config_json[:500] + "...")
34
+
35
+ with open(os.path.join(output_dir, "map_config.json"), "w") as f:
36
+ f.write(config_json)
37
+ print(f"\nConfiguration saved to {os.path.join(output_dir, 'map_config.json')}")
@@ -0,0 +1,43 @@
1
+ """Example script for adding text labels to a map."""
2
+
3
+ import json
4
+ import os
5
+ from geovizpy import Geoviz
6
+
7
+ # Define output directory
8
+ output_dir = os.path.join(os.path.dirname(__file__), "html")
9
+ os.makedirs(output_dir, exist_ok=True)
10
+
11
+ data_path = os.path.join(os.path.dirname(__file__), "data", "world.json")
12
+ try:
13
+ with open(data_path) as f:
14
+ world_data = json.load(f)
15
+ except FileNotFoundError:
16
+ print(f"{data_path} not found.")
17
+ world_data = {}
18
+
19
+ countries_to_label = ["Brazil", "China", "United States", "France", "South Africa", "Australia"]
20
+ labeled_features = [f for f in world_data.get("features", []) if f["properties"].get("NAMEen") in countries_to_label]
21
+ labeled_data = {"type": "FeatureCollection", "features": labeled_features}
22
+
23
+ viz = Geoviz(projection="EqualEarth")
24
+ viz.outline()
25
+ viz.graticule(stroke="white", strokeWidth=0.4)
26
+
27
+ viz.path(datum=world_data, fill="#e0e0e0", stroke="white")
28
+
29
+ viz.text(
30
+ data=labeled_data,
31
+ text="NAMEen",
32
+ fill="#333",
33
+ fontSize=14,
34
+ fontWeight="bold",
35
+ stroke="white",
36
+ strokeWidth=3,
37
+ paintOrder="stroke"
38
+ )
39
+
40
+
41
+
42
+ viz.header(text="Map with Labels", fontSize=20)
43
+ viz.render_html(os.path.join(output_dir, "labels.html"))
@@ -0,0 +1,70 @@
1
+ """Example script for layer control and export functionality."""
2
+
3
+ import json
4
+ import os
5
+ from geovizpy import Geoviz
6
+
7
+ # Define output directory
8
+ output_dir = os.path.join(os.path.dirname(__file__), "html")
9
+ os.makedirs(output_dir, exist_ok=True)
10
+
11
+ # Load world data
12
+ data_path = os.path.join(os.path.dirname(__file__), "data", "world.json")
13
+ try:
14
+ with open(data_path) as f:
15
+ world_data = json.load(f)
16
+ except FileNotFoundError:
17
+ print(f"{data_path} not found.")
18
+ world_data = {}
19
+
20
+ # Create a map
21
+ viz = Geoviz(projection="EqualEarth", zoomable=True)
22
+ viz.outline(id="outline")
23
+ viz.graticule(stroke="white", strokeWidth=0.4, id="graticule")
24
+
25
+ # Add a choropleth layer with an ID and legend position
26
+ viz.choro(
27
+ data=world_data,
28
+ var="gdppc",
29
+ colors="Reds",
30
+ id="choropleth_gdp",
31
+ legend=True,
32
+ leg_title="GDP per Capita",
33
+ leg_pos=[10, 100] # Position for the choro legend
34
+ )
35
+
36
+ # Add a proportional symbol layer with an ID and legend position
37
+ viz.prop(
38
+ data=world_data,
39
+ var="pop",
40
+ fill="#4f8a8b",
41
+ stroke="white",
42
+ id="prop_population",
43
+ legend=True,
44
+ leg_title="Population",
45
+ leg_pos=[10, 250] # Position for the prop legend
46
+ )
47
+
48
+ # Add the layer control widget (hover to expand)
49
+ viz.add_layer_control(
50
+ layers=["choropleth_gdp", "prop_population", "graticule"],
51
+ title="Layers",
52
+ x=10,
53
+ y=10
54
+ )
55
+
56
+ # Add the export control widget (hover to expand)
57
+ viz.add_export_control(
58
+ pos="top-right" # Or use x, y
59
+ )
60
+
61
+ # Add opacity control for multiple layers
62
+ viz.add_opacity_control(
63
+ layers=["choropleth_gdp", "prop_population"],
64
+ title="Layers Opacity",
65
+ x=10,
66
+ y=90
67
+ )
68
+
69
+ viz.header(text="Map with Layer & Export Controls", fontSize=20)
70
+ viz.render_html(os.path.join(output_dir, "layer_control_map.html"))