Skip to content

Re-factor Circle and CircleMarker #683

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 4 commits into from
Aug 26, 2017

Conversation

ocefpaf
Copy link
Member

@ocefpaf ocefpaf commented Aug 25, 2017

This PR is the first of many that:

  • re-implements the features using leaflet's defaults
  • factor out the parsing of the options so we can re-use (Path)
  • eliminate the bogus tests that relies on updating the template (new tests are still pending!)

If this works nicely I plan to do the same for all feature.py.

Closes #430, #524, and #569

The fill opacity of the marker, between 0. and 1.
popup: string or folium.Popup, default None
Input text or visualization for object.

See http://leafletjs.com/reference-1.2.0.html#path for more otions.
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of overloading the docstring I'll leave only the main options here and refer to the original page for more.

def __init__(self, location, radius=10, popup=None, **kw):
super(Circle, self).__init__(_validate_location(location), popup=popup)
self._name = 'circle'
options = _parse_path(**kw)
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't want to make this overly complex. Just a simple function to parse the options.
Ideally this function could validade the options as well.

options = _parse_path(**kw)

options.update({'radius': radius})
self.options = json.dumps(options, sort_keys=True, indent=2)
Copy link
Member Author

Choose a reason for hiding this comment

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

First step towards a cleaner HTML. I want to eliminate blank spaces and bad indentations.

}
)
.addTo({{this._parent.get_name()}});
{{ this.options }}
Copy link
Member Author

Choose a reason for hiding this comment

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

We should use json.dumps everywhere to reduce the amount of code like 'true' if something else 'false'.

weight: int, default 2
Stroke weight in pixels
fill_color: str, default 'black'
fill: bool, default False
Copy link
Member Author

Choose a reason for hiding this comment

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

That is different from the current defaults! Here I applied leaflet's defaults everywhere.

@@ -1,6 +0,0 @@
var {{ circle }} = L.circleMarker([{{ lat }}, {{ lon }}], {
Copy link
Member Author

Choose a reason for hiding this comment

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

First step to eliminate all these render templates.

assert circle.get_bounds() == expected_bounds
assert json.dumps(circle.to_dict()) == circle.to_json()
assert circle.location == [-27.551667, -48.478889]
assert circle.options == json.dumps(options, sort_keys=True, indent=2)
Copy link
Member Author

Choose a reason for hiding this comment

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

We should follow this example to re-factor the tests in features.py.

@ocefpaf ocefpaf merged commit 208c99d into python-visualization:master Aug 26, 2017
@ocefpaf ocefpaf deleted the refactor_circle branch August 26, 2017 15:37
sanga pushed a commit to sanga/folium that referenced this pull request Oct 24, 2017
* refactor circle

* add tests

* fix typo

* update changelog
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.

1 participant