'Custom method to create a Style for a Theme Layer
- splits data into 5 quintiles
- uses Colorbrewer to create a 5-class colorblind-safe printer-friendly Sequential scheme
@ToDo: Divergent colour scheme option
@ToDo: Select # of classes
@ToDo: Select full range of colour schemes
@ToDo: Alternate class breaks mechanisms (pretty breaks, etc)'

@staticmethod
def gis_theme_style(r, **attr):

    classes = 5
    nature = 'sequential'
    db = current.db
    table = db.gis_theme_data
    rows = db((table.layer_theme_id == r.id)).select(table.value)
    values = [float(row.value) for row in rows]
    q = []
    qappend = q.append
    for i in range((classes - 1)):
        qappend(((1.0 / classes) * (i + 1)))
    breaks = current.s3db.stats_quantile(values, q)
    breaks = list(breaks)
    values_min = min(values)
    values_max = max(values)
    breaks.insert(0, values_min)
    breaks.append(values_max)
    if (nature == 'sequential'):
        colours = ['F1EEF6', 'D7B5D8', 'DF65B0', 'DD1C77', '980043']
    elif (nature == 'divergent'):
        colours = ['A6611A', 'DFC27D', 'F5F5F5', '80CDC1', '018571']
    style = []
    sappend = style.append
    for i in range(classes):
        sappend({'low': breaks[i], 'high': breaks[(i + 1)], 'fill': colours[i]})
    current.response.headers['Content-Type'] = 'application/json'
    return json.dumps(style)
