Folium Arrow Icon Visualization System¶
viz_arrow_icon
¶
ResolvedArrowIconFeature
dataclass
¶
Bases: ResolvedFeature
Resolved visual properties of an animated arrow icon: location, angle, arrow type, size, color and animation.
ArrowIconGenerator draws one marker with this icon per data item.
Source code in src/mesqual/visualizations/folium_viz_system/viz_arrow_icon.py
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 67 68 69 70 71 72 73 74 75 76 77 | |
ArrowIconFeatureResolver
¶
Bases: FeatureResolver[ResolvedArrowIconFeature]
Resolves the visual properties of an animated arrow icon, for example a border flow drawn as an arrow in the direction of the flow.
The arrow types and the animation come from the package captain_arro.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arrow_type
|
PropertyMapper | ArrowTypeEnum
|
Type of arrow from ArrowTypeEnum (static value or PropertyMapper) |
None
|
color
|
PropertyMapper | str
|
Arrow color (static value or PropertyMapper) |
'#2563eb'
|
stroke_width
|
PropertyMapper | int
|
Arrow stroke width in pixels (static value or PropertyMapper) |
8
|
width
|
PropertyMapper | int
|
Arrow icon width in pixels (static value or PropertyMapper) |
60
|
height
|
PropertyMapper | int
|
Arrow icon height in pixels (static value or PropertyMapper) |
60
|
speed_in_px_per_second
|
PropertyMapper | float | None
|
Animation speed in pixels/second (static value or PropertyMapper).
Set it to None to use |
20.0
|
speed_in_duration_seconds
|
PropertyMapper | float | None
|
Animation duration in seconds (static value or PropertyMapper).
Needs |
None
|
num_arrows
|
PropertyMapper | int
|
Number of animated arrows (static value or PropertyMapper) |
3
|
opacity
|
PropertyMapper | float
|
Icon opacity 0-1 (static value or PropertyMapper) |
0.8
|
reverse_direction
|
PropertyMapper | bool
|
Reverse arrow direction (static value or PropertyMapper) |
False
|
tooltip
|
PropertyMapper | str | bool
|
Tooltip content, see |
True
|
popup
|
PropertyMapper | Popup | bool
|
Popup content, see |
False
|
location
|
PropertyMapper | Point
|
Point of the icon. Default: the first |
None
|
offset
|
PropertyMapper | tuple[float, float]
|
Offset of the icon from its location as (x, y) (static value or PropertyMapper) |
(0, 0)
|
azimuth_angle
|
PropertyMapper | float
|
Arrow rotation angle in degrees (static value or PropertyMapper).
By default, it reads |
None
|
**property_mappers
|
PropertyMapper | Any
|
Additional custom property mappings |
{}
|
Examples:
Static styling:
>>> from captain_arro import ArrowTypeEnum
>>> resolver = ArrowIconFeatureResolver(
... arrow_type=ArrowTypeEnum.MOVING_FLOW_ARROW,
... color='#FF0000',
... width=50,
... height=30,
... )
Direction from the sign of the flow. The location and the angle come from the
projection_point and azimuth_angle of the border model:
>>> from mesqual.kpis import Aggregations, FlagAggKPIBuilder
>>> from mesqual.visualizations.folium_viz_system import KPIDataItem, PropertyMapper
>>> dataset.add_kpis_from_definitions(
... FlagAggKPIBuilder().for_flag('CountryBorder.Results.flow_sent_net').with_aggregation(Aggregations.Mean).build()
... )
>>> flow = KPIDataItem(dataset.kpi_collection.filter(object_name='C1 - C2')[0])
>>> resolver = ArrowIconFeatureResolver(
... arrow_type=ArrowTypeEnum.MOVING_FLOW_ARROW,
... reverse_direction=PropertyMapper.from_kpi_value(lambda v: v < 0),
... )
>>> feature = resolver.resolve_feature(flow)
>>> print(feature.location, feature.azimuth_angle, feature.reverse_direction)
POINT (9 48) 90.0 True
Source code in src/mesqual/visualizations/folium_viz_system/viz_arrow_icon.py
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 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 186 187 188 189 190 191 192 193 194 195 196 197 | |
ArrowIconGenerator
¶
Bases: FoliumObjectGenerator[ArrowIconFeatureResolver]
Generates folium Marker objects with animated SVG arrow icons.
Creates one marker per data item with an animated arrow icon of the captain_arro library, rotated to the azimuth angle of the item. Typical uses are border flows or price spreads, with the size or color from the value.
Examples:
>>> from mesqual.kpis import Aggregations, FlagAggKPIBuilder
>>> from mesqual.visualizations.folium_viz_system import PropertyMapper
>>> dataset.add_kpis_from_definitions(
... FlagAggKPIBuilder().for_flag('CountryBorder.Results.flow_sent_net').with_aggregation(Aggregations.Mean).build()
... )
>>> flows = dataset.kpi_collection.filter(flag='CountryBorder.Results.flow_sent_net')
>>> import folium
>>> from captain_arro import ArrowTypeEnum
>>> from mesqual.visualizations.value_mapping_system import SegmentedContinuousInputToContinuousOutputMapping
>>> sizes = SegmentedContinuousInputToContinuousOutputMapping(segments={(0, 1000): [20, 60]})
>>> generator = ArrowIconGenerator(
... ArrowIconFeatureResolver(
... arrow_type=PropertyMapper.from_kpi_value(
... lambda v: ArrowTypeEnum.MOVING_FLOW_ARROW if abs(v) > 50 else ArrowTypeEnum.BOUNCING_SPREAD_ARROW
... ),
... width=PropertyMapper.from_kpi_value(sizes, use_abs_kpi_value=True),
... reverse_direction=PropertyMapper.from_kpi_value(lambda v: v < 0),
... speed_in_px_per_second=None,
... speed_in_duration_seconds=4,
... )
... )
>>> fg = generator.generate_objects_for_kpi_collection(flows, folium.FeatureGroup('Flow arrows'))
Source code in src/mesqual/visualizations/folium_viz_system/viz_arrow_icon.py
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 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
generate
¶
generate(data_item: VisualizableDataItem, feature_group: FeatureGroup) -> None
Generate and add a folium Marker with animated SVG arrow icon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_item
|
VisualizableDataItem
|
Data item containing point location and associated data |
required |
feature_group
|
FeatureGroup
|
Folium feature group to add the arrow marker to |
required |
Source code in src/mesqual/visualizations/folium_viz_system/viz_arrow_icon.py
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 273 274 275 | |