Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"+------------------+")
# Switch on non-defaults
renderer = BarChart(5, 30, [fn(5), fn(10)], scale=10.0, axes=BarChart.BOTH,
intervals=2.5, labels=True, border=False,
keys=["A", "B"])
self.assertEqual(
str(renderer),
"A |############# : \n" +
" | : : : \n" +
"B |########################## \n" +
" +-----+------+-----+------- \n" +
" 0 2.5 5.0 7.5 10.0 ")
# Check gradients
renderer = BarChart(7, 20, [fn(10), fn(10)], gradient=[(4, 1), (8, 2), (15, 2)])
self.assertEqual(
str(renderer),
"+------------------+\n" +
"| |\n" +
"| |###### |\n" +
"| | |\n" +
"| |###### |\n" +
"| |\n" +
"+------------------+")
self.assertEqual(
renderer.rendered_text[1][2],
[(7, 2, 0),
(None, 0, 0),
(None, 0, 0),
(7, 2, 0),
(1, 2, 0),
def test_bar_chart(self):
"""
Check that the BarChart renderer works.
"""
# Internal test function for rendering
def fn(x):
return lambda: x
# Check default implementation
renderer = BarChart(7, 20, [fn(10), fn(10)])
self.assertEqual(
str(renderer),
"+------------------+\n" +
"| |\n" +
"| |###### |\n" +
"| | |\n" +
"| |###### |\n" +
"| |\n" +
"+------------------+")
self.assertEqual(
"\n".join(renderer.images[0]),
"+------------------+\n" +
"| |\n" +
"| |###### |\n" +
"| | |\n" +
"| |###### |\n" +
"| |\n" +
"+------------------+")
self.assertEqual(
"\n".join(renderer.images[0]),
"+------------------+\n" +
"| |\n" +
"| |###### |\n" +
"| | |\n" +
"| |###### |\n" +
"| |\n" +
"+------------------+")
# Switch on non-defaults
renderer = BarChart(5, 30, [fn(5), fn(10)], scale=10.0, axes=BarChart.BOTH,
intervals=2.5, labels=True, border=False,
keys=["A", "B"])
self.assertEqual(
str(renderer),
"A |############# : \n" +
" | : : : \n" +
"B |########################## \n" +
" +-----+------+-----+------- \n" +
" 0 2.5 5.0 7.5 10.0 ")
# Check gradients
renderer = BarChart(7, 20, [fn(10), fn(10)], gradient=[(4, 1), (8, 2), (15, 2)])
self.assertEqual(
str(renderer),
"+------------------+\n" +
"| |\n" +
chart = BarChart(13, 60,
[wv(1), wv(2), wv(3), wv(4), wv(5), wv(7), wv(8), wv(9)],
colour=Screen.COLOUR_GREEN,
axes=BarChart.BOTH,
scale=2.0)
print(chart)
chart = BarChart(7, 60, [lambda: time.time() * 10 % 101],
gradient=[(10, 234), (20, 236), (30, 238), (40, 240),
(50, 242), (60, 244), (70, 246), (80, 248),
(90, 250), (100, 252)],
char=">",
scale=100.0,
labels=True,
axes=BarChart.X_AXIS)
print(chart)
chart = BarChart(10, 60,
[wv(1), wv(2), wv(3), wv(4), wv(5), wv(7), wv(8), wv(9)],
colour=[c for c in range(1, 8)],
scale=2.0,
axes=BarChart.X_AXIS,
intervals=0.5,
labels=True,
border=False)
print(chart)
def demo():
chart = BarChart(10, 40, [fn, fn],
char="=",
gradient=[(20, Screen.COLOUR_GREEN),
(30, Screen.COLOUR_YELLOW),
(40, Screen.COLOUR_RED)])
print(chart)
chart = BarChart(13, 60,
[wv(1), wv(2), wv(3), wv(4), wv(5), wv(7), wv(8), wv(9)],
colour=Screen.COLOUR_GREEN,
axes=BarChart.BOTH,
scale=2.0)
print(chart)
chart = BarChart(7, 60, [lambda: time.time() * 10 % 101],
gradient=[(10, 234), (20, 236), (30, 238), (40, 240),
(50, 242), (60, 244), (70, 246), (80, 248),
(90, 250), (100, 252)],
char=">",
scale=100.0,
labels=True,
axes=BarChart.X_AXIS)
print(chart)
chart = BarChart(10, 60,
[wv(1), wv(2), wv(3), wv(4), wv(5), wv(7), wv(8), wv(9)],
colour=[c for c in range(1, 8)],
scale=2.0,
axes=BarChart.X_AXIS,
intervals=0.5,
labels=True,
border=False)
def demo():
chart = BarChart(10, 40, [fn, fn],
char="=",
gradient=[(20, Screen.COLOUR_GREEN),
(30, Screen.COLOUR_YELLOW),
(40, Screen.COLOUR_RED)])
print(chart)
chart = BarChart(13, 60,
[wv(1), wv(2), wv(3), wv(4), wv(5), wv(7), wv(8), wv(9)],
colour=Screen.COLOUR_GREEN,
axes=BarChart.BOTH,
scale=2.0)
print(chart)
chart = BarChart(7, 60, [lambda: time.time() * 10 % 101],
gradient=[(10, 234), (20, 236), (30, 238), (40, 240),
(50, 242), (60, 244), (70, 246), (80, 248),
(90, 250), (100, 252)],
char=">",
(40, Screen.COLOUR_RED)])
print(chart)
chart = BarChart(13, 60,
[wv(1), wv(2), wv(3), wv(4), wv(5), wv(7), wv(8), wv(9)],
colour=Screen.COLOUR_GREEN,
axes=BarChart.BOTH,
scale=2.0)
print(chart)
chart = BarChart(7, 60, [lambda: time.time() * 10 % 101],
gradient=[(10, 234), (20, 236), (30, 238), (40, 240),
(50, 242), (60, 244), (70, 246), (80, 248),
(90, 250), (100, 252)],
char=">",
scale=100.0,
labels=True,
axes=BarChart.X_AXIS)
print(chart)
chart = BarChart(10, 60,
[wv(1), wv(2), wv(3), wv(4), wv(5), wv(7), wv(8), wv(9)],
colour=[c for c in range(1, 8)],
scale=2.0,
axes=BarChart.X_AXIS,
intervals=0.5,
labels=True,
border=False)
print(chart)