Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/python_nvd3-0.14.2-py3.8.egg/nvd3/multiBarHorizontalChart.py: 43%

14 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-03 06:25 +0000

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 multiBarHorizontalChart(TemplateMixin, NVD3Chart): 

16 """ 

17 A multiple horizontal bar graph contains comparisons of two or more categories or bars. 

18 

19 Python example:: 

20 

21 from nvd3 import multiBarHorizontalChart 

22 chart = multiBarHorizontalChart(name='multiBarHorizontalChart', height=400, width=400) 

23 xdata = [-14, -7, 7, 14] 

24 ydata = [-6, 5, -1, 9] 

25 y2data = [-23, -6, -32, 9] 

26 

27 extra_serie = {"tooltip": {"y_start": "", "y_end": " balls"}} 

28 chart.add_serie(name="Serie 1", y=ydata, x=xdata, extra=extra_serie) 

29 

30 extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}} 

31 chart.add_serie(name="Serie 2", y=y2data, x=xdata, extra=extra_serie) 

32 chart.buildcontent() 

33 

34 Javascript generated: 

35 

36 .. raw:: html 

37 

38 <div id="multiBarHorizontalChart"><svg style="height:450px; width:100%"></svg></div> 

39 <script> 

40 

41 data_multiBarHorizontalChart=[{"values": 

42 [{"y": -6, "x": -14}, {"y": 5, "x": -7}, {"y": -1, "x": 7}, {"y": 9, "x": 14}], 

43 "key": "Serie 1", "yAxis": "1"}, 

44 {"values": 

45 [{"y": -23, "x": -14}, {"y": -6, "x": -7}, {"y": -32, "x": 7}, {"y": 9, "x": 14}], 

46 "key": "Serie 2", "yAxis": "1"}]; 

47 

48 nv.addGraph(function() { 

49 var chart = nv.models.multiBarHorizontalChart(); 

50 

51 chart.margin({top: 30, right: 60, bottom: 20, left: 60}); 

52 

53 var datum = data_multiBarHorizontalChart; 

54 

55 chart.xAxis 

56 .tickFormat(d3.format(',.2f')); 

57 chart.yAxis 

58 .tickFormat(d3.format(',.2f')); 

59 

60 chart.tooltipContent(function(key, y, e, graph) { 

61 var x = String(graph.point.x); 

62 var y = String(graph.point.y); 

63 if(key == 'Serie 1'){ 

64 var y = String(graph.point.y) + ' balls'; 

65 } 

66 if(key == 'Serie 2'){ 

67 var y = String(graph.point.y) + ' calls'; 

68 } 

69 

70 tooltip_str = '<center><b>'+key+'</b></center>' + y + ' at ' + x; 

71 return tooltip_str; 

72 }); 

73 

74 chart.showLegend(true); 

75 

76 d3.select('#multiBarHorizontalChart svg') 

77 .datum(datum) 

78 .transition().duration(500) 

79 .attr('width', 400) 

80 .attr('height', 400) 

81 .call(chart); 

82 }); 

83 </script> 

84 

85 """ 

86 

87 CHART_FILENAME = "./multibarcharthorizontal.html" 

88 template_chart_nvd3 = NVD3Chart.template_environment.get_template(CHART_FILENAME) 

89 

90 def __init__(self, **kwargs): 

91 super(multiBarHorizontalChart, self).__init__(**kwargs) 

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

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

94 

95 self.create_x_axis('xAxis', format=kwargs.get('x_axis_format', '.2f')) 

96 self.create_y_axis('yAxis', format=kwargs.get('y_axis_format', '.2f')) 

97 

98 self.set_graph_height(height) 

99 if width: 

100 self.set_graph_width(width)