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

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

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

16 

17 """ 

18 A scatter plot or scattergraph is a type of mathematical diagram using Cartesian 

19 coordinates to display values for two variables for a set of data. 

20 The data is displayed as a collection of points, each having the value of one variable 

21 determining the position on the horizontal axis and the value of the other variable 

22 determining the position on the vertical axis. 

23 

24 Python example:: 

25 

26 from nvd3 import scatterChart 

27 chart = scatterChart(name='scatterChart', height=400, width=400) 

28 xdata = [3, 4, 0, -3, 5, 7] 

29 ydata = [-1, 2, 3, 3, 15, 2] 

30 ydata2 = [1, -2, 4, 7, -5, 3] 

31 

32 kwargs1 = {'shape': 'circle', 'size': '1'} 

33 kwargs2 = {'shape': 'cross', 'size': '10'} 

34 

35 extra_serie = {"tooltip": {"y_start": "", "y_end": " call"}} 

36 chart.add_serie(name="series 1", y=ydata, x=xdata, extra=extra_serie, **kwargs1) 

37 

38 extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} 

39 chart.add_serie(name="series 2", y=ydata2, x=xdata, extra=extra_serie, **kwargs2) 

40 chart.buildhtml() 

41 print(chart.content) 

42 

43 Javascript generated: 

44 

45 .. include:: ./examples/scatterChart.html 

46 

47 """ 

48 

49 CHART_FILENAME = "./scatterchart.html" 

50 template_chart_nvd3 = NVD3Chart.template_environment.get_template(CHART_FILENAME) 

51 

52 def __init__(self, **kwargs): 

53 super(scatterChart, self).__init__(**kwargs) 

54 self.model = 'scatterChart' 

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

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

57 self.create_x_axis('xAxis', format=kwargs.get('x_axis_format', '.02f'), 

58 label=kwargs.get('x_axis_label', None)) 

59 self.create_y_axis('yAxis', format=kwargs.get('y_axis_format', '.02f'), 

60 label=kwargs.get('y_axis_label', None)) 

61 self.set_graph_height(height) 

62 if width: 

63 self.set_graph_width(width)