from jinja2 import Template
from IPython.display import IFrame
import os


class Plotter(object):

    """Class for creating c3js plots in ipython"""

    def __init__(self):
        super(Plotter, self).__init__()
        self.template = '''
<!-- Load c3.css -->
<link href='https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css' rel="stylesheet" type="text/css"/>

<!-- Load d3.js and c3.js -->
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js'></script>
<div id=chart></div>
<script> c3.generate({{data}}); </script>
    '''

    def plot(self, data, name='c3', w=800, h=420):
        html = Template(self.template).render(data=data)
        with open(os.path.join(os.getcwd(), name + '.html'), 'w') as f:
            f.write(html)
        print os.path.join(os.getcwd(), name + '.html')
        return IFrame(os.path.join(os.getcwd(), name + '.html'), w, h)

@@ -749,34 +749,8 @@
 pen(
-os.path.join(os.getcwd(), 
 name
@@ -759,17 +759,16 @@
  '.html'
-)
 , 'w') a
@@ -810,104 +810,22 @@
     
-print os.path.join(os.getcwd(), name + '.html')%0A        return IFrame(os.path.join(os.getcwd(), 
+return IFrame(
 name
@@ -834,17 +834,16 @@
  '.html'
-)
 , w, h)%0A

fix for 404 ## To make a commit, type your commit message and press SUPER-ENTER. To cancel ## the commit, close the window. To sign off the commit press SUPER-S.