# Path: pycha/color.py
# class ColorScheme(dict):
#     """A color scheme is a dictionary where the keys match the keys
#     constructor argument and the values are colors"""
# 
#     __metaclass__ = ColorSchemeMetaclass
#     __registry__ = {}
# 
#     def __init__(self, keys):
#         super(ColorScheme, self).__init__()
# 
#     @classmethod
#     def registerColorScheme(cls):
#         key = cls.__name__.replace('ColorScheme', '').lower()
#         if key:
#             cls.__registry__[key] = cls
# 
#     @classmethod
#     def getColorScheme(cls, name, default=None):
#         return cls.__registry__.get(name, default)
# 
# def hex2rgb(hexstring, digits=2):
#     """Converts a hexstring color to a rgb tuple.
# 
#     Example: #ff0000 -> (1.0, 0.0, 0.0)
# 
#     digits is an integer number telling how many characters should be
#     interpreted for each component in the hexstring.
#     """
#     if isinstance(hexstring, (tuple, list)):
#         return hexstring
# 
#     top = float(int(digits * 'f', 16))
#     r = int(hexstring[1:digits+1], 16)
#     g = int(hexstring[digits+1:digits*2+1], 16)
#     b = int(hexstring[digits*2+1:digits*3+1], 16)
#     return r / top, g / top, b / top
# 
# DEFAULT_COLOR = '#3c581a'
# 
# Path: pycha/utils.py
# def safe_unicode(obj, encoding=None):
#     """Return a unicode value from the argument"""
#     if isinstance(obj, unicode):
#         return obj
#     elif isinstance(obj, str):
#         if encoding is None:
#             return unicode(obj)
#         else:
#             return unicode(obj, encoding)
#     else:
#         # it may be an int or a float
#         return unicode(obj)


import copy
import inspect
import math
import cairo
from pycha.color import ColorScheme, hex2rgb, DEFAULT_COLOR
from pycha.utils import safe_unicode
                yval = self.minyval + (i * roughSeparation)
                pos = 1.0 - ((yval - self.minyval) * self.yscale)
                if 0.0 <= pos <= 1.0:
                    pretty_label = round(yval, prec)
                    if prec == 0:
                        pretty_label = int(pretty_label)
                    self.yticks.append((pos, pretty_label))

    def _renderBackground(self, cx):
        """Renders the background area of the chart"""
        if self.options.background.hide:
            return

        cx.save()

        if self.options.background.baseColor:
            cx.set_source_rgb(*hex2rgb(self.options.background.baseColor))
            cx.paint()

        if self.options.background.chartColor:
            cx.set_source_rgb(*hex2rgb(self.options.background.chartColor))
            surface_width, surface_height = self.getSurfaceSize()
            cx.rectangle(self.options.padding.left, self.options.padding.top,
                         surface_width - (self.options.padding.left
                                          + self.options.padding.right),
                         surface_height - (self.options.padding.top
                                           + self.options.padding.bottom))
            cx.fill()

        if self.options.background.lineColor:

# Path: pycha/color.py
# class ColorScheme(dict):
#     """A color scheme is a dictionary where the keys match the keys
#     constructor argument and the values are colors"""
# 
#     __metaclass__ = ColorSchemeMetaclass
#     __registry__ = {}
# 
#     def __init__(self, keys):
#         super(ColorScheme, self).__init__()
# 
#     @classmethod
#     def registerColorScheme(cls):
#         key = cls.__name__.replace('ColorScheme', '').lower()
#         if key:
#             cls.__registry__[key] = cls
# 
#     @classmethod
#     def getColorScheme(cls, name, default=None):
#         return cls.__registry__.get(name, default)
# 
# def hex2rgb(hexstring, digits=2):
#     """Converts a hexstring color to a rgb tuple.
# 
#     Example: #ff0000 -> (1.0, 0.0, 0.0)
# 
#     digits is an integer number telling how many characters should be
#     interpreted for each component in the hexstring.
#     """
#     if isinstance(hexstring, (tuple, list)):
#         return hexstring
# 
#     top = float(int(digits * 'f', 16))
#     r = int(hexstring[1:digits+1], 16)
#     g = int(hexstring[digits+1:digits*2+1], 16)
#     b = int(hexstring[digits*2+1:digits*3+1], 16)
#     return r / top, g / top, b / top
# 
# DEFAULT_COLOR = '#3c581a'
# 
# Path: pycha/utils.py
# def safe_unicode(obj, encoding=None):
#     """Return a unicode value from the argument"""
#     if isinstance(obj, unicode):
#         return obj
#     elif isinstance(obj, str):
#         if encoding is None:
#             return unicode(obj)
#         else:
#             return unicode(obj, encoding)
#     else:
#         # it may be an int or a float
#         return unicode(obj)


# Path: pycha/chart.py
import copy
import inspect
import math
import cairo
from pycha.color import ColorScheme, hex2rgb, DEFAULT_COLOR
from pycha.utils import safe_unicode

                yval = self.minyval + (i * roughSeparation)
                pos = 1.0 - ((yval - self.minyval) * self.yscale)
                if 0.0 <= pos <= 1.0:
                    pretty_label = round(yval, prec)
                    if prec == 0:
                        pretty_label = int(pretty_label)
                    self.yticks.append((pos, pretty_label))

    def _renderBackground(self, cx):
        """Renders the background area of the chart"""
        if self.options.background.hide:
            return

        cx.save()

        if self.options.background.baseColor:
            cx.set_source_rgb(*hex2rgb(self.options.background.baseColor))
            cx.paint()

        if self.options.background.chartColor:
            cx.set_source_rgb(*hex2rgb(self.options.background.chartColor))
            surface_width, surface_height = self.getSurfaceSize()
            cx.rectangle(self.options.padding.left, self.options.padding.top,
                         surface_width - (self.options.padding.left
                                          + self.options.padding.right),
                         surface_height - (self.options.padding.top
                                           + self.options.padding.bottom))
            cx.fill()

        if self.options.background.lineColor:

            cx.set_source_rgb(*hex2rgb(self.options.background.lineColor))