Skip to content

Commit

Permalink
allow table to specify radius for circles
Browse files Browse the repository at this point in the history
  • Loading branch information
papajohn committed Mar 23, 2016
1 parent 6d6cd17 commit 6a094ed
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions datascience/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,13 @@ def _convert_point(cls, feature):
return cls(lat, lon)

@classmethod
def map(cls, latitudes, longitudes, labels=None, colors=None, **kwargs):
"""Return markers from columns of coordinates, labels, & colors."""
def map(cls, latitudes, longitudes, labels=None, colors=None, radii=None, **kwargs):
"""Return markers from columns of coordinates, labels, & colors.
The radii column is not applicable to markers, but sets circle radius.
"""
assert len(latitudes) == len(longitudes)
assert radii is None or hasattr(cls, '_has_radius'), "A " + cls.__name__ + " has no radius"
inputs = [latitudes, longitudes]
if labels is not None:
assert len(labels) == len(latitudes)
Expand All @@ -428,6 +432,9 @@ def map(cls, latitudes, longitudes, labels=None, colors=None, **kwargs):
if colors is not None:
assert len(colors) == len(latitudes)
inputs.append(colors)
if radii is not None:
assert len(radii) == len(latitudes)
inputs.append(radii)
ms = [cls(*args, **kwargs) for args in zip(*inputs)]
return Map(ms)

Expand All @@ -448,10 +455,22 @@ class Circle(Marker):
fill_opacity: float, default 0.6
Circle fill opacity
For example, to draw three circles:
t = Table().with_columns([
'lat', [37.8, 38, 37.9],
'lon', [-122, -122.1, -121.9],
'label', ['one', 'two', 'three'],
'color', ['red', 'green', 'blue'],
'radius', [3000, 4000, 5000],
])
Circle.map_table(t)
"""

_map_method_name = 'circle_marker'
_color_param = 'fill_color'
_has_radius = True

def __init__(self, lat, lon, popup='', color='blue', radius=10, **kwargs):
super().__init__(lat, lon, popup, color, radius=radius, line_color=None, **kwargs)
Expand Down

0 comments on commit 6a094ed

Please sign in to comment.