def test_params(self): #Test params chart = bearcart.Chart(width=500, height=1000, plt_type='area') assert chart.height == 1000 assert chart.width == 500 assert chart.renderer == 'area' #Test component removal chart = bearcart.Chart(x_axis=False, legend=False) nt.assert_list_equal(chart.template_vars.keys(), ['y_axis', 'hover', 'slider'])
def test_build_graph(self): '''Test graph build''' series = self.price['AAPL'] chart = bearcart.Chart(series) chart._build_graph() vars = { 'dataset': [{ 'name': 'AAPL', 'color': 'palette.color()', 'data': 'json[0].data', }], 'width': 750, 'height': 400, 'render': 'line', 'min': "min: 'auto'," } graph_templ = self.templates.get_template('graph.js') graph = graph_templ.render(vars) assert chart.colors == {'AAPL': 'palette.color()'} assert chart.template_vars['graph'] == graph
def test_non_timeseries(self): tabular_data = [random.randint(10, 100) for x in range(0, 25, 1)] df = pd.DataFrame({'Data 1': tabular_data}) chart = bearcart.Chart(df, x_time=False) nt.assert_in('x_axis_num', chart.template_vars) nt.assert_in('xFormatter: function(x)' '{return Math.floor(x / 10) * 10}\n}', chart.template_vars['hover'])
def test_data(self): #Test data series = self.price['AAPL'] chart = bearcart.Chart(series) assert_almost_equal(chart.raw_data, series) assert chart.json_data[0]['name'] == 'AAPL' assert len(series) == len(chart.json_data[0]['data']) nt.eq_(time.mktime(series.index[0].timetuple()), chart.json_data[0]['data'][0]['x'])
def test_init(self): '''Test bearcart chart creation''' #Test defaults chart = bearcart.Chart() assert chart.height == 400 assert chart.width == 750 assert chart.renderer == 'line' temps = { x.split('.')[0]: x.split('.')[1] for x in self.templates.list_templates() } for key, value in chart.template_vars.iteritems(): template = self.templates.get_template('.'.join([key, temps[key]])) assert value == template.render()
def test_build_graph(self): series = self.price['AAPL'] chart = bearcart.Chart(series) chart._build_graph() vars = {'dataset': [{'name': 'AAPL', 'color': 'palette.color()', 'data': 'json[0].data', }], 'width': 750, 'height': 400, 'render': 'line', 'min': "min: 'auto',", "chart_id": chart.chart_id} graph_templ = self.templates.get_template('graph.js') graph = graph_templ.render(vars) self.assertDictEqual(chart.colors, {'AAPL': 'palette.color()'}) self.assertEqual(chart.template_vars['graph'], graph)
def test_init(self): #Test defaults chart = bearcart.Chart(colors={'Data 1': '#25aeb0'}) self.assertEqual(chart.height, 400) self.assertEqual(chart.width, 750) self.assertEqual(chart.renderer, 'line') self.assertDictEqual(chart.colors, {'Data 1': "'#25aeb0'"}) temps = {x.split('.')[0]: x.split('.')[1] for x in self.templates.list_templates()} for key, value in chart.template_vars.iteritems(): template = self.templates.get_template('.'.join([key, temps[key]])) kwargs = { 'height': 400, 'y_axis_id': chart.y_axis_id, 'legend_id': chart.legend_id, 'slider_id': chart.slider_id } self.assertEqual(value, template.render(kwargs))
html_path = r'index.html' data_path = r'data.json' js_path = 'rickshaw.min.js' css_path = 'rickshaw.min.css' tabular_data_1 = [random.randint(10, 100) for x in range(0, 25, 1)] tabular_data_2 = [random.randint(10, 100) for x in range(0, 25, 1)] tabular_data_3 = [random.randint(10, 100) for x in range(0, 25, 1)] df = pd.DataFrame({ 'Data 1': tabular_data_1, 'Data 2': tabular_data_2, 'Data 3': tabular_data_3 }) vis = bearcart.Chart(df, x_time=False) vis.create_chart(html_path=html_path, data_path=data_path, js_path=js_path, css_path=css_path) #Bunch of data, area chart vis = bearcart.Chart(df, x_time=False, plt_type='area') vis.create_chart(html_path=html_path, data_path=data_path, js_path=js_path, css_path=css_path) #Bunch of data, bar chart vis = bearcart.Chart(df, x_time=False, plt_type='bar') vis.create_chart(html_path=html_path,
import pandas.io.data as web all_data = {} for ticker in ['AAPL', 'GOOG', 'XOM', 'MSFT', 'INTC', 'YHOO']: all_data[ticker] = web.get_data_yahoo(ticker, '1/1/2012', '1/1/2013') price = pd.DataFrame( {tic: data['Adj Close'] for tic, data in all_data.iteritems()}) #Two data, line chart df = pd.concat([price['AAPL'], price['GOOG']], axis=1) vis = bearcart.Chart(df) vis.create_chart(html_path=html_path, data_path=data_path, js_path=js_path, css_path=css_path) #Bunch of data, area chart vis = bearcart.Chart(price, plt_type='area') vis.create_chart(html_path=html_path, data_path=data_path, js_path=js_path, css_path=css_path) #Two data, custom colors, scatterplot vis = bearcart.Chart(df, plt_type='scatterplot',