def draw_edgelabels(self, text=None, color=None): """Draw labels for a selection of edges. Parameters ---------- text : dict A dictionary of edge labels as key-text pairs. The default value is ``None``, in which case every edge will be labelled with its key. color : str, tuple, dict The color sepcification of the labels. String values are interpreted as hex colors (e.g. ``'#ff0000'`` for red). Tuples are interpreted as RGB component specifications (e.g. ``(255, 0, 0) for red``. Individual colors can be assigned using a dictionary of key-color pairs. Missing keys will be assigned the default face color (``self.defaults['edge.color']``). The default is ``None``, in which case all edges are assigned the default edge color. Notes ----- All labels are assigned a name using the folling template: ``"{}.edge.{}".format(self.datastructure.name, key)``. """ if text is None: textdict = {(u, v): "{}-{}".format(u, v) for u, v in self.datastructure.edges()} elif isinstance(text, dict): textdict = text else: raise NotImplementedError colordict = color_to_colordict(color, textdict.keys(), default=self.defaults.get('color.edge'), colorformat='rgb', normalize=False) labels = [] for (u, v), text in iter(textdict.items()): labels.append({ 'pos': self.datastructure.edge_midpoint(u, v), 'name': self.datastructure.edge_label_name(u, v), 'color': colordict[(u, v)], 'text': textdict[(u, v)], 'layer': self.datastructure.get_edge_attribute((u, v), 'layer', None) }) return compas_ghpython.draw_labels(labels)
def draw_vertexlabels(self, text=None, color=None): """Draw labels for a selection vertices. Parameters ---------- text : dict A dictionary of vertex labels as key-text pairs. The default value is ``None``, in which case every vertex will be labelled with its key. color : str, tuple, dict The color sepcification of the labels. String values are interpreted as hex colors (e.g. ``'#ff0000'`` for red). Tuples are interpreted as RGB component specifications (e.g. ``(255, 0, 0) for red``. If a dictionary of specififcations is provided, the keys of the should refer to vertex keys and the values should be color specifications in the form of strings or tuples. The default value is ``None``, in which case the labels are assigned the default vertex color (``self.defaults['color.vertex']``). Notes ----- All labels are assigned a name using the folling template: ``"{}.vertex.label.{}".format(self.datastructure.name, key)``. """ if text is None: textdict = {key: str(key) for key in self.datastructure.vertices()} elif isinstance(text, dict): textdict = text else: raise NotImplementedError colordict = color_to_colordict( color, textdict.keys(), default=self.defaults.get('color.vertex'), colorformat='rgb', normalize=False) labels = [] for key, text in iter(textdict.items()): labels.append({ 'pos': self.datastructure.vertex_coordinates(key), 'name': self.datastructure.vertex_label_name(key), 'color': colordict[key], 'text': textdict[key], 'layer': self.datastructure.get_vertex_attribute(key, 'layer', None) }) return compas_ghpython.draw_labels(labels)
def draw_edgelabels(self, text=None, color=None): """Draw labels for a selection of edges. Parameters ---------- text : dict A dictionary of edge labels as key-text pairs. The default value is ``None``, in which case every edge will be labelled with its key. color : str, tuple, dict The color sepcification of the labels. String values are interpreted as hex colors (e.g. ``'#ff0000'`` for red). Tuples are interpreted as RGB component specifications (e.g. ``(255, 0, 0) for red``. Individual colors can be assigned using a dictionary of key-color pairs. Missing keys will be assigned the default face color (``self.settings['color.edges']``). The default is ``None``, in which case all edges are assigned the default edge color. Returns ------- list of :class:`Rhino.Geometry.TextDot` """ if text is None: textdict = {(u, v): "{}-{}".format(u, v) for u, v in self.volmesh.edges()} elif isinstance(text, dict): textdict = text else: raise NotImplementedError colordict = color_to_colordict(color, textdict.keys(), default=self.settings['color.edges'], colorformat='rgb', normalize=False) labels = [] for (u, v), text in iter(textdict.items()): labels.append({ 'pos': self.volmesh.edge_midpoint(u, v), 'name': "{}.edgelabel.{}-{}".format(self.volmesh.name, u, v), 'color': colordict[(u, v)], 'text': textdict[(u, v)] }) return compas_ghpython.draw_labels(labels)
def draw_facelabels(self, text=None, color=None): """Draw labels for a selection of faces. Parameters ---------- text : dict A dictionary of face labels as key-text pairs. The default value is ``None``, in which case every face will be labelled with its key. color : str, tuple, dict The color sepcification of the labels. String values are interpreted as hex colors (e.g. ``'#ff0000'`` for red). Tuples are interpreted as RGB component specifications (e.g. ``(255, 0, 0) for red``. If a dictionary of specififcations is provided, the keys of the should refer to face keys and the values should be color specifications in the form of strings or tuples. The default value is ``None``, in which case the labels are assigned the default face color (``self.settings['color.faces']``). Returns ------- list of :class:`Rhino.Geometry.TextDot` """ if text is None: textdict = {key: str(key) for key in self.volmesh.faces()} elif isinstance(text, dict): textdict = text else: raise NotImplementedError colordict = color_to_colordict(color, textdict.keys(), default=self.settings['color.faces'], colorformat='rgb', normalize=False) labels = [] for key, text in iter(textdict.items()): labels.append({ 'pos': self.volmesh.face_center(key), 'name': "{}.facelabel.{}".format(self.volmesh.name, key), 'color': colordict[key], 'text': textdict[key] }) return compas_ghpython.draw_labels(labels)