Repository: CartoDB/cartoframes
Pull request #1450 (2020-01-08 09:51:59)

Update legend properties
Related issue https://github.com/CartoDB/cartoframes/issues/1442


Patch:
diff --git a/cartoframes/viz/constants.py b/cartoframes/viz/constants.py
index e4221af2..abd6b9e5 100644
--- a/cartoframes/viz/constants.py
+++ b/cartoframes/viz/constants.py
@@ -29,16 +29,16 @@ STYLE_PROPERTIES = [
 
 LEGEND_PROPERTIES = [
     'color',
-    'stroke-color',
+    'stroke_color',
     'size',
-    'stroke-width'
+    'stroke_width'
 ]
 
 VIZ_PROPERTIES_MAP = {
     'color': 'color',
-    'stroke-color': 'strokeColor',
+    'stroke_color': 'strokeColor',
     'size': 'width',
-    'stroke-width': 'strokeWidth'
+    'stroke_width': 'strokeWidth'
 }
 
 LEGEND_TYPES = [
diff --git a/cartoframes/viz/legends/color_bins_legend.py b/cartoframes/viz/legends/color_bins_legend.py
index 1c27e25e..c80da60c 100644
--- a/cartoframes/viz/legends/color_bins_legend.py
+++ b/cartoframes/viz/legends/color_bins_legend.py
@@ -12,7 +12,7 @@ def color_bins_legend(title='', description='', footer='', prop='color',
             Description in legend.
         footer (str, optional):
             Footer of legend. This is often used to attribute data sources.
-        prop (str, optional): Allowed properties are 'color' and 'stroke-color'.
+        prop (str, optional): Allowed properties are 'color' and 'stroke_color'.
             It is 'color' by default.
         variable (str, optional):
             If the information in the legend depends on a different value than the
diff --git a/cartoframes/viz/legends/color_category_legend.py b/cartoframes/viz/legends/color_category_legend.py
index f9e9175d..2a8fa31e 100644
--- a/cartoframes/viz/legends/color_category_legend.py
+++ b/cartoframes/viz/legends/color_category_legend.py
@@ -12,7 +12,7 @@ def color_category_legend(title='', description='', footer='', prop='color',
             Description in legend.
         footer (str, optional):
             Footer of legend. This is often used to attribute data sources.
-        prop (str, optional): Allowed properties are 'color' and 'stroke-color'.
+        prop (str, optional): Allowed properties are 'color' and 'stroke_color'.
             It is 'color' by default.
         variable (str, optional):
             If the information in the legend depends on a different value than the
diff --git a/cartoframes/viz/legends/color_continuous_legend.py b/cartoframes/viz/legends/color_continuous_legend.py
index 609784a3..7d185567 100644
--- a/cartoframes/viz/legends/color_continuous_legend.py
+++ b/cartoframes/viz/legends/color_continuous_legend.py
@@ -12,7 +12,7 @@ def color_continuous_legend(title='', description='', footer='', prop='color',
             Description in legend.
         footer (str, optional):
             Footer of legend. This is often used to attribute data sources.
-        prop (str, optional): Allowed properties are 'color' and 'stroke-color'.
+        prop (str, optional): Allowed properties are 'color' and 'stroke_color'.
             It is 'color' by default.
         variable (str, optional):
             If the information in the legend depends on a different value than the
diff --git a/cartoframes/viz/legends/size_bins_legend.py b/cartoframes/viz/legends/size_bins_legend.py
index ed1e2f8f..7d04ba9a 100644
--- a/cartoframes/viz/legends/size_bins_legend.py
+++ b/cartoframes/viz/legends/size_bins_legend.py
@@ -12,7 +12,7 @@ def size_bins_legend(title='', description='', footer='', prop='size',
             Description in legend.
         footer (str, optional):
             Footer of legend. This is often used to attribute data sources.
-        prop (str, optional): Allowed properties are 'size' and 'stroke-width'.
+        prop (str, optional): Allowed properties are 'size' and 'stroke_width'.
             It is 'size' by default.
         variable (str, optional):
             If the information in the legend depends on a different value than the
diff --git a/cartoframes/viz/legends/size_category_legend.py b/cartoframes/viz/legends/size_category_legend.py
index e3221dbe..2307a588 100644
--- a/cartoframes/viz/legends/size_category_legend.py
+++ b/cartoframes/viz/legends/size_category_legend.py
@@ -12,7 +12,7 @@ def size_category_legend(title='', description='', footer='', prop='size',
             Description in legend.
         footer (str, optional):
             Footer of legend. This is often used to attribute data sources.
-        prop (str, optional): Allowed properties are 'size' and 'stroke-width'.
+        prop (str, optional): Allowed properties are 'size' and 'stroke_width'.
             It is 'size' by default.
         variable (str, optional):
             If the information in the legend depends on a different value than the
diff --git a/docs/developers/migrations/rc1.md b/docs/developers/migrations/rc1.md
index 99181a73..18aae63e 100644
--- a/docs/developers/migrations/rc1.md
+++ b/docs/developers/migrations/rc1.md
@@ -235,9 +235,9 @@ Map(
 Available properties for legends are changed to:
 
 * "color" -> "color"
-* "strokeColor" -> "stroke-color"
+* "strokeColor" -> "stroke_color"
 * "width" -> "size"
-* "strokeWidth" -> "stroke-width"
+* "strokeWidth" -> "stroke_width"
 
 * From:
 
@@ -260,7 +260,7 @@ Map(
   Layer(
     'table_name',
     style=color_category_style('column_name'),
-    legends=color_category_legend('color-bins', title='Legend Title', prop='stroke-color')
+    legends=color_category_legend('color-bins', title='Legend Title', prop='stroke_color')
   )
 )
 ```
diff --git a/examples/legends/size_bins_legend.ipynb b/examples/legends/size_bins_legend.ipynb
index dae4a0f7..3523b74a 100644
--- a/examples/legends/size_bins_legend.ipynb
+++ b/examples/legends/size_bins_legend.ipynb
@@ -6,7 +6,7 @@
    "source": [
     "# Size bins legend\n",
     "\n",
-    "The `size-bins` type draws a classed legend based on point or line data using either the `size` (default) or `stroke-width` property of your visualization.\n",
+    "The `size-bins` type draws a classed legend based on point or line data using either the `size` (default) or `stroke_width` property of your visualization.\n",
     "\n",
     "To view available legend parameters, run `help(size_bins_legend)`\n",
     "\n",
diff --git a/examples/legends/size_category_legend.ipynb b/examples/legends/size_category_legend.ipynb
index 21f799ad..c0c80fc5 100644
--- a/examples/legends/size_category_legend.ipynb
+++ b/examples/legends/size_category_legend.ipynb
@@ -6,7 +6,7 @@
    "source": [
     "# Size category legend\n",
     "\n",
-    "The `size-category` type draws a legend based on categorical data and geometry type using either the `size` (default) or `stroke-width` property of your visualization.\n",
+    "The `size-category` type draws a legend based on categorical data and geometry type using either the `size` (default) or `stroke_width` property of your visualization.\n",
     "\n",
     "To view available legend parameters, run `help(size_category_legend)`\n",
     "\n",
diff --git a/examples/legends/size_continuous_legend.ipynb b/examples/legends/size_continuous_legend.ipynb
index a8cbef77..46fac2c8 100644
--- a/examples/legends/size_continuous_legend.ipynb
+++ b/examples/legends/size_continuous_legend.ipynb
@@ -6,7 +6,7 @@
    "source": [
     "# Size continuous legend\n",
     "\n",
-    "The `size-continuous` type draws an unclassed legend based on your data's geometry using either the `size` (default) or `stroke-width` property of your visualization.\n",
+    "The `size-continuous` type draws an unclassed legend based on your data's geometry using either the `size` (default) or `stroke_width` property of your visualization.\n",
     "\n",
     "To view available legend parameters, run `help(size_continuous_legend)`\n",
     "\n",
diff --git a/examples/legends/stroke_color_legend.ipynb b/examples/legends/stroke_color_legend.ipynb
index 40bb9b5f..78c1acd3 100644
--- a/examples/legends/stroke_color_legend.ipynb
+++ b/examples/legends/stroke_color_legend.ipynb
@@ -6,9 +6,9 @@
    "source": [
     "# Use stroke color for legend\n",
     "\n",
-    "For any color-based legend type, you can use either the `color` or `stroke-color` property of your visualization to draw legend items using the `prop` parameter.\n",
+    "For any color-based legend type, you can use either the `color` or `stroke_color` property of your visualization to draw legend items using the `prop` parameter.\n",
     "\n",
-    "In this example, displaying the top 5 tree species in San Francisco, the legend is set to read from the `stroke-color` property."
+    "In this example, displaying the top 5 tree species in San Francisco, the legend is set to read from the `stroke_color` property."
    ]
   },
   {
@@ -958,7 +958,7 @@
     "    strokeWidth: 1.5\n",
     "    ''',\n",
     "    legends=color_category_legend(\n",
-    "        prop='stroke-color',\n",
+    "        prop='stroke_color',\n",
     "        title='Trees in San Francisco',\n",
     "        description='Top 5 species',\n",
     "        footer='Data: City of SF'\n",


Test patch:
diff --git a/tests/unit/viz/test_legend.py b/tests/unit/viz/test_legend.py
index e0ced1ad..91cc8c57 100644
--- a/tests/unit/viz/test_legend.py
+++ b/tests/unit/viz/test_legend.py
@@ -11,14 +11,14 @@ class TestLegend(object):
     def test_legend_init_properties(self):
         """Legend should be properly initialized when passing properties"""
         legend = Legend('color-category',
-                        prop='stroke-color',
+                        prop='stroke_color',
                         title='[title]',
                         description='[description]',
                         footer='[footer]',
                         dynamic=False)
 
         assert legend._type == 'color-category'
-        assert legend._prop == 'stroke-color'
+        assert legend._prop == 'stroke_color'
         assert legend._title == '[title]'
         assert legend._description == '[description]'
         assert legend._footer == '[footer]'
@@ -57,7 +57,7 @@ class TestLegend(object):
     def test_wrong_prop(self):
         """Legend should raise an error if legend prop is not valid"""
         msg = 'Legend property "xxx" is not valid. Valid legend properties are: ' + \
-            'color, stroke-color, size, stroke-width.'
+            'color, stroke_color, size, stroke_width.'
         with pytest.raises(ValueError) as e:
             Legend('color-category', prop='xxx').get_info()
         assert str(e.value) == msg