Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_line(self):
chart = leather.Chart()
chart.add_lines(self.data1)
chart.add_lines(self.data2)
chart.add_lines(self.data3)
output = six.StringIO()
chart.to_svg(output)
def test_add_one(self):
chart1 = leather.Chart()
chart1.add_dots(self.data1)
chart2 = leather.Chart()
chart2.add_dots(self.data2)
grid = leather.Grid()
grid.add_one(chart1)
grid.add_one(chart2)
svg = self.render_chart(grid)
self.assertElementCount(svg, '.axis', 4)
self.assertElementCount(svg, '.series', 2)
self.assertElementCount(svg, '.dots', 2)
self.assertElementCount(svg, 'circle', 9)
def test_column(self):
chart = leather.Chart()
chart.add_columns(self.data1)
chart.add_columns(self.data2)
chart.add_columns(self.data3)
output = six.StringIO()
chart.to_svg(output)
def test_dot(self):
chart = leather.Chart()
chart.add_dots(self.data1)
chart.add_dots(self.data2)
chart.add_dots(self.data3)
output = six.StringIO()
chart.to_svg(output)
def test_to_svg_file_handle(self):
chart1 = leather.Chart()
chart1.add_dots(self.data1)
chart2 = leather.Chart()
chart2.add_dots(self.data2)
grid = leather.Grid()
grid.add_many([chart1, chart2, chart1])
with open('.test.svg', 'w') as f:
grid.to_svg(f)
self.assertTrue(os.path.exists(TEST_SVG))
def test_multiple_series(self):
chart = leather.Chart()
chart.add_dots(self.data1)
chart.add_dots(self.data2)
svg = self.render_chart(chart)
self.assertElementCount(svg, '.axis', 2)
self.assertElementCount(svg, '.series', 2)
self.assertElementCount(svg, '.dots', 2)
self.assertElementCount(svg, 'circle', 9)
def test_scale_domain_warning(self):
chart = leather.Chart()
chart.add_x_scale(4, 7)
chart.add_y_scale(0, 20)
chart.add_dots(self.data1)
with warnings.catch_warnings():
warnings.simplefilter('error')
with self.assertRaises(UserWarning):
self.render_chart(chart)
def test_to_svg_file_name(self):
chart = leather.Chart()
chart.add_dots(self.data1)
chart.to_svg('.test.svg')
self.assertTrue(os.path.exists(TEST_SVG))
import random
import leather
dot_data = [(random.randint(0, 250), random.randint(0, 250)) for i in range(100)]
def colorizer(d):
return 'rgb(%i, %i, %i)' % (d.x, d.y, 150)
chart = leather.Chart('Colorized dots')
chart.add_dots(dot_data, fill_color=colorizer)
chart.to_svg('examples/charts/colorized_dots.svg')
import leather
import math
import csv
chart = leather.Chart('Income vs. health')
with open('data.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile)
data = list(reader)
def size_dot_by_area(x, y, i):
return math.sqrt(int(data[i]['population'])) / 1000
dots = leather.Dots('rgba(0,0,0,0.5)', radius=size_dot_by_area)
series = leather.Series(
data,
dots,
x=lambda row, i: math.log(float(row['income'])),
y=lambda row, i: float(row['health']))