def make_transform_graph_docs(transform_graph): """ Generates a string that can be used in other docstrings to include a transformation graph, showing the available transforms and coordinate systems. Parameters ---------- transform_graph : `~.coordinates.TransformGraph` Returns ------- docstring : str A string that can be added to the end of a docstring to show the transform graph. """ from textwrap import dedent coosys = [transform_graph.lookup_name(item) for item in transform_graph.get_names()] # currently, all of the priorities are set to 1, so we don't need to show # then in the transform graph. graphstr = transform_graph.to_dot_graph(addnodes=coosys, priorities=False) docstr = """ The diagram below shows all of the built in coordinate systems, their aliases (useful for converting other coordinates to them using attribute-style access) and the pre-defined transformations between them. The user is free to override any of these transformations by defining new transformations between these systems, but the pre-defined transformations should be sufficient for typical usage. The color of an edge in the graph (i.e. the transformations between two frames) is set by the type of transformation; the legend box defines the mapping from transform class name to color. .. Wrap the graph in a div with a custom class to allow themeing. .. container:: frametransformgraph .. graphviz:: """ docstr = dedent(docstr) + ' ' + graphstr.replace('\n', '\n ') # colors are in dictionary at the bottom of transformations.py from astropy.coordinates.transformations import trans_to_color html_list_items = [] for cls, color in trans_to_color.items(): block = u""" <li style='list-style: none;'> <p style="font-size: 12px;line-height: 24px;font-weight: normal;color: #848484;padding: 0;margin: 0;"> <b>{0}:</b> <span style="font-size: 24px; color: {1};"><b>➝</b></span> </p> </li> """.format(cls.__name__, color) html_list_items.append(block) graph_legend = u""" .. raw:: html <ul> {} </ul> """.format("\n".join(html_list_items)) docstr = docstr + dedent(graph_legend) return docstr
def make_transform_graph_docs(transform_graph): """ Generates a string that can be used in other docstrings to include a transformation graph, showing the available transforms and coordinate systems. Parameters ---------- transform_graph : `~.coordinates.TransformGraph` Returns ------- docstring : str A string that can be added to the end of a docstring to show the transform graph. """ from textwrap import dedent coosys = [ transform_graph.lookup_name(item) for item in transform_graph.get_names() ] # currently, all of the priorities are set to 1, so we don't need to show # then in the transform graph. graphstr = transform_graph.to_dot_graph(addnodes=coosys, priorities=False) docstr = """ The diagram below shows all of the built in coordinate systems, their aliases (useful for converting other coordinates to them using attribute-style access) and the pre-defined transformations between them. The user is free to override any of these transformations by defining new transformations between these systems, but the pre-defined transformations should be sufficient for typical usage. The color of an edge in the graph (i.e. the transformations between two frames) is set by the type of transformation; the legend box defines the mapping from transform class name to color. .. Wrap the graph in a div with a custom class to allow themeing. .. container:: frametransformgraph .. graphviz:: """ docstr = dedent(docstr) + ' ' + graphstr.replace('\n', '\n ') # colors are in dictionary at the bottom of transformations.py from astropy.coordinates.transformations import trans_to_color html_list_items = [] for cls, color in trans_to_color.items(): block = """ <li style='list-style: none;'> <p style="font-size: 12px;line-height: 24px;font-weight: normal;color: #848484;padding: 0;margin: 0;"> <b>{}:</b> <span style="font-size: 24px; color: {};"><b>➝</b></span> </p> </li> """.format(cls.__name__, color) html_list_items.append(block) graph_legend = """ .. raw:: html <ul> {} </ul> """.format("\n".join(html_list_items)) docstr = docstr + dedent(graph_legend) return docstr