# -*- coding: utf-8 -*-

""" Charts are normal CoordinateSystemElements """

import math as mod_math
import collections as mod_collections
import types as mod_types

from . import main as mod_main
from . import colors as mod_colors

# Default color palete from: http://www.colourlovers.com/pattern/2429885/Spring_flower_aerial
DEFAULT_COLORS = (
        (141, 198, 183),
        (207, 249, 117),
        (230, 193, 238),
        (242, 229, 229),
)

ChartData = mod_collections.namedtuple(
        'ChartData',
        ('key', 'value', 'size', 'label', 'label_position', 'color', 'fill_color'))

def get_generator(data):
    """
    In case of a big dataset, no need to load the entire list in memory, it can be given to
    cartesius as a generator function.

    In case data is callable and the result is a generator, then data is returned, oherwisea the
    result is a function that returns a generator through data.
    """
    if callable(data):
        if isinstance(data(), mod_types.GeneratorType):
            return data

    if not data:
        raise Exception('Invalid or empty data: {0}'.format(data))

    def generator():