import simplejson
from django.utils.html import escape


def render_highcharts_options(render_to, categories, series, title, x_axis_title, y_axis_title, series_name):
    """Accepts the parameters to render a chart and returns a JSON serialized Highcharts options object."""

    # Escape all the character strings to make them HTML safe.
    render_to = escape(render_to.encode('ascii', 'ignore')) if render_to else 'render_to'
    title = escape(title.encode('ascii', 'ignore')) if title else 'title'
    x_axis_title = escape(x_axis_title.encode('ascii', 'ignore')) if x_axis_title else 'x axis'
    y_axis_title = escape(y_axis_title.encode('ascii', 'ignore')) if y_axis_title else 'y axis'
    # Categories (dimensions) come from the use. Escape them too.
    categories = [escape(c.encode('ascii', 'ignore')) for c in categories]

    hco = {
        "chart": {
            "renderTo": render_to,
            "type": 'column'
        },
        "title": {
            "text": title
        },
        "xAxis": {
            "title": {
                "text": x_axis_title
            },
            "categories": categories
        },
        "yAxis": {
            "title": {
                "text": y_axis_title,
            }
        },
        "series": [{
            "name": series_name,
            "data": series,
        }]
    }

    return simplejson.dumps(hco, use_decimal=True)

@@ -365,18 +365,18 @@
 nder_to.
+d
 e
-n
 code('as
@@ -443,26 +443,26 @@
 scape(title.
+d
 e
-n
 code('ascii'
@@ -527,34 +527,34 @@
 pe(x_axis_title.
+d
 e
-n
 code('ascii', 'i
@@ -631,18 +631,18 @@
 s_title.
+d
 e
-n
 code('as
@@ -781,18 +781,18 @@
 scape(c.
+d
 e
-n
 code('as

Fix unicode decode errors