def test_stylesheet_setter_A(self): mock_data = [ ["Month","Web Traffic","Call to actions"], ["January",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["February",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["March",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["April",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["May",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["June",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["July",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["August",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["September",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["October",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["November",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["December",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})] ] stylesheet1 = StyleSheet() stylesheet2 = StyleSheet() options = { 'data': mock_data, 'title': 'My First Heatmap title', 'subtitle': 'The first heatmap subtitle', 'theme': Theme(), 'stylesheet': stylesheet1, 'xaxis_title': 'Title of X-Axis', 'yaxis_title': 'Title of Y-Axis' } heatmap = HeatMap(options) file_output_writer=FileOutputWriter(filepath="filepath.file",heatmap=heatmap) self.assertEqual(file_output_writer.stylesheet, stylesheet1) file_output_writer.stylesheet = stylesheet2 self.assertEqual(file_output_writer.stylesheet, stylesheet2)
def test_heatmap_setter_A(self): mock_data1 = [ ["Month","Web Traffic","Call to actions"], ["January",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["February",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["March",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["April",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["May",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["June",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["July",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["August",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["September",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["October",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["November",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["December",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})] ] mock_data2 = [ ["Month","Web Traffic","Call to actions"], ["January",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["February",Tile({'value': 60.67, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["March",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["April",Tile({'value': 20, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 10, 'rgb': '#a45aff', 'alpha': 0.56})], ["May",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.345})], ["June",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 15.89, 'rgb': '#a45aff', 'alpha': 0.34})], ["July",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["August",Tile({'value': 67.89, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["September",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.553})], ["October",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.45}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.11})], ["November",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.5}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.911})], ["December",Tile({'value': 908, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.734})] ] options1 = { 'data': mock_data1, 'title': 'My First Heatmap title', 'subtitle': 'The first heatmap subtitle', 'theme': Theme(), 'stylesheet': StyleSheet(), 'xaxis_title': 'Title of X-Axis', 'yaxis_title': 'Title of Y-Axis' } options2 = { 'data': mock_data2, 'title': 'My First Heatmap title', 'subtitle': 'The first heatmap subtitle', 'theme': Theme(), 'stylesheet': StyleSheet(), 'xaxis_title': 'Title of X-Axis', 'yaxis_title': 'Title of Y-Axis' } heatmap1 = HeatMap(options1) heatmap2 = HeatMap(options2) file_output_writer=FileOutputWriter(filepath="filepath.file",heatmap=heatmap1) self.assertEqual(file_output_writer.heatmap, heatmap1) file_output_writer.heatmap = heatmap2 self.assertEqual(file_output_writer.heatmap, heatmap2)
def test_write_A(self): mock_data = [ ["Month","Web Traffic","Call to actions"], ["January",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["February",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["March",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["April",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["May",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})] ] stylesheet = StyleSheet() options = { 'data': mock_data, 'title': 'My First Heatmap title', 'subtitle': 'The first heatmap subtitle', 'theme': Theme(), 'stylesheet': stylesheet, 'xaxis_title': 'Title of X-Axis', 'yaxis_title': 'Title of Y-Axis' } filepath = "myoutputfile.html" heatmap = HeatMap(options) html_writer = HTMLWriter(filepath=filepath, heatmap=heatmap) html_writer.write() self.assertTrue(os.path.exists(filepath)) os.remove(filepath)
def test___init__A(self): options = dict() options['title'] = "A Title" options['subtitle'] = "A Subtitle" options['theme'] = Theme() options['stylesheet'] = StyleSheet() options['xaxis_title'] = 'XAxis Title' options['yaxis_title'] = 'YAxis Title' # declare some mock tiles. t1 = Tile({'value': 105, 'alpha': 0.45, 'rgb': '#f00000'}) t2 = Tile({'value': 10, 'alpha': 0.2566, 'rgb': '#f10000'}) t3 = Tile({'value': 123, 'alpha': 0.89, 'rgb': '#f20000'}) t4 = Tile({'value': 45, 'alpha': 0.15, 'rgb': '#f30000'}) t5 = Tile({'value': 35, 'alpha': 0.97, 'rgb': '#f40000'}) t6 = Tile({'value': 89, 'alpha': 0.24, 'rgb': '#f50000'}) t7 = Tile({'value': 67.43, 'alpha': 0.522, 'rgb': '#f60000'}) t8 = Tile({'value': 49, 'alpha': 0.567, 'rgb': '#f70000'}) t9 = Tile({'value': 100, 'alpha': 0.11, 'rgb': '#f80000'}) options['data'] = [ ['', 'Monday', 'Tuesday', 'Wednesday'], ['Morning', t1, t2, t3], ['Midday', t4, t5, t6], ['Afternoon', t7, t8, t9], ] heatmap = HeatMap(options)
def test___init__A(self): mock_data = [ ["Month","Web Traffic","Call to actions"], ["January",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["February",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["March",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["April",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["May",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}), Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})] ] stylesheet = StyleSheet() options = { 'data': mock_data, 'title': 'My First Heatmap title', 'subtitle': 'The first heatmap subtitle', 'theme': Theme(), 'stylesheet': stylesheet, 'xaxis_title': 'Title of X-Axis', 'yaxis_title': 'Title of Y-Axis' } filepath = "myfilepath.html" heatmap = HeatMap(options) html_writer = HTMLWriter(filepath=filepath, heatmap=heatmap) self.assertRaises(TypeError, HTMLWriter, filepath=filepath, heatmap=list())
def setUp(self): self.options = dict() self.options['title'] = "A Title" self.options['subtitle'] = "A Subtitle" self.options['theme'] = Theme() self.options['stylesheet'] = StyleSheet() self.options['xaxis_title'] = 'XAxis Title' self.options['yaxis_title'] = 'YAxis Title' # declare some mock tiles. self.t1 = Tile({'value': 105, 'alpha': 0.45, 'rgb': '#f00000'}) self.t2 = Tile({'value': 10, 'alpha': 0.2566, 'rgb': '#f10000'}) self.t3 = Tile({'value': 123, 'alpha': 0.89, 'rgb': '#f20000'}) self.t4 = Tile({'value': 45, 'alpha': 0.15, 'rgb': '#f30000'}) self.t5 = Tile({'value': 45, 'alpha': 0.15, 'rgb': '#f30000'}) self.t6 = Tile({'value': 89, 'alpha': 0.24, 'rgb': '#f50000'}) self.t7 = Tile({'value': 89, 'alpha': 0.24, 'rgb': '#f50000'}) self.t8 = Tile({'value': 89, 'alpha': 0.24, 'rgb': '#f50000'}) self.t9 = Tile({'value': 100, 'alpha': 0.11, 'rgb': '#f80000'}) self.options['data'] = [ ['', 'Monday', 'Tuesday', 'Wednesday'], ['Morning', self.t1, self.t2, self.t3], ['Midday', self.t4, self.t5, self.t6], ['Afternoon', self.t7, self.t8, self.t9], ] self.heatmap = HeatMap(self.options)
def test_styles_B(self): stylesheet = StyleSheet() keys = [ 'tile_size', 'plane_top_margin', 'canvas_size_factor', 'canvas_top_margin', 'canvas_bottom_margin', 'ylabel_margin', 'xlabel_margin', 'axes_title_font', 'axes_title_size', 'axes_title_bold', 'axes_tick_length', 'axes_label_font', 'axes_label_size', 'axes_label_bold', 'title_font', 'title_size', 'title_bold', 'title_ycoord', 'subtitle_font', 'subtitle_size', 'subtitle_bold', 'subtitle_ycoord' ] self.assertEqual(len(stylesheet.styles.keys()), len(keys)) for key in keys: self.assertTrue(key in stylesheet.styles.keys())
def test_write_A(self): mock_data = [ ["Month","Web Traffic","Call to actions"], ["January",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["February",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["March",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["April",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})], ["May",Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56}),Tile({'value': 60, 'rgb': '#a45aff', 'alpha': 0.56})] ] stylesheet = StyleSheet() options = { 'data': mock_data, 'title': 'My First Heatmap title', 'subtitle': 'The first heatmap subtitle', 'theme': Theme(), 'stylesheet': stylesheet, 'xaxis_title': 'Title of X-Axis', 'yaxis_title': 'Title of Y-Axis' } heatmap = HeatMap(options) file_output_writer=FileOutputWriter(filepath="filepath.file",heatmap=heatmap) self.assertRaises(NotImplementedError, file_output_writer.write)
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
def test_styles_F(self): s1 = StyleSheet(axes_label_bold=True) self.assertEqual(s1.styles['axes_label_bold'], True)
def test_styles_E(self): s1 = StyleSheet(title_font="Arial") self.assertEqual(s1.styles['title_font'], "Arial")
def test_styles_D(self): s1 = StyleSheet(axes_label_size=56) self.assertEqual(s1.styles['axes_label_size'], 56)
def test___init__A(self): s1 = StyleSheet() s2 = StyleSheet(tile_size=(80, 100)) s3 = StyleSheet(title_ycoord=50) s4 = StyleSheet(axes_tick_length=100) s5 = StyleSheet(axes_label_bold=True, tile_size=(10, 10))
def test_styles_C(self): s1 = StyleSheet(canvas_size_factor=0.24) self.assertEqual(s1.styles['canvas_size_factor'], 0.24)
def test_styles_A(self): self.assertIsInstance(StyleSheet().styles, dict)
def test___init__B(self): mock_data = [["Month", "Web Traffic", "Call to actions"], [ "January", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "February", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "March", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "April", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "May", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "June", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "July", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "August", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "September", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "October", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "November", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ], [ "December", Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }), Tile({ 'value': 60, 'rgb': '#a45aff', 'alpha': 0.56 }) ]] options = { 'data': mock_data, 'title': 'My First Heatmap title', 'subtitle': 'The first heatmap subtitle', 'theme': Theme(), 'stylesheet': StyleSheet(), 'xaxis_title': 'Title of X-Axis', 'yaxis_title': 'Title of Y-Axis' } heatmap = HeatMap(options) HeatMapWindow(self.parent, heatmap=heatmap)