Ejemplo n.º 1
0
 def test_get_scheme_cartocss(self):
     """styling.get_scheme_cartocss"""
     # test on category
     self.assertEqual(get_scheme_cartocss('acadia', self.vivid),
                      'ramp([acadia], cartocolor(Vivid), category(4))')
     # test on quantative
     self.assertEqual(get_scheme_cartocss('acadia', self.purp),
                      'ramp([acadia], cartocolor(Purp), quantiles(4), <=)')
     # test on custom
     self.assertEqual(
         get_scheme_cartocss(
             'acadia',
             styling.custom(('#FFF', '#888', '#000'),
                            bins=3,
                            bin_method='equal')),
         'ramp([acadia], (#FFF,#888,#000), equal(3), <=)')
Ejemplo n.º 2
0
    def test_get_scheme_cartocss(self):
        """styling.get_scheme_cartocss"""
        # test on category
        self.assertEqual(get_scheme_cartocss('acadia', self.vivid),
                         'ramp([acadia], cartocolor(Vivid), category(4), =)')
        # test on quantative
        self.assertEqual(get_scheme_cartocss('acadia', self.purp),
                         'ramp([acadia], cartocolor(Purp), quantiles(4), >)')
        # test on custom
        self.assertEqual(
            get_scheme_cartocss(
                'acadia',
                styling.custom(('#FFF', '#888', '#000'),
                               bins=3,
                               bin_method='equal')),
            'ramp([acadia], (#FFF,#888,#000), equal(3), >)')

        # test with non-int quantification
        self.assertEqual(
            get_scheme_cartocss('acadia', styling.sunset([1, 2, 3])),
            'ramp([acadia], cartocolor(Sunset), (1,2,3), >=)')
Ejemplo n.º 3
0
    def _get_cartocss(self, basemap):
        """Generate cartocss for class properties"""
        if isinstance(self.size, int):
            size_style = self.size
        elif isinstance(self.size, dict):
            size_style = ('ramp([{column}],'
                          ' range({min_range},{max_range}),'
                          ' {bin_method}({bins}))').format(
                              column=self.size['column'],
                              min_range=self.size['range'][0],
                              max_range=self.size['range'][1],
                              bin_method=self.size['bin_method'],
                              bins=self.size['bins'])

        if self.scheme:
            color_style = get_scheme_cartocss(self.color, self.scheme)
        else:
            color_style = self.color

        line_color = '#000' if basemap.source == 'dark' else '#FFF'
        return cssify({
            # Point CSS
            "#layer['mapnik::geometry_type'=1]": {
                'marker-width': size_style,
                'marker-fill': color_style,
                'marker-fill-opacity': '1',
                'marker-allow-overlap': 'true',
                'marker-line-width': '0.5',
                'marker-line-color': line_color,
                'marker-line-opacity': '1',
            },
            # Line CSS
            "#layer['mapnik::geometry_type'=2]": {
                'line-width': '1.5',
                'line-color': color_style,
            },
            # Polygon CSS
            "#layer['mapnik::geometry_type'=3]": {
                'polygon-fill': color_style,
                'polygon-opacity': '0.9',
                'polygon-gamma': '0.5',
                'line-color': '#FFF',
                'line-width': '0.5',
                'line-opacity': '0.25',
                'line-comp-op': 'hard-light',
            }
        })
Ejemplo n.º 4
0
    def _get_cartocss(self, basemap, has_time=False):
        """Generate cartocss for class properties"""
        if isinstance(self.size, int):
            size_style = self.size or 4
        elif isinstance(self.size, dict):
            size_style = ('ramp([{column}],'
                          ' range({min_range},{max_range}),'
                          ' {bin_method}({bins}))').format(
                              column=self.size['column'],
                              min_range=self.size['range'][0],
                              max_range=self.size['range'][1],
                              bin_method=self.size['bin_method'],
                              bins=self.size['bins'])

        if self.scheme:
            color_style = get_scheme_cartocss(
                'value' if has_time else self.color,
                self.scheme)
        else:
            color_style = self.color

        line_color = '#000' if basemap.source == 'dark' else '#FFF'
        if self.time:
            css = cssify({
                # Torque Point CSS
                "#layer": {
                    'marker-width': size_style,
                    'marker-fill': color_style,
                    'marker-fill-opacity': 0.9,
                    'marker-allow-overlap': 'true',
                    'marker-line-width': 0,
                    'marker-line-color': line_color,
                    'marker-line-opacity': 1,
                    'comp-op': 'source-over',
                }
            })
            if self.color in self.style_cols:
                css += cssify({
                    '#layer[{} = null]'.format(self.color): {
                        'marker-fill': '#666'}
                    })
            for trail_num in range(1, self.time['trails'] + 1):
                # Trails decay as 1/2^n, and grow 30% at each step
                trail_temp = cssify({
                    '#layer[frame-offset={}]'.format(trail_num): {
                        'marker-width': size_style * (1.0 + trail_num * 0.3),
                        'marker-opacity': 0.9 / 2.0**trail_num,
                    }
                })
                css += trail_temp
            return css
        else:
            if self.geom_type == 'point':
                css = cssify({
                    # Point CSS
                    "#layer": {
                        'marker-width': size_style,
                        'marker-fill': color_style,
                        'marker-fill-opacity': '1',
                        'marker-allow-overlap': 'true',
                        'marker-line-width': '0.5',
                        'marker-line-color': line_color,
                        'marker-line-opacity': '1',
                    }})
                if self.color in self.style_cols:
                    css += cssify({
                        '#layer[{} = null]'.format(self.color): {
                            'marker-fill': '#ccc'}
                        })
                return css
            elif self.geom_type == 'line':
                css = cssify({
                    "#layer": {
                        'line-width': '1.5',
                        'line-color': color_style,
                    }})
                if self.color in self.style_cols:
                    css += cssify({
                        '#layer[{} = null]'.format(self.color): {
                            'line-color': '#ccc'}
                        })
                return css
            elif self.geom_type == 'polygon':
                css = cssify({
                    "#layer": {
                        'polygon-fill': color_style,
                        'polygon-opacity': '0.9',
                        'polygon-gamma': '0.5',
                        'line-color': '#FFF',
                        'line-width': '0.5',
                        'line-opacity': '0.25',
                        'line-comp-op': 'hard-light',
                    }})
                if self.color in self.style_cols:
                    css += cssify({
                        '#layer[{} = null]'.format(self.color): {
                            'polygon-fill': '#ccc'}
                        })
                return css
            else:
                raise ValueError('Unsupported geometry type: {}'.format(
                    self.geom_type))