Folium Legends¶
legends
¶
Legends of value mappings on folium maps.
ContinuousColorscaleLegend
¶
Bases: ContinuousLegendBase[SegmentedContinuousColorscale]
Legend for continuous color mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
ContinuousMappingType
|
Segmented continuous color scale. |
required |
**kwargs
|
Any
|
Passed to |
{}
|
Source code in src/mesqual/visualizations/folium_viz_system/legends/continuous_color.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
ContinuousLineWidthMapLegend
¶
Bases: ContinuousLegendBase[SegmentedContinuousLineWidthMapping]
Legend for continuous line width mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
SegmentedContinuousLineWidthMapping
|
Segmented continuous line width mapping. |
required |
line_color
|
str
|
CSS color of the line shapes. |
'#000000'
|
show_pixel_values
|
bool
|
If True, show the width in px below the line shape of each segment. |
False
|
**kwargs
|
Any
|
Passed to |
{}
|
Source code in src/mesqual/visualizations/folium_viz_system/legends/continuous_line_width.py
7 8 9 10 11 12 13 14 15 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 56 57 58 59 60 61 62 | |
DiscreteColorLegend
¶
Bases: DiscreteLegendBase[DiscreteColorMapping]
Legend for discrete color mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
DiscreteColorMapping
|
Discrete color mapping. |
required |
swatch_size
|
int
|
Size of the color swatch in px. |
20
|
**kwargs
|
Any
|
Passed to |
{}
|
Source code in src/mesqual/visualizations/folium_viz_system/legends/discrete_color.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
DiscreteLineDashLegend
¶
Bases: DiscreteLegendBase[DiscreteLineDashPatternMapping]
Legend for line dash pattern mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
DiscreteLineDashPatternMapping
|
Discrete line dash pattern mapping. |
required |
line_color
|
str
|
CSS color of the lines. |
'#000000'
|
line_width
|
int
|
Line width in px. |
2
|
**kwargs
|
Any
|
Passed to |
{}
|
Source code in src/mesqual/visualizations/folium_viz_system/legends/discrete_line_dash.py
7 8 9 10 11 12 13 14 15 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 | |
DiscreteLineWidthLegend
¶
Bases: DiscreteLegendBase[DiscreteLineWidthMapping]
Legend for discrete line width mappings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
DiscreteLineWidthMapping
|
Discrete line width mapping. |
required |
line_color
|
str
|
CSS color of the lines. |
'#000000'
|
show_pixel_values
|
bool
|
If True, show the width in px behind each label. |
False
|
**kwargs
|
Any
|
Passed to |
{}
|
Source code in src/mesqual/visualizations/folium_viz_system/legends/discrete_line_width.py
7 8 9 10 11 12 13 14 15 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 56 57 58 | |
Base classes¶
base
¶
Base class of all legends of value mappings.
BaseLegend
¶
Bases: MacroElement, ABC, Generic[ValueMappingType]
Base class for all mapping legends with common functionality.
The title and the labels are text: the legend HTML-escapes them, so a value
such as A<B shows as written.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
ValueMappingType
|
Value mapping that the legend describes. |
required |
title
|
str
|
Legend title, as text. |
''
|
background_color
|
str
|
CSS background color of the legend box. |
'white'
|
title_color
|
str
|
CSS color of the title. |
'#333333'
|
title_font_size
|
int
|
Title font size in px. |
14
|
title_margin_bottom
|
int
|
Space below the title in px. |
8
|
font_family
|
str
|
CSS font family. |
'Arial, sans-serif'
|
width
|
int
|
Width of the legend content in px. |
200
|
padding
|
int
|
Padding of the legend box in px. |
10
|
border_radius
|
int
|
Corner radius of the legend box in px. |
5
|
position
|
dict[str, int | float | str] | None
|
CSS position of the legend, for example |
None
|
value_formatter
|
Callable[[Any], str] | None
|
Function that returns the label text of every tick of a
continuous legend and of every key of a discrete legend. Continuous
legends pass the tick value as a float. Discrete legends pass the
mapping key. The legend escapes the returned text. |
None
|
Examples:
Show values of a scale with the suffixes B and M:
>>> from mesqual.visualizations.folium_viz_system.legends import ContinuousColorscaleLegend
>>> from mesqual.visualizations.value_mapping_system import SegmentedContinuousColorscale
>>> def to_suffix(value: float) -> str:
... if abs(value) >= 1e9:
... return f"{value / 1e9:g}B"
... if abs(value) >= 1e6:
... return f"{value / 1e6:g}M"
... return f"{value:g}"
>>> mapping = SegmentedContinuousColorscale(segments={(0, 2e9): ["#0000ff", "#ff0000"]})
>>> legend = ContinuousColorscaleLegend(mapping, value_formatter=to_suffix)
>>> "2B" in legend.render_content() and "2000000000" not in legend.render_content()
True
Source code in src/mesqual/visualizations/folium_viz_system/legends/base.py
12 13 14 15 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 56 57 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 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 | |
additional_styles
abstractmethod
¶
additional_styles() -> str
Return additional CSS styles specific to this legend type
Source code in src/mesqual/visualizations/folium_viz_system/legends/base.py
136 137 138 139 | |
render_content
abstractmethod
¶
render_content() -> str
Return the HTML content for the legend
Source code in src/mesqual/visualizations/folium_viz_system/legends/base.py
141 142 143 144 | |
base_continuous
¶
Base class of legends for continuous value mappings.
ContinuousLegendBase
¶
Bases: Generic[ContinuousMappingType], BaseLegend[ContinuousMappingType]
Base class for continuous mapping legends with column-based segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
ContinuousMappingType
|
Continuous value mapping that the legend describes. |
required |
segment_spacing
|
int
|
Space between segments in px. |
0
|
tick_font_size
|
int
|
Tick label font size in px. |
12
|
tick_color
|
str | None
|
CSS color of the tick labels. Default is the title color. |
None
|
n_ticks_per_segment
|
int
|
Number of ticks per segment. |
2
|
segment_height
|
int
|
Height of the segment visual in px. |
30
|
merge_adjacent_ticks
|
bool
|
If True, the shared boundary of two segments gets one tick. |
True
|
**kwargs
|
Any
|
Passed to |
{}
|
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_continuous.py
12 13 14 15 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 56 57 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
additional_styles
¶
additional_styles() -> str
Return the CSS of the segment columns and ticks, followed by specific_visual_styles().
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_continuous.py
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 78 79 | |
render_content
¶
render_content() -> str
Return the HTML of the segments, sorted by their bounds.
Each segment has the visual of create_segment_visual and
n_ticks_per_segment ticks, spaced evenly from its start to its end.
With merge_adjacent_ticks, each segment after the first leaves out
its first tick.
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_continuous.py
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 | |
specific_visual_styles
abstractmethod
¶
specific_visual_styles() -> str
Return CSS styles specific to the visual representation
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_continuous.py
132 133 134 135 | |
create_segment_visual
abstractmethod
¶
create_segment_visual(start: float, end: float, values: any) -> str
Create the visual representation for a segment
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_continuous.py
137 138 139 140 | |
base_discrete
¶
Base class of legends for discrete value mappings.
DiscreteLegendBase
¶
Bases: BaseLegend[DiscreteMappingType], Generic[DiscreteMappingType]
Base class for discrete mapping legends with two-column layout.
The legend has one row per entry of mapping.mapping, in its order, read
when the map renders. A last row with the label default_label shows
default_output when mapping.default_used is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
DiscreteMappingType
|
Discrete value mapping that the legend describes. |
required |
visual_column_width
|
int
|
Width of the visual column in px. |
60
|
column_spacing
|
int
|
Space between the visual and the label column in px. |
10
|
row_spacing
|
int
|
Space between rows in px. |
8
|
label_font_size
|
int
|
Label font size in px. |
12
|
default_label
|
str
|
Label of the row of |
'Other'
|
**kwargs
|
Any
|
Passed to |
{}
|
Examples:
The default row appears after the mapping has used default_output:
>>> from mesqual.visualizations.folium_viz_system.legends import DiscreteColorLegend
>>> from mesqual.visualizations.value_mapping_system import DiscreteColorMapping
>>> colors = DiscreteColorMapping(mapping={'wind': '#1f77b4'}, default_output='#cccccc')
>>> colors('coal')
'#cccccc'
>>> legend = DiscreteColorLegend(colors, title='Technology', default_label='Not mapped')
>>> 'Not mapped' in legend.render_content()
True
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_discrete.py
11 12 13 14 15 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 56 57 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 118 119 120 121 122 | |
additional_styles
¶
additional_styles() -> str
Return the CSS of the rows and their two columns, followed by specific_visual_styles().
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_discrete.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
specific_visual_styles
abstractmethod
¶
specific_visual_styles() -> str
Return CSS styles specific to the visual representation
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_discrete.py
82 83 84 85 | |
create_visual_element
abstractmethod
¶
create_visual_element(value: any) -> str
Create the visual representation for a given value
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_discrete.py
87 88 89 90 | |
render_content
¶
render_content() -> str
Return the HTML of the rows.
One row per entry of mapping.mapping, then the row of
default_output if mapping.default_used is True and
default_output is not None.
Source code in src/mesqual/visualizations/folium_viz_system/legends/base_discrete.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |