コード例 #1
0
ファイル: datastructures.py プロジェクト: louisronron/ColorEx
    def __validate(self):

        # left must ONLY be int, float or None
        if (not isinstance(self.left, int)
                and not isinstance(self.left, float)
                and self.left is not None):
            raise TypeError(
                "arguments 'left' and 'right' can only be of type 'int', 'float', or None"
            )

        # right must ONLY be int, float or None
        if (not isinstance(self.right, int)
                and not isinstance(self.right, float)
                and self.right is not None):
            raise TypeError(
                "arguments 'left' and 'right' can only be of type 'int', 'float', or None"
            )

        # left value should be less than right value.
        if ((isinstance(self.left, float) or isinstance(self.left, int)) and
            (isinstance(self.right, int) or isinstance(self.right, float))):
            if (self.left > self.right):
                raise ValueError("argument 'left' must be less than 'right'")

        # left and right cannot BOTH be false.
        if (self.left == False and self.right == False):
            raise ValueError(
                "only one out of arguments 'left' and 'right can be 'False'")

        # inclusive left must only be bool
        if (not isinstance(self.inclusive_left, bool)):
            raise TypeError("argument 'inclusive_left' must be of type 'bool'")

        # inclusive right must only be bool
        if (not isinstance(self.inclusive_right, bool)):
            raise TypeError(
                "argument 'inclusive_right' must be of type 'bool'")

        # label must be specified
        if (self.label == ""):
            raise TypeError(
                "required argument 'label' must be specified, and must be of type 'str'"
            )

        # label must only be string.
        if (not isinstance(self.label, str)):
            raise TypeError("argument 'label' must be of type 'str'")

        # color, if specified, must be a valid hex, or color string
        if (self.color is not None):
            if (not Themes().is_rgb_hex(self.color)
                    and not Themes().is_color_name(self.color)):
                raise TypeError(
                    "argument 'color' must be color hex string, or valid color name"
                )
コード例 #2
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_generate_alpha_rgb_bicolor_B(self):
		rgb1 = (170,0,0)
		rgb2 = (255,102,0)
		alpha = 0.3
		rgb_out = (230,72,0)
		self.assertEqual(
			Themes().generate_alpha_rgb_bicolor(rgb1,rgb2,alpha),
			rgb_out)
コード例 #3
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_generate_alpha_rgb_bicolor_F(self):
		rgb1 = (170,0,136)
		rgb2 = (229,128,255)
		alpha = 1.0
		rgb_out = (170,0,136)
		self.assertEqual(
			Themes().generate_alpha_rgb_bicolor(rgb1,rgb2,alpha),
			rgb_out)
コード例 #4
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_generate_alpha_rgb_bicolor_H(self):
		rgb1 = (0,128,0)
		rgb2 = (0,255,102)
		alpha = 0.0
		rgb_out = (0,255,102)
		self.assertEqual(
			Themes().generate_alpha_rgb_bicolor(rgb1,rgb2,alpha),
			rgb_out)
コード例 #5
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_generate_alpha_rgb_bicolor_A(self):
		rgb1 = (0,0,128)
		rgb2 = (0,255,255)
		alpha = 0.5
		rgb_out = (0,128,192)
		self.assertEqual(
			Themes().generate_alpha_rgb_bicolor(rgb1,rgb2,alpha),
			rgb_out)
コード例 #6
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_generate_alpha_rgb_bicolor_I(self):
		rgb1 = (255,0,0)
		rgb2 = (255,204,0)
		alpha = 0.0
		rgb_out = (255,204,0)
		self.assertEqual(
			Themes().generate_alpha_rgb_bicolor(rgb1,rgb2,alpha),
			rgb_out)
コード例 #7
0
ファイル: datastructures.py プロジェクト: louisronron/ColorEx
    def __init__(self, options):
        '''Initialize a single Tile object '''

        # ensure options passed is a dictionary
        if (not isinstance(options, dict)):
            raise TypeError(
                "required argument 'options' must be of type 'dict'")

        # ensure validity of 'value' in options
        if ('value' not in options):
            raise TypeError("required argument 'value' \
                not specified")
        elif (not isinstance(options['value'], int)
              and not isinstance(options['value'], float)):
            raise TypeError("argument 'value' must be \
                of type 'int' or 'float'")

        # ensure validity of 'alpha' in options
        elif ('alpha' not in options):
            raise TypeError("required argument 'alpha' \
                not specified")
        elif (not isinstance(options['alpha'], int)
              and not isinstance(options['alpha'], float)):
            raise TypeError("argument 'alpha' must be \
                of type 'int' or 'float'")
        elif (options['alpha'] < 0 or options['alpha'] > 1):
            raise ValueError("argument 'alpha' must be \
                between 0-1 inclusively")

        # ensure validity of 'rgb' in options
        elif ('rgb' not in options):
            raise TypeError("required argument 'rgb' not \
                specified")
        elif (not isinstance(options['rgb'], str)):
            raise TypeError("argument 'rgb' must be of type 'str'")

        elif (not Themes().is_rgb_hex(options['rgb'])):
            raise ValueError("argument 'rgb' must be \
                between #000000 to \
                #ffffff, and preceded with '#'")

        # ensure validity of 'label' in options if it is ever passed.
        elif ('label' not in options):
            self.__label = None
        elif ('label' in options):
            if (not isinstance(options['label'], str)
                    and options['label'] is not None):
                raise TypeError("argument 'label' must be of type 'str'")
            self.__label = options['label']

        self.__value = options['value']
        self.__alpha = options['alpha']
        self.__rgb = options['rgb']
        self.__options = options
コード例 #8
0
ファイル: datastructures.py プロジェクト: louisronron/ColorEx
    def __init__(self,
                 left,
                 right,
                 inclusive_left=True,
                 inclusive_right=False,
                 label="",
                 color=None):

        # define class variables.
        self.left = left
        self.right = right
        self.inclusive_left = inclusive_left
        self.inclusive_right = inclusive_right
        self.label = label
        self.color = color

        # validate all arguments.
        self.__validate()

        # convert color to hex where necessary.
        if (Themes().is_rgb_hex(self.color)):
            self.color = color
        elif (Themes().is_color_name(self.color)):
            self.color = Themes().colors[self.color]
コード例 #9
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_themes_B(self):
		themes = dict()
		default = dict()
		default['primary'] = '#0044aa'
		default['secondary'] = '#aaccff'
		default['on-primary'] = '#d7eef4'
		default['on-secondary'] = '#f9f9f9'
		sun = dict()
		sun['primary'] = '#d45500'
		sun['secondary'] = '#ffccaa'
		sun['on-primary'] = '#ffccaa'
		sun['on-secondary'] = '#000000'
		themes['default'] = default
		themes['sun'] = sun
		self.assertEqual(Themes().themes,
        	themes)
コード例 #10
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_colors_B(self):
		colors = dict()
		colors['default'] = '#000000'
		colors['black'] = '#000000'
		colors['white'] = '#ffffff'
		colors['red'] = '#ff0000'
		colors['lime'] = '#00ff00'
		colors['blue'] = '#0000ff'
		colors['yellow'] = '#ffff00'
		colors['cyan'] = '#00ffff'
		colors['aqua'] = '#00ffff'
		colors['magenta'] = '#ff00ff'
		colors['fuchsia'] = '#ff00ff'
		colors['silver'] = '#c0c0c0'
		colors['gray'] = '#808080'
		colors['grey'] = '#808080'
		colors['maroon'] = '#800000'
		colors['olive'] = '#808000'
		colors['green'] = '#008000'
		colors['purple'] = '#800080'
		colors['teal'] = '#008080'
		colors['navy'] = '#000080'
		self.assertEqual(Themes().colors,
			colors)
コード例 #11
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_rgb_hex_C(self):
		test_rgb_hex = '#1c1caa'
		self.assertTrue(
			Themes().is_rgb_hex(test_rgb_hex))
コード例 #12
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_rgb_hex_B(self):
		test_rgb_hex = '#4411bb'
		self.assertTrue(
			Themes().is_rgb_hex(test_rgb_hex))
コード例 #13
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test___init__A(self):
		self.assertIsInstance(
			Themes(), Themes)
コード例 #14
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_color_name_G(self):
		color_name = "pink"
		self.assertFalse(
			Themes().is_color_name(color_name))
コード例 #15
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_colors_A(self):
		self.assertIsInstance(
			Themes().colors, dict)
コード例 #16
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_color_name_F(self):
		color_name = 897429
		self.assertFalse(
			Themes().is_color_name(color_name))
コード例 #17
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_color_name_E(self):
		color_name = "lightgray"
		self.assertFalse(
			Themes().is_color_name(color_name))
コード例 #18
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_rgb_hex_F(self):
		test_rgb_hex = 'color1'
		self.assertFalse(
			Themes().is_rgb_hex(test_rgb_hex))
コード例 #19
0
ファイル: colorex.py プロジェクト: louisronron/ColorEx
    def generate_tile(self, data_item, min_value, max_value, theme):
        ''' generates a new tile of type Tile '''
        # set some colors to use.
        highColor = theme.palette["primary"]
        lowColor = theme.palette["secondary"]
        highColorDec = Themes().rgb_hex_to_decimal(highColor)
        lowColorDec = Themes().rgb_hex_to_decimal(lowColor)
        label = None

        thereAreGroupings = self.grouping is not None
        groupingHasColor = False
        tileInGroup = False
        if(thereAreGroupings):
            tileInGroup = self.grouping.group(data_item.value) is not None
        if(thereAreGroupings and tileInGroup):
            groupingHasColor = self.grouping.group(data_item.value).color is not None
            label = self.grouping.group(data_item.value).label
        
        # first, check if tile groups available, with colors specified.
        if(thereAreGroupings):
            # there are groupings
            if(tileInGroup):
                # Current Tile is in group
                if(groupingHasColor):
                    # grouping has color so just use specified color.
                    rgb = self.grouping.group(data_item.value).color
                    alpha = 1.0
                else:
                    # grouping has no color, so use generated color
                    # based on the group's alpha.
                    alpha = self.grouping.alpha(data_item.value)
                    alpha_color = Themes().generate_alpha_rgb_bicolor(
                        highColorDec, lowColorDec, alpha)
                    rgb = Themes().decimal_to_rgb_hex(alpha_color)
            else:
                # there are no groupings, so generate alpha color
                # as usual. This is the typical behavior.
                alpha_color = Themes().generate_alpha_rgb_bicolor(
                    highColorDec,lowColorDec,self.calculate_rgb_alpha(
                        data_item.value, min_value, max_value))
                rgb = Themes().decimal_to_rgb_hex(alpha_color)
                alpha = self.calculate_rgb_alpha(data_item.value, 
                    min_value, max_value)

        elif(not thereAreGroupings):
            # there are no groupings, so generate alpha color
            # as usual. This is the typical behavior.
            alpha_color = Themes().generate_alpha_rgb_bicolor(
                highColorDec,lowColorDec,self.calculate_rgb_alpha(
                    data_item.value, min_value, max_value))
            rgb = Themes().decimal_to_rgb_hex(alpha_color)
            alpha = self.calculate_rgb_alpha(data_item.value, 
                min_value, max_value)

        # create a dictionary for all Tile options.
        tile_options = {
                'value': data_item.value,
                'alpha': alpha,
                'rgb': rgb,
                'label': label
        }
        # return a Tile object, passing the options too.
        return Tile(tile_options)            
コード例 #20
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_rgb_hex_D(self):
		test_rgb_hex = '#f190ac'
		self.assertTrue(
			Themes().is_rgb_hex(test_rgb_hex))
コード例 #21
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_decimal_to_rgb_hex_E(self):
		rgb_hex = "#aa44abc"
		self.assertRaises(TypeError,
			Themes().decimal_to_rgb_hex,
			rgb_hex)
コード例 #22
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_decimal_to_rgb_hex_F(self):
		rgb_hex = "aa44ff"
		self.assertRaises(TypeError,
			Themes().decimal_to_rgb_hex,
			rgb_hex)
コード例 #23
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_decimal_to_rgb_hex_G(self):
		rgb_hex = "blue"
		self.assertRaises(TypeError,
			Themes().decimal_to_rgb_hex,
			rgb_hex)
コード例 #24
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_decimal_to_rgb_hex_H(self):
		rgb_hex = 190
		self.assertRaises(TypeError,
			Themes().decimal_to_rgb_hex,
			rgb_hex)
コード例 #25
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_rgb_hex_E(self):
		test_rgb_hex = '#45acbb'
		self.assertTrue(
			Themes().is_rgb_hex(test_rgb_hex))
コード例 #26
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_color_name_A(self):
		color_name = "green"
		self.assertTrue(
			Themes().is_color_name(color_name))
コード例 #27
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_rgb_hex_G(self):
		test_rgb_hex = '9018'
		self.assertFalse(
			Themes().is_rgb_hex(test_rgb_hex))
コード例 #28
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_color_name_C(self):
		color_name = "black"
		self.assertTrue(
			Themes().is_color_name(color_name))
コード例 #29
0
ファイル: colorex.py プロジェクト: louisronron/ColorEx
    def __init__(self, options=dict()):
        ''' Initialize a new engine '''
        # determine the validity of arguments passed.
        if('source' not in options):
            raise TypeError("required argument 'source' \
                not specified")
        elif('title' not in options):
            raise TypeError("required argument 'title' \
                not specified")
        elif(not isinstance("title", str)):
            raise TypeError("argument 'title' must be \
                of type 'str'")
        elif('subtitle' not in options):
            raise TypeError("required argument 'subtitle' \
                not specified")
        elif(not isinstance("subtitle", str)):
            raise TypeError("argument 'subtitle' must \
                be of type 'str'")



        # determine data input source type and source
        self.__source = options["source"]
        self.__sourcetype = ""
        # check if source is a filename
        if(isinstance(self.__source,str) and len(
            self.__source.split('.'))>1):
            # check what type of file it is based on file 
            # type suffix '.'
            filetype = self.__source.split('.')[-1]
            if(filetype == "csv"):
                self.__sourcetype = "csv"
            else:
                raise ValueError("source file type \
                    '"+filetype+"' not supported")
        # check if source is a data grid
        elif(isinstance(self.__source, DataGrid)):
            self.__sourcetype = 'datagrid'

        else:
            # the source is not supported so raise exception.
            raise TypeError("source type '"+\
                type(self.__source)+"' not supported")



        # set title and subtitle values
        self.__title = options["title"]
        self.__subtitle = options["subtitle"]



        # set the optional arguments and their values.
        # theme settings
        if('theme' in options):
            self.__theme = options["theme"]
        else:
            self.__theme = Theme()

        # stylesheet settings
        if('stylesheet' in options):
            self.__stylesheet = options["stylesheet"]
        else:
            self.__stylesheet = StyleSheet()

        # xaxis_title settings
        if("xaxis_title" in options):
            self.__xaxistitle = options["xaxis_title"]
        else:
            self.__xaxistitle = ""

        # yaxis_title settings
        if("yaxis_title" in options):
            self.__yaxistitle = options["yaxis_title"]
        else:
            self.__yaxistitle = ""

        # xaxis_labels settings
        if("xaxis_labels" in options):
            self.__xaxislabels = options['xaxis_labels']
        else:
            self.__xaxislabels = None

        # yaxis_labels settings
        if("yaxis_labels" in options):
            self.__yaxislabels = options['yaxis_labels']
        else:
            self.__yaxislabels = None

        # rowcol_headers settings
        if("rowcol_headers" in options):
            self.__rowcolheaders = options["rowcol_headers"]
        else:
            self.__rowcolheaders = True


        # data_formatter settings
        if("data_formatter" in options):
            if(not isinstance(options["data_formatter"], 
                DataFormatter)):
                raise TypeError("argument 'data_formatter' must be of type 'DataFormatter'")
            self.__data_formatter = options["data_formatter"]
        else:
            self.__data_formatter = None


        # grouping settings.
        if('grouping' in options):
            if(not isinstance(options['grouping'], TileGroups)):
                raise TypeError("argument 'grouping' must be of type 'TileGroup'")
            else:
                self.__grouping = options['grouping']
        else:
            self.__grouping = None



        # set dictionary of available colors and themes
        # for reference.
        self.__colors = Themes().colors
        self.__themes = Themes().themes
コード例 #30
0
ファイル: test_Themes.py プロジェクト: louisronron/ColorEx
	def test_is_color_name_D(self):
		color_name = "purple"
		self.assertTrue(
			Themes().is_color_name(color_name))