Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions highcharts/highcharts/highcharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json, uuid
import re
import datetime
import urllib2
import html
from collections import Iterable
from .options import BaseOptions, ChartOptions, ColorAxisOptions, \
Expand Down Expand Up @@ -51,6 +52,9 @@ def __init__(self, **kwargs):
This is the base class for all the charts. The following keywords are
accepted:
:keyword: **display_container** - default: ``True``
**offline - default: ``False``
If True, download all .js and .css file and put them
into the generated .html so it can be viewed offline.
"""
# set the model
self.model = self.__class__.__name__ #: The chart model,
Expand All @@ -59,6 +63,7 @@ def __init__(self, **kwargs):
# an Instance of Jinja2 template
self.template_page_highcharts = template_page
self.template_content_highcharts = template_content


# set Javascript src, Highcharts lib needs to make sure it's up to date
self.JSsource = [
Expand All @@ -74,6 +79,9 @@ def __init__(self, **kwargs):
'https://www.highcharts.com/highslide/highslide.css',

]

self.offline = kwargs.get("offline", False)

# set data
self.data = []
self.data_temp = []
Expand Down Expand Up @@ -323,13 +331,27 @@ def buildhtmlheader(self):
if self.drilldown_flag:
self.add_JSsource('http://code.highcharts.com/modules/drilldown.js')

self.header_css = [
'<link href="%s" rel="stylesheet" />' % h for h in self.CSSsource
]

self.header_js = [
'<script type="text/javascript" src="%s"></script>' % h for h in self.JSsource
]

if self.offline:
opener = urllib2.build_opener()
opener.addheaders = [('User-Agent', 'Mozilla/5.0')]

self.header_css = [
'<style>%s</style>' % opener.open(h).read() for h in self.CSSsource
]

self.header_js = [
'<script type="text/javascript">%s</script>' % opener.open(h).read() for h in self.JSsource
]
else:
self.header_css = [
'<link href="%s" rel="stylesheet" />' % h for h in self.CSSsource
]

self.header_js = [
'<script type="text/javascript" src="%s"></script>' % h for h in self.JSsource
]

self.htmlheader = ''
for css in self.header_css:
Expand Down