# Path: graphos/utils.py
# DEFAULT_HEIGHT = 400
# 
# DEFAULT_WIDTH = 800
# 
# def get_random_string():
#     random_letter = lambda: random.choice(string.ascii_letters)
#     random_string = "".join([random_letter()
#                              for el in range(10)])
#     return random_string
# 
# class JSONEncoderForHTML(json.JSONEncoder):
#     """An encoder that produces JSON safe to embed in HTML.
#     To embed JSON content in, say, a script tag on a web page, the
#     characters &, < and > should be escaped. They cannot be escaped
#     with the usual entities (e.g. &amp;) because they are not expanded
#     within <script> tags.
#     """
#     def default(self, obj):
#         # Taken from https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/utils/encoders.py
#         # For Date Time string spec, see ECMA 262
#         # http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.15
#         if isinstance(obj, Promise):
#             return force_text(obj)
#         elif isinstance(obj, datetime.datetime):
#             representation = obj.isoformat()
#             if representation.endswith('+00:00'):
#                 representation = representation[:-6] + 'Z'
#             return representation
#         elif isinstance(obj, datetime.date):
#             return obj.isoformat()
#         elif isinstance(obj, datetime.time):
#             if timezone and timezone.is_aware(obj):
#                 raise ValueError("JSON can't represent timezone-aware times.")
#             representation = obj.isoformat()
#             if obj.microsecond:
#                 representation = representation[:12]
#             return representation
#         elif isinstance(obj, decimal.Decimal):
#             # Serializers will coerce decimals to strings by default.
#             return float(obj)
#         elif isinstance(obj, uuid.UUID):
#             return six.text_type(obj)
#         elif isinstance(obj, QuerySet):
#             return tuple(obj)
#         elif isinstance(obj, six.binary_type):
#             # Best-effort for binary blobs. See #4187.
#             return obj.decode('utf-8')
#         elif hasattr(obj, 'tolist'):
#             # Numpy arrays and array scalars.
#             return obj.tolist()
#         elif hasattr(obj, '__getitem__'):
#             try:
#                 return dict(obj)
#             except:
#                 pass
#         elif hasattr(obj, '__iter__'):
#             return tuple(item for item in obj)
#         return super(JSONEncoderForHTML, self).default(obj)
# 
# 
#     def encode(self, o):
#         # Override JSONEncoder.encode because it has hacks for
#         # performance that make things more complicated.
#         chunks = self.iterencode(o, True)
#         if self.ensure_ascii:
#             return ''.join(chunks)
#         else:
#             return u''.join(chunks)
# 
#     def iterencode(self, o, _one_shot=False):
#         try:
#             chunks = super(JSONEncoderForHTML, self).iterencode(o, _one_shot)
#         except TypeError:
#             # for python 2.6 compatibility
#             chunks = super(JSONEncoderForHTML, self).iterencode(o)
#         for chunk in chunks:
#             chunk = chunk.replace('&', '&amp;')
#             chunk = chunk.replace('<', '&lt;')
#             chunk = chunk.replace('>', '&gt;')
#             yield chunk
# 
# Path: graphos/encoders.py
# class GraphosEncoder(DjangoJSONEncoder):
#     pass


import json
import sys
from django.template.loader import render_to_string
from ..exceptions import GraphosException
from ..utils import DEFAULT_HEIGHT, DEFAULT_WIDTH, get_random_string, JSONEncoderForHTML
from ..encoders import GraphosEncoder



class BaseChart(object):

    def __init__(self, data_source, html_id=None,
                 width=None, height=None,
                 options=None, encoder=GraphosEncoder,
                 *args, **kwargs):
        """
        : param data_source: :type graphos.sources.base.BaseDataSource subclass instance.
        : param html_id: :type string: Id of the div where you would like chart to be rendered
        : param width: :type integer: Width of the chart div
        : param height: :type integer: Height of the chart div
        """
        self.data_source = data_source

# Path: graphos/utils.py
# DEFAULT_HEIGHT = 400
# 
# DEFAULT_WIDTH = 800
# 
# def get_random_string():
#     random_letter = lambda: random.choice(string.ascii_letters)
#     random_string = "".join([random_letter()
#                              for el in range(10)])
#     return random_string
# 
# class JSONEncoderForHTML(json.JSONEncoder):
#     """An encoder that produces JSON safe to embed in HTML.
#     To embed JSON content in, say, a script tag on a web page, the
#     characters &, < and > should be escaped. They cannot be escaped
#     with the usual entities (e.g. &amp;) because they are not expanded
#     within <script> tags.
#     """
#     def default(self, obj):
#         # Taken from https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/utils/encoders.py
#         # For Date Time string spec, see ECMA 262
#         # http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.15
#         if isinstance(obj, Promise):
#             return force_text(obj)
#         elif isinstance(obj, datetime.datetime):
#             representation = obj.isoformat()
#             if representation.endswith('+00:00'):
#                 representation = representation[:-6] + 'Z'
#             return representation
#         elif isinstance(obj, datetime.date):
#             return obj.isoformat()
#         elif isinstance(obj, datetime.time):
#             if timezone and timezone.is_aware(obj):
#                 raise ValueError("JSON can't represent timezone-aware times.")
#             representation = obj.isoformat()
#             if obj.microsecond:
#                 representation = representation[:12]
#             return representation
#         elif isinstance(obj, decimal.Decimal):
#             # Serializers will coerce decimals to strings by default.
#             return float(obj)
#         elif isinstance(obj, uuid.UUID):
#             return six.text_type(obj)
#         elif isinstance(obj, QuerySet):
#             return tuple(obj)
#         elif isinstance(obj, six.binary_type):
#             # Best-effort for binary blobs. See #4187.
#             return obj.decode('utf-8')
#         elif hasattr(obj, 'tolist'):
#             # Numpy arrays and array scalars.
#             return obj.tolist()
#         elif hasattr(obj, '__getitem__'):
#             try:
#                 return dict(obj)
#             except:
#                 pass
#         elif hasattr(obj, '__iter__'):
#             return tuple(item for item in obj)
#         return super(JSONEncoderForHTML, self).default(obj)
# 
# 
#     def encode(self, o):
#         # Override JSONEncoder.encode because it has hacks for
#         # performance that make things more complicated.
#         chunks = self.iterencode(o, True)
#         if self.ensure_ascii:
#             return ''.join(chunks)
#         else:
#             return u''.join(chunks)
# 
#     def iterencode(self, o, _one_shot=False):
#         try:
#             chunks = super(JSONEncoderForHTML, self).iterencode(o, _one_shot)
#         except TypeError:
#             # for python 2.6 compatibility
#             chunks = super(JSONEncoderForHTML, self).iterencode(o)
#         for chunk in chunks:
#             chunk = chunk.replace('&', '&amp;')
#             chunk = chunk.replace('<', '&lt;')
#             chunk = chunk.replace('>', '&gt;')
#             yield chunk
# 
# Path: graphos/encoders.py
# class GraphosEncoder(DjangoJSONEncoder):
#     pass


# Path: graphos/renderers/base.py
import json
import sys
from django.template.loader import render_to_string
from ..exceptions import GraphosException
from ..utils import DEFAULT_HEIGHT, DEFAULT_WIDTH, get_random_string, JSONEncoderForHTML
from ..encoders import GraphosEncoder




class BaseChart(object):

    def __init__(self, data_source, html_id=None,
                 width=None, height=None,
                 options=None, encoder=GraphosEncoder,
                 *args, **kwargs):
        """
        : param data_source: :type graphos.sources.base.BaseDataSource subclass instance.
        : param html_id: :type string: Id of the div where you would like chart to be rendered
        : param width: :type integer: Width of the chart div
        : param height: :type integer: Height of the chart div
        """
        self.data_source = data_source

        self.html_id = html_id or get_random_string()