Skip to content

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

Merged
merged 25 commits into from
Sep 3, 2018
Merged

Mouse Position plugin #916

merged 25 commits into from
Sep 3, 2018

Conversation

btozer
Copy link
Contributor

@btozer btozer commented Jul 19, 2018

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

@@ -41,6 +42,7 @@
'HeatMapWithTime',
'MarkerCluster',
'MeasureControl',
'MousePosition',

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

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

With the MIT License as below:
Copy link
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.

{% endmacro %}
""") # noqa

def __init__(self, position='bottomright', separator=' : ', emptyString='Unavailable', lngFirst=False, numDigits=5,
Copy link
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.


Parameters
----------
position: location of the widget
Copy link
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.


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
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
Copy link
Member

Conengmo commented Jul 21, 2018

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

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

----------
position : str, default 'bottomright'
Location of the widget.

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

{% endmacro %}
""") # noqa

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

Choose a reason for hiding this comment

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

W291 trailing whitespace

""") # noqa

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

Choose a reason for hiding this comment

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

W291 trailing whitespace


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

Choose a reason for hiding this comment

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

W291 trailing whitespace

emptyString='Unavailable', lngFirst=False,
numDigits=5, lngFormatter=None, latFormatter=None,
prefix=""):

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

----------
position : str, default 'bottomright'
Location of the widget.

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

emptyString='Unavailable', lngFirst=False,
numDigits=5, lngFormatter=None, latFormatter=None,
prefix=""):

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

empty_string='Unavailable', lng_first=False,
num_digits=5, lng_formatter=None, lat_formatter=None,
prefix=""):

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
Copy link
Contributor Author

btozer commented Aug 21, 2018

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
Copy link
Member

Conengmo commented Sep 2, 2018

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.

@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*-

# CONVERTED TO PYTHON FROM: https://github.com/ardhi/Leaflet.MousePosition
Copy link
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.

'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
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
Copy link
Member

ocefpaf commented Sep 2, 2018

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
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
Copy link
Member

Conengmo commented Sep 3, 2018

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