Ejemplo n.º 1
0
 def _get_shaded_paths(self, distribution_map):
     path_nodes = distribution_map.svg_map.xpath('svg:g/svg:path',
                                                 namespaces=NAMESPACES)
     paths = [Path(path_node) for path_node in path_nodes]
     shaded_paths = []
     for path in paths:
         style = path.get_style()
         if style.find('fill:#') > -1 and style.find('fill:#fff') == -1:
             shaded_paths.append(path)
     return shaded_paths
Ejemplo n.º 2
0
    def shade(self):
        """Set the colors of the states and provinces based
        on distribution data.
        """
        if self.distribution_records:
            path_nodes = self.svg_map.xpath(self.PATH_NODES_XPATH,
                namespaces=NAMESPACES)
            matching_regions = {}
            for record in self.distribution_records:
                region = STATES_MAP.get(record.value_str)
                region = ((region in CANADIAN_PROVINCES and 'ca-' or 'us-') +
                          region)
                matching_regions[region] = True

            for node in path_nodes:
                if node.get('style'):
                    node_id = node.get('id').lower()
                    box = Path(node)
                    if node_id in matching_regions:
                        box.color(PRESENT_COLOR)
                    else:
                        box.color(ABSENT_COLOR)
        return self
Ejemplo n.º 3
0
 def test_plant_with_no_distribution_data_returns_blank_map(self):
     SCIENTIFIC_NAME = 'Foo bar'
     self.distribution_map.set_plant(SCIENTIFIC_NAME)
     self.distribution_map.shade()
     # Verify that the map is not shaded.
     path_nodes = self.distribution_map.svg_map.findall(
         '{http://www.w3.org/2000/svg}path')
     paths = [Path(path_node) for path_node in path_nodes]
     for path in paths:
         style = path.get_style()
         self.assertTrue(
             style.find('fill:#fff') > -1 or style.find('fill:none') > -1)
     # Verify that the legend contains only a 'no data' label.
     labels = get_legend_labels(self.distribution_map.legend)
     self.assertEqual(['no data', '', '', '', '', ''], labels)
Ejemplo n.º 4
0
 def _verify_shaded_counties(self, legend_labels_found):
     path_nodes = self.distribution_map.svg_map.findall(
         '{http://www.w3.org/2000/svg}path')
     paths = [Path(path_node) for path_node in path_nodes]
     statuses_verified = []
     for path in paths:
         style = path.get_style()
         status = None
         if style.find('fill:#78bf47') > -1:
             status = 'native'
         elif style.find('fill:#fff') > -1:
             status = 'absent'
         if status and status not in statuses_verified:
             statuses_verified.append(status)
         if statuses_verified == legend_labels_found:
             break
     self.assertEqual(statuses_verified.sort(), legend_labels_found.sort())
Ejemplo n.º 5
0
    def shade(self):
        """Set the colors of the states and provinces based
        on distribution data.
        """
        if self.distribution_records:
            path_nodes = self.svg_map.xpath(self.PATH_NODES_XPATH,
                                            namespaces=NAMESPACES)
            matching_regions = {}
            for record in self.distribution_records:
                region = STATES_MAP.get(record.value_str)
                region = ((region in CANADIAN_PROVINCES and 'ca-' or 'us-') +
                          region)
                matching_regions[region] = True

            for node in path_nodes:
                if node.get('style'):
                    node_id = node.get('id').lower()
                    box = Path(node)
                    if node_id in matching_regions:
                        box.color(PRESENT_COLOR)
                    else:
                        box.color(ABSENT_COLOR)
        return self
Ejemplo n.º 6
0
 def setUp(self):
     dist_map = NewEnglandPlantDistributionMap()
     path_nodes = dist_map.svg_map.findall(
         '{http://www.w3.org/2000/svg}path')
     self.path = Path(path_nodes[0])
Ejemplo n.º 7
0
class PathTestCase(TestCase):
    def setUp(self):
        dist_map = NewEnglandPlantDistributionMap()
        path_nodes = dist_map.svg_map.findall(
            '{http://www.w3.org/2000/svg}path')
        self.path = Path(path_nodes[0])

    def test_get_style(self):
        self.assertTrue(self.path.get_style().find('fill:#fff') > -1)

    def test_set_style(self):
        NEW_STYLE = 'font-size:14px'
        self.path.set_style(NEW_STYLE)
        self.assertEqual(NEW_STYLE, self.path.get_style())

    def test_color(self):
        FILL_COLOR = '#ff0'
        self.path.color(FILL_COLOR)
        self.assertTrue(
            self.path.get_style().find('fill:%s' % FILL_COLOR) > -1)

    def test_color_with_stroke_color(self):
        FILL_COLOR = '#ff0'
        STROKE_COLOR = '#ccc'
        self.path.color(FILL_COLOR, stroke_color=STROKE_COLOR)
        self.assertTrue(
            self.path.get_style().find('fill:%s' % FILL_COLOR) > -1)
        self.assertTrue(
            self.path.get_style().find('stroke:%s' % STROKE_COLOR) > -1)
Ejemplo n.º 8
0
 def _get_paths(self):
     return [
         Path(box_node)
         for box_node in self.legend.svg_map.xpath('svg:rect',
                                                   namespaces=NAMESPACES)
     ]
Ejemplo n.º 9
0
 def setUp(self):
     dist_map = NewEnglandPlantDistributionMap()
     path_nodes = dist_map.svg_map.findall(
         '{http://www.w3.org/2000/svg}path')
     self.path = Path(path_nodes[0])
Ejemplo n.º 10
0
class PathTestCase(TestCase):
    def setUp(self):
        dist_map = NewEnglandPlantDistributionMap()
        path_nodes = dist_map.svg_map.findall(
            '{http://www.w3.org/2000/svg}path')
        self.path = Path(path_nodes[0])

    def test_get_style(self):
        self.assertTrue(self.path.get_style().find('fill:#fff') > -1)

    def test_set_style(self):
        NEW_STYLE = 'font-size:14px'
        self.path.set_style(NEW_STYLE)
        self.assertEqual(NEW_STYLE, self.path.get_style())

    def test_color(self):
        FILL_COLOR = '#ff0'
        self.path.color(FILL_COLOR)
        self.assertTrue(
            self.path.get_style().find('fill:%s' % FILL_COLOR) > -1)

    def test_color_with_stroke_color(self):
        FILL_COLOR = '#ff0'
        STROKE_COLOR = '#ccc'
        self.path.color(FILL_COLOR, stroke_color=STROKE_COLOR)
        self.assertTrue(
            self.path.get_style().find('fill:%s' % FILL_COLOR) > -1)
        self.assertTrue(
            self.path.get_style().find('stroke:%s' % STROKE_COLOR) > -1)