generate_io_overview.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # -*- coding: utf-8 -*-
  2. """
  3. This generate diagram of the (raw)ios and formats
  4. Author: Julia Sprenger
  5. """
  6. import pygraphviz
  7. import neo
  8. # from datetime import datetime
  9. #
  10. # import numpy as np
  11. # import quantities as pq
  12. # from matplotlib import pyplot
  13. # from matplotlib.patches import Rectangle, ArrowStyle, FancyArrowPatch
  14. # from matplotlib.font_manager import FontProperties
  15. #
  16. # from neo.test.generate_datasets import fake_neo
  17. #
  18. # line_heigth = .22
  19. # fontsize = 10.5
  20. # left_text_shift = .1
  21. # dpi = 100
  22. default_style = {'shape': 'rectangle',
  23. 'color': 'black',
  24. 'fontcolor': 'black'}
  25. IO_style = default_style.copy()
  26. IO_style['fontsize'] = '30'
  27. IO_style['penwidth'] = 6
  28. styles = {'IO': {'ro': IO_style.copy(),
  29. 'rw': IO_style.copy(),
  30. 'raw': IO_style.copy()
  31. },
  32. 'main': default_style.copy(),
  33. 'ext': default_style.copy()}
  34. styles['IO']['ro']['color'] = '#20B2AA '
  35. styles['IO']['rw']['color'] = '#4169E1 '
  36. styles['IO']['raw']['color'] = '#008080 '
  37. styles['ext']['shape'] = 'circle'
  38. styles['ext']['fillcolor'] = 'red'
  39. styles['ext']['style'] = 'filled'
  40. # styles['ext']['fixedsize'] = 'True'
  41. def generate_diagram(filename, plot_extensions=False):
  42. dia = pygraphviz.AGraph(strict=False, splines='true')
  43. G=dia
  44. G.node_attr['fontname'] = 'Arial'
  45. # G.node_attr['shape'] = 'circle'
  46. # G.node_attr['fixedsize'] = 'true'
  47. # G.node_attr['sep'] = '-100'
  48. G.node_attr['fixedsize'] = 'False'
  49. # G.graph_attr['overlap'] = 'False'
  50. G.graph_attr['packMode'] = 'clust'
  51. # G.graph_attr['levelsgap'] = -500
  52. G.node_attr['fontsize'] = '20'
  53. G.edge_attr['minlen'] = '0'
  54. # G.node_attr['style'] = 'filled'
  55. # G.graph_attr['outputorder'] = 'edgesfirst'
  56. # G.graph_attr['splines'] = "compound"
  57. G.graph_attr['label'] = "NEO {}".format(neo.__version__)
  58. G.graph_attr['ratio'] = '1.0'
  59. # G.edge_attr['color'] = '#1100FF'
  60. G.edge_attr['style'] = 'setlinewidth(4)'
  61. dia.add_node('NEO', shape='circle', fontsize=50)
  62. for io in neo.io.iolist:
  63. io_name = io.name
  64. rawio = False
  65. if issubclass(io, neo.io.basefromrawio.BaseFromRaw):
  66. rawio = True
  67. if io_name == 'BaseIO':
  68. io_name = io.__name__.rstrip('RawIO')
  69. if io_name is None:
  70. try:
  71. io_name = io.__name__.rstrip('IO')
  72. except:
  73. continue
  74. if 'example' in io_name:
  75. continue
  76. if io.is_writable and io.is_readable:
  77. mode = 'rw'
  78. elif io.is_readable:
  79. mode = 'ro'
  80. if rawio:
  81. mode = 'raw'
  82. dia.add_node(io_name, **styles['IO'][mode])
  83. dia.add_edge('NEO', io_name)
  84. if plot_extensions:
  85. for ext in io.extensions:
  86. dia.add_node(ext, **styles['ext'])
  87. dia.add_edge(io_name, ext, minlen=0)
  88. dia.layout(prog='fdp') #neato, dot, twopi, circo, fdp, nop, wc, acyclic, gvpr, gvcolor,
  89. # ccomps, sccmap, tred, sfdp.
  90. for ext in ['png', 'svg', 'eps']:
  91. dia.draw('{}.{}'.format(filename, ext))
  92. if __name__ == '__main__':
  93. generate_diagram('IODiagram', plot_extensions=False)
  94. generate_diagram('IODiagram_ext', plot_extensions=True)
  95. # pyplot.show()