Skip to content

Mouse Position plugin - #916

Merged
Conengmo merged 25 commits into
python-visualization:masterfrom
btozer:master
Sep 3, 2018
Merged

Conengmo merged 25 commits into
python-visualization:masterfrom
btozer:master

Conversation

@btozer

@btozer btozer commented Jul 19, 2018

Copy link
Copy Markdown
Contributor

Original plugin from: Ardhi Lukianto
https://github.com/ardhi/Leaflet.MousePosition
MIT Licence
Copyright 2012 Ardhi Lukianto

Comment thread folium/plugins/__init__.py Outdated
'HeatMapWithTime',
'MarkerCluster',
'MeasureControl',
'MousePosition',

Copy link
Copy Markdown

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
Comment thread folium/plugins/mouse_position.py Outdated

https://github.com/ardhi/Leaflet.MousePosition

With the MIT License as below:

Copy link
Copy Markdown
Member

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.

Comment thread folium/plugins/mouse_position.py Outdated
{% endmacro %}
""") # noqa

def __init__(self, position='bottomright', separator=' : ', emptyString='Unavailable', lngFirst=False, numDigits=5,

Copy link
Copy Markdown
Member

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.

Comment thread folium/plugins/mouse_position.py Outdated

Parameters
----------
position: location of the widget

Copy link
Copy Markdown
Member

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.

Comment thread 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"""

Copy link
Copy Markdown
Member

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.

@Conengmo

Conengmo commented Jul 21, 2018 •

Copy link
Copy Markdown
Member

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 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:

- Added `FeatureGroupSubGroup` plugin (shtrom #875)

@Conengmo Conengmo mentioned this pull request Jul 21, 2018
Parameters doc string reformatted. 
Licence shifted to header. 
__init__ < 80 chars.

from jinja2 import Template

class MousePosition(MacroElement):

Copy link
Copy Markdown

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

Comment thread folium/plugins/mouse_position.py Outdated
----------
position : str, default 'bottomright'
Location of the widget.

Copy link
Copy Markdown

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

Comment thread folium/plugins/mouse_position.py Outdated
{% endmacro %}
""") # noqa

def __init__(self, position='bottomright', separator=' : ',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace

Comment thread folium/plugins/mouse_position.py Outdated
""") # noqa

def __init__(self, position='bottomright', separator=' : ',
emptyString='Unavailable', lngFirst=False,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace

Comment thread folium/plugins/mouse_position.py Outdated

def __init__(self, position='bottomright', separator=' : ',
emptyString='Unavailable', lngFirst=False,
numDigits=5, lngFormatter=None, latFormatter=None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace

Comment thread folium/plugins/mouse_position.py Outdated
emptyString='Unavailable', lngFirst=False,
numDigits=5, lngFormatter=None, latFormatter=None,
prefix=""):

Copy link
Copy Markdown

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

Comment thread folium/plugins/mouse_position.py Outdated
----------
position : str, default 'bottomright'
Location of the widget.

Copy link
Copy Markdown

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

Comment thread folium/plugins/mouse_position.py Outdated
emptyString='Unavailable', lngFirst=False,
numDigits=5, lngFormatter=None, latFormatter=None,
prefix=""):

Copy link
Copy Markdown

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

Comment thread folium/plugins/mouse_position.py Outdated
empty_string='Unavailable', lng_first=False,
num_digits=5, lng_formatter=None, lat_formatter=None,
prefix=""):

Copy link
Copy Markdown

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

@btozer

btozer commented Aug 21, 2018 •

Copy link
Copy Markdown
Contributor Author

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.
-> Done

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.
-> Done

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?
-> Added all the parameters to the docstring.

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.
-> Done see examples/plugin-MousePosition.ipynb

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.
-> Skipped this

Changelog

Finally, just before merging, you should add a line in the changelog. Here's an example line from another plugin that was added:
-> Done - Added MousePosition plugin (btozer #916)

@Conengmo

Conengmo commented Sep 2, 2018

Copy link
Copy Markdown
Member

I made two changes:

  • The formatter option didn't work, because the functions were passed as string, where they should be Javascript functions. So instead I load them directly into the template. Note that in a Jupyter notebook this still gives an error, but I'm not really interested in solving that :) Instead I added an example in the docstring.
  • In the example notebook I put the second example in a new map, because the two MousePosition objects were interfering. I noticed that because the lng_first option was not working.

Maybe you have anything to add to this? Otherwise I'll go merge this in a few days.

Comment thread folium/plugins/mouse_position.py Outdated
@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*-

# CONVERTED TO PYTHON FROM: https://github.com/ardhi/Leaflet.MousePosition

Copy link
Copy Markdown
Member

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.

Comment thread 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

Copy link
Copy Markdown
Member

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.

@ocefpaf

ocefpaf commented Sep 2, 2018

Copy link
Copy Markdown
Member

Maybe you have anything to add to this? Otherwise I'll go merge this in a few days.

I have just one monor comment about the license header added and I'm +1 to merge this.

"""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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Conengmo
Conengmo merged commit 1ea034a into python-visualization:master Sep 3, 2018
@Conengmo

Conengmo commented Sep 3, 2018

Copy link
Copy Markdown
Member

Thanks @btozer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants