当前位置: 首页>>代码示例>>Python>>正文


Python Pie.render_to_file方法代码示例

本文整理汇总了Python中pygal.Pie.render_to_file方法的典型用法代码示例。如果您正苦于以下问题:Python Pie.render_to_file方法的具体用法?Python Pie.render_to_file怎么用?Python Pie.render_to_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygal.Pie的用法示例。


在下文中一共展示了Pie.render_to_file方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_donut

# 需要导入模块: from pygal import Pie [as 别名]
# 或者: from pygal.Pie import render_to_file [as 别名]
def test_donut():
    file_name = '/tmp/test_graph-%s.svg' % uuid.uuid4()
    if os.path.exists(file_name):
        os.remove(file_name)
    chart = Pie(inner_radius=.3, pretty_print=True)
    chart.title = 'Browser usage in February 2012 (in %)'
    chart.add('IE', 19.5)
    chart.add('Firefox', 36.6)
    chart.add('Chrome', 36.3)
    chart.add('Safari', 4.5)
    chart.add('Opera', 2.3)
    chart.render_to_file(file_name)
    with open(file_name) as f:
        assert 'pygal' in f.read()
    os.remove(file_name)
开发者ID:cleder,项目名称:pygal,代码行数:17,代码来源:test_donut.py

示例2: test_multiseries_donut

# 需要导入模块: from pygal import Pie [as 别名]
# 或者: from pygal.Pie import render_to_file [as 别名]
def test_multiseries_donut():
    #this just demos that the multiseries pie does not respect the inner_radius
    file_name = '/tmp/test_graph-%s.svg' % uuid.uuid4()
    if os.path.exists(file_name):
        os.remove(file_name)
    chart = Pie(inner_radius=.3, pretty_print=True)
    chart.title = 'Browser usage by version in February 2012 (in %)'
    chart.add('IE', [5.7, 10.2, 2.6, 1])
    chart.add('Firefox', [.6, 16.8, 7.4, 2.2, 1.2, 1, 1, 1.1, 4.3, 1])
    chart.add('Chrome', [.3, .9, 17.1, 15.3, .6, .5, 1.6])
    chart.add('Safari', [4.4, .1])
    chart.add('Opera', [.1, 1.6, .1, .5])
    chart.render_to_file(file_name)
    with open(file_name) as f:
        assert 'pygal' in f.read()
    os.remove(file_name)
开发者ID:cleder,项目名称:pygal,代码行数:18,代码来源:test_donut.py

示例3: _generate_pie_chart

# 需要导入模块: from pygal import Pie [as 别名]
# 或者: from pygal.Pie import render_to_file [as 别名]
    def _generate_pie_chart(self, datas):
        """
        After generate the pie chart,save to file and return the chart path

        Keyword arguments:
        datas -- Dict object of parsed information for a pie chart
        """
        if not datas:
            return ""

        pie_chart = Pie(fill=True, interpolate="cubic", style=LightStyle)

        for key, value in datas.items():
            pie_chart.add(key, value)

        path = os.path.join(tempfile.gettempdir(), "pie{}.svg".format(str(int(time.time()))))
        pie_chart.render_to_file(path)
        logging.info("Pie chart was created successfully.")

        return path
开发者ID:burakkose,项目名称:reporter-daemon,代码行数:22,代码来源:generator.py

示例4: __init__

# 需要导入模块: from pygal import Pie [as 别名]
# 或者: from pygal.Pie import render_to_file [as 别名]

#.........这里部分代码省略.........
	def sort_data_by_size(self, data):
		"""Used to sort the pie slices by time from largest to smallest."""
		# Make a duplicate of the data so it does not get tampered with
		sorted_data = data
		# Sort from smallest to largest based on time.
		sorted_data.sort(key=itemgetter(1))
		# Make sure that the Other entry is at the end of the list if it exists
		for entry in sorted_data:
			if entry[0] == 'Other ':
				sorted_data.insert(0,sorted_data.pop(sorted_data.index(entry)))
		# Then set data as the sorted data.
		data = sorted_data#[::-1]

	def sort_colorlist(self, data):
		"""Used to make the order of the color_list match the order of the 
			pie_list's activity colors"""
		# Create an empty list to put the sorted colors in
		sorted_colorlist = []
		# Iterate through the chart data
		for entry in data:
			# Get the specified color from the chart data 
			color = int(entry[2])
			# Arrange the colorlist so that the given datum recieves that color
			if color < (len(CONST_COLOR_LIST)-1) or entry[0] == 'Other ':
				sorted_colorlist.append(CONST_COLOR_LIST[color])
			else:
				sorted_colorlist.append(CONST_COLOR_LIST[(color-(len(CONST_COLOR_LIST)-1))])
		# Set the colorlist to the sorted_colorlist
		self.colorlist = sorted_colorlist
		if not self.colorlist == []:
			self.style = Style(background='#F7F6F6',
						plot_background='#F7F6F6',
						foreground='#888a85',
						foreground_light='#888a85',
						foreground_dark='#555753',
						opacity='.6',
						opacity_hover='.9',
						transition='200ms ease-in',
							colors=(self.colorlist))

	def sort(self, data):
		"""Sort the data and colors"""
		if not data == []:
			self.compound_other_data(data)
			self.sort_data_by_size(data)
			self.sort_colorlist(data)

	def send_to_svg(self):
		"""Send the prepared pie graph to an SVG file"""
		self.chart.render_to_file(self.filepath)
		# Set the font in the svg file to the font specified during __init__ 
		self.fix_font()
		if hasattr(self.chart, 'y_labels'):
			self.fix_tooltip()	
			for label in self.chart.y_labels:
				self.convert_y_axis_to_time(label)

	def fix_font(self):
		"""Changes the SVG file's default font (monospace) to the font specified
			when the charter was initialized"""
		if not self.font == None:
			system(("sed -i 's/font-family:monospace/font-family:" + self.font 
						+ "/g' " + self.filepath))

	def start_loading_animation(self):
		"""Callback to start loading animation"""      
        GLib.timeout_add(400, self.get_loading_animation)
	
	def get_loading_animation(self):
		"""Checks to see wheteher or not we should continue loading animation"""
		if self.visible:
	        chart_loading = not (str(self.webview.get_load_status()) == '<enum WEBKIT_LOAD_FAILED of type WebKitLoadStatus>' 
	                    or str(self.webview.get_load_status()) == '<enum WEBKIT_LOAD_FINISHED of type WebKitLoadStatus>')
	        if not chart_loading:
	            self.loading_spinner.stop()
	            self.loading_spinner.set_visible(False)
	            self.webview_window.set_visible(True)
	        return chart_loading
	    else:
	    	return False       

	def load_into_webview(self, initial=False):
		"""Load the SVG file for the chart into the webview"""
		#self.sort()
		self.send_to_svg()
		if initial:
			self.webview.open(self.filepath)
		else:
			self.webview.reload()
			if self.visible:
				self.webview_window.set_visible(False)
				self.loading_spinner.set_visible(True)
				self.loading_spinner.start()
				self.start_loading_animation()

	def set_visible(self, visible=True):
		self.visible = visible
		self.webview_window.set_visible(visible)
		if not visible:
			self.loading_spinner.set_visible(False)
开发者ID:NicholasShatokhin,项目名称:spindl,代码行数:104,代码来源:charter.py


注:本文中的pygal.Pie.render_to_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。