def __init__(self, a_color = "green", a_shape = "circle", size = 10.0, opacity = 1.0):
     if a_color is not "green":
         self.set_color(a_color)
     if a_shape is not "circle":
         self.set_shape(a_shape)
     if size is not 10.0:
         self.set_size(10.0)
     if opacity is not 1.0:
         self.set_opacity(opacity)
     else:
         self.color = Color(None, 70, 130, 180, 1.0)
Esempio n. 2
0
class ColorGrid(Grid):
    QUOTE = "\""
    COMMA = ","
    COLON = ":"
    OPEN_CURLY = "{"
    CLOSE_CURLY = "}"
    OPEN_PAREN = "("
    CLOSE_PAREN = ")"
    OPEN_BOX = "["
    CLOSE_BOX = "]"

    baseColor = Color(r = 0,g = 0,b = 0,a = 1.0)

    def get_data_structure_type(self):
        return "ColorGrid"

    #
    #  Grid constructor with size arguments
    #
    #  @param rows - int representing the number of rows of the grid
    #  @param cols - int representing the number of columns of the grid
    #  @param color - Color object
    #
    def __init__(self, rows = None, cols = None, color = None):
        if rows is None and cols is None and color is None:
            self.__init__(10, 10, self.baseColor)
        elif rows is not None and cols is not None and color is None:
            self.__init__(rows, cols, self.baseColor)
        elif rows is not None and cols is not None and color is not None:
            super(ColorGrid, self).__init__(rows = rows, cols = cols)
            self.baseColor = color
            self.gridSize = [rows, cols]

            self.initializeGrid()

   ##
   #  Populate the grid with the base color
   #
   #
    def initializeGrid(self):
        for i in range(self.gridSize[0]):
            for j in range(self.gridSize[1]):
                self.set(i, j, self.baseColor)

    ##
    # set the (row, col) element in the ColorGrid
    #
    def set(self, row, col, color):
        super(ColorGrid, self).set(row, col, color)

    ##
    # get the Run Length Encoding of ColorGrid
    #
    def getRLE(self):
        imgBytes = bytearray()
        count = 0
        totalCount = 0
        pos = 0
        last = self.grid[0][0]

        while (pos < self.gridSize[0] * self.gridSize[1]):
            posY = pos / self.gridSize[1]
            posX = pos % self.gridSize[1]
            current = self.grid[posY][posX]

            if count == 0:
                count = 1
                last = current
            else:
                if last == current:
                    count += 1
                else:
                    totalCount += count
                    imgBytes.append(count-1)
                    imgBytes.append(last.getByteRepresentation())
                    count = 1
                    last = current
            if count == 256:
                totalCount += count
                imgBytes.append(count-1)
                imgBytes.append(last.getByteRepresentation())
                count = 0
            pos += 1
        totalCount += count
        imgBytes.append(count-1)
        imgBytes.append(last.getByteRepresentation())

        if(totalCount != self.gridSize[0] * self.gridSize[1]):
            print("Something broke in getRLE cinstruction")

        #flip the array to reset position to 0
        imgBytes.reverse()

        return imgBytes

    ##
    # get raw encoding of ColorGrid
    def getRAW(self):
        imgBytes = bytearray()
        for i in range(self.gridSize[0]):
            if self.grid[i] is not None:
                for j in range(self.gridSize[1]):
                    if self.grid[i][j] is not None:
                        color = self.grid[i][j]
                        imgBytes.append(color.getByteRepresentation())
        return imgBytes





    ##
    #  
    #   get the JSON representation of the color grid
    #
    #   @return the JSON representation of the color grid
    #
    def get_data_structure_representation(self):
        # imageBytes = bytearray()
        # for i in range(self.gridSize[0]):
        #     if (self.grid[i] is not None):
        #         for j in range(self.gridSize[1]):
        #             color = self.grid[i][j]
        #             color = color.getByteRepresentation()
        #             for k in range(len(color)):
        #                 imageBytes.append(color[k])
                    # for k in range(len(color)):
                    #     imageBytes.append(int.from_bytes(color[k], 'little'))
        byte_buff = self.getRLE()
        encoding = "RLE"

        if len(byte_buff) > self.gridSize[0] * self.gridSize[1] * 4:
            encoding = "RAW"
            byte_buff = self.getRAW()


        # json_str = self.QUOTE + "nodes" + self.QUOTE + self.COLON + self.OPEN_BOX + self.QUOTE + base64.b64encode((imageBytes)).decode() + self.QUOTE + self.CLOSE_BOX + self.COMMA
        json_str = self.QUOTE + "encoding" + self.QUOTE + self.COLON + self.QUOTE + encoding + self.QUOTE + self.COMMA + self.QUOTE + "nodes" + self.QUOTE + self.COLON + self.OPEN_BOX  + self.QUOTE + base64.b64encode(byte_buff) + self.QUOTE + self.CLOSE_BOX + self.COMMA

        json_str += self.QUOTE + "dimensions" + self.QUOTE + self.COLON + self.OPEN_BOX + str(self.gridSize[0]) + "," + str(self.gridSize[1]) + self.CLOSE_BOX + self.CLOSE_CURLY

        return json_str
Esempio n. 3
0
class ColorGrid(Grid):
    QUOTE = "\""
    COMMA = ","
    COLON = ":"
    OPEN_CURLY = "{"
    CLOSE_CURLY = "}"
    OPEN_PAREN = "("
    CLOSE_PAREN = ")"
    OPEN_BOX = "["
    CLOSE_BOX = "]"

    baseColor = Color(r=0, g=0, b=0, a=1.0)

    def get_data_structure_type(self):
        return "ColorGrid"

    #
    #  Grid constructor with size arguments
    #
    #  @param rows - int representing the number of rows of the grid
    #  @param cols - int representing the number of columns of the grid
    #  @param color - Color object
    #
    def __init__(self, rows=None, cols=None, color=None):
        if rows is None and cols is None and color is None:
            self.__init__(10, 10, self.baseColor)
        elif rows is not None and cols is not None and color is None:
            self.__init__(rows, cols, self.baseColor)
        elif rows is not None and cols is not None and color is not None:
            super(ColorGrid, self).__init__(rows=rows, cols=cols)
            self.baseColor = color
            self.gridSize = [rows, cols]

            self.initializeGrid()

##
#  Populate the grid with the base color
#
#

    def initializeGrid(self):
        for i in range(self.gridSize[0]):
            for j in range(self.gridSize[1]):
                self.set(i, j, self.baseColor)

    ##
    # set the (row, col) element in the ColorGrid
    #
    def set(self, row, col, color):
        super(ColorGrid, self).set(row, col, color)

    ##
    #
    #   get the JSON representation of the color grid
    #
    #   @return the JSON representation of the color grid
    #
    def get_data_structure_representation(self):
        imageBytes = bytearray()
        for i in range(self.gridSize[0]):
            if (self.grid[i] is not None):
                for j in range(self.gridSize[1]):
                    color = self.grid[i][j]
                    color = color.getByteRepresentation()
                    for k in range(len(color)):
                        imageBytes.append(color[k])
                    # for k in range(len(color)):
                    #     imageBytes.append(int.from_bytes(color[k], 'little'))

        json_str = self.QUOTE + "nodes" + self.QUOTE + self.COLON + self.OPEN_BOX + self.QUOTE + base64.b64encode(
            (imageBytes)).decode() + self.QUOTE + self.CLOSE_BOX + self.COMMA

        json_str += self.QUOTE + "dimensions" + self.QUOTE + self.COLON + self.OPEN_BOX + str(
            self.gridSize[0]) + "," + str(
                self.gridSize[1]) + self.CLOSE_BOX + self.CLOSE_CURLY

        return json_str
Esempio n. 4
0
 def __init__(self):
     # super(LinkVisualizer.LinkVisualizer, self).__init__()
     self.color = Color(None, 70, 130, 180, 1.0)
     self.set_color(None, 70, 130, 180, 1.0)
     self.set_thickness(1.0)
     self.set_weight(1.0)
Esempio n. 5
0
class LinkVisualizer(object):
    #  Link visualization properties for this element.
    #  maintains mapping from the terminating vertex to its
    #  visual properties
    #  implemented as a hashmap mapping into properties, which
    #  is als a hashmap, to keep the accesses constant time.
    QUOTE = "\""
    COMMA = ","
    COLON = ":"
    OPEN_CURLY = "{"
    CLOSE_CURLY = "}"
    OPEN_PAREN = "("
    CLOSE_PAREN = ")"
    OPEN_BOX = "["
    CLOSE_BOX = "]"

    #  link color
    # color = Color.Color(None, 70, 130, 180, 1.0)

    #  link thickness
    thickness = float()

    #  link weight
    weight = float()

    def __init__(self):
        # super(LinkVisualizer.LinkVisualizer, self).__init__()
        self.color = Color(None, 70, 130, 180, 1.0)
        self.set_color(None, 70, 130, 180, 1.0)
        self.set_thickness(1.0)
        self.set_weight(1.0)

    ##
    # Set the thickness of the link in the Bridge Visualization in pixels; thickness
    # shoudl be in the range 0-50.0
    #
    # @param thickness
    #
    #
    def set_thickness(self, th):
        # Validation.validateThickness(th)
        self.thickness = th

    ##
    # Get the thickness of the link in the Bridges Visualiation
    #
    # @return the size in pixels of the Element in the Bridges Visualization
    #
    def get_thickness(self):
        return self.thickness

    ##
    # Set the weight of the link, useful in graph algorithms, for example.
    # weight value is user defined, and determined by the input graph specification.
    #
    # @param weight
    #
    #
    def set_weight(self, wt):
        #  is user defined so no checking
        self.weight = wt

    ##
    # Get the weight of the link
    #
    # @return the stored edge weight
    #
    def get_weight(self):
        return self.weight

    ##
    #
    #	Set the color of the link in the Bridges Visualization to "aColor".
    #
    # 	@param col_name the string reprsenting the color of the Element in
    #		the Bridges Visualization; supported named colors are
    #  	"red", "green", "blue", "yellow", "cyan", "magenta", "white", "black",
    #  	"orange", "turquoise", "maroon", "aquamarine", "azure", "beige",
    #  	"brown", "tan", "olive", "chartreuse", "khaki", "bisque", "coral",
    #  	"pink", "lavender", "purple", "gold"
    #
    #
    def set_color(self, col_name=None, r=None, g=None, b=None, a=None):
        if col_name is not None:
            col = col_name.lower()
            #  validates and returns a 4 component RGBA val
            red = int()
            green = int()
            blue = int()
            alpha = 1.0
            if col_name == "red":
                self.red = 255
                self.green = 0
                self.blue = 0
            elif col_name == "green":
                self.red = 0
                self.green = 255
                self.blue = 0
            elif col_name == "blue":
                self.red = 0
                self.green = 0
                self.blue = 255
            elif col_name == "yellow":
                self.red = 255
                self.green = 255
                self.blue = 0
            elif col_name == "cyan":
                self.red = 0
                self.green = 255
                self.blue = 255
            elif col_name == "magenta":
                self.red = 255
                self.green = 0
                self.blue = 255
            elif col_name == "white":
                self.red = 255
                self.green = 255
                self.blue = 255
            elif col_name == "black":
                self.red = 0
                self.green = 0
                self.blue = 0
            elif col_name == "orange":
                self.red = 255
                self.green = 155
                self.blue = 0
            elif col_name == "turquoise":
                self.red = 173
                self.green = 234
                self.blue = 234
            elif col_name == "maroon":
                self.red = 176
                self.green = 48
                self.blue = 96
            elif col_name == "aquamarine":
                self.red = 127
                self.green = 255
                self.blue = 212
            elif col_name == "azure":
                self.red = 240
                self.green = 255
                self.blue = 255
            elif col_name == "beige":
                self.red = 245
                self.green = 245
                self.blue = 220
            elif col_name == "brown":
                self.red = 166
                self.green = 42
                self.blue = 42
            elif col_name == "tan":
                self.red = 210
                self.green = 180
                self.blue = 140
            elif col_name == "olive":
                self.red = 128
                self.green = 128
                self.blue = 0
            elif col_name == "chartreuse":
                self.red = 127
                self.green = 255
                self.blue = 0
            elif col_name == "khaki":
                self.red = 240
                self.green = 230
                self.blue = 140
            elif col_name == "bisque":
                self.red = 255
                self.green = 228
                self.blue = 196
            elif col_name == "coral":
                self.red = 255
                self.green = 127
                self.blue = 0
            elif col_name == "pink":
                self.red = 255
                self.green = 192
                self.blue = 203
            elif col_name == "lavender":
                self.red = 230
                self.green = 230
                self.blue = 250
            elif col_name == "purple":
                self.red = 160
                self.green = 32
                self.blue = 240
            elif col_name == "gold":
                self.red = 255
                self.green = 215
                self.blue = 0
            else:
                raise ValueError("Invalid color " + "'" + col_name + "'" +
                                 "." +
                                 " Only named primaries supported now. \n")
            # self.color.set_red(self.red)
            # self.color.set_blue(self.blue)
            # self.color.set_green(self.green)
            self.color.set_color(None, self.red, self.blue, self.green, 1.0)
        else:
            self.color.set_red(r)
            self.color.set_blue(b)
            self.color.set_green(g)
            self.color.set_alpha(a)

    ##
    #
    #	Get the color of the link in the Bridges Visualization
    #
    #	@return the Color object representing the color of the link
    #
    #
    def get_color(self):
        return self.color

    ##
    # Sets the opacity of the link in the Bridges Visualization
    #
    # @param opacity a float between 0 and 1 representing how transparent
    #	the node
    #            should be on the Bridges Visualization. 0 for invisible, 1 for
    #            fully visible, a decimal between 0 and 1 for varying
    #            transparency.
    #
    def set_opacity(self, opacity):
        self.color.set_alpha(opacity)

    ##
    #
    # 	Get the opacity of the link in the Bridges Visualization
    #
    # 	@return the opacity value (in the range 0.0-1.0
    #
    #
    def get_opacity(self):
        return self.color.get_alpha()

    def get_link_properties(self):
        link_props = self.QUOTE + "color" + self.QUOTE + self.COLON + self.OPEN_BOX + str(
            self.get_color().get_red()
        ) + self.COMMA + str(self.get_color().get_green(
        )) + self.COMMA + str(self.get_color().get_blue()) + self.COMMA + str(
            self.get_color().get_alpha()
        ) + self.CLOSE_BOX + self.COMMA + self.QUOTE + "thickness" + self.QUOTE + self.COLON + str(
            self.get_thickness()
        ) + self.COMMA + self.QUOTE + "weight" + self.QUOTE + self.COLON + str(
            self.get_weight())
        return link_props
    def set_color(self, col_name):

        #  this.aColor = aColor;
        a_color = col_name.lower()

        red = int()
        green = int()
        blue = int()
        alpha = float()

        if col_name is not None:
            if col_name == "red":
                self.red = 255
                self.green = 0
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "green":
                self.red = 0
                self.green = 255
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "blue":
                self.red = 0
                self.green = 0
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "yellow":
                self.red = 255
                self.green = 255
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "cyan":
                self.red = 0
                self.green = 255
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "magenta":
                self.red = 255
                self.green = 0
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "white":
                self.red = 255
                self.green = 255
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "black":
                self.red = 0
                self.green = 0
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "orange":
                self.red = 255
                self.green = 155
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "turquoise":
                self.red = 173
                self.green = 234
                self.blue = 234
                self.alpha = 1.0

            elif col_name == "maroon":
                self.red = 176
                self.green = 48
                self.blue = 96
                self.alpha = 1.0

            elif col_name == "aquamarine":
                self.red = 127
                self.green = 255
                self.blue = 212
                self.alpha = 1.0

            elif col_name == "azure":
                self.red = 240
                self.green = 255
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "beige":
                self.red = 245
                self.green = 245
                self.blue = 220
                self.alpha = 1.0

            elif col_name == "brown":
                self.red = 166
                self.green = 42
                self.blue = 42
                self.alpha = 1.0

            elif col_name == "tan":
                self.red = 210
                self.green = 180
                self.blue = 140
                self.alpha = 1.0

            elif col_name == "olive":
                self.red = 128
                self.green = 128
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "chartreuse":
                self.red = 127
                self.green = 255
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "khaki":
                self.red = 240
                self.green = 230
                self.blue = 140
                self.alpha = 1.0

            elif col_name == "bisque":
                self.red = 255
                self.green = 228
                self.blue = 196
                self.alpha = 1.0

            elif col_name == "coral":
                self.red = 255
                self.green = 127
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "pink":
                self.red = 255
                self.green = 192
                self.blue = 203
                self.alpha = 1.0

            elif col_name == "lavender":
                self.red = 230
                self.green = 230
                self.blue = 250
                self.alpha = 1.0

            elif col_name == "purple":
                self.red = 160
                self.green = 32
                self.blue = 240
                self.alpha = 1.0

            elif col_name == "gold":
                self.red = 255
                self.green = 215
                self.blue = 0
                self.alpha = 1.0

        self.prop["color"] = a_color

        self.color = Color(None, self.red, self.green, self.blue, self.alpha)
class ElementVisualizer():
    #  Visualization properties for this Node.

    shape = "circle"
    key = ""
    locationX = Decimal("Infinity")
    locationY = Decimal("Infinity")
    size = 10.0
    opacity = 1.0


    prop = dict()
    color = Color(None, 70, 130, 180, 1.0)

    prop["color"] = "[70, 130, 180, 1.0]"
    prop["opacity"] = "1.0"
    prop["size"] = "10.0"
    prop["shape"] = "circle"
    prop["key"] = ""
    prop["locationX"] = str(locationX)
    prop["locationY"] = str(locationY)

    ##
    # Construct an ElementVisualizer with the default visualization settings.
    # The default settings are color = green, opacity = 1.0, size = 10.0, shape
    # = circle.
    #
    def __init__(self, a_color = "green", a_shape = "circle", size = 10.0, opacity = 1.0):
        if a_color is not "green":
            self.set_color(a_color)
        if a_shape is not "circle":
            self.set_shape(a_shape)
        if size is not 10.0:
            self.set_size(10.0)
        if opacity is not 1.0:
            self.set_opacity(opacity)
        else:
            self.color = Color(None, 70, 130, 180, 1.0)


    ##
    # Set the size of the Element in the Bridge Visualization in pixels
    #
    # @param size
    #            the pixel size of the Element in the Bridges Visualization
    #
    def set_size(self, size):
        self.prop["size"] = str(size)
        self.size = size

    ##
    # Get the size of the Element in the Bridges Visualiation
    #
    # @return the size in pixels of the Element in the Bridges Visualization
    #
    def get_size(self):
        return self.size

    ##
    #  Set the color of the Element in the Bridges Visualization to "aColor".
    #  @param aColor the string reprsenting the color of the Element in the Bridges Visualization
    #
    def set_color(self, col_name):

        #  this.aColor = aColor;
        a_color = col_name.lower()

        red = int()
        green = int()
        blue = int()
        alpha = float()

        if col_name is not None:
            if col_name == "red":
                self.red = 255
                self.green = 0
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "green":
                self.red = 0
                self.green = 255
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "blue":
                self.red = 0
                self.green = 0
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "yellow":
                self.red = 255
                self.green = 255
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "cyan":
                self.red = 0
                self.green = 255
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "magenta":
                self.red = 255
                self.green = 0
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "white":
                self.red = 255
                self.green = 255
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "black":
                self.red = 0
                self.green = 0
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "orange":
                self.red = 255
                self.green = 155
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "turquoise":
                self.red = 173
                self.green = 234
                self.blue = 234
                self.alpha = 1.0

            elif col_name == "maroon":
                self.red = 176
                self.green = 48
                self.blue = 96
                self.alpha = 1.0

            elif col_name == "aquamarine":
                self.red = 127
                self.green = 255
                self.blue = 212
                self.alpha = 1.0

            elif col_name == "azure":
                self.red = 240
                self.green = 255
                self.blue = 255
                self.alpha = 1.0

            elif col_name == "beige":
                self.red = 245
                self.green = 245
                self.blue = 220
                self.alpha = 1.0

            elif col_name == "brown":
                self.red = 166
                self.green = 42
                self.blue = 42
                self.alpha = 1.0

            elif col_name == "tan":
                self.red = 210
                self.green = 180
                self.blue = 140
                self.alpha = 1.0

            elif col_name == "olive":
                self.red = 128
                self.green = 128
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "chartreuse":
                self.red = 127
                self.green = 255
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "khaki":
                self.red = 240
                self.green = 230
                self.blue = 140
                self.alpha = 1.0

            elif col_name == "bisque":
                self.red = 255
                self.green = 228
                self.blue = 196
                self.alpha = 1.0

            elif col_name == "coral":
                self.red = 255
                self.green = 127
                self.blue = 0
                self.alpha = 1.0

            elif col_name == "pink":
                self.red = 255
                self.green = 192
                self.blue = 203
                self.alpha = 1.0

            elif col_name == "lavender":
                self.red = 230
                self.green = 230
                self.blue = 250
                self.alpha = 1.0

            elif col_name == "purple":
                self.red = 160
                self.green = 32
                self.blue = 240
                self.alpha = 1.0

            elif col_name == "gold":
                self.red = 255
                self.green = 215
                self.blue = 0
                self.alpha = 1.0

        self.prop["color"] = a_color

        self.color = Color(None, self.red, self.green, self.blue, self.alpha)
    ##
    # Get the color of the Element in the Bridges Visualization
    #  @return the string reprsenting the color of the Element in the Bridges Visualization
    #
    def get_color(self):
        return self.color

    ##
    # Get the shape of the Element in the Bridges Visualization.
    # @return the string that represents the Element's shape in the Bridges Visualization.
    #
    def get_shape(self):
        return self.shape

    ##
    # Sets the shape of the Element in the Bridges Visualization
    #
    # @param aShape the string representing the shape of the Element in the Bridges Visualization
    #
    def set_shape(self, a_shape):
        #  this.aShape = aShape;
        a_shape = a_shape.lower()
        #Validation.validateShape(a_shape)
        self.prop["shape"] = a_shape
        self.shape = a_shape

    ##
    # Sets the opacity of the Element in the Bridges Visualization
    #
    # @param opacity a double between 0 and 1 representing how transparent the node
    #            should be on the Bridges Visualization. 0 for invisible, 1 for
    #            fully visible, a decimal between 0 and 1 for varying
    #            transparency.
    #
    def set_opacity(self, opacity):
        #Validation.validateOpacity(opacity)
        self.prop["opacity"] = Decimal(opacity)
        self.color.set_alpha(opacity)
        self.opacity = opacity

    ##
    #  Get the opacity of the Element in the Bridges Visualization
    # @return the opacity value
    #
    def get_opacity(self):
        return self.color.get_alpha()

    ##
    # The randomColor method selects a random color from the available list of
    # colors found in Validation.java and sets the color of the current element
    #
    # @return a color name as a string value
    #
    # def random_color(self):
    #     a = Validation.COLOR_NAMES.toArray()
    #     return self.setColor(a[Random().nextInt(a.length)].__str__())

    def set_location(self, x, y):
        self.locationX = x
        self.locationY = y

    def get_locationX(self):
        return self.locationX

    def get_locationY(self):
        return self.locationY