示例#1
0
文件: tests.py 项目: Bouska/pygal
    def test_bar_links():
        bar = Bar(style=styles['neon'])
        bar.js = ('http://l:2343/svg.jquery.js',
                  'http://l:2343/pygal-tooltips.js')
        bar.add('1234', [
            {'value': 10,
             'label': 'Ten',
             'xlink': 'http://google.com?q=10'},
            {'value': 20,
             'tooltip': 'Twenty',
             'xlink': 'http://google.com?q=20'},
            30,
            {'value': 40,
             'label': 'Forty',
             'xlink': 'http://google.com?q=40'}
        ])

        bar.add('4321', [40, {
            'value': 30,
            'label': 'Thirty',
            'xlink': 'http://google.com?q=30'
        }, 20, 10])
        bar.x_labels = map(str, range(1, 5))
        bar.logarithmic = True
        bar.zero = 1
        return bar.render_response()
示例#2
0
def genSvg(fpath, mathd, biologyd):
    keys = ['0-59']
    [keys.append('%d-%d' % (val, val + 9 + (val / 90))) for val in range(60, 100, 10)]
    # print(keys, type(keys))
    # ['0-59', '60-69', '70-79', '80-89', '90-100'] <class 'list'>

    line_chart = Bar()
    # print(line_chart, type(line_chart))
    # <pygal.graph.bar.Bar object at 0x02F24330> <class 'pygal.graph.bar.Bar'>

    line_chart.title = 'Score Spread'
    # print(line_chart.title, type(line_chart.title))
    # Score Spread <class 'str'>

    line_chart.x_labels = keys
    # print(line_chart.x_labels, type(line_chart.x_labels))
    # ['0-59', '60-69', '70-79', '80-89', '90-100'] <class 'list'>

    line_chart.add('math', mathd.values())
    line_chart.add('biology', biologyd.values())
    # print(mathd, type(mathd))
    # {'0-59': 3, '60-69': 2, '70-79': 3, '80-89': 0, '90-100': 2} <class 'dict'>
    # print(mathd.values(), type(mathd.values()))
    # dict_values([3, 2, 3, 0, 2]) <class 'dict_values'>

    line_chart.render_to_file(fpath)
示例#3
0
    def test_bar_links():
        bar = Bar(style=styles['neon'])
        bar.add('1234', [{
            'value': 10,
            'label': 'Ten',
            'xlink': 'http://google.com?q=10'
        }, {
            'value': 20,
            'label': 'Twenty',
            'xlink': 'http://google.com?q=20'
        }, 30, {
            'value': 40,
            'label': 'Forty',
            'xlink': 'http://google.com?q=40'
        }])

        bar.add('4321', [
            40, {
                'value': 30,
                'label': 'Thirty',
                'xlink': 'http://google.com?q=30'
            }, 20, 10
        ])
        bar.x_labels = map(str, range(1, 5))
        bar.logarithmic = True
        bar.zero = 1
        return bar.render_response()
示例#4
0
 def test_multiline_title():
     bar = Bar()
     bar.add('Looooooooooooooooooooooooooooooooooong', [2, None, 12])
     bar.title = (
         'First line \n Second line \n Third line'
     )
     return bar.render_response()
示例#5
0
def statistics():
    """ Page display data visualization about statistics for the recipes """

    # Count how many recipes have each meal time to send to the pie chart
    breakfast = mongo.db.recipes.find({'meal_time': 'breakfast'}).count()
    lunch = mongo.db.recipes.find({'meal_time': 'lunch'}).count()
    dinner = mongo.db.recipes.find({'meal_time': 'dinner'}).count()

    # Build pie chart
    pie_chart = Pie()
    pie_chart.title = 'Meal Times'
    pie_chart.add('Breakfast', breakfast)
    pie_chart.add('Lunch', lunch)
    pie_chart.add('Dinner', dinner)
    pie_chart = pie_chart.render_data_uri()

    # Count how many recipes have each training type to send to line chart
    endurance = mongo.db.recipes.find({'training_type': 'endurance'}).count()
    speed = mongo.db.recipes.find({'training_type': 'speed'}).count()
    strength = mongo.db.recipes.find({'training_type': 'strength'}).count()
    power = mongo.db.recipes.find({'training_type': 'power'}).count()

    # Build line chart
    line_chart = Bar()
    line_chart.title = 'Training Types'
    line_chart.add('Endurance', [{'value': endurance, 'label': 'Endurance'}])
    line_chart.add('Strength', [{'value': strength, 'label': 'Strength'}])
    line_chart.add('Power', [{'value': power, 'label': 'Power'}])
    line_chart.add('Speed', [{'value': speed, 'label': 'Speed'}])
    line_chart = line_chart.render_data_uri()

    return render_template('statists.html',
                           title='Statistics',
                           pie_chart=pie_chart,
                           line_chart=line_chart)
示例#6
0
def show_one_die_bar(numbers, num_sides=6):
    """投掷骰子numbers次,看每个面出现的次数,用直方图显示结果"""
    die = Die(num_sides)
    results = []
    title_num_sides = "D" + str(num_sides)

    # 投掷骰子,把结果保存在results中
    for number in range(numbers):
        results.append(die.roll())

    # 分析结果
    frequencies = []
    for value in range(1, die.num_sides+1):
        frequencies.append(results.count(value))

    # 显示结果在Console窗口
    #print(results)
    #print(frequencies)

    # 对结果可视化
    hist = Bar()
    
    hist.title = "Results of rolling one " + title_num_sides + " " + str(numbers) + " times"
    hist.x_labels = [str(num) for num in range(1,num_sides + 1)]
    hist.x_title = "Result"
    hist.y_title = "Frequency of Result"

    hist.add(title_num_sides, frequencies)
    hist.render_to_file("die_visual_" + title_num_sides + "_"
                        + str(numbers) + ".svg")
示例#7
0
文件: graphs.py 项目: Qalthos/locutus
def graph_records(record_files):
    chart = Bar(BaseConfig)
    max_len = max(map(len, record_files.values()))
    for name, record_list in sort_domains(record_files.items()):
        chart.add(name, [x[0].total_seconds()/86400 for x in record_list] +
                        [None] * (max_len - len(record_list)))

    return chart.render()
示例#8
0
 def __call__(self, T):
     subplot = Bar(legend_at_bottom=True, explicit_size=True, width=800, height=150)
     subplot.add("Difference", self.data)
     subplot = subplot.render_tree()
     subplot = subplot.xpath("g")[0]
     T.insert(2, subplot)
     T.xpath("g")[1].set('transform', 'translate(0,150), scale(1,0.75)')
     return T
示例#9
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()
示例#10
0
 def __init__(self, sides=6, dice=2, shooter=360):
     super().__init__(sides, dice, shooter)
     self.come_out_roll = self.come_out_roll()
     self.dice_freq = self.dice_freq()
     self.chart = Bar(print_values=True,
                      print_values_position='top',
                      print_zeroes=False,
                      style=custom_style)
示例#11
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()
示例#12
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()
示例#13
0
 def test_bar_print_values():
     bar = Bar(print_values=True, js=[],
               style=styles['default'](
                   value_font_family='googlefont:Raleway',
                   value_font_size=30,
                   value_colors=(None, None, 'blue', 'red', 'green')
               ))
     for i in range(12):
         bar.add('', i)
     return bar.render_response()
示例#14
0
 def test_long_title():
     bar = Bar()
     bar.add('Looooooooooooooooooooooooooooooooooong', [2, None, 12])
     bar.title = (
         '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 '
         '12345678901 123456789012 1234567890123 12345678901234 '
         '123456789012345 1234567890123456 12345678901234567 '
         '123456789012345678 1234567890123456789 12345678901234567890 '
         '123456789012345 1234567890123456 12345678901234567 '
         '12345678901 123456789012 1234567890123 12345678901234 '
         '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890')
     return bar.render_response()
示例#15
0
 def test_long_title():
     bar = Bar()
     bar.add("Looooooooooooooooooooooooooooooooooong", [2, None, 12])
     bar.title = (
         "1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 "
         "12345678901 123456789012 1234567890123 12345678901234 "
         "123456789012345 1234567890123456 12345678901234567 "
         "123456789012345678 1234567890123456789 12345678901234567890 "
         "123456789012345 1234567890123456 12345678901234567 "
         "12345678901 123456789012 1234567890123 12345678901234 "
         "1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890"
     )
     return bar.render_response()
示例#16
0
文件: tests.py 项目: wuzesheng/pygal
 def test_long_labels():
     bar = Bar()
     bar.add('Long', [2, None, 12])
     bar.title = (
         '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890')
     bar.x_labels = 'a' * 100, 'b ' * 50, 'cc ! ' * 20
     bar.x_label_rotation = 45
     return bar.render_response()
示例#17
0
def test_xml_filters_round_trip():
    plot = Bar()
    plot.add("A", [60, 75, 80, 78, 83, 90])
    plot.add("B", [92, 87, 81, 73, 68, 55])
    before = plot.render()
    plot.add_xml_filter(lambda T: T)
    after = plot.render()
    assert before == after
示例#18
0
    def getBar(self):
        from pygal import Bar
        path = os.path.join(base_path, 'pygal_js', 'javascripts', 'bar', 'bar_chart.svg')
        config.width = 500
        config.height = 400
        bar_chart = Bar(config, width=400, height=300, legend_box_size=10)
        bar_chart.add('Fibonacci', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55])  # Add some values
        bar_chart.render_to_file(path)
        #fileio = StringIO()
        #im.save(fileio, 'svg')
        ##im.save('img.gif', 'gif')
        #im.show()
        #return ''.join(char), fileio

        return os.path.join(SVG_PATH, 'bar', 'bar_chart.svg')
示例#19
0
文件: test_bar.py 项目: signed0/pygal
def test_simple_bar():
    bar = Bar()
    rng = [-3, -32, -39]
    bar.add('test1', rng)
    bar.add('test2', map(abs, rng))
    bar.x_labels = map(str, rng)
    bar.title = "Bar test"
    q = bar.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".legend")) == 2
    assert len(q(".plot .series rect")) == 2 * 3
示例#20
0
 def test_bar():
     bar = Bar(dynamic_print_values=True, show_minor_x_labels=False)
     bar.add('1', [1, 2, 3])
     bar.add('2', [4, 5, 6])
     bar.x_labels = [2, 4, 6]
     bar.x_labels_major = [4]
     return bar.render_response()
示例#21
0
 def test_long_labels():
     bar = Bar()
     bar.add("Long", [2, None, 12])
     bar.title = "1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890"
     bar.x_labels = "a" * 100, "b " * 50, "cc ! " * 20
     bar.x_label_rotation = 45
     return bar.render_response()
示例#22
0
	def create_bar_chart(self, data, span):
		"""Creates a bar chart from the the data"""
		# Initialize the chart_list
		chart_list = []
		for log in data:
			activity_time = 0
			activity = log[0]
			log_start = unformat_time(tuple_time(log[1]))
			log_end = unformat_time(tuple_time(log[2]))
			color = log[3]
			minimum = span[1]
			maximum = span[2]	
			minimum = unformat_time(minimum)
			maximum = unformat_time(maximum)
			activity_time += time_in_span(log_start, log_end, minimum, maximum)
			in_chart_list = False
			for entry in chart_list:
				if entry[0] == activity:
					entry[1] += activity_time
					in_chart_list = True
			if not in_chart_list and activity_time > 0:
				chart_list.append([activity, activity_time, color])
		self.sort(chart_list)
		# Data must be organized for day, month, etc. before using
		# If size has been specified
		if not self.size == (None, None):
			self.chart = Bar(style=self.style, y_scale=60.0,
								print_values=False, include_x_axis=True,
								width=self.size[0], height=self.size[1])
		# If size has not already been specified
		else:
			# Let the graph dynamically resize within webview
			self.chart = Bar(style=self.style, print_values=False,
								include_x_axis=True, y_scale=60.0)
		self.set_y_labels(chart_list)
		## Add each entry is the chart_list to the chart	
		if not chart_list == []:
			for entry in chart_list:
				time = str(timedelta(seconds=entry[1]))
				if time[1] == ':':
					time = '0' + time
				self.chart.add(entry[0], [{'value':entry[1], 'label':time}])
		else:
			self.chart = Pie(style=self.style, width=self.size[0],
								height=self.size[1])
示例#23
0
文件: tests.py 项目: Cortana-/pygal
    def test_bar_links():
        bar = Bar(style=styles["neon"])
        bar.js = ("http://l:2343/svg.jquery.js", "http://l:2343/pygal-tooltips.js")
        bar.add(
            "1234",
            [
                {"value": 10, "label": "Ten", "xlink": "http://google.com?q=10"},
                {"value": 20, "tooltip": "Twenty", "xlink": "http://google.com?q=20"},
                30,
                {"value": 40, "label": "Forty", "xlink": "http://google.com?q=40"},
            ],
        )

        bar.add("4321", [40, {"value": 30, "label": "Thirty", "xlink": "http://google.com?q=30"}, 20, 10])
        bar.x_labels = map(str, range(1, 5))
        bar.logarithmic = True
        bar.zero = 1
        return bar.render_response()
def init_bar_graph():
    config = Config()
    config.x_label_rotation = 45
    config.show_legend = True
    config.title = 'Most-Starred Top-5 Programming Languages\'s Projects on Github'
    config.y_title = 'Stars'
    chart = Bar(config)

    return chart
示例#25
0
def test_xml_filters_round_trip():
    plot = Bar()
    plot.add("A", [60, 75, 80, 78, 83, 90])
    plot.add("B", [92, 87, 81, 73, 68, 55])
    before = plot.render()
    plot.add_xml_filter(lambda T: T)
    after = plot.render()
    assert before == after
示例#26
0
 def test_long_labels():
     bar = Bar()
     bar.add('Long', [2, None, 12])
     bar.title = (
         '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890')
     bar.x_labels = 'a' * 100, 'b ' * 50, 'cc ! ' * 20
     bar.x_label_rotation = 45
     return bar.render_response()
示例#27
0
def test_simple_bar():
    bar = Bar()
    rng = [-3, -32, -39]
    bar.add("test1", rng)
    bar.add("test2", map(abs, rng))
    bar.x_labels = map(str, rng)
    bar.title = "Bar test"
    q = bar.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".legend")) == 2
    assert len(q(".plot .series rect")) == 2 * 3
示例#28
0
def main():
    # Set the dice up
    numSides = 20
    die1 = Die(numSides)
    die2 = Die(numSides)

    numRolls = 100000

    # Roll the die numRoll times and store the sum of the two.
    results = []

    for roll in range(numRolls):
        result = die1.roll() + die2.roll()
        results.append(result)

    # Anaylizing the results from above.
    frequencies = []

    maxResult = die1.numSides + die2.numSides
    for value in range(2, maxResult + 1):
        frequency = results.count(value)
        frequencies.append(frequency)

    # Create a graph from the results.
    graph = Bar()

    graph.title = f'Results of rolling two D{numSides} die {numRolls} times.'

    # Create the x labels
    graph.x_labels = []
    for x in range(2, maxResult + 1):
        graph.x_labels.append(f'{x}')

    # Add axii titles.
    graph.x_title = 'Result'
    graph.y_title = 'Frequency of Result'

    graph.add(f'D{numSides} + D{numSides}',
              frequencies)  # Add teh frequencies to the graph

    # Get the script directory and add the file name to it.
    filePath = f'{path.dirname(__file__)}/d{numSides}_dice_simulation.svg'
    graph.render_to_file(filePath)  # Create the visual file.
示例#29
0
def static_pcap():
    if request.method == 'POST':
        #temporarily store upload pcap file
        print request
        traceFile = request.files['file']
        traceFile.save("temporary/temp_pcap_file.pcap")

        ft = filter_static.Static_Filter(
            fileName="temporary/temp_pcap_file.pcap")
        device_traffic_dict = ft.detect_Device()

        #line chart for individual device data sent historys
        pkt_line = XY(width=800, height=600, explicit_size=True)
        pkt_line.title = 'Device Package Curve'
        for key, list in device_traffic_dict.iteritems():
            pkt_line.add(key, list)
        chart = pkt_line.render()

        # bar chart for device data sent summary
        pkt_Bar = Bar(width=800, height=600, explicit_size=True)
        pkt_Bar.title = 'Device Package Sum'
        for key, list in device_traffic_dict.iteritems():
            zipped = map(sum, zip(*list))
            pkt_Bar.add(key, zipped[1])
        pkt_Bar = pkt_Bar.render()

        del ft
        html = """{} {}""".format(chart, pkt_Bar)
        return html

    else:
        return current_app.send_static_file('static.html')
示例#30
0
class DiceGraph(PyDice):
    '''
    Utiliza a classe Pygal e PyDicepara gerar gráfico 
    baseado na frequência dos dados.
    '''
    def __init__(self, sides=6, dice=2, shooter=360):
        super().__init__(sides, dice, shooter)
        self.come_out_roll = self.come_out_roll()
        self.dice_freq = self.dice_freq()
        self.chart = Bar(print_values=True,
                         print_values_position='top',
                         print_zeroes=False,
                         style=custom_style)

    def dice_graphics(self):
        '''
        Retorna um gráfico de barras contído de média, mediana e
        desvio padrão.
        '''
        dice_mean = round(mean(self.dice_freq), 2)
        dice_median = round(median(self.dice_freq), 2)
        dice_desvpa = round(stdev(self.dice_freq), 2)

        self.chart.title = "Resultado obtido ao jogar " + str(self.dice) + \
            " dado(s) D" + str(self.sides) + " " + \
            str(self.shooter) + " vez(es)."

        self.chart.x_labels = list(range(self.dice, self.max_results + 1))
        self.chart.x_title = "Resultado\n" + "Média " + str(dice_mean) + "," \
            " Mediana " + str(dice_median) + "," \
            " Desvio padrão " + str(dice_desvpa) + "."

        self.chart.y_title = 'Frequência'
        self.chart.add('Dados', self.dice_freq)
        self.chart.render_to_file('rcg_chart_resultado.svg')

    def terminal(self):
        '''Classe que exibe os resultados em texto.'''
        print('Dados sorteados:      ' + str(self.come_out_roll[:11]))
        print('Frequência dos dados: ' + str(self.dice_freq))
示例#31
0
文件: tests.py 项目: Kozea/pygal
 def test_bar():
     bar = Bar(dynamic_print_values=True, show_minor_x_labels=False)
     bar.add('1', [1, 2, 3])
     bar.add('2', [4, 5, 6])
     bar.x_labels = [2, 4, 6]
     bar.x_labels_major = [4]
     return bar.render_response()
示例#32
0
 def test_multiline_title():
     bar = Bar()
     bar.add('Looooooooooooooooooooooooooooooooooong', [2, None, 12])
     bar.title = (
         'First line \n Second line \n Third line'
     )
     return bar.render_response()
示例#33
0
def test_xml_filters_change_bars():
    plot = Bar(legend_at_bottom=True, explicit_size=True,
               width=800, height=600)
    A = [60, 75, 80, 78, 83, 90]
    B = [92, 87, 81, 73, 68, 55]
    plot.add("A", A)
    plot.add("B", B)
    plot.add_xml_filter(ChangeBarsXMLFilter(A, B))
    q = plot.render_tree()
    assert len(q.findall("g")) == 2
    assert q.findall("g")[1].attrib[
        "transform"] == "translate(0,150), scale(1,0.75)"
示例#34
0
def bar_route():
    projects = Project.select()
    bar_chart = Bar()
    bar_chart.title = 'Bar graphs (in %)'

    # instatiating two variables internal and external
    title = 0
    amount = 0

    for project in projects:
        if (project.type == 'title'):
            title += 1
        else:
            amount += 1
    bar_chart.add('title', title)
    bar_chart.add('amount', amount)

    bar_chart.render()
    chart = bar_chart.render_data_uri()

    return render_template('index.html',
                           projects_to_send=projects,
                           chart=chart)
示例#35
0
 def __call__(self, T):
     subplot = Bar(legend_at_bottom=True, explicit_size=True,
                   width=800, height=150)
     subplot.add("Difference", self.data)
     subplot = subplot.render_tree()
     subplot = subplot.findall("g")[0]
     T.insert(2, subplot)
     T.findall("g")[1].set('transform', 'translate(0,150), scale(1,0.75)')
     return T
示例#36
0
def test_xml_filters_change_bars():
    plot = Bar(legend_at_bottom=True, explicit_size=True, width=800, height=600)
    A = [60, 75, 80, 78, 83, 90]
    B = [92, 87, 81, 73, 68, 55]
    plot.add("A", A)
    plot.add("B", B)
    plot.add_xml_filter(ChangeBarsXMLFilter(A,B))
    q = plot.render_tree()
    assert len(q.xpath("g")) == 2
    assert q.xpath("g")[1].attrib["transform"] == "translate(0,150), scale(1,0.75)"
示例#37
0
 def test_ylabels():
     chart = Bar()
     chart.x_labels = "Red", "Blue", "Green"
     chart.y_labels = [
         {"value": 0.0001, "label": "LOL"},
         {"value": 0.0003, "label": "ROFL"},
         {"value": 0.0004, "label": "MAO"},
         {"value": 0.00045, "label": "LMFAO"},
         {"value": 0.0005, "label": "GMCB"},
     ]
     chart.add("line", [0.0002, 0.0005, 0.00035])
     return chart.render_response()
示例#38
0
文件: tests.py 项目: wuzesheng/pygal
 def test_long_title():
     bar = Bar()
     bar.add('Looooooooooooooooooooooooooooooooooong', [2, None, 12])
     bar.title = (
         '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 '
         '12345678901 123456789012 1234567890123 12345678901234 '
         '123456789012345 1234567890123456 12345678901234567 '
         '123456789012345678 1234567890123456789 12345678901234567890 '
         '123456789012345 1234567890123456 12345678901234567 '
         '12345678901 123456789012 1234567890123 12345678901234 '
         '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890')
     return bar.render_response()
示例#39
0
 def test_ylabels():
     chart = Bar()
     chart.x_labels = 'Red', 'Blue', 'Green'
     chart.y_labels = [
         {'value': .0001,
          'label': 'LOL'},
         {'value': .0003,
          'label': 'ROFL'},
         {'value': .0004,
          'label': 'MAO'},
         {'value': .00045,
          'label': 'LMFAO'},
         {'value': .0005,
          'label': 'GMCB'}]
     chart.add('line', [.0002, .0005, .00035])
     return chart.render_response()
示例#40
0
 def test_ylabels():
     chart = Bar()
     chart.x_labels = 'Red', 'Blue', 'Green'
     chart.y_labels = [
         {'value': .0001,
          'label': 'LOL'},
         {'value': .0003,
          'label': 'ROFL'},
         {'value': .0004,
          'label': 'MAO'},
         {'value': .00045,
          'label': 'LMFAO'},
         {'value': .0005,
          'label': 'GMCB'}]
     chart.add('line', [.0002, .0005, .00035])
     return chart.render_response()
示例#41
0
def test_include_x_axis(Chart):
    chart = Chart()
    if Chart in (Pie, Treemap, Radar, Funnel, Dot, Gauge, Worldmap,
                 SupranationalWorldmap, Histogram, Box, FrenchMap_Regions,
                 FrenchMap_Departments):
        return
    if not chart.cls._dual:
        data = 100, 200, 150
    else:
        data = (1, 100), (3, 200), (2, 150)
    chart.add('_', data)
    q = chart.render_pyquery()
    # Ghost thing
    yaxis = ".axis.%s .guides text" % ('y' if not chart._last__inst.horizontal
                                       else 'x')
    if not issubclass(chart.cls, Bar().cls):
        assert '0.0' not in q(yaxis).map(texts)
    else:
        assert '0.0' in q(yaxis).map(texts)
    chart.include_x_axis = True
    q = chart.render_pyquery()
    assert '0.0' in q(yaxis).map(texts)
示例#42
0
    def get(self):
        from pygal import Bar
        path = os.path.join(base_path, 'pygal_js', 'javascripts', 'bar', 'bar_chart.svg')
        config.width = 500
        config.height = 400
        #bar_chart = Bar(config, width=400, height=300, legend_box_size=10)
        args = self.args
        for k, v in args.items():
            if v.isdigit():
                args[k] = int(v)
        bar_chart = Bar(config, **args)
        data = self.args.get("data", "")
        x_labels = self.args.get("x_labels", "")
        bar_chart.add('Fibonacci', [int(i) for i in data.split(",")])  # Add some values
        bar_chart.x_labels = x_labels.split(",")
        bar_chart.render_to_file(path)
        #fileio = StringIO()
        #im.save(fileio, 'svg')
        ##im.save('img.gif', 'gif')
        #im.show()
        #return ''.join(char), fileio

        return self.write(simplejson.dumps({"data":os.path.join(SVG_PATH, 'bar', 'bar_chart.svg')}))
示例#43
0
 def test_bar():
     bar = Bar()
     bar.add('1', [1, 2, 3])
     bar.add('2', [4, 5, 6])
     return bar.render_response()
示例#44
0
def test_bar_percent_difference():
    bar = Bar()
    rng = [-3, -32, -39]
    bar.add('test1', rng)
    bar.add('test2', map(abs, rng))
    bar.x_labels = map(str, rng)

    barpercent = Bar(percent_values=True)
    rng = [-3, -32, -39]
    barpercent.add('test1', rng)
    barpercent.add('test2', map(abs, rng))
    barpercent.x_labels = map(str, rng)

    assert (bar != barpercent)
else:
    roll = 2000
    print(
        'Input was not provided or invalid, so the default value of 1,000 will be used.'
    )

L = sorted(L)

result = []
for i in range(roll):
    sums = 0
    for j in range(len(L)):
        sums += randint(1, L[j])
    result.append(sums)

range_of_sums = list(set(result))
counts = [result.count(i) for i in range_of_sums]
counts = [{
    'value': count,
    'label': f'Frequency: {count / roll:.2f}'
} for count in counts]

histogram = Bar(style=Style(colors=('#228B22', ), major_label_font_size=12),
                show_legend=False)
histogram.title = f'Simulation for {roll} rolls of the dice: {sorted(L)}'
histogram.x_labels = [str(i) for i in range_of_sums]
histogram.x_title = 'Possible sums'
histogram.y_title = 'Counts'
histogram.add('', counts)
histogram.render_to_file('dice_rolls.svg')
示例#46
0
def test_difference():
    bar = Bar(bar_values=False)
    rng = [-3, -32, -39]
    bar.add('test1', rng)
    bar.add('test2', map(abs, rng))
    bar.x_labels = map(str, rng)
    bar_labelled = Bar(bar_values=True)
    rng = [-3, -32, -39]
    bar_labelled.add('test1', rng)
    bar_labelled.add('test2', map(abs, rng))
    bar.labelled = map(str, rng)

    assert bar != bar_labelled
                a_b_fighter_num[0] = 0

    if a_b_alive_num[0] > 0:
        print('a win!')
        return a_b_alive_num[0] * 1
    elif a_b_alive_num[1] > 0:
        print('b win!')
        return a_b_alive_num[1] * (-1)
    else:
        print('tie!')
        return 0


pygame.init()
screen = pygame.display.set_mode((600, 120))
pygame.display.set_caption('progress')
rect = pygame.Rect(10, 10, 0, 100)
result = [0 for num in range(0, 15)]
for num in range(0, 7000):
    check_event()
    rect.width = int(580 * (num + 1) / 7000)
    pygame.draw.rect(screen, (255, 255, 255), rect)
    result[check() + 7] += 1
    pygame.display.update()

hist = Bar()
hist.title = 'a:[[100,100,n],[5,5,p],[4,4,s],[3,3,st],[2,2,p],[7,700,pt],[6,6,pst]]\n' + 'b:[[5,5,p],[2,2,p],[4,4,s],[100,100,n],[3,3,st],[7,700,pt],[6,6,pst]]'

hist.add('result', result)
hist.render_to_file('result_1.svg')
示例#48
0
文件: tests.py 项目: wuzesheng/pygal
 def test_bar():
     bar = Bar()
     bar.add('1', [1, 2, 3])
     bar.add('2', [4, 5, 6])
     return bar.render_response()
示例#49
0
文件: tests.py 项目: wuzesheng/pygal
 def test_unsorted():
     bar = Bar(style=styles['neon'])
     bar.add('A', {'red': 10, 'green': 12, 'blue': 14})
     bar.add('B', {'green': 11, 'blue': 7})
     bar.add('C', {'blue': 7})
     bar.add('D', {})
     bar.add('E', {'blue': 2, 'red': 13})
     bar.x_labels = ('red', 'green', 'blue')
     return bar.render_response()
示例#50
0
文件: tests.py 项目: Kozea/pygal
 def test_bar_none():
     bar = Bar()
     bar.add('Lol', [2, None, 12])
     bar.x_labels = range(1, 4)
     return bar.render_response()
示例#51
0
 def test_bar_none():
     bar = Bar()
     bar.add('Lol', [2, None, 12])
     bar.x_labels = range(1, 4)
     return bar.render_response()
示例#52
0
 def test_unsorted():
     bar = Bar(style=styles["neon"], human_readable=True)
     bar.add("A", {"red": 10, "green": 12, "blue": 14})
     bar.add("B", {"green": 11, "blue": 7})
     bar.add("C", {"blue": 7})
     bar.add("D", {})
     bar.add("E", {"blue": 2, "red": 13})
     bar.x_labels = ("red", "green", "blue")
     return bar.render_response()
示例#53
0
 def test_bar_none():
     bar = Bar()
     bar.add('Lol', [2, None, 12])
     return bar.render_response()
示例#54
0
文件: tests.py 项目: arthru/pygal
 def test_long_title():
     bar = Bar()
     bar.add('Lol', [2, None, 12])
     bar.title = '123456789 ' * 30
     return bar.render_response()
示例#55
0
 def test_bar():
     bar = Bar()
     bar.add('1', [1, 2, 3])
     bar.add('2', [4, 5, 6])
     bar.x_labels = ['a']
     return bar.render_response()
示例#56
0
文件: tests.py 项目: wuzesheng/pygal
 def test_bar_none():
     bar = Bar()
     bar.add('Lol', [2, None, 12])
     return bar.render_response()
示例#57
0
 def test_unsorted():
     bar = Bar(style=styles['neon'])
     bar.add('A', {'red': 10, 'green': 12, 'blue': 14})
     bar.add('B', {'green': 11, 'blue': 7})
     bar.add('C', {'blue': 7})
     bar.add('D', {})
     bar.add('E', {'blue': 2, 'red': 13})
     bar.x_labels = ('red', 'green', 'blue')
     return bar.render_response()
示例#58
0
def test_chart_renders():
    line_chart = Bar(print_values=True, percent_values=True, print_values_position='top')
    line_chart.title = 'Browser usage evolution (in %)'
    line_chart.x_labels = map(str, range(2002, 2013))
    line_chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1])
    line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
    line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
    line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])
    assert line_chart.render()