Coverage for src/lcdoc/mkdocs/lp/plugs/chartist/__init__.py: 100.00%

Shortcuts 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

21 statements  

1# :docs:page_assets_example 

2page_assets = { 

3 'header': [ 

4 '//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css', 

5 '//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js', 

6 ] 

7} 

8# :docs:page_assets_example 

9 

10 

11# for convenience we allow to declare aspect not only as name but also as ratio: 

12ar = ''' 

13ct-square>1 

14ct-minor-second>15:16 

15ct-major-second>8:9 

16ct-minor-third>5:6 

17ct-major-third>4:5 

18ct-perfect-fourth>3:4 

19ct-perfect-fifth>2:3 

20ct-minor-sixth>5:8 

21ct-golden-section>1:1.618 

22ct-major-sixth>3:5 

23ct-minor-seventh>9:16 

24ct-major-seventh>8:15 

25ct-octave>1:2 

26ct-major-tenth>2:5 

27ct-major-eleventh>3:8 

28ct-major-twelfth>1:3 

29ct-double-octave>1:4 

30''' 

31 

32ar = [l for l in ar.strip().splitlines()] lp|features/lp/plugs/chartist/index.md

33ar = dict([l.split('>') for l in ar]) lp|features/lp/plugs/chartist/index.md

34AR = {v: k for k, v in ar.items()} lp|features/lp/plugs/chartist/index.md

35 

36 

37C = '<div class="ct-chart %(aspect)s" id="%(id)s"></div>' lp|features/lp/plugs/chartist/index.md

38 

39JSF = ''' 

40 

41<script > 

42function do_%(id)s () { %(body)s }; 

43do_%(id)s(); 

44</script> 

45 

46''' 

47 

48 

49P2J = ''' 

50var data = %(data)s; 

51var options = %(options)s; 

52new Chartist.%(type)s('_id_', data, options); 

53''' 

54 

55 

56def py_to_js(cmd): lp|features/lp/plugs/chartist/index.md

57 ml, mg = {}, {} lp|features/lp/plugs/chartist/index.md

58 exec(cmd, mg, ml) lp|features/lp/plugs/chartist/index.md

59 ml['options'] = ml.get('options', {}) lp|features/lp/plugs/chartist/index.md

60 return P2J % ml lp|features/lp/plugs/chartist/index.md

61 

62 

63def run(cmd, kw): lp|features/lp/plugs/chartist/index.md

64 ar = kw.get('aspect', 'ct-square') lp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/chartist/index.md

65 kw['aspect'] = AR.get(ar, ar) lp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/chartist/index.md

66 div = C % kw lp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/chartist/index.md

67 lpjs = py_to_js(cmd) if kw.get('lang') == 'python' else cmd lp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/chartist/index.md

68 lpjs = lpjs.replace('_id_', '#' + kw['id']) lp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/chartist/index.md

69 lpjs = JSF % {'body': lpjs, 'id': kw['id']} lp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/chartist/index.md

70 return {'res': div, 'formatted': True, 'footer': lpjs} lp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/chartist/index.md