def interpolation(): width, height = 600, 400 config = Config() config.width = width config.height = height config.fill = True config.style = styles['neon'] data = random.randrange(1, 10) order = random.randrange(1, 10) series = b64encode(pickle.dumps(_random_series(type, data, order))) svgs = [] for interpolation in ('linear', 'slinear', 'nearest', 'zero', 'quadratic', 'cubic', 'krogh', 'barycentric', 'univariate', 4, 5, 6, 7, 8): config.title = "%s interpolation" % interpolation config.interpolate = interpolation svgs.append({ 'type': 'StackedLine', 'series': series, 'config': b64encode(pickle.dumps(config)) }) return render_template('svgs.jinja2', svgs=svgs, width=width, height=height)
def rotation(): width, height = 375, 245 config = Config() config.width = width config.height = height config.fill = True config.style = styles['neon'] data = random.randrange(1, 10) order = random.randrange(1, 10) series = b64encode(pickle.dumps(_random_series(type, data, order))) labels = [random_label() for i in range(data)] svgs = [] config.show_legend = bool(random.randrange(0, 2)) for angle in range(0, 370, 10): config.title = "%d rotation" % angle config.x_labels = labels config.x_label_rotation = angle config.y_label_rotation = angle svgs.append({'type': 'pygal.Bar', 'series': series, 'config': b64encode(pickle.dumps(config))}) return render_template('svgs.jinja2', svgs=svgs, width=width, height=height)
def all(style='default', interpolate=None): width, height = 600, 400 data = random.randrange(1, 10) order = random.randrange(1, 10) xy_series = _random(data, order) other_series = [] for title, values in xy_series: other_series.append((title, cut(values, 1))) xy_series = b64encode(pickle.dumps(xy_series)) other_series = b64encode(pickle.dumps(other_series)) config = Config() config.width = width config.height = height config.fill = bool(random.randrange(0, 2)) config.human_readable = True config.interpolate = interpolate config.style = styles[style] config.x_labels = [random_label() for i in range(data)] svgs = [] for chart in pygal.CHARTS: type = chart.__name__ svgs.append({ 'type': type, 'series': xy_series if type == 'XY' else other_series, 'config': b64encode(pickle.dumps(config)) }) return render_template('svgs.jinja2', svgs=svgs, width=width, height=height)
def make_bar_chart(title, label, data, width=960, height=400): """Make a bar chart with given data and the appropriate style :param title: The title of the chart :param label: The label of the chart :param data: The data :param width: The width of the chart :param data: The height of the chart :returns chart: """ # Chart style custom_style = BlueStyle custom_style.background = "transparent" custom_style.plot_background = "transparent" custom_style.major_guide_stroke_dasharray = '0,0' custom_style.guide_stroke_dasharray = '0,0' # Chart config css_style = Path(PACKAGE_DIR).joinpath('static/git/css/graph.css') config = Config() config.css.append('file://' + css_style.as_posix()) print(config.css) chart = pygal.Bar(config) chart.width = 960 chart.height = 400 chart.style = custom_style chart.x_label_rotation = 45 chart.show_y_guides=True chart.show_x_guides=False chart.explicit_size=True chart.title = title chart.add('Count', data[0:20]) return chart
def __init__(self, config=None, **kwargs): """Init config""" name = self.__class__.__name__ self.cls = REAL_CHARTS[name] if config and isinstance(config, type): config = config() if config: config = config.copy() else: config = Config() config(**kwargs) self.config = config self.raw_series = []
def interpolation(): width, height = 600, 400 config = Config() config.width = width config.height = height config.fill = True config.style = styles['neon'] data = random.randrange(1, 10) order = random.randrange(1, 10) series = b64encode(pickle.dumps(_random_series(type, data, order))) svgs = [] for interpolation in 'quadratic', 'cubic', 'lagrange', 'trigonometric': config.title = "%s interpolation" % interpolation config.interpolate = interpolation svgs.append({ 'type': 'pygal.StackedLine', 'series': series, 'config': b64encode(pickle.dumps(config)) }) for params in [{'type': 'catmull_rom'}, {'type': 'finite_difference'}, {'type': 'cardinal', 'c': .25}, {'type': 'cardinal', 'c': .5}, {'type': 'cardinal', 'c': .75}, {'type': 'cardinal', 'c': 1.5}, {'type': 'cardinal', 'c': 2}, {'type': 'cardinal', 'c': 5}, {'type': 'kochanek_bartels', 'b': 1, 'c': 1, 't': 1}, {'type': 'kochanek_bartels', 'b': -1, 'c': 1, 't': 1}, {'type': 'kochanek_bartels', 'b': 1, 'c': -1, 't': 1}, {'type': 'kochanek_bartels', 'b': 1, 'c': 1, 't': -1}, { 'type': 'kochanek_bartels', 'b': -1, 'c': 1, 't': -1 }, {'type': 'kochanek_bartels', 'b': -1, 'c': -1, 't': 1}, {'type': 'kochanek_bartels', 'b': -1, 'c': -1, 't': -1}]: config.title = "Hermite interpolation with params %r" % params config.interpolate = 'hermite' config.interpolation_parameters = params svgs.append({ 'type': 'pygal.StackedLine', 'series': series, 'config': b64encode(pickle.dumps(config)) }) return render_template( 'svgs.jinja2', svgs=svgs, width=width, height=height )
def __init__(self, config=None, **kwargs): """Config preparation and various initialization""" if config: if isinstance(config, type): config = config() else: config = config.copy() else: config = Config() config(**kwargs) self.config = config self.state = None self.uuid = str(uuid4()) self.raw_series = [] self.xml_filters = []
def all(style='default', color=None, interpolate=None, base_style=None): width, height = 600, 400 data = random.randrange(1, 10) order = random.randrange(1, 10) if color is None: style = styles[style] else: style = parametric_styles[style](color, base_style=styles[base_style or 'default']) xy_series = _random(data, order) other_series = [] for title, values, config in xy_series: other_series.append((title, cut(values, 1), config)) xy_series = b64encode(pickle.dumps(xy_series)) other_series = b64encode(pickle.dumps(other_series)) config = Config() config.width = width config.height = height config.fill = bool(random.randrange(0, 2)) config.interpolate = interpolate config.style = style svgs = [] for chart in pygal.CHARTS: type = '.'.join((chart.__module__, chart.__name__)) if chart._dual: config.x_labels = None else: config.x_labels = [random_label() for i in range(data)] svgs.append({ 'type': type, 'series': xy_series if chart._dual else other_series, 'config': b64encode(pickle.dumps(config)) }) return render_template('svgs.jinja2', svgs=svgs, width=width, height=height)