Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/nvd3/pieChart.py: 27%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

22 statements  

1#!/usr/bin/python 

2# -*- coding: utf-8 -*- 

3 

4""" 

5Python-nvd3 is a Python wrapper for NVD3 graph library. 

6NVD3 is an attempt to build re-usable charts and chart components 

7for d3.js without taking away the power that d3.js gives you. 

8 

9Project location : https://github.com/areski/python-nvd3 

10""" 

11 

12from .NVD3Chart import NVD3Chart, TemplateMixin 

13 

14 

15class pieChart(TemplateMixin, NVD3Chart): 

16 

17 """ 

18 A pie chart (or a circle graph) is a circular chart divided into sectors, 

19 illustrating numerical proportion. In chart, the arc length of each sector 

20 is proportional to the quantity it represents. 

21 

22 Python example:: 

23 

24 from nvd3 import pieChart 

25 chart = pieChart(name='pieChart', color_category='category20c', 

26 height=400, width=400) 

27 

28 xdata = ["Orange", "Banana", "Pear", "Kiwi", "Apple", "Strawbery", 

29 "Pineapple"] 

30 ydata = [3, 4, 0, 1, 5, 7, 3] 

31 

32 extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} 

33 chart.add_serie(y=ydata, x=xdata, extra=extra_serie) 

34 chart.buildhtml() 

35 print(chart.content) 

36 

37 Javascript generated: 

38 

39 .. include:: ./examples/pieChart.html 

40 

41 """ 

42 CHART_FILENAME = "./piechart.html" 

43 template_chart_nvd3 = NVD3Chart.template_environment.get_template(CHART_FILENAME) 

44 

45 def __init__(self, **kwargs): 

46 super(pieChart, self).__init__(**kwargs) 

47 

48 height = kwargs.get('height', 450) 

49 width = kwargs.get('width', None) 

50 self.donut = kwargs.get('donut', False) 

51 self.donutRatio = kwargs.get('donutRatio', 0.35) 

52 self.color_list = [] 

53 self.create_x_axis('xAxis', format=None) 

54 self.create_y_axis('yAxis', format=None) 

55 # must have a specified height, otherwise it superimposes both chars 

56 if height: 

57 self.set_graph_height(height) 

58 if width: 

59 self.set_graph_width(width) 

60 self.donut = kwargs.get('donut', False) 

61 self.donutRatio = kwargs.get('donutRatio', 0.35) 

62 self.callback = kwargs.get('callback', None)