Folium Text-Overlay Visualization System¶
viz_text_overlay
¶
ResolvedTextOverlayFeature
dataclass
¶
Bases: ResolvedFeature
Resolved visual properties for text overlay elements.
Container for all computed styling properties of text overlay visualizations, including font styling, positioning, colors, and shadow effects. Used by TextOverlayGenerator to create folium markers with styled text content.
Source code in src/mesqual/visualizations/folium_viz_system/viz_text_overlay.py
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 56 57 58 59 60 61 62 63 64 65 66 | |
TextOverlayFeatureResolver
¶
Bases: FeatureResolver[ResolvedTextOverlayFeature]
Resolves visual properties for text overlay elements.
Specialized feature resolver for text overlay visualizations that handles text content, font styling, positioning, and visual effects. Commonly used for adding data labels, value displays, or annotations to map elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_color
|
PropertyMapper | str
|
Text color (static value or PropertyMapper) |
'#3A3A3A'
|
font_size
|
PropertyMapper | str
|
Font size with units like '10pt' (static value or PropertyMapper) |
'10pt'
|
font_weight
|
PropertyMapper | str
|
Font weight like 'bold', 'normal' (static value or PropertyMapper) |
'bold'
|
background_color
|
PropertyMapper | str
|
Background color for text (static value or PropertyMapper) |
None
|
shadow_size
|
PropertyMapper | str
|
Text shadow size like '0.5px' (static value or PropertyMapper) |
'0.5px'
|
shadow_color
|
PropertyMapper | str | None
|
Text shadow color (static value or PropertyMapper) |
'#F2F2F2'
|
text_print_content
|
PropertyMapper | str | bool
|
Text content to display (True for auto-generated).
The text is HTML-escaped, so |
True
|
text_is_html
|
PropertyMapper | bool
|
True to write |
False
|
tooltip
|
PropertyMapper | str | bool
|
Tooltip content, see |
True
|
popup
|
PropertyMapper | Popup | bool
|
Popup content, see |
False
|
location
|
PropertyMapper | Point
|
Point of the label. Default: the first |
None
|
**property_mappers
|
PropertyMapper | Any
|
Additional custom property mappings |
{}
|
Examples:
Static styling:
>>> resolver = TextOverlayFeatureResolver(text_color='#000000', font_size='12pt', font_weight='bold')
Color and text from the KPI value:
>>> from mesqual.visualizations.folium_viz_system import PropertyMapper
>>> resolver = TextOverlayFeatureResolver(
... text_color=PropertyMapper.from_kpi_value(lambda v: '#FF0000' if v > 100 else '#000000'),
... text_print_content=PropertyMapper.from_kpi_value(lambda v: f'{v:.0f} MW'),
... )
Two-line labels with HTML markup:
>>> resolver = TextOverlayFeatureResolver(
... text_print_content=PropertyMapper.from_item_attr('name', lambda name: f'<b>{name}</b><br>zone'),
... text_is_html=True,
... )
Source code in src/mesqual/visualizations/folium_viz_system/viz_text_overlay.py
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 118 119 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 | |
TextOverlayGenerator
¶
Bases: FoliumObjectGenerator[TextOverlayFeatureResolver]
Generates text labels for map data items.
Creates one folium Marker per data item with a styled HTML text label at the location of the item. Typical uses are KPI values on areas or lines, data labels and categorical labels.
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.units import Units
>>> generator = TextOverlayGenerator(
... TextOverlayFeatureResolver(
... text_print_content=PropertyMapper(
... lambda item: Units.get_pretty_text_for_quantity(item.kpi.quantity, decimals=0, include_unit=False)
... ),
... font_size='10pt',
... font_weight='bold',
... )
... )
>>> fg = generator.generate_objects_for_kpi_collection(prices, folium.FeatureGroup('Price labels'))
Areas and labels in one feature group:
>>> from mesqual.visualizations.folium_viz_system import AreaGenerator
>>> fg = folium.FeatureGroup('Countries')
>>> fg = AreaGenerator().generate_objects_for_model_df(dataset.fetch('Country.Model'), fg)
>>> fg = TextOverlayGenerator().generate_objects_for_model_df(dataset.fetch('Country.Model'), fg)
Source code in src/mesqual/visualizations/folium_viz_system/viz_text_overlay.py
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
generate
¶
generate(data_item: VisualizableDataItem, feature_group: FeatureGroup) -> None
Generate and add a folium Marker with styled text overlay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_item
|
VisualizableDataItem
|
Data item containing point location and text content |
required |
feature_group
|
FeatureGroup
|
Folium feature group to add the text marker to |
required |
Source code in src/mesqual/visualizations/folium_viz_system/viz_text_overlay.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |