<commit_before>import cairo

from . import base
from .. import manager

__all__ = [
    'CPUGraph',
    'MemoryGraph',
    'SwapGraph',
    'NetGraph'
]

class _Graph(base._Widget):
    fixed_upper_bound = False
    defaults = manager.Defaults(
        ("graph_color", "18BAEB", "Graph color"),
        ("fill_color", "1667EB.3", "Fill color for linefill graph"),
        ("background", "000000", "Widget background"),
        ("border_color", "215578", "Widget border color"),
        ("border_width", 2, "Widget background"),
        ("margin_x", 3, "Margin X"),
        ("margin_y", 3, "Margin Y"),
        ("samples", 100, "Count of graph samples."),
        ("frequency", 1, "Update frequency in seconds"),
        ("type", "linefill", "'box', 'line', 'linefill'"),
        ("line_width", 3, "Line width"),
        ("start_pos", "bottom", "Drawer starting position ('bottom'/'top')")
    )

    def __init__(self, width = 100, **config):
        base._Widget.__init__(self, width, **config)
        self.values = [0]*self.samples
        self.maxvalue = 0

    @property
    def graphwidth(self):
        return self.width - self.border_width*2 - self.margin_x*2

    @property
    def graphheight(self):
        return self.bar.height - self.margin_y*2 - self.border_width*2

    def draw_box(self, x, y, values):
        step = self.graphwidth/float(self.samples)
        for val in values:
            val = self.val(val)
            self.drawer.fillrect(x, y-val, step, val, self.graph_color)
            x += step 

    def draw_line(self, x, y, values):
        step = self.graphwidth/float(self.samples-1)
        self.drawer.ctx.set_line_join(cairo.LINE_JOIN_ROUND)
        self.drawer.set_source_rgb(self.graph_color)
        self.drawer.ctx.set_line_width(self.line_width)
        for val in values:
            self.drawer.ctx.line_to(x, y-self.val(val))
            x += step 
        self.drawer.ctx.stroke()

    def draw_linefill(self, x, y, values):
        step = self.graphwidth/float(self.samples-1)
        self.drawer.ctx.set_line_join(cairo.LINE_JOIN_ROUND)
        self.drawer.set_source_rgb(self.graph_color)
        self.drawer.ctx.set_line_width(self.line_width)
        current = x
        for val in values:
            self.drawer.ctx.line_to(current, y-self.val(val))
            current += step 
        self.drawer.ctx.stroke_preserve()
        self.drawer.ctx.line_to(current, y - 1 + self.line_width/2.0)
        self.drawer.ctx.line_to(x, y + self.line_width/2.0)
        self.drawer.set_source_rgb(self.fill_color)
        self.drawer.ctx.fill()

    def val(self, val):
        if self.start_pos == 'bottom':
            return val
        elif self.start_pos == 'top':
            return -val
        else:
            raise ValueError("Unknown starting position: %s."%self.start_pos)

    def draw(self):
        self.drawer.clear(self.background)
        if self.border_width:
            self.drawer.set_source_rgb(self.border_color)
            self.drawer.ctx.set_line_width(self.border_width)
            self.drawer.ctx.rectangle(
                self.margin_x + self.border_width/2.0, self.margin_y + self.border_width/2.0,
                self.graphwidth + self.border_width,
                self.bar.height - self.margin_y*2 - self.border_width,
            )
            self.drawer.ctx.stroke()
        x = self.margin_x + self.border_width
        y = self.margin_y + self.border_width
        if self.start_pos == 'bottom':
            y += self.graphheight
        elif not self.start_pos == 'top':<commit_msg>fixed 1pixel glitch while on top<commit_after>import cairo

from . import base
from .. import manager

__all__ = [
    'CPUGraph',
    'MemoryGraph',
    'SwapGraph',
    'NetGraph'
]

class _Graph(base._Widget):
    fixed_upper_bound = False
    defaults = manager.Defaults(
        ("graph_color", "18BAEB", "Graph color"),
        ("fill_color", "1667EB.3", "Fill color for linefill graph"),
        ("background", "000000", "Widget background"),
        ("border_color", "215578", "Widget border color"),
        ("border_width", 2, "Widget background"),
        ("margin_x", 3, "Margin X"),
        ("margin_y", 3, "Margin Y"),
        ("samples", 100, "Count of graph samples."),
        ("frequency", 1, "Update frequency in seconds"),
        ("type", "linefill", "'box', 'line', 'linefill'"),
        ("line_width", 3, "Line width"),
        ("start_pos", "bottom", "Drawer starting position ('bottom'/'top')")
    )

    def __init__(self, width = 100, **config):
        base._Widget.__init__(self, width, **config)
        self.values = [0]*self.samples
        self.maxvalue = 0

    @property
    def graphwidth(self):
        return self.width - self.border_width*2 - self.margin_x*2

    @property
    def graphheight(self):
        return self.bar.height - self.margin_y*2 - self.border_width*2

    def draw_box(self, x, y, values):
        step = self.graphwidth/float(self.samples)
        for val in values:
            val = self.val(val)
            self.drawer.fillrect(x, y-val, step, val, self.graph_color)
            x += step 

    def draw_line(self, x, y, values):
        step = self.graphwidth/float(self.samples-1)
        self.drawer.ctx.set_line_join(cairo.LINE_JOIN_ROUND)
        self.drawer.set_source_rgb(self.graph_color)
        self.drawer.ctx.set_line_width(self.line_width)
        for val in values:
            self.drawer.ctx.line_to(x, y-self.val(val))
            x += step 
        self.drawer.ctx.stroke()

    def draw_linefill(self, x, y, values):
        step = self.graphwidth/float(self.samples-1)
        self.drawer.ctx.set_line_join(cairo.LINE_JOIN_ROUND)
        self.drawer.set_source_rgb(self.graph_color)
        self.drawer.ctx.set_line_width(self.line_width)
        current = x
        for val in values:
            self.drawer.ctx.line_to(current, y-self.val(val))
            current += step 
        self.drawer.ctx.stroke_preserve()
        self.drawer.ctx.line_to(current, y - 1 + self.line_width/2.0)
        self.drawer.ctx.line_to(x, y - 1 + self.line_width/2.0)
        self.drawer.set_source_rgb(self.fill_color)
        self.drawer.ctx.fill()

    def val(self, val):
        if self.start_pos == 'bottom':
            return val
        elif self.start_pos == 'top':
            return -val
        else:
            raise ValueError("Unknown starting position: %s."%self.start_pos)

    def draw(self):
        self.drawer.clear(self.background)
        if self.border_width:
            self.drawer.set_source_rgb(self.border_color)
            self.drawer.ctx.set_line_width(self.border_width)
            self.drawer.ctx.rectangle(
                self.margin_x + self.border_width/2.0, self.margin_y + self.border_width/2.0,
                self.graphwidth + self.border_width,
                self.bar.height - self.margin_y*2 - self.border_width,
            )
            self.drawer.ctx.stroke()
        x = self.margin_x + self.border_width
        y = self.margin_y + self.border_width
        if self.start_pos == 'bottom':
            y += self.graphheight
        elif not self.start_pos == 'top':
{'fraction_non_alphanumeric': 0.13256041346556782, 'fraction_numerical': 0.013689062718256739, 'mean_word_length': 2.273891175125743, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3592199', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2305, 'n_words': 455}