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 lineWithFocusChart(TemplateMixin, NVD3Chart):
16 """
17 A lineWithFocusChart or line graph is a type of chart which displays information
18 as a series of data points connected by straight line segments.
19 The lineWithFocusChart provide a smaller chart that act as a selector,
20 this is very useful if you want to zoom on a specific time period.
21
22 Python example::
23
24 from nvd3 import lineWithFocusChart
25 chart = lineWithFocusChart(name='lineWithFocusChart', x_is_date=True, x_axis_format="%d %b %Y")
26 xdata = [1365026400000, 1365026500000, 1365026600000, 1365026700000, 1365026800000, 1365026900000, 1365027000000]
27 ydata = [-6, 5, -1, 2, 4, 8, 10]
28
29 extra_serie = {"tooltip": {"y_start": "", "y_end": " ext"},
30 "date_format": "%d %b %Y"}
31 chart.add_serie(name="Serie 1", y=ydata, x=xdata, extra=extra_serie)
32 chart.buildhtml()
33 print(chart.content)
34
35 Javascript generated:
36
37 .. include:: ./examples/lineWithFocusChart.html
38
39
40 """
41
42 CHART_FILENAME = "./linewfocuschart.html"
43 template_chart_nvd3 = NVD3Chart.template_environment.get_template(CHART_FILENAME)
44
45 def __init__(self, **kwargs):
46 super(lineWithFocusChart, self).__init__(**kwargs)
47 self.model = 'lineWithFocusChart'
48
49 height = kwargs.get('height', 450)
50 width = kwargs.get('width', None)
51
52 if kwargs.get('x_is_date', False):
53 self.set_date_flag(True)
54 self.create_x_axis('xAxis', format=kwargs.get('x_axis_format',
55 '%d %b %Y %H %S'),
56 date=True)
57 self.create_x_axis('x2Axis', format=kwargs.get('x_axis_format',
58 '%d %b %Y %H %S'),
59 date=True)
60 self.set_custom_tooltip_flag(True)
61 else:
62 self.create_x_axis('xAxis', format=kwargs.get('x_axis_format',
63 '.2f'))
64 self.create_x_axis('x2Axis', format=kwargs.get('x_axis_format',
65 '.2f'))
66
67 self.create_y_axis('yAxis', format=kwargs.get('y_axis_format', '.2f'))
68 self.create_y_axis('y2Axis', format=kwargs.get('y_axis_format', '.2f'))
69
70 self.set_graph_height(height)
71 if width:
72 self.set_graph_width(width)