Skip to content

Fix small issues with Timeline and TreeLayerControl docs #1923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/user_guide/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ Plugins
plugins/side_by_side_layers
plugins/tag_filter_button
plugins/terminator
plugins/timeline
plugins/timeslider_choropleth
plugins/timestamped_geojson
plugins/treelayercontrol
plugins/vector_tiles
plugins/WmsTimeDimension

Expand Down Expand Up @@ -96,10 +98,14 @@ Plugins
- Creates a Tag Filter Button to filter elements based on different criteria.
* - :doc:`Terminator <plugins/terminator>`
- Overlay day and night regions on a map.
* - :doc:`Timeline <plugins/timeline>`
- Create a timeline with a time slider for geojson data with start and end times.
* - :doc:`Timeslider Choropleth <plugins/timeslider_choropleth>`
- Create a choropleth with a timeslider for timestamped data.
* - :doc:`Timestamped GeoJSON <plugins/timestamped_geojson>`
- Add time-aware GeoJSON into the map.
- Add GeoJSON data with timestamps to a map.
* - :doc:`TreeLayerControl <plugins/treelayercontrol>`
- Add a control for a tree of layers with checkboxes for visibility control.
* - :doc:`Vector Tiles using VectorGridProtobuf <plugins/vector_tiles>`
- Display gridded vector data (GeoJSON or TopoJSON sliced with geojson-vt, or protobuf vector tiles).
* - :doc:`WMS Time Dimension <plugins/WmsTimeDimension>`
Expand Down
2 changes: 2 additions & 0 deletions docs/user_guide/plugins/timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Depending on your input geojson, one plugin may be more convenient than the othe
The `Timeline` plugin can only show data from the past. If you want live updates,
you need the `Realtime` plugin.

### Example of Timeline and TimelineSlider

```{code-cell} ipython3
import folium
from folium.utilities import JsCode
Expand Down
5 changes: 3 additions & 2 deletions docs/user_guide/plugins/treelayercontrol.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ from folium.plugins.treelayercontrol import TreeLayerControl
from folium.features import Marker

m = folium.Map(location=[46.603354, 1.8883335], zoom_start=5)
osm = folium.TileLayer("openstreetmap").add_to(m)

overlay_tree = {
"label": "Points of Interest",
Expand Down Expand Up @@ -71,5 +70,7 @@ overlay_tree = {
]
}

control = TreeLayerControl(overlay_tree=overlay_tree).add_to(m)
TreeLayerControl(overlay_tree=overlay_tree).add_to(m)

m
```
104 changes: 50 additions & 54 deletions folium/plugins/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,36 @@

class Timeline(GeoJson):
"""
Creates a layer from GeoJSON with time data to append
into a map with Map.add_child.
Create a layer from GeoJSON with time data to add to a map.

To add time data, you need to do one of the following:
To add time data, you need to do one of the following:

* Add a 'start' and 'end' property to each feature. The start and end
can be any comparable item.
* Add a 'start' and 'end' property to each feature. The start and end
can be any comparable item.

Alternatively, you can provide
a `get_interval` function.
Alternatively, you can provide a `get_interval` function.

* This function should be a JsCode object and take as parameter
a GeoJson feature and return a dict containing values for
'start', 'end', 'startExclusive' and 'endExcusive' (or false if no
data could be extracted from the feature).
* 'start' and 'end' can be any comparable items
* 'startExclusive' and 'endExclusive' should be boolean values.
* This function should be a JsCode object and take as parameter
a GeoJson feature and return a dict containing values for
'start', 'end', 'startExclusive' and 'endExcusive' (or false if no
data could be extracted from the feature).
* 'start' and 'end' can be any comparable items
* 'startExclusive' and 'endExclusive' should be boolean values.

Parameters
----------
data: file, dict or str.
The geojson data you want to plot.
Parameters
----------
data: file, dict or str.
The geojson data you want to plot.

get_interval: JsCode, optional
Called for each feature, and should return either a time range for the
feature or `false`, indicating that it should not be included in the
timeline. The time range object should have 'start' and 'end' properties.
Optionally, the boolean keys 'startExclusive' and 'endExclusive' allow the
interval to be considered exclusive.
get_interval: JsCode, optional
Called for each feature, and should return either a time range for the
feature or `false`, indicating that it should not be included in the
timeline. The time range object should have 'start' and 'end' properties.
Optionally, the boolean keys 'startExclusive' and 'endExclusive' allow the
interval to be considered exclusive.

If `get_interval` is not provided, 'start' and 'end' properties are
assumed to be present on each feature.
If `get_interval` is not provided, 'start' and 'end' properties are
assumed to be present on each feature.

Examples
--------
Expand Down Expand Up @@ -142,35 +140,33 @@ def _get_self_bounds(self):

class TimelineSlider(JSCSSMixin, MacroElement):
"""
Creates a timeline slider for timeline layers.

Parameters
----------
auto_play: bool, default True
Whether the animation shall start automatically at startup.

start: str, int or float, default earliest 'start' in GeoJson
The beginning/minimum value of the timeline.
end: str, int or float, default latest 'end' in GeoJSON
The end/maximum value of the timeline.

date_options: str, default "YYYY-MM-DD HH:mm:ss"
A format string to render the currently active time in the control.
enable_playback: bool, default True
Show playback controls (i.e. prev/play/pause/next).
enable_keyboard_controls: bool, default False
Allow playback to be controlled using the spacebar (play/pause) and
right/left arrow keys (next/previous).
show_ticks: bool, default True
Show tick marks on the slider
steps: int, default 1000
How many steps to break the timeline into.
Each step will then be (end-start) / steps. Only affects playback.
playback_duration: int, default 10000
Minimum time, in ms, for the playback to take. Will almost certainly
actually take at least a bit longer -- after each frame, the next
one displays in playback_duration/steps ms, so each frame really
takes frame processing time PLUS step time.
Creates a timeline slider for timeline layers.

Parameters
----------
auto_play: bool, default True
Whether the animation shall start automatically at startup.
start: str, int or float, default earliest 'start' in GeoJson
The beginning/minimum value of the timeline.
end: str, int or float, default latest 'end' in GeoJSON
The end/maximum value of the timeline.
date_options: str, default "YYYY-MM-DD HH:mm:ss"
A format string to render the currently active time in the control.
enable_playback: bool, default True
Show playback controls (i.e. prev/play/pause/next).
enable_keyboard_controls: bool, default False
Allow playback to be controlled using the spacebar (play/pause) and
right/left arrow keys (next/previous).
show_ticks: bool, default True
Show tick marks on the slider
steps: int, default 1000
How many steps to break the timeline into.
Each step will then be (end-start) / steps. Only affects playback.
playback_duration: int, default 10000
Minimum time, in ms, for the playback to take. Will almost certainly
actually take at least a bit longer -- after each frame, the next
one displays in playback_duration/steps ms, so each frame really
takes frame processing time PLUS step time.

Examples
--------
Expand Down