Debian Codegraph @

mplexporter/tools.py

raw symbols SCIP
1 """
2 Tools for matplotlib plot exporting
3 """
4
5
6 def ipynb_vega_init():
7 """Initialize the IPython notebook display elements
8
9 This function borrows heavily from the excellent vincent package:
10 http://github.com/wrobstory/vincent
11 """
12 try:
13 from IPython.core.display import display, HTML
14 except ImportError:
15 print('IPython Notebook could not be loaded.')
16
17 require_js = '''
18 if (window['d3'] === undefined) {{
19 require.config({{ paths: {{d3: "http://d3js.org/d3.v3.min"}} }});
20 require(["d3"], function(d3) {{
21 window.d3 = d3;
22 {0}
23 }});
24 }};
25 if (window['topojson'] === undefined) {{
26 require.config(
27 {{ paths: {{topojson: "http://d3js.org/topojson.v1.min"}} }}
28 );
29 require(["topojson"], function(topojson) {{
30 window.topojson = topojson;
31 }});
32 }};
33 '''
34 d3_geo_projection_js_url = "http://d3js.org/d3.geo.projection.v0.min.js"
35 d3_layout_cloud_js_url = ("http://wrobstory.github.io/d3-cloud/"
36 "d3.layout.cloud.js")
37 topojson_js_url = "http://d3js.org/topojson.v1.min.js"
38 vega_js_url = 'http://trifacta.github.com/vega/vega.js'
39
40 dep_libs = '''$.getScript("%s", function() {
41 $.getScript("%s", function() {
42 $.getScript("%s", function() {
43 $.getScript("%s", function() {
44 $([IPython.events]).trigger("vega_loaded.vincent");
45 })
46 })
47 })
48 });''' % (d3_geo_projection_js_url, d3_layout_cloud_js_url,
49 topojson_js_url, vega_js_url)
50 load_js = require_js.format(dep_libs)
51 html = '<script>'+load_js+'</script>'
52 display(HTML(html))