-
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
replace GeoJsonStyle by kwarg style_function in GeoJson #266
Conversation
@@ -184,22 +184,56 @@ def __init__(self, data): | |||
|
|||
# providing string | |||
GeoJson(open('foo.json').read()) | |||
style_function: function, default None | |||
A function mapping a GeoJson Feature to a style dict. | |||
Ex: If you GeoJson has the form |
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.
If your
I like that as a low level interface: powerful and simple. We just need to provide some high level methods wrapping that and, as you mention, the choropleth is the first obvious one. I also think we should comply with the simple-spec by default. That would solve #198 and #120. @BibMartin if I understood your implementation it would be a matter if writing a PS: Another killer PR! Thanks!! |
I'm against this as it is now, unless you manage to convince me. 😀 In folium the name In the end we want:
Let me know what you think about this. 😄 |
Agreed. And we are working on that here.
This PR removes the
But that is styling that goes in the
And I believe that this implementation, with a default set to comply with the simple-spec, achieve this goal. What do you think @BibMartin?
Why not just another styling function that we can, and should, add another method that call this class and pass a styling function for easy choropleth generation. Note that we do not need to force anything beyond the simple-spec as the default, but if people have wonky JSONs styles then have the tool to pass them here. |
With this PR, you can:
True. I imagine we shall have the
I did not thought about creating a
If you're okay, I would at least let the simple-style part for another PR. |
Yes, but I believe that the simple-spec is more wide spread than Leaflet's defaults. I see it a lot in many different mapping clients.
That is desirable sometimes. Like the choropleth stuff:
Maybe that is the real question. What should be folium's default? simple-spec or Leaflet's standards? I am inclined to simple-spec. However, since PR makes it easy to provide styling functions, maybe we can provide the simple-spec function as a built-in option. Not sure 😑
Yes. I am OK with that. You already have a rebase on your plate 😜 |
I'm okay, but it means that we cannot support the full spec with this object. We need to have a style object that can contain a Icon, Popup and so on. I'll think about how to do it simply for another PR. As for this PR, do I break the |
That is fine. I though something along the lines of mapping Maybe, under that light, the simplespec should not be the default. We can still implement a simple-spec styling function and provide it as an option. That function would be the first step to adding a simple-spec GeoJSON. And we can think about implementing this mapping style function + some Icon/Pop loop that would make a "simple-spec method." To me that is another 👍 to the robustness of this PR. |
It is (painfully) rebased ; and ready to merge.
by
I can do it before squashing. |
@@ -169,7 +169,7 @@ def render(self, **kwargs): | |||
|
|||
|
|||
class GeoJson(MacroElement): | |||
def __init__(self, data): | |||
def __init__(self, data, style_function=None): |
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.
We still need to add a slim version of the simple-spec option. I am OK doing that in another PR. Let's just open an issue to keep track. (Or a new comment on the current issues we have open about the simple-spec.)
Sorry. I won't wait so long to review typos and pep8 style. (And I should not do that when we have many PRs pending.)
I think we are better off doing that in another PR. I made a quick review. Nothing important. Let me know if you want to address those here or if you want me to do those later. @themiurgo are you in peace with this PR or do you still have some doubts? Your comments are valuable to us! I am 👍 to merge this PR. |
I'm mainly ok. I'm not 100% ok with the name, but let's include it and see how it work out in the future. 👍 |
I hear your concerns, but at the moment |
Thanks @themiurgo and @ocefpaf for the review.
I'll try to apply changes tonight (CET) and squash in the same time. |
No rush. Just ping me once you are done. |
@BibMartin Could you please squash everything, so that I can merge? :) |
Done.
Yes, that's why challenging PEP8 before merge is a good habit. Maybe one day I'll be able to write PEP8-complianty code directly. Thanks to both of you for review, and thanks @ocefpaf for 👻 |
@BibMartin can we do something about the |
def geo_json(self, geo_path=None, geo_str=None, data_out='data.json', | ||
def geo_json(self, *args, **kwargs): | ||
"""This method is deprecated, see `Map.choropleth` instead.""" | ||
warnings.warn('This method is deprecated. Please use Map.choropleth instead.') |
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.
Let's add and will be removed in v0.2.1
To deal with the legend_name: string, default empty string Copy-and-paste docstring update too 😉 |
I had it for |
Let me update my branch and try again. I got that PS: do you think you can rebase this to get the |
If you're finished, I do an extra commit and wait for your feedback before re-squashing What repr_html fix ? |
From #275. Just because I am lazy and it will make it easier to see the results on the notebook. |
Just re-run all my notebooks that uses choropleths and they look awesome! @BibMartin great work! And sorry for the last minute burst review. Squash? |
It'd be great if this could be squashed again. Sorry @BibMartin you can blame it on @ocefpaf 😜 |
I take all the blame as long as @BibMartin keeps sending awesome PRs 😸 |
Squashed (sorry for the 2 hours delay ; I was in a meeting) |
Merge! Congrats to @BibMartin and thanks to @ocefpaf for the comments. |
Replace GeoJsonStyle by kwarg style_function in GeoJson
🎉 |
To simplify choropleth generation.
You have to provide a function
feature -> style
which is to me the most generic API.I need to update
Map.geo_json
and tests before merge.