shinymap 0.2.1__tar.gz → 0.4.0__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.
- {shinymap-0.2.1 → shinymap-0.4.0}/.gitignore +14 -0
- shinymap-0.4.0/LICENSE +21 -0
- shinymap-0.4.0/PKG-INFO +95 -0
- shinymap-0.4.0/README.md +73 -0
- {shinymap-0.2.1 → shinymap-0.4.0}/pyproject.toml +11 -6
- shinymap-0.4.0/src/shinymap/__init__.py +64 -0
- shinymap-0.4.0/src/shinymap/_map.py +246 -0
- shinymap-0.4.0/src/shinymap/_stilllife.py +567 -0
- shinymap-0.4.0/src/shinymap/_swatches.py +148 -0
- shinymap-0.4.0/src/shinymap/aes/__init__.py +54 -0
- shinymap-0.4.0/src/shinymap/aes/_core.py +888 -0
- shinymap-0.4.0/src/shinymap/aes/_defaults.py +43 -0
- shinymap-0.2.1/src/shinymap/aes.py → shinymap-0.4.0/src/shinymap/aes/_factory.py +50 -36
- {shinymap-0.2.1/src/shinymap → shinymap-0.4.0/src/shinymap/aes}/color/__init__.py +11 -3
- {shinymap-0.2.1/src/shinymap → shinymap-0.4.0/src/shinymap/aes}/color/binary.py +8 -0
- shinymap-0.4.0/src/shinymap/aes/color/cycle.py +68 -0
- {shinymap-0.2.1/src/shinymap → shinymap-0.4.0/src/shinymap/aes}/color/neutral.py +1 -0
- shinymap-0.4.0/src/shinymap/aes/color/qualitative.py +29 -0
- {shinymap-0.2.1/src/shinymap → shinymap-0.4.0/src/shinymap/aes}/color/scale.py +70 -1
- shinymap-0.4.0/src/shinymap/aes/color/sequential.py +54 -0
- shinymap-0.4.0/src/shinymap/aes/line/__init__.py +13 -0
- shinymap-0.2.1/src/shinymap/linestyle.py → shinymap-0.4.0/src/shinymap/aes/line/style.py +9 -8
- shinymap-0.4.0/src/shinymap/geometry/__init__.py +12 -0
- shinymap-0.4.0/src/shinymap/kit/__init__.py +46 -0
- shinymap-0.4.0/src/shinymap/kit/_caption.py +173 -0
- shinymap-0.4.0/src/shinymap/kit/_code_gen.py +242 -0
- shinymap-0.4.0/src/shinymap/kit/caption/__init__.py +1 -0
- shinymap-0.4.0/src/shinymap/kit/caption/__main__.py +120 -0
- shinymap-0.4.0/src/shinymap/kit/sketch/__init__.py +0 -0
- {shinymap-0.2.1/src/shinymap/geometry/converter → shinymap-0.4.0/src/shinymap/kit/sketch}/__main__.py +13 -15
- shinymap-0.4.0/src/shinymap/kit/sketch/_tab_finish.py +136 -0
- shinymap-0.4.0/src/shinymap/kit/sketch/_tab_infer.py +263 -0
- shinymap-0.4.0/src/shinymap/kit/sketch/_tab_original.py +213 -0
- shinymap-0.4.0/src/shinymap/kit/sketch/_tab_relabel.py +795 -0
- shinymap-0.4.0/src/shinymap/kit/sketch/app.py +206 -0
- shinymap-0.4.0/src/shinymap/mode.py +508 -0
- shinymap-0.4.0/src/shinymap/outline/__init__.py +109 -0
- shinymap-0.4.0/src/shinymap/outline/_core.py +56 -0
- {shinymap-0.2.1/src/shinymap/geometry → shinymap-0.4.0/src/shinymap/outline}/_export.py +33 -27
- shinymap-0.4.0/src/shinymap/outline/_outline.py +1178 -0
- {shinymap-0.2.1/src/shinymap/geometry → shinymap-0.4.0/src/shinymap/outline}/_regions.py +7 -4
- {shinymap-0.2.1/src/shinymap/geometry → shinymap-0.4.0/src/shinymap/outline}/_repr_config.py +22 -34
- shinymap-0.4.0/src/shinymap/outline/_sample.py +51 -0
- shinymap-0.4.0/src/shinymap/outline/converter/__init__.py +11 -0
- shinymap-0.4.0/src/shinymap/outline/sample/NOTICE.md +35 -0
- shinymap-0.4.0/src/shinymap/outline/sample/japan.json +404 -0
- shinymap-0.4.0/src/shinymap/outline/sample/us_states.json +383 -0
- shinymap-0.4.0/src/shinymap/outline/sample/world.json +1246 -0
- shinymap-0.4.0/src/shinymap/payload/__init__.py +15 -0
- shinymap-0.4.0/src/shinymap/payload/_aes.py +128 -0
- {shinymap-0.2.1 → shinymap-0.4.0}/src/shinymap/relative.py +54 -143
- shinymap-0.4.0/src/shinymap/svg/__init__.py +45 -0
- {shinymap-0.2.1/src/shinymap/geometry → shinymap-0.4.0/src/shinymap/svg}/_elements.py +110 -20
- shinymap-0.2.1/src/shinymap/geometry/_element_mixins.py → shinymap-0.4.0/src/shinymap/svg/_mixins.py +24 -14
- shinymap-0.4.0/src/shinymap/types.py +113 -0
- shinymap-0.4.0/src/shinymap/ui/__init__.py +45 -0
- shinymap-0.4.0/src/shinymap/ui/_ui.py +223 -0
- shinymap-0.4.0/src/shinymap/uicore/__init__.py +21 -0
- shinymap-0.4.0/src/shinymap/uicore/_input_map.py +113 -0
- shinymap-0.4.0/src/shinymap/uicore/_output_map.py +140 -0
- shinymap-0.4.0/src/shinymap/uicore/_registry.py +12 -0
- shinymap-0.4.0/src/shinymap/uicore/_render_map.py +221 -0
- shinymap-0.4.0/src/shinymap/uicore/_update_map.py +89 -0
- shinymap-0.4.0/src/shinymap/uicore/_util.py +107 -0
- shinymap-0.4.0/src/shinymap/uicore/_wash.py +902 -0
- shinymap-0.4.0/src/shinymap/utils/__init__.py +12 -0
- shinymap-0.4.0/src/shinymap/utils/_dict.py +17 -0
- shinymap-0.2.1/src/shinymap/utils/__init__.py → shinymap-0.4.0/src/shinymap/utils/_linspace.py +13 -15
- shinymap-0.4.0/src/shinymap/utils/_svg.py +281 -0
- shinymap-0.4.0/src/shinymap/www/shinymap-shiny.js +1 -0
- shinymap-0.4.0/src/shinymap/www/shinymap.global.js +69 -0
- shinymap-0.2.1/PKG-INFO +0 -143
- shinymap-0.2.1/README.md +0 -122
- shinymap-0.2.1/examples/data/scripts/README.md +0 -248
- shinymap-0.2.1/src/shinymap/__init__.py +0 -73
- shinymap-0.2.1/src/shinymap/_aesthetics.py +0 -472
- shinymap-0.2.1/src/shinymap/_base.py +0 -520
- shinymap-0.2.1/src/shinymap/_sentinel.py +0 -42
- shinymap-0.2.1/src/shinymap/_theme.py +0 -64
- shinymap-0.2.1/src/shinymap/_ui.py +0 -575
- shinymap-0.2.1/src/shinymap/_validation.py +0 -160
- shinymap-0.2.1/src/shinymap/_wash.py +0 -509
- shinymap-0.2.1/src/shinymap/color/cycle.py +0 -43
- shinymap-0.2.1/src/shinymap/color/qualitative.py +0 -18
- shinymap-0.2.1/src/shinymap/color/sequential.py +0 -42
- shinymap-0.2.1/src/shinymap/geometry/__init__.py +0 -139
- shinymap-0.2.1/src/shinymap/geometry/_bounds.py +0 -374
- shinymap-0.2.1/src/shinymap/geometry/_conversion.py +0 -336
- shinymap-0.2.1/src/shinymap/geometry/_core.py +0 -96
- shinymap-0.2.1/src/shinymap/geometry/_geometry.py +0 -681
- shinymap-0.2.1/src/shinymap/geometry/_loader.py +0 -156
- shinymap-0.2.1/src/shinymap/geometry/converter/README.md +0 -104
- shinymap-0.2.1/src/shinymap/geometry/converter/__init__.py +0 -28
- shinymap-0.2.1/src/shinymap/geometry/converter/_app.py +0 -568
- shinymap-0.2.1/src/shinymap/geometry/converter/_tool.py +0 -71
- shinymap-0.2.1/src/shinymap/mode.py +0 -295
- shinymap-0.2.1/src/shinymap/www/shinymap-shiny.js +0 -369
- shinymap-0.2.1/src/shinymap/www/shinymap.global.js +0 -22744
|
@@ -23,3 +23,17 @@ r/shinyjpmap/.Rproj.user/
|
|
|
23
23
|
|
|
24
24
|
# temporary
|
|
25
25
|
archive
|
|
26
|
+
|
|
27
|
+
# Documentation build artifacts
|
|
28
|
+
docs/_site/
|
|
29
|
+
docs/.quarto/
|
|
30
|
+
docs/python/
|
|
31
|
+
docs/typescript/
|
|
32
|
+
docs/images/generated/
|
|
33
|
+
docs/gallery.qmd
|
|
34
|
+
|
|
35
|
+
# Playwright MCP session artifacts
|
|
36
|
+
.playwright-mcp/
|
|
37
|
+
|
|
38
|
+
# Natural Earth downloads for `make sample-maps`
|
|
39
|
+
scripts/sample_maps/.cache/
|
shinymap-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 shinymap contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
shinymap-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: shinymap
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Interactive SVG map components for Shiny for Python
|
|
5
|
+
Project-URL: Homepage, https://github.com/kenjisato/shinymap
|
|
6
|
+
Author: shinymap contributors
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: interactive,maps,shiny,svg,visualization
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Requires-Dist: shiny>=1.4.0
|
|
17
|
+
Requires-Dist: svg-py<2.0.0,>=1.9.0
|
|
18
|
+
Provides-Extra: demo
|
|
19
|
+
Requires-Dist: colour-science>=0.4.7; extra == 'demo'
|
|
20
|
+
Requires-Dist: shiny-querynav>=0.1.0; extra == 'demo'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# shinymap
|
|
24
|
+
|
|
25
|
+
Clickable shapes as Shiny for Python inputs.
|
|
26
|
+
|
|
27
|
+
shinymap turns the regions of an SVG into a Shiny input: seats in a theater, slices of
|
|
28
|
+
a color wheel, rooms on a floor plan, parts of a diagram, or areas on a map. Clicking a
|
|
29
|
+
region selects it, and the server reads the selection like any other input. The same
|
|
30
|
+
shapes can also show your data, one color per region.
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from shiny import App, render, ui
|
|
36
|
+
|
|
37
|
+
from shinymap import Outline, input_map
|
|
38
|
+
from shinymap.mode import Multiple
|
|
39
|
+
|
|
40
|
+
# Four rows of eight seats: "A1" ... "D8", each a 10 x 10 square
|
|
41
|
+
seats = Outline.from_dict(
|
|
42
|
+
{
|
|
43
|
+
f"{row}{n}": f"M{12 * n} {12 * i} H{12 * n + 10} V{12 * i + 10} H{12 * n} Z"
|
|
44
|
+
for i, row in enumerate("ABCD")
|
|
45
|
+
for n in range(1, 9)
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
app_ui = ui.page_fixed(
|
|
50
|
+
ui.h3("Choose up to four seats"),
|
|
51
|
+
input_map("seats", seats, mode=Multiple(max_selection=4), height="240px"),
|
|
52
|
+
ui.output_text("chosen"),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def server(input, output, session):
|
|
57
|
+
@render.text
|
|
58
|
+
def chosen():
|
|
59
|
+
return "Selected: " + (", ".join(sorted(input.seats())) or "none")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
app = App(app_ui, server)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`input.seats()` is the tuple of chosen seat IDs, such as `("B4", "B5")`.
|
|
66
|
+
|
|
67
|
+
## Install
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install shinymap
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## What it does
|
|
74
|
+
|
|
75
|
+
- Inputs that behave like familiar controls. `mode="single"` works like radio buttons
|
|
76
|
+
and gives `str | None`; `mode="multiple"` works like checkboxes and gives `tuple[str, ...]`;
|
|
77
|
+
`Cycle` and `Count` step a region through states or count clicks and give
|
|
78
|
+
`dict[str, int]`.
|
|
79
|
+
- Outputs that color regions by value: `output_map()` with `@render_map` returning
|
|
80
|
+
`Map(fill_color=...)`, and color scales in `shinymap.aes.color`.
|
|
81
|
+
- Looks per region, group and state (base, hover, selected).
|
|
82
|
+
- The same picture as a static SVG with `StillLife`, for reports and slides.
|
|
83
|
+
- `python -m shinymap.kit.sketch` turns an SVG file into named regions and writes the
|
|
84
|
+
Python code to load them.
|
|
85
|
+
|
|
86
|
+
## Learn more
|
|
87
|
+
|
|
88
|
+
- Documentation: <https://kenjisato.github.io/shinymap/>
|
|
89
|
+
- For AI assistants: <https://kenjisato.github.io/shinymap/llms.txt> and
|
|
90
|
+
[`llms-full.txt`](https://kenjisato.github.io/shinymap/llms-full.txt)
|
|
91
|
+
- Example apps: [`packages/shinymap/python/examples/gallery`](https://github.com/kenjisato/shinymap/tree/main/packages/shinymap/python/examples/gallery)
|
|
92
|
+
- Changes: [CHANGELOG](https://github.com/kenjisato/shinymap/blob/main/CHANGELOG.md).
|
|
93
|
+
shinymap is before 1.0, so a release can change the API.
|
|
94
|
+
|
|
95
|
+
shinymap is MIT licensed.
|
shinymap-0.4.0/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# shinymap
|
|
2
|
+
|
|
3
|
+
Clickable shapes as Shiny for Python inputs.
|
|
4
|
+
|
|
5
|
+
shinymap turns the regions of an SVG into a Shiny input: seats in a theater, slices of
|
|
6
|
+
a color wheel, rooms on a floor plan, parts of a diagram, or areas on a map. Clicking a
|
|
7
|
+
region selects it, and the server reads the selection like any other input. The same
|
|
8
|
+
shapes can also show your data, one color per region.
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from shiny import App, render, ui
|
|
14
|
+
|
|
15
|
+
from shinymap import Outline, input_map
|
|
16
|
+
from shinymap.mode import Multiple
|
|
17
|
+
|
|
18
|
+
# Four rows of eight seats: "A1" ... "D8", each a 10 x 10 square
|
|
19
|
+
seats = Outline.from_dict(
|
|
20
|
+
{
|
|
21
|
+
f"{row}{n}": f"M{12 * n} {12 * i} H{12 * n + 10} V{12 * i + 10} H{12 * n} Z"
|
|
22
|
+
for i, row in enumerate("ABCD")
|
|
23
|
+
for n in range(1, 9)
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
app_ui = ui.page_fixed(
|
|
28
|
+
ui.h3("Choose up to four seats"),
|
|
29
|
+
input_map("seats", seats, mode=Multiple(max_selection=4), height="240px"),
|
|
30
|
+
ui.output_text("chosen"),
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def server(input, output, session):
|
|
35
|
+
@render.text
|
|
36
|
+
def chosen():
|
|
37
|
+
return "Selected: " + (", ".join(sorted(input.seats())) or "none")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
app = App(app_ui, server)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`input.seats()` is the tuple of chosen seat IDs, such as `("B4", "B5")`.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install shinymap
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## What it does
|
|
52
|
+
|
|
53
|
+
- Inputs that behave like familiar controls. `mode="single"` works like radio buttons
|
|
54
|
+
and gives `str | None`; `mode="multiple"` works like checkboxes and gives `tuple[str, ...]`;
|
|
55
|
+
`Cycle` and `Count` step a region through states or count clicks and give
|
|
56
|
+
`dict[str, int]`.
|
|
57
|
+
- Outputs that color regions by value: `output_map()` with `@render_map` returning
|
|
58
|
+
`Map(fill_color=...)`, and color scales in `shinymap.aes.color`.
|
|
59
|
+
- Looks per region, group and state (base, hover, selected).
|
|
60
|
+
- The same picture as a static SVG with `StillLife`, for reports and slides.
|
|
61
|
+
- `python -m shinymap.kit.sketch` turns an SVG file into named regions and writes the
|
|
62
|
+
Python code to load them.
|
|
63
|
+
|
|
64
|
+
## Learn more
|
|
65
|
+
|
|
66
|
+
- Documentation: <https://kenjisato.github.io/shinymap/>
|
|
67
|
+
- For AI assistants: <https://kenjisato.github.io/shinymap/llms.txt> and
|
|
68
|
+
[`llms-full.txt`](https://kenjisato.github.io/shinymap/llms-full.txt)
|
|
69
|
+
- Example apps: [`packages/shinymap/python/examples/gallery`](https://github.com/kenjisato/shinymap/tree/main/packages/shinymap/python/examples/gallery)
|
|
70
|
+
- Changes: [CHANGELOG](https://github.com/kenjisato/shinymap/blob/main/CHANGELOG.md).
|
|
71
|
+
shinymap is before 1.0, so a release can change the API.
|
|
72
|
+
|
|
73
|
+
shinymap is MIT licensed.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["hatchling>=1.
|
|
2
|
+
requires = ["hatchling>=1.26"]
|
|
3
3
|
build-backend = "hatchling.build"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "shinymap"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "Interactive SVG map components for Shiny for Python"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{name = "shinymap contributors"}]
|
|
11
|
-
license =
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"] # a copy of the repository's LICENSE, inside the package root
|
|
12
13
|
requires-python = ">=3.12"
|
|
13
14
|
dependencies = [
|
|
14
15
|
"shiny>=1.4.0",
|
|
@@ -18,7 +19,6 @@ keywords = ["shiny", "visualization", "interactive", "maps", "svg"]
|
|
|
18
19
|
classifiers = [
|
|
19
20
|
"Development Status :: 3 - Alpha",
|
|
20
21
|
"Intended Audience :: Developers",
|
|
21
|
-
"License :: OSI Approved :: MIT License",
|
|
22
22
|
"Programming Language :: Python :: 3",
|
|
23
23
|
"Programming Language :: Python :: 3.12",
|
|
24
24
|
"Topic :: Scientific/Engineering :: Visualization",
|
|
@@ -29,6 +29,7 @@ Homepage = "https://github.com/kenjisato/shinymap"
|
|
|
29
29
|
|
|
30
30
|
[project.optional-dependencies]
|
|
31
31
|
demo = [
|
|
32
|
+
"colour-science>=0.4.7",
|
|
32
33
|
"shiny-querynav>=0.1.0",
|
|
33
34
|
]
|
|
34
35
|
|
|
@@ -36,13 +37,15 @@ demo = [
|
|
|
36
37
|
packages = ["src/shinymap"]
|
|
37
38
|
|
|
38
39
|
[tool.hatch.build.targets.sdist]
|
|
39
|
-
include = ["src", "README.md"]
|
|
40
|
+
include = ["/src", "/README.md"] # anchored: "README.md" also matched nested READMEs
|
|
40
41
|
|
|
41
42
|
[dependency-groups]
|
|
42
43
|
dev = [
|
|
44
|
+
"colour-science>=0.4.7",
|
|
43
45
|
"mypy>=1.19.0",
|
|
44
46
|
"pytest>=9.0.1",
|
|
45
47
|
"pytest-asyncio>=1.3.0",
|
|
48
|
+
"pytest-playwright>=0.7.0",
|
|
46
49
|
"ruff>=0.14.8",
|
|
47
50
|
]
|
|
48
51
|
|
|
@@ -73,8 +76,10 @@ python_functions = ["test_*"]
|
|
|
73
76
|
addopts = "-v --strict-markers"
|
|
74
77
|
markers = [
|
|
75
78
|
"unit: Unit tests",
|
|
76
|
-
"integration: Integration tests",
|
|
79
|
+
"integration: Integration tests (require Playwright)",
|
|
77
80
|
]
|
|
81
|
+
asyncio_mode = "auto"
|
|
82
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
78
83
|
|
|
79
84
|
[tool.mypy]
|
|
80
85
|
python_version = "3.12"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Core Shiny for Python bindings for the shinymap renderer."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__version__ = "0.4.0"
|
|
6
|
+
|
|
7
|
+
from . import aes, outline, svg, types, ui, utils
|
|
8
|
+
from ._map import Map
|
|
9
|
+
from ._stilllife import StillLife
|
|
10
|
+
from .outline import Outline
|
|
11
|
+
from .relative import (
|
|
12
|
+
PARENT,
|
|
13
|
+
AestheticConfig,
|
|
14
|
+
RegionState,
|
|
15
|
+
RelativeExpr,
|
|
16
|
+
preview_region,
|
|
17
|
+
resolve_region,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
# Re-export from ui for convenience
|
|
21
|
+
from .ui import (
|
|
22
|
+
default_wash,
|
|
23
|
+
input_checkbox_group,
|
|
24
|
+
input_map,
|
|
25
|
+
input_radio_buttons,
|
|
26
|
+
output_map,
|
|
27
|
+
render_map,
|
|
28
|
+
swatches,
|
|
29
|
+
update_map,
|
|
30
|
+
)
|
|
31
|
+
from .uicore import Wash
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
"__version__",
|
|
35
|
+
"Outline",
|
|
36
|
+
"Map",
|
|
37
|
+
"StillLife",
|
|
38
|
+
"render_map",
|
|
39
|
+
"swatches",
|
|
40
|
+
"input_map",
|
|
41
|
+
"input_radio_buttons",
|
|
42
|
+
"input_checkbox_group",
|
|
43
|
+
"output_map",
|
|
44
|
+
"update_map",
|
|
45
|
+
# Wash factory (watercolor-inspired aesthetic configuration)
|
|
46
|
+
"Wash",
|
|
47
|
+
"default_wash", # the Wash behind input_map/output_map/render_map
|
|
48
|
+
# Aesthetic module (aes.Shape(), aes.Line(), aes.color, aes.line, aes.default)
|
|
49
|
+
"aes",
|
|
50
|
+
# PARENT proxy and relative expressions
|
|
51
|
+
"PARENT",
|
|
52
|
+
"RelativeExpr",
|
|
53
|
+
# Aesthetic debugging utilities
|
|
54
|
+
"RegionState",
|
|
55
|
+
"AestheticConfig",
|
|
56
|
+
"resolve_region",
|
|
57
|
+
"preview_region",
|
|
58
|
+
# Subpackages
|
|
59
|
+
"outline", # Outline utilities
|
|
60
|
+
"svg", # SVG element classes (Circle, Path, etc.)
|
|
61
|
+
"types", # Type definitions (MapBuilder, etc.)
|
|
62
|
+
"ui", # UI components (input_map, output_map, etc.)
|
|
63
|
+
"utils", # Utility functions (linspace, path_bb, strip_unit)
|
|
64
|
+
]
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"""Map data model for shinymap.
|
|
2
|
+
|
|
3
|
+
This module provides the core Map/MapBuilder classes for constructing
|
|
4
|
+
map payloads that can be rendered by UI components.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from collections.abc import Mapping
|
|
10
|
+
from typing import TYPE_CHECKING, Any
|
|
11
|
+
|
|
12
|
+
from .aes._core import BaseAesthetic, ByGroup, ByState
|
|
13
|
+
from .types import CountMap, TooltipMap
|
|
14
|
+
from .uicore._util import _validate_value
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from .outline import Outline
|
|
18
|
+
|
|
19
|
+
# Type alias for resolved aesthetics stored in MapBuilder
|
|
20
|
+
ResolvedAesType = ByGroup | None
|
|
21
|
+
|
|
22
|
+
# Type aliases
|
|
23
|
+
AesType = ByGroup | ByState | BaseAesthetic | None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _viewbox_to_str(view_box: tuple[float, float, float, float] | str | None) -> str | None:
|
|
27
|
+
"""Convert viewBox tuple to string format, or pass through string."""
|
|
28
|
+
if view_box is None:
|
|
29
|
+
return None
|
|
30
|
+
if isinstance(view_box, str):
|
|
31
|
+
return view_box
|
|
32
|
+
return f"{view_box[0]} {view_box[1]} {view_box[2]} {view_box[3]}"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class MapBuilder:
|
|
36
|
+
"""Fluent builder for constructing map payloads with method chaining.
|
|
37
|
+
|
|
38
|
+
Parameters can be provided here or via output_map(). When both are provided,
|
|
39
|
+
builder parameters take precedence.
|
|
40
|
+
|
|
41
|
+
Example (traditional):
|
|
42
|
+
@render_map
|
|
43
|
+
def my_map():
|
|
44
|
+
return (
|
|
45
|
+
Map(outline, tooltips=tooltips, view_box=viewbox)
|
|
46
|
+
.with_value(my_counts)
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
Example (with static params in output_map()):
|
|
50
|
+
# UI layer
|
|
51
|
+
output_map("my_map", outline, tooltips=TOOLTIPS, view_box=VIEWBOX)
|
|
52
|
+
|
|
53
|
+
# Server layer
|
|
54
|
+
@render_map
|
|
55
|
+
def my_map():
|
|
56
|
+
return Map().with_value(my_counts)
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
regions: Mapping[str, Any] | None = None,
|
|
62
|
+
*,
|
|
63
|
+
tooltips: TooltipMap = None,
|
|
64
|
+
view_box: tuple[float, float, float, float] | None = None,
|
|
65
|
+
_outline: Outline | None = None,
|
|
66
|
+
_resolved_aes: ResolvedAesType = None,
|
|
67
|
+
_mode: Any = None,
|
|
68
|
+
):
|
|
69
|
+
"""Internal constructor - use Map() function instead.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
regions: Dict of main regions {regionId: [element1, ...]}
|
|
73
|
+
tooltips: Optional region tooltips
|
|
74
|
+
view_box: ViewBox as tuple (x, y, width, height)
|
|
75
|
+
_outline: (Private) Full Outline object for StillLife analysis
|
|
76
|
+
_resolved_aes: (Private) Pre-resolved ByGroup aesthetics from Wash
|
|
77
|
+
_mode: (Private) Mode object, so StillLife can render indexed aesthetics
|
|
78
|
+
"""
|
|
79
|
+
self._regions: Mapping[str, Any] | None = regions
|
|
80
|
+
self._tooltips = tooltips
|
|
81
|
+
self._value: CountMap = None
|
|
82
|
+
self._view_box = view_box
|
|
83
|
+
self._aes: AesType = None
|
|
84
|
+
self._layers: Mapping[str, list[str] | None] | None = None
|
|
85
|
+
# Private fields for StillLife static analysis
|
|
86
|
+
self._outline: Outline | None = _outline
|
|
87
|
+
self._resolved_aes: ResolvedAesType = _resolved_aes
|
|
88
|
+
self._mode: Any = _mode
|
|
89
|
+
|
|
90
|
+
def with_tooltips(self, tooltips: TooltipMap) -> MapBuilder:
|
|
91
|
+
"""Set region tooltips."""
|
|
92
|
+
self._tooltips = tooltips
|
|
93
|
+
return self
|
|
94
|
+
|
|
95
|
+
def with_value(self, value: CountMap) -> MapBuilder:
|
|
96
|
+
"""Set region values (counts, selection state).
|
|
97
|
+
|
|
98
|
+
Values determine both visual state and selection:
|
|
99
|
+
- value = 0: not selected (base aesthetic)
|
|
100
|
+
- value > 0: selected (select aesthetic applied)
|
|
101
|
+
|
|
102
|
+
Integer-like values (e.g. numpy ints from pandas) are converted to ``int``.
|
|
103
|
+
"""
|
|
104
|
+
self._value = _validate_value(value, "value")
|
|
105
|
+
return self
|
|
106
|
+
|
|
107
|
+
def with_view_box(self, view_box: tuple[float, float, float, float]) -> MapBuilder:
|
|
108
|
+
"""Set the SVG viewBox as tuple (x, y, width, height)."""
|
|
109
|
+
self._view_box = view_box
|
|
110
|
+
return self
|
|
111
|
+
|
|
112
|
+
def with_aes(self, aes: AesType) -> MapBuilder:
|
|
113
|
+
"""Set aesthetic configuration.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
aes: Aesthetic config (ByGroup, ByState, or BaseAesthetic)
|
|
117
|
+
"""
|
|
118
|
+
self._aes = aes
|
|
119
|
+
return self
|
|
120
|
+
|
|
121
|
+
def with_fill_color(self, fill_color: Mapping[str, str]) -> MapBuilder:
|
|
122
|
+
"""Color regions by ID, e.g. with the output of ``aes.color.scale_sequential``.
|
|
123
|
+
|
|
124
|
+
Each entry becomes ``aes.Shape(fill_color=...)`` for that region, layered
|
|
125
|
+
over any aes already set: other properties of the region are kept.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
fill_color: Mapping of region ID to color.
|
|
129
|
+
|
|
130
|
+
Examples:
|
|
131
|
+
```pycon
|
|
132
|
+
@render_map
|
|
133
|
+
def my_map():
|
|
134
|
+
colors = scale_sequential(counts, region_ids, max_count=5)
|
|
135
|
+
return Map().with_value(counts).with_fill_color(colors)
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
"""
|
|
139
|
+
from .aes._core import ByGroup, ShapeAesthetic
|
|
140
|
+
from .uicore._wash import layer_user_aes
|
|
141
|
+
|
|
142
|
+
fills = ByGroup(**{rid: ShapeAesthetic(fill_color=c) for rid, c in fill_color.items()})
|
|
143
|
+
self._aes = layer_user_aes(self._aes, fills)
|
|
144
|
+
return self
|
|
145
|
+
|
|
146
|
+
def with_layers(self, layers: Mapping[str, list[str] | None]) -> MapBuilder:
|
|
147
|
+
"""Set layer configuration.
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
layers: Region or group IDs per layer, with keys 'underlay', 'overlay',
|
|
151
|
+
'annotation', 'hidden'
|
|
152
|
+
"""
|
|
153
|
+
from .outline._outline import reject_plural_layer_keys
|
|
154
|
+
|
|
155
|
+
reject_plural_layer_keys(layers, "layers=")
|
|
156
|
+
self._layers = layers
|
|
157
|
+
return self
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def Map(
|
|
161
|
+
outline: Outline | None = None,
|
|
162
|
+
*,
|
|
163
|
+
view_box: tuple[float, float, float, float] | None = None,
|
|
164
|
+
tooltips: dict[str, str] | None = None,
|
|
165
|
+
value: dict[str, int] | None = None,
|
|
166
|
+
aes: AesType = None,
|
|
167
|
+
fill_color: Mapping[str, str] | None = None,
|
|
168
|
+
layers: Mapping[str, list[str] | None] | None = None,
|
|
169
|
+
) -> MapBuilder:
|
|
170
|
+
"""Create map from Outline object.
|
|
171
|
+
|
|
172
|
+
When used with output_map() that provides static outline, you can call Map()
|
|
173
|
+
without arguments. Otherwise, provide an Outline object.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
outline: Outline object with regions, viewBox, metadata.
|
|
177
|
+
Optional when used with output_map()
|
|
178
|
+
view_box: Override viewBox tuple (for zoom/pan).
|
|
179
|
+
If None, uses outline.viewbox()
|
|
180
|
+
tooltips: Region tooltips
|
|
181
|
+
value: Region values (counts, selection state).
|
|
182
|
+
Values determine both visual state and selection:
|
|
183
|
+
- value = 0: not selected (base aesthetic)
|
|
184
|
+
- value > 0: selected (select aesthetic applied)
|
|
185
|
+
aes: Aesthetic configuration (ByGroup, ByState, or BaseAesthetic).
|
|
186
|
+
ByState and single aesthetics apply to every region.
|
|
187
|
+
fill_color: Mapping of region ID to fill color, e.g. from
|
|
188
|
+
``aes.color.scale_sequential``. Layered over ``aes``.
|
|
189
|
+
layers: Region or group IDs per layer (keys: underlay, overlay, annotation,
|
|
190
|
+
hidden)
|
|
191
|
+
|
|
192
|
+
Examples:
|
|
193
|
+
```pycon
|
|
194
|
+
# Standalone usage
|
|
195
|
+
geo = Outline.from_dict(data)
|
|
196
|
+
Map(geo, value={"a": 1, "b": 1, "c": 0})
|
|
197
|
+
|
|
198
|
+
# With output_map() providing static outline
|
|
199
|
+
output_map("my_map", OUTLINE, tooltips=TOOLTIPS)
|
|
200
|
+
@render_map
|
|
201
|
+
def my_map():
|
|
202
|
+
return Map().with_value(counts)
|
|
203
|
+
|
|
204
|
+
# Coloring by value
|
|
205
|
+
@render_map
|
|
206
|
+
def my_map():
|
|
207
|
+
return Map(fill_color=scale_continuous(rates, region_ids, vmin=0, vmax=100))
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
Returns:
|
|
211
|
+
MapBuilder instance for method chaining
|
|
212
|
+
"""
|
|
213
|
+
# Validate value (must be non-negative integers)
|
|
214
|
+
value = _validate_value(value, "value")
|
|
215
|
+
|
|
216
|
+
if outline is None:
|
|
217
|
+
# No outline provided - will be merged from output_map() static params
|
|
218
|
+
builder = MapBuilder(
|
|
219
|
+
None, # Will be filled by _apply_static_params
|
|
220
|
+
view_box=view_box,
|
|
221
|
+
tooltips=tooltips,
|
|
222
|
+
)
|
|
223
|
+
else:
|
|
224
|
+
# Extract regions using Outline methods
|
|
225
|
+
main_regions = outline.main_regions()
|
|
226
|
+
|
|
227
|
+
# Create MapBuilder with extracted data
|
|
228
|
+
# Pass _outline for aes group expansion in _build_payload
|
|
229
|
+
builder = MapBuilder(
|
|
230
|
+
main_regions,
|
|
231
|
+
view_box=view_box or outline.viewbox(),
|
|
232
|
+
tooltips=tooltips,
|
|
233
|
+
_outline=outline,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
# Apply optional parameters
|
|
237
|
+
if value is not None:
|
|
238
|
+
builder = builder.with_value(value)
|
|
239
|
+
if aes is not None:
|
|
240
|
+
builder = builder.with_aes(aes)
|
|
241
|
+
if fill_color is not None:
|
|
242
|
+
builder = builder.with_fill_color(fill_color)
|
|
243
|
+
if layers is not None:
|
|
244
|
+
builder = builder.with_layers(layers)
|
|
245
|
+
|
|
246
|
+
return builder
|