Skip to content

Commit

Permalink
Merge pull request #1448 from CartoDB/fix/1446-set-ranges-to-size
Browse files Browse the repository at this point in the history
Use size instead of range
  • Loading branch information
elenatorro committed Jan 8, 2020
2 parents b4c89a4 + 0bf96e1 commit 77dd9ba
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 41 deletions.
16 changes: 8 additions & 8 deletions cartoframes/viz/layers/size_bins_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

def size_bins_layer(
source, value, title='', method='quantiles', bins=5,
breaks=None, ranges=None, color=None, opacity=None,
stroke_width=None, stroke_color=None, description='',
footer='', legend=True, popups=True, widget=False, animate=None, credentials=None):
breaks=None, color=None, size=None, stroke_width=None,
stroke_color=None, opacity=None, description='', footer='',
legend=True, popups=True, widget=False, animate=None, credentials=None):
"""Helper function for quickly creating a size symbol map with
classification method/buckets.
Expand All @@ -19,15 +19,15 @@ def size_bins_layer(
Default is "quantiles".
bins (int, optional): Number of size classes (bins) for map. Default is 5.
breaks (list<int>, optional): Assign manual class break values.
ranges (str, optional): Min/max size array as a string. Default is
'[2, 14]' for point geometries and '[1, 10]' for lines.
color (str, optional): Hex, rgb or named color value. Default is '#EE5D5A' for point geometries and
'#4CC8A3' for lines.
opacity (float, optional): Opacity value for point color and line features.
Default is '0.8'.
size (str, optional): Min/max size array as a string. Default is
'[2, 14]' for point geometries and '[1, 10]' for lines.
stroke_width (int, optional): Size of the stroke on point features.
stroke_color (str, optional): Color of the stroke on point features.
Default is '#222'.
opacity (float, optional): Opacity value for point color and line features.
Default is '0.8'.
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".
Expand All @@ -51,7 +51,7 @@ def size_bins_layer(
return Layer(
source,
style=size_bins_style(
value, method, bins, breaks, ranges, color, opacity, stroke_width, stroke_color, animate),
value, method, bins, breaks, size, color, opacity, stroke_width, stroke_color, animate),
legend=legend and {
'type': {
'point': 'size-bins-point',
Expand Down
14 changes: 7 additions & 7 deletions cartoframes/viz/layers/size_category_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

def size_category_layer(
source, value, title='', top=5, cat=None,
ranges=None, color=None, opacity=None, stroke_width=None,
stroke_color=None, description='', footer='',
color=None, size=None, stroke_width=None,
stroke_color=None, opacity=None, description='', footer='',
legend=True, popups=True, widget=False, animate=None, credentials=None):
"""Helper function for quickly creating a size category layer.
Expand All @@ -17,15 +17,15 @@ def size_category_layer(
top (int, optional): Number of size categories for layer. Default is
5. Valid values range from 1 to 16.
cat (str, optional): Category list as a string.
ranges (str, optional): Min/max size array. Default is
'[2, 20]' for point geometries and '[1, 10]' for lines.
color (str, optional): Hex, rgb or named color value. Default is '#F46D43' for point geometries and
'#4CC8A3' for lines.
opacity (float, optional): Opacity value for point color and line features.
Default is '0.8'.
size (str, optional): Min/max size array. Default is
'[2, 20]' for point geometries and '[1, 10]' for lines.
stroke_width (int, optional): Size of the stroke on point features.
stroke_color (str, optional): Color of the stroke on point features.
Default is '#222'.
opacity (float, optional): Opacity value for point color and line features.
Default is '0.8'.
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".
Expand All @@ -49,7 +49,7 @@ def size_category_layer(
return Layer(
source,
style=size_category_style(
value, top, cat, ranges, color, opacity, stroke_color, stroke_width, animate),
value, top, cat, size, color, opacity, stroke_color, stroke_width, animate),
legend=legend and {
'type': {
'point': 'size-category-point',
Expand Down
12 changes: 6 additions & 6 deletions cartoframes/viz/layers/size_continuous_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def size_continuous_layer(
source, value, title='', range_min=None, range_max=None, ranges=None, color=None,
source, value, title='', range_min=None, range_max=None, size=None, color=None,
opacity=None, stroke_width=None, stroke_color=None, description='', footer='',
legend=True, popups=True, widget=False, animate=None, credentials=None):
"""Helper function for quickly creating a size symbol map with
Expand All @@ -14,14 +14,14 @@ def size_continuous_layer(
or text representing a table or query associated with user account.
value (str): Column to symbolize by.
title (str, optional): Title of legend and popup hover.
color (str, optional): Hex, rgb or named color value. Defaults is '#FFB927' for point geometries and
'#4CC8A3' for lines.
size (str, optional): Min/max size array as a string. Default is
'[2, 40]' for point geometries and '[1, 10]' for lines.
range_min (int, optional): The minimum value of the data range for the continuous
size ramp. Defaults to the globalMIN of the dataset.
range_max (int, optional): The maximum value of the data range for the continuous
size ramp. Defaults to the globalMAX of the dataset.
ranges (str, optional): Min/max size array as a string. Default is
'[2, 40]' for point geometries and '[1, 10]' for lines.
color (str, optional): Hex, rgb or named color value. Defaults is '#FFB927' for point geometries and
'#4CC8A3' for lines.
opacity (float, optional): Opacity value for point color and line features.
Default is '0.8'.
stroke_width (int, optional): Size of the stroke on point features.
Expand Down Expand Up @@ -50,7 +50,7 @@ def size_continuous_layer(
return Layer(
source,
style=size_continuous_style(
value, range_min, range_max, ranges, color, opacity, stroke_color, stroke_width, animate),
value, range_min, range_max, size, color, opacity, stroke_color, stroke_width, animate),
legend=legend and {
'type': {
'point': 'size-continuous-point',
Expand Down
2 changes: 1 addition & 1 deletion cartoframes/viz/styles/color_continuous_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def color_continuous_style(
value, range_min=None, range_max=None, palette=None, size=None, opacity=None,
value, size=None, range_min=None, range_max=None, palette=None, opacity=None,
stroke_color=None, stroke_width=None, animate=None):
"""Helper function for quickly creating a color continuous style.
Expand Down
8 changes: 4 additions & 4 deletions cartoframes/viz/styles/size_bins_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def size_bins_style(
value, method='quantiles', bins=5, breaks=None, ranges=None, color=None,
value, method='quantiles', bins=5, breaks=None, size=None, color=None,
opacity=None, stroke_width=None, stroke_color=None, animate=None):
"""Helper function for quickly creating a size bind style with
classification method/buckets.
Expand All @@ -17,7 +17,7 @@ def size_bins_style(
Default is "quantiles".
bins (int, optional): Number of size classes (bins) for map. Default is 5.
breaks (list<int>, optional): Assign manual class break values.
ranges (int, optional): Min/max size array as a string. Default is
size (int, optional): Min/max size array as a string. Default is
'[2, 14]' for point geometries and '[1, 10]' for lines.
color (str, optional): Hex, rgb or named color value. Default is '#EE5D5A' for point geometries and
'#4CC8A3' for lines.
Expand Down Expand Up @@ -53,7 +53,7 @@ def size_bins_style(
get_value(color, 'color', 'point'),
get_value(opacity, 0.8)),
'width': 'ramp({0}(${1}, {2}), {3})'.format(
func, value, breaks or bins, ranges or [2, 14]),
func, value, breaks or bins, size or [2, 14]),
'strokeColor': get_value(stroke_color, 'strokeColor', 'point'),
'strokeWidth': get_value(stroke_width, 'strokeWidth', 'point'),
'filter': animation_filter
Expand All @@ -63,7 +63,7 @@ def size_bins_style(
get_value(color, 'color', 'line'),
get_value(opacity, 0.8)),
'width': 'ramp({0}(${1}, {2}), {3})'.format(
func, value, breaks or bins, ranges or [1, 10]),
func, value, breaks or bins, size or [1, 10]),
'filter': animation_filter
}
}
Expand Down
8 changes: 4 additions & 4 deletions cartoframes/viz/styles/size_category_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def size_category_style(
value, top=5, cat=None, ranges=None, color=None, opacity=None,
value, top=5, cat=None, size=None, color=None, opacity=None,
stroke_color=None, stroke_width=None, animate=None):
"""Helper function for quickly creating a size category style.
Expand All @@ -15,7 +15,7 @@ def size_category_style(
top (int, optional): Number of size categories. Default is 5. Values
can range from 1 to 16.
cat (list<str>, optional): Category list as a string.
ranges (str, optional): Min/max size array as a string. Default is
size (str, optional): Min/max size array as a string. Default is
'[2, 20]' for point geometries and '[1, 10]' for lines.
color (str, optional): hex, rgb or named color value.
Default is '#F46D43' for point geometries and '#4CC8A3' for lines.
Expand All @@ -40,7 +40,7 @@ def size_category_style(
get_value(color, 'color', 'point'),
get_value(opacity, 1)),
'width': 'ramp({0}(${1}, {2}), {3})'.format(
func, value, cat or top, ranges or [2, 20]),
func, value, cat or top, size or [2, 20]),
'strokeColor': get_value(stroke_color, 'strokeColor', 'point'),
'strokeWidth': get_value(stroke_width, 'strokeWidth', 'point'),
'filter': animation_filter
Expand All @@ -50,7 +50,7 @@ def size_category_style(
get_value(color, 'color', 'line'),
get_value(opacity, 1)),
'width': 'ramp({0}(${1}, {2}), {3})'.format(
func, value, cat or top, ranges or [1, 10]),
func, value, cat or top, size or [1, 10]),
'filter': animation_filter
}
}
Expand Down
14 changes: 7 additions & 7 deletions cartoframes/viz/styles/size_continuous_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@


def size_continuous_style(
value, range_min=None, range_max=None, ranges=None, color=None, opacity=None,
value, size=None, range_min=None, range_max=None, color=None, opacity=None,
stroke_color=None, stroke_width=None, animate=None, credentials=None):
"""Helper function for quickly creating a size continuous style.
Args:
value (str): Column to symbolize by.
size (str, optional): Min/max size array as a string. Default is
'[2, 40]' for point geometries and '[1, 10]' for lines.
range_min (int, optional): The minimum value of the data range for the continuous
size ramp. Defaults to the globalMIN of the dataset.
range_max (int, optional): The maximum value of the data range for the continuous
size ramp. Defaults to the globalMAX of the dataset.
ranges (str, optional): Min/max size array as a string. Default is
'[2, 40]' for point geometries and '[1, 10]' for lines.
color (str, optional): hex, rgb or named color value.
Defaults is '#FFB927' for point geometries and '#4CC8A3' for lines.
opacity (float, optional): Opacity value for point color and line features.
Expand All @@ -42,24 +42,24 @@ def size_continuous_style(
data = {
'point': {
'@width_value': 'ramp(linear(${0}, {1}, {2}), {3})'.format(
value, range_min, range_max, ranges or [2, 40]),
value, range_min, range_max, size or [2, 40]),
'color': 'opacity({0}, {1})'.format(
get_value(color, 'color', 'point'),
get_value(opacity, 0.8)),
'width': 'ramp(linear(sqrt(${0}), sqrt({1}), sqrt({2})), {3})'.format(
value, range_min, range_max, ranges or [2, 40]),
value, range_min, range_max, size or [2, 40]),
'strokeColor': get_value(stroke_color, 'strokeColor', 'point'),
'strokeWidth': get_value(stroke_width, 'strokeWidth', 'point'),
'filter': animation_filter
},
'line': {
'@width_value': 'ramp(linear(${0}, {1}, {2}), {3})'.format(
value, range_min, range_max, ranges or [1, 10]),
value, range_min, range_max, size or [1, 10]),
'color': 'opacity({0}, {1})'.format(
get_value(color, 'color', 'line'),
get_value(opacity, 0.8)),
'width': 'ramp(linear(${0}, {1}, {2}), {3})'.format(
value, range_min, range_max, ranges or [1, 10]),
value, range_min, range_max, size or [1, 10]),
'filter': animation_filter
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/legends/size_category_legend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@
"source": [
"Layer(\n",
" 'spain_populated_places',\n",
" size_category_style('featurecla', cat=['Populated place','Admin-1 capital', 'Admin-0 capital'], ranges=[3,7,15]),\n",
" size_category_style('featurecla', cat=['Populated place','Admin-1 capital', 'Admin-0 capital'], size=[3,7,15]),\n",
" legends=size_category_legend(\n",
" title='Spanish Cities',\n",
" footer='Source: Natural Earth'\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/legends/size_continuous_legend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@
"source": [
"Layer(\n",
" 'sf_nbhd_crime',\n",
" size_continuous_style('value', ranges=[8,40]),\n",
" size_continuous_style('value', size=[8,40]),\n",
" legends=size_continuous_legend(\n",
" title='Crime Counts',\n",
" description='by neighborhood',\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/styles/size_category_style.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@
" size_category_style(\n",
" 'type',\n",
" cat=['Major Highway', 'Secondary Highway', 'Track', 'Ferry'],\n",
" ranges=[5,3,2,1]\n",
" size=[5,3,2,1]\n",
" )\n",
")"
]
Expand Down
2 changes: 1 addition & 1 deletion examples/styles/size_continuous_style.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@
" 'total_pop',\n",
" range_min=100000,\n",
" range_max=5000000,\n",
" ranges=[5,50],\n",
" size=[5,50],\n",
" color='blue',\n",
" stroke_color='turquoise',\n",
" stroke_width=1,\n",
Expand Down

0 comments on commit 77dd9ba

Please sign in to comment.