def include_chart_jscss(static_dir=''): """ Include the html for the chart container and css for nvd3 This will include something similar as : <link media="all" href="/static/nvd3/src/nv.d3.css" type="text/css" rel="stylesheet" /> <script src="/static/d3/d3.min.js" type="text/javascript"></script> <script src="/static/nvd3/nv.d3.min.js" type="text/javascript"></script> **usage**: {% include_chart_jscss 'newfies' %} **Arguments**: * ``static_dir`` - """ if static_dir: static_dir += '/' chart = NVD3Chart() chart.header_css = [ '<link media="all" href="%s" type="text/css" rel="stylesheet" />\n' % h for h in ("http://cdn.bootcss.com/nvd3/1.1.13-beta/nv.d3.min.css", ) ] chart.header_js = [ '<script src="%s" type="text/javascript"></script>\n' % h for h in ("http://cdn.bootcss.com/d3/3.3.8/d3.min.js", "http://cdn.bootcss.com/nvd3/1.1.13-beta/nv.d3.min.js") ] chart.buildhtmlheader() return mark_safe(chart.htmlheader + '\n')
def include_nvd3jscss(use_cdn=True): """ Include the javascript and css for nvd3 This will include something similar as : <link media="all" href="http://nvd3.org/src/nv.d3.css" type="text/css" rel="stylesheet" /> <script src="http://nvd3.org/lib/d3.v2.js" type="text/javascript"></script> <script src="http://nvd3.org/nv.d3.js" type="text/javascript"></script> **usage**: {% include_nvd3jscss True %} **Arguments**: * ``use_cdn`` - option to use the public cdn or link to static folder """ chart = NVD3Chart() if not use_cdn: chart.header_css = [settings.STATIC_URL + 'nvd3/css/nv.d3.css'] chart.header_js = [ settings.STATIC_URL + 'nvd3/js/d3.v2.js', settings.STATIC_URL + 'nvd3/js/nv.d3.js' ] chart.buildhtmlheader() return mark_safe(chart.htmlheader + '\n')
def include_chart_jscss(static_dir='', css_dir='', js_dir=''): """ Include the html for the chart container and css for nvd3 This will include something similar as : <link media="all" href="/static/nvd3/src/nv.d3.css" type="text/css" rel="stylesheet" /> <script src="/static/d3/d3.min.js" type="text/javascript"></script> <script src="/static/nvd3/nv.d3.min.js" type="text/javascript"></script> **usage**: {% include_chart_jscss %} Or if you want to specify a subdirectory below STATIC_URL for all static files, {% include_chart_jscss 'newfies' %} Or if you have all your CSS and JS files in particular directories and want to specify them, {% include_chart_jscss css_dir='css' js_dir='js' %} **Arguments**: * ``static_dir`` - * ``css_dir`` - * ``js_dir`` - """ if static_dir: static_dir += '/' css_files_dirs = collections.OrderedDict() js_files_dirs = collections.OrderedDict() css_files_dirs['nv.d3.min.css'] = '%s%snvd3/build/' % (settings.STATIC_URL, static_dir) js_files_dirs['d3.min.js'] = '%s%sd3/' % (settings.STATIC_URL, static_dir) js_files_dirs['nv.d3.min.js'] = '%s%snvd3/build/' % (settings.STATIC_URL, static_dir) if css_dir: if not css_dir.endswith('/'): css_dir += '/' for css_file in css_files_dirs: css_files_dirs[css_file] = '%s%s%s' % (settings.STATIC_URL, static_dir, css_dir) if js_dir: if not js_dir.endswith('/'): js_dir += '/' for js_file in js_files_dirs: js_files_dirs[js_file] = '%s%s%s' % (settings.STATIC_URL, static_dir, js_dir) chart = NVD3Chart() chart.header_css = [ '<link media="all" href="%s" type="text/css" rel="stylesheet" />\n' % h for h in ( '%s%s' % (path, css_file) for css_file, path in css_files_dirs.items() ) ] chart.header_js = [ '<script src="%s" type="text/javascript" charset="utf-8"></script>\n' % h for h in ( '%s%s' % (path, js_file) for js_file, path in js_files_dirs.items() ) ] chart.buildhtmlheader() return mark_safe(chart.htmlheader + '\n')
def include_container(include_container, height=400, width=600): """ Include the html for the chart container and css for nvd3 This will include something similar as : <div id="containername"><svg style="height:400px;width:600px;"></svg></div> **usage**: {% include_container "lineWithFocusChart" 400 400 %} **Arguments**: * ``include_container`` - container_name * ``height`` - Chart height * ``width`` - Chart width """ chart = NVD3Chart() chart.name = str(include_container) chart.set_graph_height(height) chart.set_graph_width(width) # chart.margin_left(2000) chart.buildcontainer() return mark_safe(chart.container + '\n')