Example #1
0
 def test_timeseries(self):
     vis_data = {
         'data': [self.ts_data, ],
         'names': ['Fibonacci Numbers', ],
         'colors': ['#7C8BD9', ],
         'linestyles': ['-', ],
         }
     vis_labels = {
         'title': 'First Ten Fibonacci Numbers',
         'x': 'Sequence Number',
         'y': 'Fibonacci Number'}
     chart_png_str = create_chart_as_png_str(
         'timeseries',
         vis_data,
         labels_dct=vis_labels,
         template='clean',)
     # In case you want to see the chart with your own eyes:
     #
     # ts_chart_filename = "ts_chart_from_unittest.png"
     # the_file = open(ts_chart_filename, 'w')
     # the_file.write(chart_png_str)
     # the_file.close()
     #
     # Otherwise, trust this hash of what the chart should be:
     assert hash(chart_png_str) == -7569801611015431504
 def test_timeseries(self):
     vis_data = {
         'data': [
             self.bar_data,
         ],
         'names': [
             'Foo Data',
         ],
         'colors': [
             '#7C8BD9',
         ],
     }
     vis_labels = {'title': 'Some Kind of Data', 'x': 'Data', 'y': 'Value'}
     chart_png_str = create_chart_as_png_str(
         'barchart',
         vis_data,
         labels_dct=vis_labels,
         template='clean',
     )
     # In case you want to see the chart with your own eyes:
     #
     # ts_chart_filename = "bar_chart_from_unittest.png"
     # the_file = open(ts_chart_filename, 'w')
     # the_file.write(chart_png_str)
     # the_file.close()
     #
     assert hash(chart_png_str) == 6805953041015498766
 def test_timeseries(self):
     vis_data = {
         'data': [
             self.ts_data,
         ],
         'names': [
             'Fibonacci Numbers',
         ],
         'colors': [
             '#7C8BD9',
         ],
         'linestyles': [
             '-',
         ],
     }
     vis_labels = {
         'title': 'First Ten Fibonacci Numbers',
         'x': 'Sequence Number',
         'y': 'Fibonacci Number'
     }
     chart_png_str = create_chart_as_png_str(
         'timeseries',
         vis_data,
         labels_dct=vis_labels,
         template='clean',
     )
     # In case you want to see the chart with your own eyes:
     #
     # ts_chart_filename = "ts_chart_from_unittest.png"
     # the_file = open(ts_chart_filename, 'w')
     # the_file.write(chart_png_str)
     # the_file.close()
     #
     # Otherwise, trust this hash of what the chart should be:
     assert hash(chart_png_str) == -7569801611015431504
 def test_bad_chart_data(self):
     vis_data = [1, 2, 3, 4, 5]
     vis_labels = {'title': 'Some Kind of Data', 'x': 'Data', 'y': 'Value'}
     with pytest.raises(AssertionError):
         chart_png_str = create_chart_as_png_str(
             'timeseries',
             vis_data,
             labels_dct=vis_labels,
             template='clean',
         )
Example #5
0
 def test_bad_chart_data(self):
     vis_data = [1, 2, 3, 4, 5]
     vis_labels = {
         'title': 'Some Kind of Data',
         'x': 'Data',
         'y': 'Value'}
     with pytest.raises(AssertionError):
         chart_png_str = create_chart_as_png_str(
             'timeseries',
             vis_data,
             labels_dct=vis_labels,
             template='clean',)
Example #6
0
 def test_bad_chart_labels(self):
     vis_data = {
         'data': [self.bar_data, ],
         'names': ['Foo barchart data', ],
         }
     vis_labels = {'foo': 'bar'}
     with pytest.raises(AssertionError):
         chart_png_str = create_chart_as_png_str(
             'barchart',
             vis_data,
             labels_dct=vis_labels,
             template='clean',)
Example #7
0
def show_ts_plot_png(request):
    fake_data_dct = {'data': [[1, 2, 1, 2, 3, -1, 4, -2, 2.5, 1.3]]}
    img_str = create_chart_as_png_str('timeseries', fake_data_dct, {}, '')
    #
    # From here the Django-specific part follows; not much to it:
    #
    response = HttpResponse(img_str, mimetype='image/png')
    # Development note: the function create_timeseries_png_str uses a
    # StringIO approach, which is better than some examples (on the
    # web) using print_png(response); when I tried those (as below) it
    # causes timeout error messages on the server-side.
    #
    # figure.print_png(response)
    return response
Example #8
0
 def test_bad_chart_type(self):
     vis_data = {
         'data': [self.bar_data, ],
         'names': ['Foo barchart data', ],
         }
     vis_labels = {
         'title': 'Some Kind of Data',
         'x': 'Data',
         'y': 'Value'}
     with pytest.raises(AssertionError):
         chart_png_str = create_chart_as_png_str(
             'foo',
             vis_data,
             labels_dct=vis_labels,
             template='clean',)
Example #9
0
 def test_bad_chart_data_two(self):
     vis_data = {
         'data': [[], []],
         'names': ['Foo data', ],
         }
     vis_labels = {
         'title': '',
         'x': '',
         'y': ''}
     with pytest.raises(AssertionError):
         chart_png_str = create_chart_as_png_str(
             'barchart',
             vis_data,
             labels_dct=vis_labels,
             template='clean',)
Example #10
0
 def test_bad_chart_data_two(self):
     vis_data = {
         'data': [[], []],
         'names': [
             'Foo data',
         ],
     }
     vis_labels = {'title': '', 'x': '', 'y': ''}
     with pytest.raises(AssertionError):
         chart_png_str = create_chart_as_png_str(
             'barchart',
             vis_data,
             labels_dct=vis_labels,
             template='clean',
         )
Example #11
0
def show_ts_plot_png(request):
    fake_data_dct = {
        'data': [[1, 2, 1, 2, 3, -1, 4, -2, 2.5, 1.3]]}
    img_str = create_chart_as_png_str('timeseries', fake_data_dct, {}, '')
    #
    # From here the Django-specific part follows; not much to it:
    #
    response = HttpResponse(img_str, mimetype='image/png')
    # Development note: the function create_timeseries_png_str uses a
    # StringIO approach, which is better than some examples (on the
    # web) using print_png(response); when I tried those (as below) it
    # causes timeout error messages on the server-side.
    #
    # figure.print_png(response)
    return response
Example #12
0
 def test_bad_chart_type(self):
     vis_data = {
         'data': [
             self.bar_data,
         ],
         'names': [
             'Foo barchart data',
         ],
     }
     vis_labels = {'title': 'Some Kind of Data', 'x': 'Data', 'y': 'Value'}
     with pytest.raises(AssertionError):
         chart_png_str = create_chart_as_png_str(
             'foo',
             vis_data,
             labels_dct=vis_labels,
             template='clean',
         )
Example #13
0
 def test_bad_chart_labels(self):
     vis_data = {
         'data': [
             self.bar_data,
         ],
         'names': [
             'Foo barchart data',
         ],
     }
     vis_labels = {'foo': 'bar'}
     with pytest.raises(AssertionError):
         chart_png_str = create_chart_as_png_str(
             'barchart',
             vis_data,
             labels_dct=vis_labels,
             template='clean',
         )
Example #14
0
 def test_timeseries(self):
     vis_data = {
         'data': [self.bar_data, ],
         'names': ['Foo Data', ],
         'colors': ['#7C8BD9', ],
         }
     vis_labels = {
         'title': 'Some Kind of Data',
         'x': 'Data',
         'y': 'Value'}
     chart_png_str = create_chart_as_png_str(
         'barchart',
         vis_data,
         labels_dct=vis_labels,
         template='clean',)
     # In case you want to see the chart with your own eyes:
     #
     # ts_chart_filename = "bar_chart_from_unittest.png"
     # the_file = open(ts_chart_filename, 'w')
     # the_file.write(chart_png_str)
     # the_file.close()
     #
     assert hash(chart_png_str) == 6805953041015498766
Example #15
0
from webplotlib.chart_builders import create_chart_as_png_str
chart_png_str = create_chart_as_png_str(
    'timeseries',
    {'data': [[1, 2, 3, 4]], 'names': 'MyDataLine'},
    labels_dct={'title': 'TheBigBoard', 'x': 'Data', 'y': 'Value'})
Example #16
0
def show_bar_plot_png(request):
    fake_data_dct = {'data': [[1, 2, 1, 2, 3, -11, 4, -2, 2.5, 1.3]]}
    img_str = create_chart_as_png_str('barchart', fake_data_dct, {}, '')
    response = HttpResponse(img_str, mimetype='image/png')
    return response
Example #17
0
def show_bar_plot_png(request):
    fake_data_dct = {
        'data': [[1, 2, 1, 2, 3, -11, 4, -2, 2.5, 1.3]]}
    img_str = create_chart_as_png_str('barchart', fake_data_dct, {}, '')
    response = HttpResponse(img_str, mimetype='image/png')
    return response