-
Notifications
You must be signed in to change notification settings - Fork 64
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
677 popup api #682
677 popup api #682
Conversation
cartoframes/vis/popup.py
Outdated
output = [] | ||
for item in array: | ||
if isinstance(item, str): | ||
name = gen_variable_name(item) |
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.
local variable 'name' is assigned to but never used
cartoframes/vis/popup.py
Outdated
""" | ||
|
||
def __init__(self, data=None): | ||
self._init_popup(data) |
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.
trailing whitespace
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.
Looks good, other than the lack of tests and the formatting which I think we can leave as-is right now
attrs.forEach((item) => { | ||
let value = feature.variables[item.name].value; | ||
if (typeof value === 'number') { | ||
if (Math.abs(value) > 1000) { |
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.
This is fine for now, but we should probably use a proper formatter for this
Tests added / updated. |
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.
Just reviewed a couple of typos and a suggestion, the rest looks ✨
cartoframes/vis/layer.py
Outdated
popup (dict, :py:class:`Popup <cartoframes.vis.Popup>`, optional): | ||
This option adds interactivity (click and hover) to a layer to show popups. | ||
The columns to be shown must be added in a list format for each event. It | ||
must be written using `CARTL VL expressions syntax |
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.
typo: using CARTO VL expressions syntax
cartoframes/vis/popup.py
Outdated
Args: | ||
data (dict): The popup definition for a layer. It contains the information | ||
to show a popup on 'click' and 'hover' events with the attributes provided | ||
in the definition using the `VL expressions syntax |
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.
typo: using the CARTO VL expressions syntax (maybe is not a typo, but I wouldn't use only VL)
raise ValueError('Wrong popup input') | ||
return output | ||
|
||
def get_variables(self): |
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.
As a suggestion, I think _get_vars
method shouldn't modify the input since it's supposed, by its name, to return some variables. I would do something like:
def _parse_popup_variables(self, variables):
popup_variables = {}
# same but using o popup_variables instead of variables and variables instead of array
return popup_variables
def get_variables(self):
return self._parse_vars(self._click + self._hover)
Since the values would be overwritten we could use a Set ( return self._parse_vars(list(set(self._click + self._hover)))
), but I think this is only available in Python 3.
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.
True. This is a nice refactor :)
There is not a problem with repeated variables because each key is related 1:1 with the value.
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.
Updated!
'v8e0f74': '$name' | ||
}) | ||
|
||
def test_wrong_attribute(self): |
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.
Nice tests!!
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.
LGTM 👍
Related to #677.