<commit_before>import pygal
from pygal.style import Style
import base64
import logging

logger = logging.getLogger("Graphs")

def plot(data, title=None, graph_type='Pie', max_entries=None, other_label="Other", y_title=None, labels=False):
    logger.error(data)
    custom_style = Style(
        background='transparent',
        font_family='sans-serif',
        plot_background='transparent',
        foreground='FFFFFF',
        foreground_light='black',
        foreground_dark='#FFFFFF',
        opacity='.9',
        opacity_hover='.5',
        transition='400ms ease-in',
        colors=('#4d4d4d', '#5da5da', '#faa43a', '#60bd68', '#f17cb0', '#b2912f', '#b276b2', '#decf3f', '#f15854'))
    data.sort(reverse=True, key=lambda x:x[1])
    if graph_type == 'Pie':
        chart = pygal.Pie(style=custom_style, inner_radius=.4)
    else:
        chart = pygal.HorizontalBar(style=custom_style)
        if data:
            chart.y_labels = map(repr, range(data[len(data)-1][1] - 1, data[0][1] + 1))
            chart.value_formatter = lambda x: str(int(x))
    if title:
        chart.title = title
    data.sort(key=lambda x:x[1])
    if max_entries and (len(data) > max_entries):
        cut = len(data) - max_entries
        remaining_data = reduce(lambda x, y: ('',x[1]+y[1]), data[:cut])
        data = data[cut:]
        data.insert(0,(other_label,  remaining_data[1], 'Other'))
    for item in data:
        if labels:
            chart.add(item[0], [{'value': item[1], 'label': item[2]}])
        else:
            chart.add(item[0], [{'value': item[1], 'label': item[0]}])
    if y_title:
        chart.y_title = y_title
    return base64.b64encode(chart.render())<commit_msg>Change from horizontal graphs to basic histograms<commit_after>import pygal
from pygal.style import Style
import base64
import logging

logger = logging.getLogger("Graphs")

def plot(data, title=None, graph_type='Pie', max_entries=None, other_label="Other", y_title=None, labels=False):
    custom_style = Style(
        background='transparent',
        font_family='sans-serif',
        plot_background='transparent',
        foreground='FFFFFF',
        foreground_light='black',
        foreground_dark='#FFFFFF',
        opacity='.9',
        opacity_hover='.5',
        transition='400ms ease-in',
        colors=('#5da5da', '#faa43a', '#60bd68', '#f17cb0', '#b2912f', '#b276b2', '#decf3f', '#f15854', '#4d4d4d'))
    data.sort(reverse=True, key=lambda x:x[1])
    if graph_type == 'Pie':
        chart = pygal.Pie(style=custom_style, inner_radius=.4)
    else:
        chart = pygal.Bar(style=custom_style, legend_at_bottom=True)
        if data:
            chart.y_labels = map(repr, range(data[len(data)-1][1] - 1, data[0][1] + 1))
            chart.value_formatter = lambda x: str(int(x))
    if title:
        chart.title = title
    data.sort(reverse=True, key=lambda x:x[1])
    if max_entries and (len(data) > max_entries):
        remaining_data = reduce(lambda x, y: ('',x[1]+y[1]), data[max_entries:])
        data = data[:max_entries]
        data.append((other_label,  remaining_data[1], 'Other'))
    for item in data:
        if labels:
            chart.add(item[0], [{'value': item[1], 'label': item[2]}])
        else:
            chart.add(item[0], [{'value': item[1], 'label': item[0]}])
    if y_title:
        chart.y_title = y_title
    return base64.b64encode(chart.render())
{'fraction_non_alphanumeric': 0.16372202591283863, 'fraction_numerical': 0.03386336866902238, 'mean_word_length': 3.137637028014616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4394816', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1158, 'n_words': 231}