예제 #1
0
def test_config_behaviours():
    line1 = Line()
    line1.show_legend = False
    line1.fill = True
    line1.pretty_print = True
    line1.x_labels = ['a', 'b', 'c']
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    line2 = Line(
        show_legend=False,
        fill=True,
        pretty_print=True,
        x_labels=['a', 'b', 'c'])
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2

    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    line3 = Line(LineConfig)
    line3.add('_', [1, 2, 3])
    l3 = line3.render()
    assert l1 == l3

    line4 = Line(LineConfig())
    line4.add('_', [1, 2, 3])
    l4 = line4.render()
    assert l1 == l4
예제 #2
0
def test_config_alterations_kwargs():
    class LineConfig(Config):
        no_prefix = True
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    config = LineConfig()

    line1 = Line(config)
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    line1.stroke = False
    l1bis = line1.render()
    assert l1 != l1bis

    line2 = Line(config)
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2
    assert l1bis != l2

    line3 = Line(config, title='Title')
    line3.add('_', [1, 2, 3])
    l3 = line3.render()
    assert l3 != l2

    l2bis = line2.render()
    assert l2 == l2bis
예제 #3
0
def test_config_behaviours():
    """Test that all different way to set config produce same results"""
    line1 = Line()
    line1.show_legend = False
    line1.fill = True
    line1.pretty_print = True
    line1.no_prefix = True
    line1.x_labels = ['a', 'b', 'c']
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    q = line1.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 1
    assert len(q(".legend")) == 0
    assert len(q(".x.axis .guides")) == 3
    assert len(q(".y.axis .guides")) == 11
    assert len(q(".dots")) == 3
    assert q(".axis.x text").map(texts) == ['a', 'b', 'c']

    line2 = Line(
        show_legend=False,
        fill=True,
        pretty_print=True,
        no_prefix=True,
        x_labels=['a', 'b', 'c'])
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2

    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        no_prefix = True
        x_labels = ['a', 'b', 'c']

    line3 = Line(LineConfig)
    line3.add('_', [1, 2, 3])
    l3 = line3.render()
    assert l1 == l3

    line4 = Line(LineConfig())
    line4.add('_', [1, 2, 3])
    l4 = line4.render()
    assert l1 == l4

    line_config = Config()
    line_config.show_legend = False
    line_config.fill = True
    line_config.pretty_print = True
    line_config.no_prefix = True
    line_config.x_labels = ['a', 'b', 'c']

    line5 = Line(line_config)
    line5.add('_', [1, 2, 3])
    l5 = line5.render()
    assert l1 == l5
예제 #4
0
def test_same_max_and_relative_values_sparktext():
    chart = Line()
    chart.add('_', [0, 0, 0, 0, 0])
    assert chart.render_sparktext() == u('▁▁▁▁▁')

    chart2 = Line()
    chart2.add('_', [1, 1, 1, 1, 1])
    assert chart2.render_sparktext(relative_to=1) == u('▁▁▁▁▁')
예제 #5
0
def test_no_data_sparktext():
    """Test no data sparktext"""
    chart2 = Line()
    chart2.add('_', [])
    assert chart2.render_sparktext() == u('')

    chart3 = Line()
    assert chart3.render_sparktext() == u('')
예제 #6
0
def test_negative_and_float_and_no_data_sparktext():
    chart = Line()
    chart.add('_', [0.1, 0.2, 0.9, -0.5])
    assert chart.render_sparktext() == u('▁▂█▁')

    chart2 = Line()
    chart2.add('_', [])
    assert chart2.render_sparktext() == u('')

    chart3 = Line()
    assert chart3.render_sparktext() == u('')
예제 #7
0
def draw_number_line(name, list_x, list_y, max_y = 0):
        line = Line()
        line.disable_xml_declaration = True
        line.js = []

        line.x_label_rotation = 45
        line.x_labels_major_count = 31
        #line.y_labels_major_every = 3
        line.show_legend = False
        line.print_values = False
        line.print_zeroes = False
        line.width  = 1280
        line.height = 720
        line.value_formatter = lambda x:str(int(x))
        #line.major_label_font_size = 20
        #line.print_zeroes = True
        line.show_minor_x_labels = False
        #line.show_minor_y_labels = True
        line.show_dots = False
        #line.interpolate = 'hermite'

        line.title = name
        list_int_y = [0]
        for y in list_y:
                if y != None:
                        list_int_y.append(y)
        line.range = (0, max(int(max(list_int_y)*1.1), max_y))
        line.x_labels = list_x
        #line.y_labels = map(lambda x:x*100, range(int((min(list_y)/100)-1), int((max(list_y)/100+4))))
        line.add(name, list_y)
        return line.render()
예제 #8
0
파일: test_line.py 프로젝트: sattel/pygal
def test_simple_line():
    """Simple line test"""
    line = Line()
    rng = range(-30, 31, 5)
    line.add('test1', [cos(x / 10) for x in rng])
    line.add('test2', [sin(x / 10) for x in rng])
    line.add('test3', [cos(x / 10) - sin(x / 10) for x in rng])
    line.x_labels = map(str, rng)
    line.title = "cos sin and cos - sin"
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 3
    assert len(q(".legend")) == 3
    assert len(q(".x.axis .guides")) == 13
    assert len(q(".y.axis .guides")) == 13
    assert len(q(".dots")) == 3 * 13
    assert q(".axis.x text").map(texts) == [
        '-30', '-25', '-20', '-15', '-10', '-5', '0', '5', '10', '15', '20',
        '25', '30'
    ]
    assert q(".axis.y text").map(texts) == [
        '-1.2', '-1', '-0.8', '-0.6', '-0.4', '-0.2', '0', '0.2', '0.4', '0.6',
        '0.8', '1', '1.2'
    ]
    assert q(".title").text() == 'cos sin and cos - sin'
    assert q(".legend text").map(texts) == ['test1', 'test2', 'test3']
예제 #9
0
def draw_price_line(name, list_x, list_y):
        line = Line()
        line.disable_xml_declaration = True
        line.js = []

        line.x_label_rotation = 45
        line.y_labels_major_every = 3
        line.show_legend = False
        line.print_values = False
        line.width  = 1280
        line.height = 720
        line.value_formatter = lambda x:str(int(x))
        #line.major_label_font_size = 20
        #line.print_zeroes = True
        #line.show_minor_x_labels = True
        #line.show_minor_y_labels = True

        line.title = name 
        digital_y = list(filter(lambda x:x != None, list_y))
        if digital_y == [] : digital_y = [0]
        line.range = (min(digital_y)-100, max(digital_y)+300)
        line.x_labels = list_x
        line.y_labels = map(lambda x:x*100, range(int((min(digital_y)/100)-1), int((max(digital_y)/100+4))))
        line.add(name, list_y)
        return line.render()
예제 #10
0
def test_value_formatter():
    line = Line(value_formatter=lambda x: str(x) + u('‰'))
    line.add('_', [10 ** 4, 10 ** 5, 23 * 10 ** 4])
    q = line.render_pyquery()
    assert len(q(".y.axis .guides")) == 11
    assert q(".axis.y text").map(texts) == list(map(
        lambda x: str(x) + u('‰'), map(float, range(20000, 240000, 20000))))
예제 #11
0
def test_no_data():
    line = Line()
    q = line.render_pyquery()
    assert q(".text-overlay text").text() == "No data"
    line.no_data_text = u("þæ®þ怀&ij¿’€")
    q = line.render_pyquery()
    assert q(".text-overlay text").text() == u("þæ®þ怀&ij¿’€")
예제 #12
0
파일: test_line.py 프로젝트: young-0/pygal
def test_only_major_dots():
    line = Line(show_only_major_dots=True, )
    line.add('test', range(12))
    line.x_labels = map(str, range(12))
    line.x_labels_major = ['1', '5', '11']
    q = line.render_pyquery()
    assert len(q(".dots")) == 3
예제 #13
0
def test_parametric_styles_with_parameters():
    """Test a parametric style with parameters"""
    line = Line(
        style=RotateStyle('#de3804', step=12, max_=180, base_style=LightStyle))
    line.add('_', [1, 2, 3])
    line.x_labels = 'abc'
    assert line.render()
예제 #14
0
def draw_multi_price_line(name, dict_data):
        line = Line()
        line.disable_xml_declaration = True
        line.js = []

        line.x_label_rotation = 45
        line.y_labels_major_every = 3
        #line.show_legend = False
        line.legend_at_bottom = True
        line.print_values = False
        line.width  = 1280
        line.height = 720
        line.value_formatter = lambda x:str(int(x))
        #line.major_label_font_size = 20
        #line.print_zeroes = True
        #line.show_minor_x_labels = True
        #line.show_minor_y_labels = True

        line.title = name
        min_y = None
        max_y = None
        for name in dict_data:
                #print(name)
                list_x, list_y = dict_data[name]
                line.add(name, list_y)
                min_list_y = min(list_y)
                max_list_y = max(list_y)
                if min_y == None or min_list_y < min_y : min_y = min_list_y
                if max_y == None or max_list_y > max_y : max_y = max_list_y
        if min_y == None : min_y = 0
        if max_y == None : max_y = 0 
        line.range = (min_y-100, max_y+300)
        line.x_labels = map(str, list_x)
        line.y_labels = map(lambda x:x*100, range(int((min_y/100)-1), int((max_y/100+4))))
        return line.render()
예제 #15
0
파일: test_line.py 프로젝트: young-0/pygal
def test_only_major_dots_count():
    line = Line(show_only_major_dots=True)
    line.add('test', range(12))
    line.x_labels = map(str, range(12))
    line.x_labels_major_count = 2
    q = line.render_pyquery()
    assert len(q(".dots")) == 2
예제 #16
0
파일: test_line.py 프로젝트: sattel/pygal
def test_only_major_dots_every():
    """Test major dots"""
    line = Line(show_only_major_dots=True, x_labels_major_every=3)
    line.add('test', range(12))
    line.x_labels = map(str, range(12))
    q = line.render_pyquery()
    assert len(q(".dots")) == 4
예제 #17
0
 def test_interpolate_secondary():
     chart = Line(title=u'Some different points', interpolate='cubic')
     chart.add('line', [1000, 2000, 7000])
     chart.add('other line', [100, 500, 500], secondary=True)
     chart.range = 0, 10000
     chart.secondary_range = 0, 1000
     return chart.render_response()
예제 #18
0
 def test_interruptions():
     chart = Line(allow_interruptions=True)
     chart.add('interrupt', [22, 34, 43, 12, None, 12, 55, None, 56],
               allow_interruptions=False)
     chart.add('not interrupt', [
         -a if a else None for a in (22, 34, 43, 12, None, 12, 55, None, 56)
     ])
     return chart.render_response()
예제 #19
0
 def _get_line_with_style(self):
     dark_rotate_style = RotateStyle('#9e6ffe')
     return Line(fill=False,
                 disable_xml_declaration=True,
                 include_x_axis=False,
                 human_readable=True,
                 interpolate='hermite',
                 style=dark_rotate_style)
예제 #20
0
 def test_major_dots():
     line = Line(x_labels_major_count=2, show_only_major_dots=True)
     line.add('test', range(12))
     line.x_labels = [
         'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5',
         'lol6', 'lol7', 'lol8', 'lol9', 'lol10', 'lol11']
     # line.x_labels_major = ['lol3']
     return line.render_response()
예제 #21
0
파일: test_line.py 프로젝트: rayleyva/pygal
def test_one_dot():
    line = Line()
    line.add('one dot', [12])
    line.x_labels = ['one']
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".y.axis .guides")) == 1
예제 #22
0
def test_another_sparktext():
    chart = Line()
    chart.add('_', [0, 30, 55, 80, 33, 150])
    assert chart.render_sparktext() == u('▁▂▃▄▂█')
    assert chart.render_sparktext() == chart.render_sparktext()
    chart2 = Bar()
    chart2.add('_', [0, 30, 55, 80, 33, 150])
    assert chart2.render_sparktext() == chart.render_sparktext()
예제 #23
0
def test_show_dots():
    line = Line()
    line.add('_', [1, 2, 3])
    q = line.render_pyquery()
    assert len(q(".dots")) == 3
    line.show_dots = False
    q = line.render_pyquery()
    assert len(q(".dots")) == 0
예제 #24
0
def test_show_legend():
    line = Line()
    line.add('_', [1, 2, 3])
    q = line.render_pyquery()
    assert len(q(".legend")) == 1
    line.show_legend = False
    q = line.render_pyquery()
    assert len(q(".legend")) == 0
예제 #25
0
def test_not_equal_x_labels():
    line = Line()
    line.add('test1', range(100))
    line.x_labels = map(str, range(11))
    q = line.render_pyquery()
    assert len(q(".dots")) == 100
    assert len(q(".axis.x")) == 1
    assert q(".axis.x text").map(texts) == ['0', '1', '2', '3', '4', '5', '6',
                                            '7', '8', '9', '10']
예제 #26
0
def test_parametric_styles():
    chart = None
    for style in STYLES:
        line = Line(style=style('#f4e83a'))
        line.add('_', [1, 2, 3])
        line.x_labels = 'abc'
        new_chart = line.render()
        assert chart != new_chart
        chart = new_chart
예제 #27
0
def test_another_sparktext():
    """Test that same data produces same sparktext"""
    chart = Line()
    chart.add('_', [0, 30, 55, 80, 33, 150])
    assert chart.render_sparktext() == u('▁▂▃▄▂█')
    assert chart.render_sparktext() == chart.render_sparktext()
    chart2 = Bar()
    chart2.add('_', [0, 30, 55, 80, 33, 150])
    assert chart2.render_sparktext() == chart.render_sparktext()
예제 #28
0
def test_logarithmic_bad_interpolation():
    try:
        import scipy
    except ImportError:
        return
    line = Line(logarithmic=True, interpolate='cubic')
    line.add('_', [.001, .00000001, 1])
    q = line.render_pyquery()
    assert len(q(".y.axis .guides")) == 40
예제 #29
0
def graphing(budget_list):
    the_graph = Line()
    the_graph.title = 'Maximum profits based on given prices'
    the_graph.x_labels = sorted(budget_list)
    the_graph.add('Profits', all_profits_from_prices(budget_list))

    # option to save to local dir
    # the_graph.render_to_file('profits.svg')
    return the_graph.render_data_uri()
예제 #30
0
def test_human_readable():
    line = Line()
    line.add('_', [10**4, 10**5, 23 * 10**4])
    q = line.render_pyquery()
    assert q(".axis.y text").map(texts) == list(
        map(str, map(float, range(20000, 240000, 20000))))
    line.human_readable = True
    q = line.render_pyquery()
    assert q(".axis.y text").map(texts) == list(
        map(lambda x: '%dk' % x, range(20, 240, 20)))