def wavejson_to_wavedrom(wavejson, width=None, skin='default'):
'''
Create WaveDrom display from WaveJSON data.
This code is from https://github.com/witchard/ipython-wavedrom.
Inputs:
width: Width of the display window in pixels. If left as None, the entire
waveform will be squashed into the width of the page. To prevent
this, set width to a large value. The display will then become scrollable.
skin: Selects the set of graphic elements used to draw the waveforms.
Allowable values are 'default' and 'narrow'.
'''
# Set the width of the waveform display.
style = ''
if width != None:
style = ' style="width: {w}px"'.format(w=str(int(width)))
# Generate the HTML from the JSON.
htmldata = '<div{style}><script type="WaveDrom">{json}</script></div>'.format(
style=style, json=json.dumps(wavejson))
DISP.display_html(DISP.HTML(htmldata))
# Trigger the WaveDrom Javascript that creates the graphical display.
DISP.display_javascript(
DISP.Javascript(
data='WaveDrom.ProcessAll();',
lib=[
'http://wavedrom.com/wavedrom.min.js',
'http://wavedrom.com/skins/{skin}.js'.format(skin=skin)
]))
# The following allows the display of WaveDROM in the HTML files generated by nbconvert.
# It's disabled because it makes Github's nbconvert freak out.
setup = '''
<script src="http://wavedrom.com/skins/{skin}.js" type="text/javascript"></script>
<script src="http://wavedrom.com/wavedrom.min.js" type="text/javascript"></script>
<body onload="WaveDrom.ProcessAll()">
'''.format(skin=skin)
#DISP.display_html(DISP.HTML(setup))
评论列表
文章目录