Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2@file 

3@brief Simple wrapper for `treant-js <http://fperucic.github.io/treant-js/>`_. 

4""" 

5 

6_template_html = """ 

7<style> 

8__STYLE__ 

9</style> 

10 

11<link rel="stylesheet" href="http://fperucic.github.io/treant-js/Treant.css"> 

12<script src="http://fperucic.github.io/treant-js/vendor/raphael.js"></script> 

13<script src="http://fperucic.github.io/treant-js/Treant.js"></script> 

14<div class="__CLASSCHART__" id="__DIVID__"></div> 

15""" 

16 

17_template_js = """ 

18var tree_structure__DIVID__ = { 

19 __CLASSCHART__: __JSONCHART__, 

20 nodeStructure: __JSONDATA__ 

21}; 

22new Treant( tree_structure__DIVID__ ); 

23""" 

24 

25 

26def display_treant(json_tree, json_data, css, classname): 

27 """ 

28 Display a chart using `treant-js <http://fperucic.github.io/treant-js/>`_. 

29 

30 @param json_tree json which describe global attributes of the tree 

31 @param json_data json which describe the tree structures 

32 @param css style 

33 @param classname class name associated to the section DIV which will receive the 

34 tree 

35 @return HTML object 

36 """ 

37 

38 global _template_html, _template_js # pylint: disable=W0603 

39 uid = "id_" + str(id(json_data)) 

40 

41 # this should be done with jinja2 or mako 

42 ht = _template_html.replace("__STYLE__", css) \ 

43 .replace("__CLASSCHART__", classname) \ 

44 .replace("__JSONCHART__", json_tree) \ 

45 .replace("__JSONDATA__", json_data) \ 

46 .replace("__DIVID__", uid) 

47 jv = _template_js.replace("__STYLE__", css) \ 

48 .replace("__CLASSCHART__", classname) \ 

49 .replace("__JSONCHART__", json_tree) \ 

50 .replace("__JSONDATA__", json_data) \ 

51 .replace("__DIVID__", uid) 

52 

53 from IPython.core.display import HTML 

54 return HTML(ht + "<script>" + jv + "</script>")