-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add Timeline plugin #1870
Merged
Conengmo
merged 16 commits into
python-visualization:main
from
hansthen:leaflet_timeline_controller
Apr 4, 2024
Merged
Add Timeline plugin #1870
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
49c46e4
Add interval support to timestamped_geo_json
hansthen 0faf35e
Try with separate timeline
hansthen db4bcd5
Fix error in documentation
hansthen ba996d7
Fixed breaking test
hansthen 79cb4ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bdff586
Merge branch 'main' into leaflet_timeline_controller
hansthen 26f0a89
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7a96684
Based on review comments
hansthen 78663f9
Add classes to namespace per review comments
hansthen 835d45c
Added documentation for timeline plugin
hansthen 54c82b4
Add test + fix CDN import
hansthen f71c07f
Piggyback on borders.json from the Skeat timeline repo
hansthen d917fde
Update docs/user_guide/plugins/timestamped_geojson.md
hansthen fc626dc
Updated after review comments
hansthen 46cf423
Made the example file smaller
hansthen 1c8e174
Update folium/plugins/timeline.py
hansthen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
```{code-cell} ipython3 | ||
--- | ||
nbsphinx: hidden | ||
--- | ||
import folium | ||
import folium.plugins | ||
``` | ||
|
||
## Timeline and TimelineSlider | ||
Show changing geospatial data over time. | ||
|
||
### Comparison to TimestampedGeoJson | ||
This is a plugin with a similar purpose to `TimestampedGeoJson`. They both | ||
show geospatial information that changes over time. | ||
|
||
The main difference between the two is the input format. | ||
|
||
In the `Timeline` plugin each `Feature` has its own `start` and `end` time among its properties. | ||
In the `TimestampedGeojson` each `Feature` has an array of start times. Each start time in | ||
the array corresponds to a part of the `Geometry` of that `Feature`. | ||
|
||
`TimestampedGeojson` also does not have `end` times for each `Feature`. Instead you can | ||
specify a global `duration` property that is valid for all features. | ||
|
||
Depending on your input geojson, one plugin may be more convenient than the other. | ||
|
||
### Comparison to Realtime | ||
The `Timeline` plugin can only show data from the past. If you want live updates, | ||
you need the `Realtime` plugin. | ||
|
||
```{code-cell} ipython3 | ||
import folium | ||
from folium.utilities import JsCode | ||
from folium.features import GeoJsonPopup | ||
from folium.plugins.timeline import Timeline, TimelineSlider | ||
import requests | ||
|
||
m = folium.Map() | ||
|
||
data = requests.get( | ||
"https://github.com/skeate/Leaflet.timeline/blob/master/docs/examples/borders.json" | ||
hansthen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
).json() | ||
|
||
timeline = Timeline( | ||
data, | ||
style=JsCode(""" | ||
function (data) { | ||
function getColorFor(str) { | ||
var hash = 0; | ||
for (var i = 0; i < str.length; i++) { | ||
hash = str.charCodeAt(i) + ((hash << 5) - hash); | ||
} | ||
var red = (hash >> 24) & 0xff; | ||
var grn = (hash >> 16) & 0xff; | ||
var blu = (hash >> 8) & 0xff; | ||
return "rgb(" + red + "," + grn + "," + blu + ")"; | ||
} | ||
return { | ||
stroke: false, | ||
color: getColorFor(data.properties.name), | ||
fillOpacity: 0.5, | ||
}; | ||
} | ||
""") | ||
).add_to(m) | ||
GeoJsonPopup(fields=['name'], labels=True).add_to(timeline) | ||
TimelineSlider( | ||
auto_play=False, | ||
show_ticks=True, | ||
enable_keyboard_controls=True, | ||
playback_duration=30000, | ||
).add_timelines(timeline).add_to(m) | ||
m | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference to the Skeate repo in line 42 is temporary, to make the tests pass. Once the PR is accepted I will change this to point to data inside our own repository.