Skip to content

Commit

Permalink
cleaned up imports and added .iframe property
Browse files Browse the repository at this point in the history
  • Loading branch information
ksolan committed Oct 20, 2015
1 parent 42ce7cc commit 3b3f0b4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
22 changes: 18 additions & 4 deletions highcharts/highcharts/highcharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
from past.builtins import basestring

from jinja2 import Environment, PackageLoader
# import sys
# reload(sys)
# sys.setdefaultencoding("utf-8")

import json, uuid
import datetime, random, os, inspect
import datetime
import html
from collections import Iterable
from .options import BaseOptions, ChartOptions, \
ColorsOptions, CreditsOptions, DrilldownOptions, ExportingOptions, \
Expand Down Expand Up @@ -357,6 +355,22 @@ def buildcontainer(self):
def htmlcontent(self):
return self.buildhtml()

@property
def iframe(self):
htmlsrcdoc = html.escape(self.htmlcontent)
width = int(self.options['chart'].__dict__['width']) if self.options['chart'].__dict__.get('width') else 820
height = int(self.options['chart'].__dict__['height']) if self.options['chart'].__dict__.get('height') else 520

if self.options['chart'].__dict__.get('options3d'):
if len(htmlsrcdoc) < 99965000 :
return '<iframe style="border:0;outline:none;overflow:hidden" src="data:text/html,'+ htmlsrcdoc + ' "height= ' + str(height) +' \
width =' + str(width) + '></iframe>'
else:
return '<iframe style="border:0;outline:none;overflow:hidden" srcdoc="'+ htmlsrcdoc + ' "height= '+ str(height) + ' width = ' + str(width) + '></iframe>'
else:
return '<iframe style="border:0;outline:none;overflow:hidden" srcdoc="'+ htmlsrcdoc + ' "height= '+ str(height) + ' width = ' + str(width) + '></iframe>'


def __str__(self):
"""return htmlcontent"""
#self.buildhtml()
Expand Down
19 changes: 17 additions & 2 deletions highcharts/highmaps/highmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

from past.builtins import basestring

from optparse import OptionParser
from urllib.request import urlopen
from jinja2 import Environment, PackageLoader

import json, uuid
import datetime, random, os, inspect
import datetime
import html
from collections import Iterable
from .options import BaseOptions, ChartOptions, \
ColorsOptions, ColorAxisOptions, CreditsOptions, DrilldownOptions, ExportingOptions, \
Expand Down Expand Up @@ -418,6 +418,21 @@ def buildcontainer(self):
def htmlcontent(self):
return self.buildhtml()

@property
def iframe(self):
htmlsrcdoc = html.escape(self.htmlcontent)
width = int(self.options['chart'].__dict__['width']) if self.options['chart'].__dict__.get('width') else 820
height = int(self.options['chart'].__dict__['height']) if self.options['chart'].__dict__.get('height') else 520

if self.options['chart'].__dict__.get('options3d'):
if len(htmlsrcdoc) < 99965000 :
return '<iframe style="border:0;outline:none;overflow:hidden" src="data:text/html,'+ htmlsrcdoc + ' "height= ' + str(height) +' \
width =' + str(width) + '></iframe>'
else:
return '<iframe style="border:0;outline:none;overflow:hidden" srcdoc="'+ htmlsrcdoc + ' "height= '+ str(height) + ' width = ' + str(width) + '></iframe>'
else:
return '<iframe style="border:0;outline:none;overflow:hidden" srcdoc="'+ htmlsrcdoc + ' "height= '+ str(height) + ' width = ' + str(width) + '></iframe>'

def __str__(self):
"""return htmlcontent"""
#self.buildhtml()
Expand Down
19 changes: 17 additions & 2 deletions highcharts/highstock/highstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from future.standard_library import install_aliases
install_aliases()

from optparse import OptionParser
from jinja2 import Environment, PackageLoader

import json, uuid
import datetime, random, os, inspect
import datetime
import html
from collections import Iterable
from .options import BaseOptions, ChartOptions, \
ColorsOptions, CreditsOptions, ExportingOptions, \
Expand Down Expand Up @@ -352,6 +352,21 @@ def buildcontainer(self):
def htmlcontent(self):
return self.buildhtml()

@property
def iframe(self):
htmlsrcdoc = html.escape(self.htmlcontent)
width = int(self.options['chart'].__dict__['width']) if self.options['chart'].__dict__.get('width') else 820
height = int(self.options['chart'].__dict__['height']) if self.options['chart'].__dict__.get('height') else 520

if self.options['chart'].__dict__.get('options3d'):
if len(htmlsrcdoc) < 99965000 :
return '<iframe style="border:0;outline:none;overflow:hidden" src="data:text/html,'+ htmlsrcdoc + ' "height= ' + str(height) +' \
width =' + str(width) + '></iframe>'
else:
return '<iframe style="border:0;outline:none;overflow:hidden" srcdoc="'+ htmlsrcdoc + ' "height= '+ str(height) + ' width = ' + str(width) + '></iframe>'
else:
return '<iframe style="border:0;outline:none;overflow:hidden" srcdoc="'+ htmlsrcdoc + ' "height= '+ str(height) + ' width = ' + str(width) + '></iframe>'

def __str__(self):
"""return htmlcontent"""
#self.buildhtml()
Expand Down
15 changes: 1 addition & 14 deletions highcharts/ipynb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,7 @@ def _print_html(chart):
to generate the chart. This function is bound to the ipython formatter so that
charts are displayed inline.'''

import html
htmlsrcdoc = html.escape(chart.htmlcontent)
width = int(chart.options['chart'].__dict__['width']) if chart.options['chart'].__dict__.get('width') else 820
height = int(chart.options['chart'].__dict__['height']) if chart.options['chart'].__dict__.get('height') else 520

if chart.options['chart'].__dict__.get('options3d'):
if len(htmlsrcdoc) < 99965000 :
return '<iframe style="border:0;outline:none;overflow:hidden" src="data:text/html,'+ htmlsrcdoc + ' "height= ' + str(height) +' \
width =' + str(width) + '></iframe>'
else:
return '<iframe style="border:0;outline:none;overflow:hidden" srcdoc="'+ htmlsrcdoc + ' "height= '+ str(height) + ' width = ' + str(width) + '></iframe>'
else:
return '<iframe style="border:0;outline:none;overflow:hidden" srcdoc="'+ htmlsrcdoc + ' "height= '+ str(height) + ' width = ' + str(width) + '></iframe>'

return chart.iframe

def _setup_ipython_formatter(ip):
''' Set up the ipython formatter to display HTML formatted output inline'''
Expand Down

0 comments on commit 3b3f0b4

Please sign in to comment.