def network_draw_edge_labels(network, text=None, layer=None, color=None): """Draw labels for the edges of a network. Parameters ---------- network : compas.datastructures.Network A network object. text : str (None) The name of the attribute value to display in the label. Default is to display the edge keys. layer : str (None) The layer to draw in. Default is to draw in the current layer. color : str, tuple, list, dict (None) The color specififcation for the labels. Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components. To apply the same color to all face labels, provide a single color specification. Individual colors can be assigned using a dictionary of key-color pairs. Missing keys will be assigned the default edge color (``self.defaults['edge.color']``). Default is to inherit color from the parent layer. formatter : callable (None) A formatting function. Defaults to the built-in ``str`` function. Notes ----- The labels are named using the following template: ``"{}.edge.label.{}".format(self.network.name, key)``. This name is used afterwards to identify edges of the network in the Rhino model. Examples -------- >>> """ # if formatter: # assert callable(formatter), 'The provided formatter is not callable.' # else: # formatter = str if not text or text == 'key': text = {(u, v): '{}-{}'.format(u, v) for u, v in network.edges()} elif text == 'index': text = {(u, v): str(index) for index, (u, v) in enumerate(network.edges())} else: pass artist = NetworkArtist(network) artist.layer = layer artist.clear_edgelabels() artist.draw_edgelabels(text=text, color=color) artist.redraw()
def network_draw(network, layer=None, clear_layer=False, clear_vertices=True, clear_edges=True, vertexcolor=None, edgecolor=None): """Draw a network data structure in Rhino. Parameters ---------- network : compas.datastructures.Network A network object. layer : str (None) The layer to draw in. Default is the current layer. clear_layer : bool (False) Clear the layer. vertexcolor : list, tuple, str, dict (None) The color specification for the vertices. * list, tuple: rgb color, with color specs between 0 and 255 (e.g. ``(255, 0, 0)``). * str: hex color (e.g. ``'#ff0000'``). * dict: dictionary of hex or rgb colors. edgecolor : list, tuple, str, dict (None) The color specification for the edges. * list, tuple: rgb color, with color specs between 0 and 255 (e.g. ``(255, 0, 0)``). * str: hex color (e.g. ``'#ff0000'``). * dict: dictionary of hex or rgb color. Notes ----- * Any network objects with the same name that are already present in the model will be deleted by this function. * To also clear the entire layer the network will be drawn on, for example, if you have a dedicated network layer, use the ``clear_layer`` flag as well. See Also -------- * :func:`network_draw_vertices` * :func:`network_draw_edges` Examples -------- >>> """ artist = NetworkArtist(network) artist.layer = layer if clear_layer: artist.clear_layer() if clear_vertices: artist.clear_vertices() if clear_edges: artist.clear_edges() artist.draw_vertices(color=vertexcolor) artist.draw_edges(color=edgecolor) artist.redraw()
def network_draw_vertex_labels(network, attr_name=None, layer=None, color=None, formatter=None): """Draw labels for the vertices of the network. Parameters ---------- network : compas.datastructures.Network A network object. attr_name : str (None) The name of the attribute value to display in the label. Default is is to display the vertex key. layer : str (None) The layer to draw in. Default is to draw in the current layer. color : str, tuple, list, dict (None) The color specififcation for the labels. Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components. To apply the same color to all face labels, provide a single color specification. Individual colors can be assigned using a dictionary of key-color pairs. Missing keys will be assigned the default vertex color (``self.defaults['vertex.color']``). Default is to inherit color from the parent layer. formatter : callable (None) A formatting function. Defaults to the built-in ``str`` function. Notes ----- The labels are named using the following template: ``"{}.vertex.label.{}".format(self.network.name, key)``. This name is used afterwards to identify vertices of the networkin the Rhino model. Examples -------- >>> """ if not attr_name: attr_name = 'key' if formatter: assert callable(formatter), 'The provided formatter is not callable.' else: formatter = str text = {} for index, (key, attr) in enumerate(network.vertices(True)): if 'key' == attr_name: value = key elif 'index' == attr_name: value = index else: value = attr[attr_name] text[key] = formatter(value) artist = NetworkArtist(network) artist.layer = layer artist.clear_vertexlabels() artist.draw_vertexlabels(text=text, color=color) artist.redraw()
def network_draw_edges(network, keys=None, color=None, layer=None, clear_layer=False, redraw=True): """Draw a selection of edges of the network. Parameters ---------- keys : list (None) A list of edge keys (as uv pairs) identifying which edges to draw. Default is to draw all edges. color : str, tuple, dict (None) The color specififcation for the edges. Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components. To apply the same color to all faces, provide a single color specification. Individual colors can be assigned using a dictionary of key-color pairs. Missing keys will be assigned the default face color (``self.defaults['face.color']``). Default is to inherit color from the parent layer. layer : str (None) The layer in which the vertices are drawn. Default is to draw in the current layer. clear_layer : bool (False) Clear the drawing layer. redraw : bool (True) Redraw the view after adding the vertices. Notes ----- All edges are named using the following template: ``"{}.edge.{}-{}".fromat(self.network.name, u, v)``. This name is used afterwards to identify edges of the network in the Rhino model. Examples -------- >>> network_draw_edges(network) >>> network_draw_edges(network, color='#ff0000') >>> network_draw_edges(network, color=(255, 0, 0)) >>> network_draw_edges(network, keys=network.edges_xxx()) >>> network_draw_edges(network, color={(u, v): '#00ff00' for u, v in network.edges_xxx()}) """ artist = NetworkArtist(network) artist.layer = layer if clear_layer: artist.clear_layer() artist.clear_edges() artist.draw_edges(keys=keys, color=color) if redraw: artist.redraw()