How to use the compas.utilities.valuedict function in compas

To help you get started, we’ve selected a few compas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github compas-dev / compas / src / compas / plotters / meshplotter.py View on Github external
Returns
        -------
        object
            The matplotlib face collection object.
        """
        keys = keys or list(self.mesh.faces())

        if text == 'key':
            text = {key: str(key) for key in self.mesh.faces()}
        elif text == 'index':
            text = {key: str(index) for index, key in enumerate(self.mesh.faces())}
        else:
            pass

        textdict      = valuedict(keys, text, '')
        facecolourdict = valuedict(keys, facecolour, self.defaults['face.facecolour'])
        edgecolourdict = valuedict(keys, edgecolour, self.defaults['face.edgecolour'])
        edgewidthdict = valuedict(keys, edgewidth, self.defaults['face.edgewidth'])
        textcolourdict = valuedict(keys, textcolour, self.defaults['face.textcolour'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['face.fontsize'])

        polygons = []
        for key in keys:
            polygons.append({
                'points'   : self.mesh.face_coordinates(key, 'xy'),
                'text'     : textdict[key],
                'facecolour': facecolourdict[key],
                'edgecolour': edgecolourdict[key],
                'edgewidth': edgewidthdict[key],
                'textcolour': textcolourdict[key],
                'fontsize' : fontsizedict[key]
            })
github compas-dev / compas / src / compas / plotters / meshplotter.py View on Github external
The matplotlib edge collection object.

        """
        keys = keys or list(self.mesh.edges())

        if text == 'key':
            text = {(u, v): '{}-{}'.format(u, v) for u, v in self.mesh.edges()}
        elif text == 'index':
            text = {(u, v): str(index) for index, (u, v) in enumerate(self.mesh.edges())}
        else:
            pass

        widthdict     = valuedict(keys, width, self.defaults['edge.width'])
        colourdict     = valuedict(keys, colour, self.defaults['edge.colour'])
        textdict      = valuedict(keys, text, '')
        textcolourdict = valuedict(keys, textcolour, self.defaults['edge.textcolour'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['edge.fontsize'])

        lines = []
        for u, v in keys:
            lines.append({
                'start'    : self.mesh.vertex_coordinates(u, 'xy'),
                'end'      : self.mesh.vertex_coordinates(v, 'xy'),
                'width'    : widthdict[(u, v)],
                'colour'    : colourdict[(u, v)],
                'text'     : textdict[(u, v)],
                'textcolour': textcolourdict[(u, v)],
                'fontsize' : fontsizedict[(u, v)]
            })

        collection = self.draw_lines(lines)
        self.edgecollection = collection
github compas-dev / compas / src / compas / plotters / meshplotter.py View on Github external
Returns
        -------
        object
            The matplotlib edge collection object.

        """
        keys = keys or list(self.mesh.edges())

        if text == 'key':
            text = {(u, v): '{}-{}'.format(u, v) for u, v in self.mesh.edges()}
        elif text == 'index':
            text = {(u, v): str(index) for index, (u, v) in enumerate(self.mesh.edges())}
        else:
            pass

        widthdict     = valuedict(keys, width, self.defaults['edge.width'])
        colourdict     = valuedict(keys, colour, self.defaults['edge.colour'])
        textdict      = valuedict(keys, text, '')
        textcolourdict = valuedict(keys, textcolour, self.defaults['edge.textcolour'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['edge.fontsize'])

        lines = []
        for u, v in keys:
            lines.append({
                'start'    : self.mesh.vertex_coordinates(u, 'xy'),
                'end'      : self.mesh.vertex_coordinates(v, 'xy'),
                'width'    : widthdict[(u, v)],
                'colour'    : colourdict[(u, v)],
                'text'     : textdict[(u, v)],
                'textcolour': textcolourdict[(u, v)],
                'fontsize' : fontsizedict[(u, v)]
            })
github compas-dev / compas / src / compas / plotters / facenetworkplotter.py View on Github external
Color for the face edge.
        edgewidth : list
            Width for the face edge.
        textcolor : list
            Color for the text to be displayed on the edges.
        fontsize : list
            Font size for the text to be displayed on the edges.

        Returns
        -------
        object
            The matplotlib face collection object.
        """
        keys = keys or list(self.datastructure.faces())

        textdict      = valuedict(keys, text, '')
        facecolordict = valuedict(keys, facecolor, self.defaults['face.facecolor'])
        edgecolordict = valuedict(keys, edgecolor, self.defaults['face.edgecolor'])
        edgewidthdict = valuedict(keys, edgewidth, self.defaults['face.edgewidth'])
        textcolordict = valuedict(keys, textcolor, self.defaults['face.textcolor'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['face.fontsize'])

        polygons = []
        for key in keys:
            polygons.append({
                'points'   : self.datastructure.face_coordinates(key, 'xy'),
                'text'     : textdict[key],
                'facecolor': facecolordict[key],
                'edgecolor': edgecolordict[key],
                'edgewidth': edgewidthdict[key],
                'textcolor': textcolordict[key],
                'fontsize' : fontsizedict[key]
github compas-dev / compas / src / compas / plotters / networkplotter.py View on Github external
elif isinstance(text, basestring):
            if text in self.datastructure.default_vertex_attributes:
                default = self.datastructure.default_vertex_attributes[text]
                if isinstance(default, float):
                    text = {key: '{:.1f}'.format(attr[text]) for key, attr in self.datastructure.vertices(True)}
                else:
                    text = {key: str(attr[text]) for key, attr in self.datastructure.vertices(True)}
        else:
            pass

        radiusdict    = valuedict(keys, radius, self.defaults['vertex.radius'])
        textdict      = valuedict(keys, text, '')
        facecolourdict = valuedict(keys, facecolour, self.defaults['vertex.facecolour'])
        edgecolourdict = valuedict(keys, edgecolour, self.defaults['vertex.edgecolour'])
        edgewidthdict = valuedict(keys, edgewidth, self.defaults['vertex.edgewidth'])
        textcolourdict = valuedict(keys, textcolour, self.defaults['vertex.textcolour'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['vertex.fontsize'])

        points = []
        for key in keys:
            points.append({
                'pos'      : self.datastructure.vertex_coordinates(key, 'xy'),
                'radius'   : radiusdict[key],
                'text'     : textdict[key],
                'facecolour': facecolourdict[key],
                'edgecolour': edgecolourdict[key],
                'edgewidth': edgewidthdict[key],
                'textcolour': textcolourdict[key],
                'fontsize' : fontsizedict[key]
            })

        collection = self.draw_points(points)
github compas-dev / compas / src / compas / plotters / networkplotter.py View on Github external
text = {key: str(key) for key in self.datastructure.vertices()}
        elif text == 'index':
            text = {key: str(index) for index, key in enumerate(self.datastructure.vertices())}
        elif isinstance(text, basestring):
            if text in self.datastructure.default_vertex_attributes:
                default = self.datastructure.default_vertex_attributes[text]
                if isinstance(default, float):
                    text = {key: '{:.1f}'.format(attr[text]) for key, attr in self.datastructure.vertices(True)}
                else:
                    text = {key: str(attr[text]) for key, attr in self.datastructure.vertices(True)}
        else:
            pass

        radiusdict    = valuedict(keys, radius, self.defaults['vertex.radius'])
        textdict      = valuedict(keys, text, '')
        facecolourdict = valuedict(keys, facecolour, self.defaults['vertex.facecolour'])
        edgecolourdict = valuedict(keys, edgecolour, self.defaults['vertex.edgecolour'])
        edgewidthdict = valuedict(keys, edgewidth, self.defaults['vertex.edgewidth'])
        textcolourdict = valuedict(keys, textcolour, self.defaults['vertex.textcolour'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['vertex.fontsize'])

        points = []
        for key in keys:
            points.append({
                'pos'      : self.datastructure.vertex_coordinates(key, 'xy'),
                'radius'   : radiusdict[key],
                'text'     : textdict[key],
                'facecolour': facecolourdict[key],
                'edgecolour': edgecolourdict[key],
                'edgewidth': edgewidthdict[key],
                'textcolour': textcolourdict[key],
                'fontsize' : fontsizedict[key]
github compas-dev / compas / src / compas / plotters / meshplotter.py View on Github external
if text == 'key':
            text = {key: str(key) for key in self.mesh.vertices()}
        elif text == 'index':
            text = {key: str(index) for index, key in enumerate(self.mesh.vertices())}
        elif isinstance(text, basestring):
            if text in self.mesh.default_vertex_attributes:
                default = self.mesh.default_vertex_attributes[text]
                if isinstance(default, float):
                    text = {key: '{:.1f}'.format(attr[text]) for key, attr in self.mesh.vertices(True)}
                else:
                    text = {key: str(attr[text]) for key, attr in self.mesh.vertices(True)}
        else:
            pass

        radiusdict    = valuedict(keys, radius, self.defaults['vertex.radius'])
        textdict      = valuedict(keys, text, '')
        facecolourdict = valuedict(keys, facecolour, self.defaults['vertex.facecolour'])
        edgecolourdict = valuedict(keys, edgecolour, self.defaults['vertex.edgecolour'])
        edgewidthdict = valuedict(keys, edgewidth, self.defaults['vertex.edgewidth'])
        textcolourdict = valuedict(keys, textcolour, self.defaults['vertex.textcolour'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['vertex.fontsize'])

        points = []
        for key in keys:
            points.append({
                'pos'      : self.mesh.vertex_coordinates(key, 'xy'),
                'radius'   : radiusdict[key],
                'text'     : textdict[key],
                'facecolour': facecolourdict[key],
                'edgecolour': edgecolourdict[key],
                'edgewidth': edgewidthdict[key],
github compas-dev / compas / src / compas / plotters / facenetworkplotter.py View on Github external
Color for the text to be displayed on the edges.
        fontsize : list
            Font size for the text to be displayed on the edges.

        Returns
        -------
        object
            The matplotlib face collection object.
        """
        keys = keys or list(self.datastructure.faces())

        textdict      = valuedict(keys, text, '')
        facecolordict = valuedict(keys, facecolor, self.defaults['face.facecolor'])
        edgecolordict = valuedict(keys, edgecolor, self.defaults['face.edgecolor'])
        edgewidthdict = valuedict(keys, edgewidth, self.defaults['face.edgewidth'])
        textcolordict = valuedict(keys, textcolor, self.defaults['face.textcolor'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['face.fontsize'])

        polygons = []
        for key in keys:
            polygons.append({
                'points'   : self.datastructure.face_coordinates(key, 'xy'),
                'text'     : textdict[key],
                'facecolor': facecolordict[key],
                'edgecolor': edgecolordict[key],
                'edgewidth': edgewidthdict[key],
                'textcolor': textcolordict[key],
                'fontsize' : fontsizedict[key]
            })

        collection = self.draw_polygons(polygons)
        self.facecollection = collection
github compas-dev / compas / src / compas / plotters / meshplotter.py View on Github external
Returns
        -------
        object
            The matplotlib face collection object.
        """
        keys = keys or list(self.mesh.faces())

        if text == 'key':
            text = {key: str(key) for key in self.mesh.faces()}
        elif text == 'index':
            text = {key: str(index) for index, key in enumerate(self.mesh.faces())}
        else:
            pass

        textdict      = valuedict(keys, text, '')
        facecolourdict = valuedict(keys, facecolour, self.defaults['face.facecolour'])
        edgecolourdict = valuedict(keys, edgecolour, self.defaults['face.edgecolour'])
        edgewidthdict = valuedict(keys, edgewidth, self.defaults['face.edgewidth'])
        textcolourdict = valuedict(keys, textcolour, self.defaults['face.textcolour'])
        fontsizedict  = valuedict(keys, fontsize, self.defaults['face.fontsize'])

        polygons = []
        for key in keys:
            polygons.append({
                'points'   : self.mesh.face_coordinates(key, 'xy'),
                'text'     : textdict[key],
                'facecolour': facecolourdict[key],
                'edgecolour': edgecolourdict[key],
                'edgewidth': edgewidthdict[key],
                'textcolour': textcolourdict[key],
                'fontsize' : fontsizedict[key]
github compas-dev / compas / src / compas_rhinomac / helpers / artists / volmeshartist.py View on Github external
-----
        All edges are named using the following template:
        ``"{}.edge.{}-{}".fromat(self.volmesh.attributes['name'], u, v)``.
        This name is used afterwards to identify edges of the volmesh in the Rhino model.

        Examples
        --------
        >>> artist.draw_edges()
        >>> artist.draw_edges(color='#ff0000')
        >>> artist.draw_edges(color=(255, 0, 0))
        >>> artist.draw_edges(keys=self.volmesh.edges_on_boundary())
        >>> artist.draw_edges(color={(u, v): '#00ff00' for u, v in self.volmesh.edges_on_boundary()})

        """
        keys = keys or list(self.volmesh.edges())
        colordict = valuedict(keys, color, self.defaults['edge.color'])
        lines = []
        for u, v in keys:
            lines.append({
                'start': self.volmesh.vertex_coordinates(u),
                'end'  : self.volmesh.vertex_coordinates(v),
                'color': colordict[(u, v)],
                'name' : self.volmesh.edge_name(u, v)
            })
        return compas_rhinomac.xdraw_lines(lines, layer=self.layer, clear=False, redraw=False)