Skip to content

Commit

Permalink
Merge 905b9cb into 13e6bab
Browse files Browse the repository at this point in the history
  • Loading branch information
elenatorro committed Aug 6, 2019
2 parents 13e6bab + 905b9cb commit b2c7b28
Show file tree
Hide file tree
Showing 4 changed files with 1,175 additions and 280 deletions.
280 changes: 0 additions & 280 deletions cartoframes/assets/templates/viz/map.js.j2

This file was deleted.

2 changes: 2 additions & 0 deletions cartoframes/viz/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .size_bins_layer import size_bins_layer
from .size_category_layer import size_category_layer
from .size_continuous_layer import size_continuous_layer
from .cluster_size_layer import cluster_size_layer
from .animation_layer import animation_layer


Expand All @@ -25,5 +26,6 @@ def _inspect(helper):
'size_bins_layer',
'size_category_layer',
'size_continuous_layer',
'cluster_size_layer',
'animation_layer'
]
85 changes: 85 additions & 0 deletions cartoframes/viz/helpers/cluster_size_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from __future__ import absolute_import

from ..layer import Layer


def cluster_size_layer(
source, value=None, resolution=32, title='', size=None,
color=None, description='', footer='',
legend=True, popup=True, widget=False, animate=None):
"""Helper function for quickly creating a size symbol map with
continuous size scaled by cluster.
Args:
source (:py:class:`Dataset <cartoframes.data.Dataset>` or str): Dataset
or text representing a table or query associated with user account.
value (str): Column to symbolize by.
title (str, optional): Title of legend.
size (str, optiona): Min/max size array in CARTO VL syntax. Default is
'[2, 40]' for point geometries and '[1, 10]' for lines.
color (str, optional): Hex value, rgb expression, or other valid
CARTO VL color. Defaults is '#FFB927' for point geometries and
'#4CC8A3' for lines.
description (str, optional): Description text legend placed under legend title.
footer (str, optional): Footer text placed under legend items.
legend (bool, optional): Display map legend: "True" or "False".
Set to "True" by default.
popup (bool, optional): Display popups on hover and click: "True" or "False".
Set to "True" by default.
widget (bool, optional): Display a widget for mapped data.
Set to "False" by default.
animate (str, optional): Animate features by date/time or other numeric field.
Returns:
cartoframes.viz.Layer: Layer styled by `value`.
Includes a legend, popup and widget on `value`.
"""
animation_filter = 'animation(linear(${}), 20, fade(1,1))'.format(animate) if animate else '1'

breakpoints = ', '.join([
'sqrt({0}^2)'.format(resolution / 8),
'sqrt({0}^2)'.format(resolution / 2),
'sqrt({0}^2)'.format(resolution)
])

clusterOperation = 'clusterCount()'

return Layer(
source,
style={
'point': {
'width': 'ramp(linear({0}, viewportMIN({1}), viewportMAX({2})), [{3}])'.format(
clusterOperation, clusterOperation, clusterOperation, breakpoints),
'color': 'opacity({0}, 0.8)'.format(color or '#FFB927'),
'strokeColor': 'opacity(#222, ramp(linear(zoom(), 0, 18),[0, 0.6]))',
'filter': animation_filter,
'resolution': '{0}'.format(resolution)
}
},
popup=popup and not animate and {
'hover': {
'title': title,
'value': clusterOperation
}
},
legend=legend and {
'type': {
'point': 'size-continuous-point'
},
'title': title,
'description': description,
'footer': footer
},
widgets=[
animate and {
'type': 'time-series',
'value': animate,
'title': 'Animation'
},
widget and {
'type': 'histogram',
'value': clusterOperation,
'title': 'Distribution'
}
]
)
Loading

0 comments on commit b2c7b28

Please sign in to comment.