Folium Area Visualization System¶
viz_areas
¶
ResolvedAreaFeature
dataclass
¶
Bases: ResolvedFeature
Resolved visual properties for area/polygon map elements.
Container for all computed styling properties of polygon visualizations, including fill colors, border styles, and interactive behaviors. Used by AreaGenerator to create folium GeoJson polygons.
Source code in src/mesqual/visualizations/folium_viz_system/viz_areas.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
AreaFeatureResolver
¶
Bases: FeatureResolver[ResolvedAreaFeature]
Resolves visual properties for polygon/area map elements.
Specialized feature resolver for area visualizations that handles polygon geometries, fill colors, border styling, and opacity settings. Commonly used for visualizing bidding zones, geographic regions, or any spatial areas with associated data values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fill_color
|
PropertyMapper | str
|
Area fill color (static value or PropertyMapper) |
'#D2D2D2'
|
border_color
|
PropertyMapper | str
|
Border/stroke color (static value or PropertyMapper) |
'white'
|
border_width
|
PropertyMapper | float
|
Border width in pixels (static value or PropertyMapper) |
2.0
|
fill_opacity
|
PropertyMapper | float
|
Fill transparency 0-1 (static value or PropertyMapper) |
0.8
|
highlight_border_width
|
PropertyMapper | float
|
Border width on hover (defaults to border_width) |
None
|
highlight_fill_opacity
|
PropertyMapper | float
|
Fill opacity on hover (defaults to 1.0) |
1.0
|
tooltip
|
PropertyMapper | str | bool
|
Tooltip content, see |
True
|
popup
|
PropertyMapper | Popup | bool
|
Popup content, see |
False
|
geometry
|
PropertyMapper | Polygon
|
Polygon geometry (defaults to 'geometry' attribute) |
None
|
**property_mappers
|
PropertyMapper | Any
|
Additional custom property mappings |
{}
|
Examples:
Static styling:
>>> resolver = AreaFeatureResolver(fill_color='#FF0000', border_color='white', fill_opacity=0.8)
Fill color from the KPI value:
>>> from mesqual.visualizations.folium_viz_system import PropertyMapper
>>> from mesqual.visualizations.value_mapping_system import SegmentedContinuousColorscale
>>> colors = SegmentedContinuousColorscale(segments={(30, 60): 'YlOrRd'})
>>> resolver = AreaFeatureResolver(fill_color=PropertyMapper.from_kpi_value(colors), fill_opacity=0.8)
Source code in src/mesqual/visualizations/folium_viz_system/viz_areas.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
AreaGenerator
¶
Bases: FoliumObjectGenerator[AreaFeatureResolver]
Generates folium GeoJson polygons for areas.
Creates one polygon per data item with the styling of its
AreaFeatureResolver, with tooltip and popup. Data items without a polygon
or multipolygon geometry are skipped. Typical uses are countries or bidding
zones colored by price, or regions colored by a KPI.
Examples:
>>> from mesqual.kpis import Aggregations, FlagAggKPIBuilder
>>> from mesqual.visualizations.folium_viz_system import PropertyMapper
>>> dataset.add_kpis_from_definitions(
... FlagAggKPIBuilder().for_flag('Country.Results.price').with_aggregation(Aggregations.Mean).build()
... )
>>> prices = dataset.kpi_collection.filter(flag='Country.Results.price')
>>> import folium
>>> from mesqual.visualizations.value_mapping_system import SegmentedContinuousColorscale
>>> colors = SegmentedContinuousColorscale(segments={(30, 60): 'YlOrRd'})
>>> generator = AreaGenerator(AreaFeatureResolver(fill_color=PropertyMapper.from_kpi_value(colors)))
>>> fg = generator.generate_objects_for_kpi_collection(prices, folium.FeatureGroup('Prices'))
>>> m = folium.Map(location=[48, 9], zoom_start=6)
>>> fg = fg.add_to(m)
>>> m.save('prices.html')
Source code in src/mesqual/visualizations/folium_viz_system/viz_areas.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
generate
¶
generate(data_item: VisualizableDataItem, feature_group: FeatureGroup) -> None
Generate and add a folium GeoJson polygon to the feature group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_item
|
VisualizableDataItem
|
Data item containing polygon geometry and associated data |
required |
feature_group
|
FeatureGroup
|
Folium feature group to add the polygon to |
required |
Source code in src/mesqual/visualizations/folium_viz_system/viz_areas.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |