Example #1
0
 def plot(self):
     g = Plot(
         dict(
             width=640,
             height=480,
             graph_title="Plot",
             show_graph_title=True,
             no_css=True,
             key=True,
             scale_x_integers=True,
             scale_y_integers=True,
             min_x_value=0,
             min_y_value=0,
             show_data_labels=True,
             show_x_guidelines=True,
             show_x_title=True,
             x_title="Time",
             show_y_title=True,
             y_title="Ice Cream Cones",
             y_title_text_direction='bt',
         ))
     # add a few random datasets
     for n in range(1, 4):
         g.add_data(
             dict(data=flatten(get_data_set()), title='series %d' % n))
     res = XML(g.burn())
     return render(chart=res)
Example #2
0
	def test_pairs(self):
		"""
		Test that it is acceptable to use pairs for data.
		"""
		g = Plot(dict(show_data_points=True))
		g.add_data(dict(data=[(1, 0), (2, 1)], title='pairs'))
		assert 'circle' in g.burn()
Example #3
0
	def test_pairs(self):
		"""
		Test that it is acceptable to use pairs for data.
		"""
		g = Plot(dict(show_data_points=True))
		g.add_data(dict(data=[(1, 0), (2, 1)], title='pairs'))
		assert b'circle' in g.burn()
Example #4
0
	def plot(self):
		g = Plot(dict(
			width = 640,
			height = 480,
			graph_title = "Plot",
			show_graph_title = True,
			no_css = True,
			key = True,
			scale_x_integers = True,
			scale_y_integers = True,
			min_x_value = 0,
			min_y_value = 0,
			show_data_labels = True,
			show_x_guidelines = True,
			show_x_title = True,
			x_title = "Time",
			show_y_title = True,
			y_title = "Ice Cream Cones",
			y_title_text_direction = 'bt',
		))
		# add a few random datasets
		for n in range(1, 4):
			g.add_data(dict(
				data = flatten(get_data_set()),
				title = 'series %d' % n,
				))
		res = XML(g.burn())
		return render(chart=res)
Example #5
0
def sample_PlotTextLabels():
    g = Plot(
        {
            'draw_lines_between_points': False,
            'min_x_value': 0,
            'min_y_value': 0,
            'show_x_guidelines': True,
        }
    )
    # Processed Apple production 2015
    # Any object with a .text attribute will do;
    # we like namedtuple().

    from collections import namedtuple

    Datum = namedtuple("Datum", "x y text")

    g.add_data(
        {
            'data': [
                Datum(8.24, 80.85, 'ES'),
                Datum(0.17, 6.73, 'IE'),
                Datum(0, 0, 'IS'),
            ],
            'title': 'Processed Apple',
        }
    )
    return g
Example #6
0
def sample_PlotTextLabels():
    g = Plot({
        'draw_lines_between_points': False,
        'min_x_value': 0,
        'min_y_value': 0,
        'show_x_guidelines': True
    })
    # Processed Apple production 2015
    # Any object with a .text attribute will do;
    # we like namedtuple().

    from collections import namedtuple

    Datum = namedtuple("Datum", "x y text")

    g.add_data({
        'data': [
            Datum(8.24, 80.85, 'ES'),
            Datum(0.17, 6.73, 'IE'),
            Datum(0, 0, 'IS'),
        ],
        'title':
        'Processed Apple'
    })
    return g
Example #7
0
	def test_python3_show_points(self):
		"""
		Test that show_data_points creates
		circle elements in output.
		"""
		g = Plot(dict(show_data_points=True))
		g.add_data(dict(data=[1, 0, 2, 1], title='foo'))
		assert 'circle' in g.burn()
Example #8
0
	def test_python3_show_points(self):
		"""
		Test that show_data_points creates
		circle elements in output.
		"""
		g = Plot(dict(show_data_points=True))
		g.add_data(dict(data=[1, 0, 2, 1], title='foo'))
		assert b'circle' in g.burn()
Example #9
0
	def test_iterable_data_flat(self):
		g = Plot()
		spec = dict(
			data=flatten(self.get_data()),
			title='labels',
		)
		g.add_data(spec)
		svg = g.burn()
		assert b'text="(1.00, 0.00)"' in svg
Example #10
0
 def test_iterable_data_grouped(self):
     g = Plot()
     spec = dict(
         data=self.get_data(),
         title='labels',
     )
     g.add_data(spec)
     svg = g.burn()
     assert b'text="(1.00, 0.00)"' in svg
Example #11
0
 def test_all_y_values_zero(self):
     """
     If all y values are zero, the graph should render without error.
     """
     g = Plot()
     pairs = [0, 0.0]
     spec = dict(data=pairs, title='test')
     g.add_data(spec)
     g.burn()
Example #12
0
	def test_iterable_data_flat(self):
		g = Plot()
		spec = dict(
			data=flatten(self.get_data()),
			title='labels',
		)
		g.add_data(spec)
		svg = g.burn()
		assert 'text="(1.00, 0.00)"' in svg
Example #13
0
	def test_index_error_2010_04(self):
		"""
		Reported by Jean Schurger
		a 'IndexError: tuple index out of range' when there are only two
		values returned by float_range (in the case there are only two
		different 'y' values in the data) and 'scale_y_integers == True'.

		Credit to Jean for the test code as well.
		"""
		g = Plot(dict(scale_y_integers = True))
		g.add_data(dict(data=[1, 0, 2, 1], title='foo'))
		g.burn()
Example #14
0
    def test_text(self):
        """
        Test that data with .text attributes make
        text labels.
        """
        from collections import namedtuple

        D = namedtuple("D", 'x y text')

        g = Plot(dict(show_data_values=True))
        g.add_data(dict(data=[D(1, 0, 'Sam'), D(2, 1, 'Dan')], title='labels'))
        svg = g.burn()
        assert 'Sam' in svg
        assert 'Dan' in svg
Example #15
0
    def test_text(self):
        """
        Test that data with .text attributes make
        text labels.
        """
        from collections import namedtuple

        D = namedtuple("D", 'x y text')

        g = Plot(dict(show_data_values=True))
        g.add_data(dict(data=[D(1, 0, 'Sam'), D(2, 1, 'Dan')], title='labels'))
        svg = g.burn()
        assert 'Sam' in svg
        assert 'Dan' in svg
Example #16
0
def sample_Plot():
    g = Plot(
        {
            'min_x_value': 0,
            'min_y_value': 0,
            'area_fill': True,
            'stagger_x_labels': True,
            'stagger_y_labels': True,
            'show_x_guidelines': True,
        }
    )
    g.add_data({'data': [[1, 25], [2, 30], [3, 45]], 'title': 'series 1'})
    g.add_data({'data': [[1, 30], [2, 31], [3, 40]], 'title': 'series 2'})
    g.add_data({'data': [[0.5, 35], [1, 20], [3, 10.5]], 'title': 'series 3'})
    return g
Example #17
0
def performance_plot():
    g = Plot({
        'min_x_value': 0,
        'min_y_value': 0,
        'area_fill': True,
        'stagger_x_labels': True,
        'stagger_y_labels': True,
        'show_x_guidelines': True
    })
Example #18
0
 def test_all_y_values_zero(self):
     """
     If all y values are zero, the graph should render without error.
     """
     g = Plot()
     pairs = [0, 0.0]
     spec = dict(data=pairs, title='test')
     g.add_data(spec)
     g.burn()
Example #19
0
    def test_rounding(self):
        """
        Labels should be rounded to 4 digits of precision.
        """
        g = Plot({
            'show_data_values': False,
            'show_data_points': False,
            'min_x_value': 0,
            'max_x_value': 0.5,
            'min_y_value': 0,
            'max_y_value': 1,
            'scale_y_divisions': 0.1,
            'scale_x_divisions': 0.1,
            'area_fill': False,
            'show_x_guidelines': True,
            'show_y_guidelines': True,
        })

        g.add_data({'data': self.read_data('source.csv'), 'title': 'title'})
        res = g.burn()
        assert '0.30' not in res
        assert '0.3' in res

        pathlib.Path('test.svg').write_text(res)
Example #20
0
	def test_index_error_2010_04(self):
		"""
		Reported by Jean Schurger
		a 'IndexError: tuple index out of range' when there are only two
		values returned by float_range (in the case there are only two
		different 'y' values in the data) and 'scale_y_integers == True'.

		Credit to Jean for the test code as well.
		"""
		g = Plot(dict(scale_y_integers = True))
		g.add_data(dict(data=[1, 0, 2, 1], title='foo'))
		g.burn()
Example #21
0
def sample_Plot():
    g = Plot({
        'min_x_value': 0,
        'min_y_value': 0,
        'area_fill': True,
        'stagger_x_labels': True,
        'stagger_y_labels': True,
        'show_x_guidelines': True
    })
    g.add_data({'data': [[1, 25], [2, 30], [3, 45]], 'title': 'series 1'})
    g.add_data({'data': [[1, 30], [2, 31], [3, 40]], 'title': 'series 2'})
    g.add_data({'data': [[.5, 35], [1, 20], [3, 10.5]], 'title': 'series 3'})
    return g
Example #22
0
	def test_inline_styles(self):
		g = Plot(dict(css_inline=True))
		g.add_data(dict(data=[1, 0, 2, 1], title='foo'))
		g.burn()
Example #23
0
 def test_iterable_data_grouped(self):
     g = Plot()
     spec = dict(data=self.get_data(), title='labels')
     g.add_data(spec)
     svg = g.burn()
     assert 'text="(1.00, 0.00)"' in svg
Example #24
0
import sys, os
from svg.charts.plot import Plot
g = Plot({
    'min_x_value': 0,
    'min_y_value': 0,
    'area_fill': True,
    'stagger_x_labels': True,
    'stagger_y_labels': True,
    'show_x_guidelines': True
   })
g.add_data({'data': [1, 25, 2, 30, 3, 45], 'title': 'series 1'})
g.add_data({'data': [1,30, 2, 31, 3, 40], 'title': 'series 2'})
g.add_data({'data': [.5,35, 1, 20, 3, 10.5], 'title': 'series 3'})
res = g.burn()
f = open(r'Plot.py.svg', 'w')
f.write(res)
f.close()

from svg.charts import time_series

g = time_series.Plot({})

g.timescale_divisions = '4 hours'
g.stagger_x_labels = True
g.x_label_format = '%d-%b %H:%M'
#g.max_y_value = 200

g.add_data({'data': ['2005-12-21T00:00:00', 20, '2005-12-22T00:00:00', 21], 'title': 'series 1'})

res = g.burn()
Example #25
0
	def test_inline_styles(self):
		g = Plot(dict(css_inline=True))
		g.add_data(dict(data=[1, 0, 2, 1], title='foo'))
		g.burn()