shinymap 0.3.0__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.
Files changed (82) hide show
  1. {shinymap-0.3.0 → shinymap-0.4.0}/.gitignore +5 -0
  2. shinymap-0.4.0/LICENSE +21 -0
  3. shinymap-0.4.0/PKG-INFO +95 -0
  4. shinymap-0.4.0/README.md +73 -0
  5. {shinymap-0.3.0 → shinymap-0.4.0}/pyproject.toml +7 -5
  6. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/__init__.py +5 -1
  7. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/_map.py +51 -41
  8. shinymap-0.4.0/src/shinymap/_stilllife.py +567 -0
  9. shinymap-0.4.0/src/shinymap/_swatches.py +148 -0
  10. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/__init__.py +2 -4
  11. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/_core.py +51 -144
  12. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/_defaults.py +3 -3
  13. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/_factory.py +25 -21
  14. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/color/__init__.py +9 -1
  15. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/color/binary.py +8 -0
  16. shinymap-0.4.0/src/shinymap/aes/color/cycle.py +68 -0
  17. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/color/neutral.py +1 -0
  18. shinymap-0.4.0/src/shinymap/aes/color/qualitative.py +29 -0
  19. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/color/scale.py +70 -1
  20. shinymap-0.4.0/src/shinymap/aes/color/sequential.py +54 -0
  21. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/line/style.py +1 -1
  22. shinymap-0.4.0/src/shinymap/geometry/__init__.py +12 -0
  23. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/__init__.py +16 -14
  24. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/_caption.py +28 -24
  25. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/_code_gen.py +33 -29
  26. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/sketch/_tab_original.py +1 -1
  27. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/mode.py +21 -13
  28. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/outline/__init__.py +2 -0
  29. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/outline/_core.py +5 -4
  30. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/outline/_export.py +2 -0
  31. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/outline/_outline.py +74 -11
  32. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/outline/_regions.py +1 -0
  33. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/outline/_repr_config.py +1 -0
  34. shinymap-0.4.0/src/shinymap/outline/_sample.py +51 -0
  35. shinymap-0.4.0/src/shinymap/outline/sample/NOTICE.md +35 -0
  36. shinymap-0.4.0/src/shinymap/outline/sample/japan.json +404 -0
  37. shinymap-0.4.0/src/shinymap/outline/sample/us_states.json +383 -0
  38. shinymap-0.4.0/src/shinymap/outline/sample/world.json +1246 -0
  39. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/payload/_aes.py +4 -3
  40. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/relative.py +19 -91
  41. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/svg/_elements.py +24 -9
  42. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/svg/_mixins.py +13 -9
  43. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/types.py +5 -7
  44. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/ui/__init__.py +5 -1
  45. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/ui/_ui.py +29 -16
  46. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/uicore/_input_map.py +3 -1
  47. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/uicore/_output_map.py +14 -2
  48. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/uicore/_render_map.py +63 -42
  49. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/uicore/_update_map.py +22 -34
  50. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/uicore/_util.py +16 -5
  51. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/uicore/_wash.py +269 -47
  52. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/utils/_linspace.py +3 -2
  53. shinymap-0.4.0/src/shinymap/utils/_svg.py +281 -0
  54. shinymap-0.4.0/src/shinymap/www/shinymap-shiny.js +1 -0
  55. shinymap-0.4.0/src/shinymap/www/shinymap.global.js +69 -0
  56. shinymap-0.3.0/PKG-INFO +0 -152
  57. shinymap-0.3.0/README.md +0 -131
  58. shinymap-0.3.0/examples/data/scripts/README.md +0 -248
  59. shinymap-0.3.0/src/shinymap/_stilllife.py +0 -404
  60. shinymap-0.3.0/src/shinymap/aes/color/cycle.py +0 -43
  61. shinymap-0.3.0/src/shinymap/aes/color/qualitative.py +0 -18
  62. shinymap-0.3.0/src/shinymap/aes/color/sequential.py +0 -42
  63. shinymap-0.3.0/src/shinymap/geometry/__init__.py +0 -18
  64. shinymap-0.3.0/src/shinymap/utils/_svg.py +0 -75
  65. shinymap-0.3.0/src/shinymap/www/shinymap-shiny.js +0 -1
  66. shinymap-0.3.0/src/shinymap/www/shinymap.global.js +0 -22863
  67. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/aes/line/__init__.py +0 -0
  68. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/caption/__init__.py +0 -0
  69. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/caption/__main__.py +0 -0
  70. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/sketch/__init__.py +0 -0
  71. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/sketch/__main__.py +0 -0
  72. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/sketch/_tab_finish.py +0 -0
  73. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/sketch/_tab_infer.py +0 -0
  74. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/sketch/_tab_relabel.py +0 -0
  75. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/kit/sketch/app.py +0 -0
  76. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/outline/converter/__init__.py +0 -0
  77. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/payload/__init__.py +0 -0
  78. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/svg/__init__.py +0 -0
  79. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/uicore/__init__.py +0 -0
  80. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/uicore/_registry.py +0 -0
  81. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/utils/__init__.py +0 -0
  82. {shinymap-0.3.0 → shinymap-0.4.0}/src/shinymap/utils/_dict.py +0 -0
@@ -29,6 +29,11 @@ docs/_site/
29
29
  docs/.quarto/
30
30
  docs/python/
31
31
  docs/typescript/
32
+ docs/images/generated/
33
+ docs/gallery.qmd
32
34
 
33
35
  # Playwright MCP session artifacts
34
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.
@@ -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
+ ![Clicking seats in the seat picker](https://raw.githubusercontent.com/kenjisato/shinymap/main/docs/images/seat-picker.gif)
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.
@@ -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
+ ![Clicking seats in the seat picker](https://raw.githubusercontent.com/kenjisato/shinymap/main/docs/images/seat-picker.gif)
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.18"]
2
+ requires = ["hatchling>=1.26"]
3
3
  build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "shinymap"
7
- version = "0.3.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 = {text = "MIT"}
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,10 +37,11 @@ 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",
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- __version__ = "0.3.0"
5
+ __version__ = "0.4.0"
6
6
 
7
7
  from . import aes, outline, svg, types, ui, utils
8
8
  from ._map import Map
@@ -19,11 +19,13 @@ from .relative import (
19
19
 
20
20
  # Re-export from ui for convenience
21
21
  from .ui import (
22
+ default_wash,
22
23
  input_checkbox_group,
23
24
  input_map,
24
25
  input_radio_buttons,
25
26
  output_map,
26
27
  render_map,
28
+ swatches,
27
29
  update_map,
28
30
  )
29
31
  from .uicore import Wash
@@ -34,6 +36,7 @@ __all__ = [
34
36
  "Map",
35
37
  "StillLife",
36
38
  "render_map",
39
+ "swatches",
37
40
  "input_map",
38
41
  "input_radio_buttons",
39
42
  "input_checkbox_group",
@@ -41,6 +44,7 @@ __all__ = [
41
44
  "update_map",
42
45
  # Wash factory (watercolor-inspired aesthetic configuration)
43
46
  "Wash",
47
+ "default_wash", # the Wash behind input_map/output_map/render_map
44
48
  # Aesthetic module (aes.Shape(), aes.Line(), aes.color, aes.line, aes.default)
45
49
  "aes",
46
50
  # PARENT proxy and relative expressions
@@ -11,7 +11,7 @@ from typing import TYPE_CHECKING, Any
11
11
 
12
12
  from .aes._core import BaseAesthetic, ByGroup, ByState
13
13
  from .types import CountMap, TooltipMap
14
- from .uicore._util import _normalize_outline, _strip_none, _validate_value
14
+ from .uicore._util import _validate_value
15
15
 
16
16
  if TYPE_CHECKING:
17
17
  from .outline import Outline
@@ -20,7 +20,7 @@ if TYPE_CHECKING:
20
20
  ResolvedAesType = ByGroup | None
21
21
 
22
22
  # Type aliases
23
- AesType = ByGroup | ByState | BaseAesthetic | Mapping[str, Mapping[str, Any] | None] | None
23
+ AesType = ByGroup | ByState | BaseAesthetic | None
24
24
 
25
25
 
26
26
  def _viewbox_to_str(view_box: tuple[float, float, float, float] | str | None) -> str | None:
@@ -64,6 +64,7 @@ class MapBuilder:
64
64
  view_box: tuple[float, float, float, float] | None = None,
65
65
  _outline: Outline | None = None,
66
66
  _resolved_aes: ResolvedAesType = None,
67
+ _mode: Any = None,
67
68
  ):
68
69
  """Internal constructor - use Map() function instead.
69
70
 
@@ -73,6 +74,7 @@ class MapBuilder:
73
74
  view_box: ViewBox as tuple (x, y, width, height)
74
75
  _outline: (Private) Full Outline object for StillLife analysis
75
76
  _resolved_aes: (Private) Pre-resolved ByGroup aesthetics from Wash
77
+ _mode: (Private) Mode object, so StillLife can render indexed aesthetics
76
78
  """
77
79
  self._regions: Mapping[str, Any] | None = regions
78
80
  self._tooltips = tooltips
@@ -83,6 +85,7 @@ class MapBuilder:
83
85
  # Private fields for StillLife static analysis
84
86
  self._outline: Outline | None = _outline
85
87
  self._resolved_aes: ResolvedAesType = _resolved_aes
88
+ self._mode: Any = _mode
86
89
 
87
90
  def with_tooltips(self, tooltips: TooltipMap) -> MapBuilder:
88
91
  """Set region tooltips."""
@@ -95,8 +98,10 @@ class MapBuilder:
95
98
  Values determine both visual state and selection:
96
99
  - value = 0: not selected (base aesthetic)
97
100
  - value > 0: selected (select aesthetic applied)
101
+
102
+ Integer-like values (e.g. numpy ints from pandas) are converted to ``int``.
98
103
  """
99
- self._value = value
104
+ self._value = _validate_value(value, "value")
100
105
  return self
101
106
 
102
107
  def with_view_box(self, view_box: tuple[float, float, float, float]) -> MapBuilder:
@@ -113,50 +118,43 @@ class MapBuilder:
113
118
  self._aes = aes
114
119
  return self
115
120
 
116
- def with_layers(self, layers: Mapping[str, list[str] | None]) -> MapBuilder:
117
- """Set layer configuration.
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.
118
126
 
119
127
  Args:
120
- layers: Nested dict with keys 'underlay', 'overlay', 'hidden'
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
+ ```
121
138
  """
122
- self._layers = layers
123
- return self
139
+ from .aes._core import ByGroup, ShapeAesthetic
140
+ from .uicore._wash import layer_user_aes
124
141
 
125
- def with_outline_metadata(self, metadata: Mapping[str, Any]) -> MapBuilder:
126
- """Set outline metadata (viewBox, groups)."""
127
- self._outline_metadata = metadata
142
+ fills = ByGroup(**{rid: ShapeAesthetic(fill_color=c) for rid, c in fill_color.items()})
143
+ self._aes = layer_user_aes(self._aes, fills)
128
144
  return self
129
145
 
130
- def as_json(self) -> Mapping[str, Any]:
131
- """Convert to JSON dict for JavaScript consumption.
146
+ def with_layers(self, layers: Mapping[str, list[str] | None]) -> MapBuilder:
147
+ """Set layer configuration.
132
148
 
133
- Returns snake_case keys. JavaScript (shinymap-shiny.js) handles
134
- conversion to camelCase.
149
+ Args:
150
+ layers: Region or group IDs per layer, with keys 'underlay', 'overlay',
151
+ 'annotation', 'hidden'
135
152
  """
136
- data: dict[str, Any] = {}
137
-
138
- if self._regions is not None:
139
- data["regions"] = _normalize_outline(self._regions)
140
- if self._tooltips is not None:
141
- data["tooltips"] = self._tooltips
142
- if self._value is not None:
143
- data["value"] = self._value
144
- if self._view_box is not None:
145
- data["view_box"] = _viewbox_to_str(self._view_box)
146
- if self._aes is not None:
147
- # Use to_js_dict() for aes objects, pass through dicts
148
- if hasattr(self._aes, "to_js_dict"):
149
- data["aes"] = self._aes.to_js_dict()
150
- elif hasattr(self._aes, "to_dict"):
151
- data["aes"] = self._aes.to_dict()
152
- else:
153
- data["aes"] = self._aes
154
- if self._layers is not None:
155
- data["layers"] = self._layers
156
- if hasattr(self, "_outline_metadata") and self._outline_metadata is not None:
157
- data["outline_metadata"] = self._outline_metadata
158
-
159
- return _strip_none(data)
153
+ from .outline._outline import reject_plural_layer_keys
154
+
155
+ reject_plural_layer_keys(layers, "layers=")
156
+ self._layers = layers
157
+ return self
160
158
 
161
159
 
162
160
  def Map(
@@ -166,6 +164,7 @@ def Map(
166
164
  tooltips: dict[str, str] | None = None,
167
165
  value: dict[str, int] | None = None,
168
166
  aes: AesType = None,
167
+ fill_color: Mapping[str, str] | None = None,
169
168
  layers: Mapping[str, list[str] | None] | None = None,
170
169
  ) -> MapBuilder:
171
170
  """Create map from Outline object.
@@ -185,7 +184,10 @@ def Map(
185
184
  - value > 0: selected (select aesthetic applied)
186
185
  aes: Aesthetic configuration (ByGroup, ByState, or BaseAesthetic).
187
186
  ByState and single aesthetics apply to every region.
188
- layers: Layer configuration (nested dict: underlay, overlay, hidden)
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)
189
191
 
190
192
  Examples:
191
193
  ```pycon
@@ -198,12 +200,18 @@ def Map(
198
200
  @render_map
199
201
  def my_map():
200
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
+
201
209
  ```
202
210
  Returns:
203
211
  MapBuilder instance for method chaining
204
212
  """
205
213
  # Validate value (must be non-negative integers)
206
- _validate_value(value, "value")
214
+ value = _validate_value(value, "value")
207
215
 
208
216
  if outline is None:
209
217
  # No outline provided - will be merged from output_map() static params
@@ -230,6 +238,8 @@ def Map(
230
238
  builder = builder.with_value(value)
231
239
  if aes is not None:
232
240
  builder = builder.with_aes(aes)
241
+ if fill_color is not None:
242
+ builder = builder.with_fill_color(fill_color)
233
243
  if layers is not None:
234
244
  builder = builder.with_layers(layers)
235
245