Example #1
0
def adapt(chart, data):
    if isinstance(chart, pygal.DateY):
        # Convert to a credible datetime
        return list(map(
            lambda t:
            (datetime.fromtimestamp(1360000000 + t[0] * 987654)
             if t[0] is not None else None, t[1]), data))

    if isinstance(chart, pygal.XY):
        return data

    data = cut(data)
    if isinstance(chart, pygal.Worldmap):
        return list(
            map(lambda x: list(
                COUNTRIES.keys())[
                    int(x) % len(COUNTRIES)]
                if x is not None else None, data))
    elif isinstance(chart, pygal.FrenchMap_Regions):
        return list(
            map(lambda x: list(
                REGIONS.keys())[
                    int(x) % len(REGIONS)]
                if x is not None else None, data))
    elif isinstance(chart, pygal.FrenchMap_Departments):
        return list(
            map(lambda x: list(
                DEPARTMENTS.keys())[
                    int(x) % len(DEPARTMENTS)]
                if x is not None else None, data))
    return data
Example #2
0
def adapt(chart, data):
    if isinstance(chart, pygal.DateY):
        # Convert to a credible datetime
        return list(
            map(
                lambda t: (datetime.fromtimestamp(1360000000 + t[0] * 987654)
                           if t[0] is not None else None, t[1]), data))

    if isinstance(chart, pygal.XY):
        return data

    data = cut(data)
    if isinstance(chart, pygal.Worldmap):
        return list(
            map(
                lambda x: list(COUNTRIES.keys())[x % len(COUNTRIES)]
                if x is not None else None, data))
    elif isinstance(chart, pygal.FrenchMap_Regions):
        return list(
            map(
                lambda x: list(REGIONS.keys())[x % len(REGIONS)]
                if x is not None else None, data))
    elif isinstance(chart, pygal.FrenchMap_Departments):
        return list(
            map(
                lambda x: list(DEPARTMENTS.keys())[x % len(DEPARTMENTS)]
                if x is not None else None, data))
    return data
Example #3
0
def test_metadata(Chart):
    chart = Chart()
    v = range(7)
    if Chart in (pygal.Box, ):
        return  # summary charts cannot display per-value metadata
    elif Chart == pygal.XY:
        v = list(map(lambda x: (x, x + 1), v))
    elif Chart == pygal.Worldmap or Chart == pygal.SupranationalWorldmap:
        v = [(i, k) for k, i in enumerate(i18n.COUNTRIES.keys())]
    elif Chart == pygal.FrenchMap_Regions:
        v = [(i, k) for k, i in enumerate(REGIONS.keys())]
    elif Chart == pygal.FrenchMap_Departments:
        v = [(i, k) for k, i in enumerate(DEPARTMENTS.keys())]

    chart.add('Serie with metadata', [
        v[0], {
            'value': v[1]
        }, {
            'value': v[2],
            'label': 'Three'
        }, {
            'value': v[3],
            'xlink': 'http://4.example.com/'
        }, {
            'value': v[4],
            'xlink': 'http://5.example.com/',
            'label': 'Five'
        }, {
            'value': v[5],
            'xlink': {
                'href': 'http://6.example.com/'
            },
            'label': 'Six'
        }, {
            'value': v[6],
            'xlink': {
                'href': 'http://7.example.com/',
                'target': '_blank'
            },
            'label': 'Seven'
        }
    ])
    q = chart.render_pyquery()
    for md in ('Three', 'http://4.example.com/', 'Five',
               'http://7.example.com/', 'Seven'):
        assert md in cut(q('desc'), 'text')

    if Chart == pygal.Pie:
        # Slices with value 0 are not rendered
        assert len(v) - 1 == len(q('.tooltip-trigger').siblings('.value'))
    elif Chart not in (pygal.Worldmap, pygal.SupranationalWorldmap,
                       pygal.FrenchMap_Regions, pygal.FrenchMap_Departments):
        # Tooltip are not working on maps
        assert len(v) == len(q('.tooltip-trigger').siblings('.value'))
Example #4
0
    def test_frenchmapregions():
        fmap = FrenchMap_Regions(style=choice(list(styles.values())))
        for i in range(10):
            fmap.add("s%d" % i, [(choice(list(REGIONS.keys())), randint(0, 100)) for _ in range(randint(1, 5))])

        fmap.add(
            "links",
            [
                {"value": ("02", 10), "label": "\o/", "xlink": "http://google.com?q=69"},
                {"value": ("72", 20), "label": "Y"},
            ],
        )
        fmap.add("6th", [91, 2, 41])
        fmap.title = "French map"
        return fmap.render_response()
Example #5
0
    def test_frenchmapregions():
        fmap = FrenchMap_Regions(style=choice(list(styles.values())))
        for i in range(10):
            fmap.add('s%d' % i,
                     [(choice(list(REGIONS.keys())), randint(0, 100))
                      for _ in range(randint(1, 5))])

        fmap.add('links', [{
            'value': ('02', 10),
            'label': '\o/',
            'xlink': 'http://google.com?q=69'
        }, {
            'value': ('72', 20),
            'label': 'Y',
        }])
        fmap.add('6th', [91, 2, 41])
        fmap.title = 'French map'
        return fmap.render_response()
Example #6
0
    def test_frenchmapregions():
        fmap = FrenchMap_Regions(style=choice(list(styles.values())))
        for i in range(10):
            fmap.add('s%d' % i, [
                (choice(list(REGIONS.keys())), randint(0, 100))
                for _ in range(randint(1, 5))])

        fmap.add('links', [{
            'value': ('02', 10),
            'label': '\o/',
            'xlink': 'http://google.com?q=69'
        }, {
            'value': ('72', 20),
            'label': 'Y',
        }])
        fmap.add('6th', [91, 2, 41])
        fmap.title = 'French map'
        return fmap.render_response()
Example #7
0
def test_metadata(Chart):
    chart = Chart()
    v = range(7)
    if Chart in (pygal.Box,):
        return  # summary charts cannot display per-value metadata
    elif Chart == pygal.XY:
        v = list(map(lambda x: (x, x + 1), v))
    elif Chart == pygal.Worldmap or Chart == pygal.SupranationalWorldmap:
        v = [(i, k) for k, i in enumerate(i18n.COUNTRIES.keys())]
    elif Chart == pygal.FrenchMap_Regions:
        v = [(i, k) for k, i in enumerate(REGIONS.keys())]
    elif Chart == pygal.FrenchMap_Departments:
        v = [(i, k) for k, i in enumerate(DEPARTMENTS.keys())]

    chart.add('Serie with metadata', [
        v[0],
        {'value': v[1]},
        {'value': v[2], 'label': 'Three'},
        {'value': v[3], 'xlink': 'http://4.example.com/'},
        {'value': v[4], 'xlink': 'http://5.example.com/', 'label': 'Five'},
        {'value': v[5], 'xlink': {
            'href': 'http://6.example.com/'}, 'label': 'Six'},
        {'value': v[6], 'xlink': {
            'href': 'http://7.example.com/',
            'target': '_blank'}, 'label': 'Seven'}
    ])
    q = chart.render_pyquery()
    for md in (
            'Three', 'http://4.example.com/',
            'Five', 'http://7.example.com/', 'Seven'):
        assert md in cut(q('desc'), 'text')

    if Chart == pygal.Pie:
        # Slices with value 0 are not rendered
        assert len(v) - 1 == len(q('.tooltip-trigger').siblings('.value'))
    elif Chart not in (
            pygal.Worldmap, pygal.SupranationalWorldmap,
            pygal.FrenchMap_Regions, pygal.FrenchMap_Departments):
        # Tooltip are not working on maps
        assert len(v) == len(q('.tooltip-trigger').siblings('.value'))