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 stackedAreaChart(TemplateMixin, NVD3Chart):
16 """
17 The stacked area chart is identical to the area chart, except the areas are stacked
18 on top of each other, rather than overlapping. This can make the chart much easier to read.
19
20 Python example::
21
22 from nvd3 import stackedAreaChart
23 chart = stackedAreaChart(name='stackedAreaChart', height=400, width=400)
24
25 xdata = [100, 101, 102, 103, 104, 105, 106,]
26 ydata = [6, 11, 12, 7, 11, 10, 11]
27 ydata2 = [8, 20, 16, 12, 20, 28, 28]
28
29 extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " min"}}
30 chart.add_serie(name="Serie 1", y=ydata, x=xdata, extra=extra_serie)
31 chart.add_serie(name="Serie 2", y=ydata2, x=xdata, extra=extra_serie)
32 chart.buildhtml()
33 print(chart.content)
34
35 Javascript generated:
36
37 .. include:: ./examples/stackedAreaChart.html
38
39 """
40
41 CHART_FILENAME = "./stackedareachart.html"
42 template_chart_nvd3 = NVD3Chart.template_environment.get_template(CHART_FILENAME)
43
44 def __init__(self, **kwargs):
45 super(stackedAreaChart, self).__init__(**kwargs)
46 height = kwargs.get('height', 450)
47 width = kwargs.get('width', None)
48 self.model = 'stackedAreaChart'
49
50 if kwargs.get('x_is_date', False):
51 self.set_date_flag(True)
52 self.create_x_axis('xAxis',
53 format=kwargs.get('x_axis_format', '%d %b %Y'),
54 date=True)
55 self.set_custom_tooltip_flag(True)
56 else:
57 self.create_x_axis('xAxis', format=kwargs.get('x_axis_format',
58 '.2f'))
59 self.create_y_axis('yAxis', format=kwargs.get('y_axis_format', '.2f'))
60
61 self.set_graph_height(height)
62 if width:
63 self.set_graph_width(width)