Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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