-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Mouse Position plugin #916
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
Conversation
folium/plugins/__init__.py
Outdated
@@ -41,6 +42,7 @@ | |||
'HeatMapWithTime', | |||
'MarkerCluster', | |||
'MeasureControl', | |||
'MousePosition', |
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.
E131 continuation line unaligned for hanging indent
indent position corrected
folium/plugins/mouse_position.py
Outdated
|
||
https://github.com/ardhi/Leaflet.MousePosition | ||
|
||
With the MIT License as below: |
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.
Good that you include the license. But could you put in in the file header? The docstring is converted to documentation and I don't want that littered with license texts.
folium/plugins/mouse_position.py
Outdated
{% endmacro %} | ||
""") # noqa | ||
|
||
def __init__(self, position='bottomright', separator=' : ', emptyString='Unavailable', lngFirst=False, numDigits=5, |
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.
Please make this line 80 chars wide.
folium/plugins/mouse_position.py
Outdated
|
||
Parameters | ||
---------- | ||
position: location of the widget |
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.
Docstring convention is name, type and default value on the first line, description on the second. So something like:
position : str, default 'bottomright'
Location of the widget.
folium/plugins/mouse_position.py
Outdated
|
||
def __init__(self, position='bottomright', separator=' : ', emptyString='Unavailable', lngFirst=False, numDigits=5, | ||
lngFormatter=None, latFormatter=None, prefix=""): | ||
"""Coordinate, linear, and area measure control""" |
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.
No need for a docstring on a class init when you already have the docstring above.
Thanks for this PR, it's a useful plugin! Check out my review comments for some details. Here are some longer comments: Choose between specifying all arguments or using
The fact you only included Add an example Our current way of feature discovery is through an example gallery in Jupyter Notebooks. Please add an entry which shows how to use this plugin and its effect. Optionally add a test Not a strict necessity, but it would be nice if you can add a test for this module. You can check out the other plugin tests to see how they verify if the template is rendering correctly. Changelog Finally, just before merging, you should add a line in the changelog. Here's an example line from another plugin that was added:
|
Parameters doc string reformatted. Licence shifted to header. __init__ < 80 chars.
folium/plugins/mouse_position.py
Outdated
|
||
from jinja2 import Template | ||
|
||
class MousePosition(MacroElement): |
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.
E302 expected 2 blank lines, found 1
folium/plugins/mouse_position.py
Outdated
---------- | ||
position : str, default 'bottomright' | ||
Location of the widget. | ||
|
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.
W293 blank line contains whitespace
folium/plugins/mouse_position.py
Outdated
{% endmacro %} | ||
""") # noqa | ||
|
||
def __init__(self, position='bottomright', separator=' : ', |
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.
W291 trailing whitespace
folium/plugins/mouse_position.py
Outdated
""") # noqa | ||
|
||
def __init__(self, position='bottomright', separator=' : ', | ||
emptyString='Unavailable', lngFirst=False, |
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.
W291 trailing whitespace
folium/plugins/mouse_position.py
Outdated
|
||
def __init__(self, position='bottomright', separator=' : ', | ||
emptyString='Unavailable', lngFirst=False, | ||
numDigits=5, lngFormatter=None, latFormatter=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.
W291 trailing whitespace
folium/plugins/mouse_position.py
Outdated
emptyString='Unavailable', lngFirst=False, | ||
numDigits=5, lngFormatter=None, latFormatter=None, | ||
prefix=""): | ||
|
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.
W293 blank line contains whitespace
folium/plugins/mouse_position.py
Outdated
---------- | ||
position : str, default 'bottomright' | ||
Location of the widget. | ||
|
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.
W293 blank line contains whitespace
folium/plugins/mouse_position.py
Outdated
emptyString='Unavailable', lngFirst=False, | ||
numDigits=5, lngFormatter=None, latFormatter=None, | ||
prefix=""): | ||
|
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.
W293 blank line contains whitespace
folium/plugins/mouse_position.py
Outdated
empty_string='Unavailable', lng_first=False, | ||
num_digits=5, lng_formatter=None, lat_formatter=None, | ||
prefix=""): | ||
|
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.
W293 blank line contains whitespace
Finally got around to this: Choose between specifying all arguments or using kwargs Current convention in folium is to use Python style variable names throughout. That would mean that for example the arguments emptyString and lngFirst should become empty_string and lng_first up until they're added to the options dictionary. Any variable that's an explicit argument should also be listed in the docstring parameters. So apart from position the other arguments should also be listed. The fact you only included position in the docstring says something about the usefulness of the other arguments. You could decide to leave the other arguments out, and instead accept **kwargs and add those to the options. Then users can check out the original github project to see what those arguments are. Saves work, but is a bit lazy :) What do you want to do? Add an example Our current way of feature discovery is through an example gallery in Jupyter Notebooks. Please add an entry which shows how to use this plugin and its effect. Optionally add a test Not a strict necessity, but it would be nice if you can add a test for this module. You can check out the other plugin tests to see how they verify if the template is rendering correctly. Changelog Finally, just before merging, you should add a line in the changelog. Here's an example line from another plugin that was added: |
I made two changes:
Maybe you have anything to add to this? Otherwise I'll go merge this in a few days. |
folium/plugins/mouse_position.py
Outdated
@@ -0,0 +1,120 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
# CONVERTED TO PYTHON FROM: https://github.com/ardhi/Leaflet.MousePosition |
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.
You are using the plugin and not really converting it to Python.
I'm not a lawyer but I don't think this is necessary.
folium/plugins/mouse_position.py
Outdated
'if it is not in a Figure.') | ||
|
||
figure.header.add_child( | ||
JavascriptLink('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/c32f1c84/src/L.Control.MousePosition.js')) # noqa |
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 are already using noqa
so no need for the extra line here.
I have just one monor comment about the license header added and I'm +1 to merge this. |
folium/plugins/mouse_position.py
Outdated
"""Add a field that shows the coordinates of the mouse position. | ||
|
||
Uses the Leaflet plugin by Ardhi Lukianto under MIT license. | ||
https://github.com/ardhi/Leaflet.MousePosition |
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.
👍
Thanks @btozer! |
Original plugin from: Ardhi Lukianto
https://github.com/ardhi/Leaflet.MousePosition
MIT Licence
Copyright 2012 Ardhi Lukianto