Skip to content

Commit

Permalink
Merge 612488d into 53ae818
Browse files Browse the repository at this point in the history
  • Loading branch information
elenatorro committed Sep 2, 2019
2 parents 53ae818 + 612488d commit 3db207f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 31 deletions.
7 changes: 3 additions & 4 deletions cartoframes/assets/src/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ var init = (function () {

function createLegend(layer, legendData, layerIndex, mapIndex=0) {
const element = document.querySelector(`#layer${layerIndex}_map${mapIndex}_legend`);

if (legendData.prop) {
const config = { othersLabel: 'Others' }; // TODO: i18n
const prop = legendData.prop;
const dynamic = legendData.dynamic;
const opts = { format, config, dynamic };
const variable = legendData.variable;
const opts = { format, config, dynamic, variable };

if (legendData.type.startsWith('size-continuous')) {
config.samples = 4;
Expand Down Expand Up @@ -535,8 +536,6 @@ var init = (function () {
const container = mapIndex !== undefined ? `map-${mapIndex}` : 'map';
const map = createMap(container, basemapStyle, settings.bounds, settings.mapboxtoken);

console.log('!!! settings', settings);

if (settings.show_info) {
updateViewport(map);
}
Expand Down
5 changes: 3 additions & 2 deletions cartoframes/assets/src/legends.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ export function createDefaultLegend(layers) {

export function createLegend(layer, legendData, layerIndex, mapIndex=0) {
const element = document.querySelector(`#layer${layerIndex}_map${mapIndex}_legend`);

if (legendData.prop) {
const config = { othersLabel: 'Others' }; // TODO: i18n
const prop = legendData.prop;
const dynamic = legendData.dynamic;
const opts = { format, config, dynamic };
const variable = legendData.variable;
const opts = { format, config, dynamic, variable };

if (legendData.type.startsWith('size-continuous')) {
config.samples = 4;
Expand Down
3 changes: 3 additions & 0 deletions cartoframes/viz/helpers/size_continuous_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def size_continuous_layer(
source,
style={
'point': {
'@width_value': 'ramp(linear(${0}, globalMin(${0}), globalMax(${0})), {1})'.format(
value, size or [2, 40]),
'width': 'ramp(linear(sqrt(${0}), sqrt(globalMin(${0})), sqrt(globalMax(${0}))), {1})'.format(
value, size or [2, 40]),
'color': 'opacity({0}, 0.8)'.format(
Expand Down Expand Up @@ -67,6 +69,7 @@ def size_continuous_layer(
'line': 'size-continuous-line',
'polygon': 'size-continuous-polygon'
},
'variable': 'width_value',
'title': title or value,
'description': description,
'footer': footer
Expand Down
3 changes: 3 additions & 0 deletions cartoframes/viz/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, f_arg, **kwargs):
def _init_legend(self, data, legend_type=None):
self._type = ''
self._prop = ''
self._variable = ''
self._dynamic = True
self._title = ''
self._description = ''
Expand All @@ -45,6 +46,7 @@ def _init_legend(self, data, legend_type=None):
if data is not None:
self._type = legend_type if legend_type else data.get('type', '')
self._prop = data.get('prop', '')
self._variable = data.get('variable', '')
self._dynamic = data.get('dynamic', True)
self._title = data.get('title', '')
self._description = data.get('description', '')
Expand All @@ -58,6 +60,7 @@ def get_info(self, geom_type=None):
return {
'type': _type,
'prop': _prop,
'variable': self._variable,
'dynamic': self._dynamic,
'title': self._title,
'description': self._description,
Expand Down
6 changes: 0 additions & 6 deletions cartoframes/viz/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ def _serialize_properties(self, properties={}):
for prop in properties:
if prop == 'vars':
continue
if prop not in constants.STYLE_PROPERTIES:
raise ValueError(
'Style property "{0}" is not valid. Valid style properties are: {1}'.format(
prop,
', '.join(constants.STYLE_PROPERTIES)
))
output += '{name}: {value}\n'.format(
name=prop,
value=properties.get(prop)
Expand Down
12 changes: 1 addition & 11 deletions test/viz/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,4 @@ def test_style_str(self):
self.assertTrue('color: blue' in layer.viz)
self.assertTrue('width: 10' in layer.viz)
self.assertTrue('strokeColor: black' in layer.viz)
self.assertTrue('strokeWidth: 1' in layer.viz)

def test_style_dict_valid_properties(self):
"""Layer style should set only the valid properties"""
with self.assertRaises(ValueError):
Layer(
'layer_source',
{
'invalid': 1
}
)
self.assertTrue('strokeWidth: 1' in layer.viz)
6 changes: 4 additions & 2 deletions test/viz/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def test_legend_info(self):
'title': '[TITLE]',
'description': '[description]',
'footer': '[footer]',
'dynamic': True
'dynamic': True,
'variable': ''
})

legend = Legend({
Expand All @@ -73,7 +74,8 @@ def test_legend_info(self):
'title': '',
'description': '',
'footer': '',
'dynamic': True
'dynamic': True,
'variable': ''
})

def test_wrong_input(self):
Expand Down
7 changes: 1 addition & 6 deletions test/viz/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,4 @@ def test_style_dict_variables(self):

self.assertIn('@var: 1', viz)
self.assertIn('@mimi: $pop', viz)
self.assertIn('@momo: 123', viz)

def test_wrong_attribute(self):
"""Style should raise an error if style property is not valid"""
with self.assertRaises(ValueError):
Style({'wrong': 'red'}).compute_viz('point')
self.assertIn('@momo: 123', viz)

0 comments on commit 3db207f

Please sign in to comment.