예제 #1
0
 def simple(self):
     # Instantiate the GChart instance, this is all you will need for making charts
     # GChart(type=None, dataset=None), see the doc for more
     G = GChart()
     # Set the chart type, either Google API type or regular name
     G.type('pie')
     # Update the chart's dataset, can be two dimensional and contain string data
     G.dataset('helloworld')
     # Set the size of the chart, default is 300x150
     G.size(250, 100)
     return G
예제 #2
0
def gchart(context, nodelist, type, dataset, **kwargs):
    G = GChart(type, dataset, encoding=kwargs.pop('encoding', 'text'))
    for node in nodelist:
        if isinstance(node, TextNode):
            for part in node.render(context).splitlines():
                cmd, value = parse_cmd(part)
                if cmd is None: continue
                if cmd.startswith('axes'):
                    cmd = getattr(G.axes, cmd[5:])
                else:
                    cmd = getattr(G, cmd)
                cmd(*value.split())
    if 'instance' in kwargs:
        return G
    return G.img(**kwargs)
예제 #3
0
def tarp_subsidies(request):
    estimated_subsidies = []
    subsidy_rates = []
    amounts_received = []
    names = []
    colors = []
    for r in SubsidyRecord.objects.all():
        estimated_subsidies.append(r.estimated_subsidy)
        subsidy_rates.append(r.subsidy_rate)
        amounts_received.append(r.amount_received)
        names.append(r.name)
        colors.append(r.color)

    # reverse names (API wrapper bug?)
    names.reverse()

    # estimated subsidies chart
    estimates_subsidies_normalized = _normalize_chart_range(
        estimated_subsidies)
    estimated_subsidies_chart = GChart('bhs',
                                       estimates_subsidies_normalized.values())
    estimated_subsidies_chart.size((500, 250))
    estimated_subsidies_chart.color('|'.join(colors))
    estimated_subsidies_chart.bar(18, 2, 0)
    estimated_subsidies_chart.axes.type('xy')
    estimated_subsidies_chart_xlabels = range(
        0, (_get_scale_bound(estimated_subsidies) + 1), 5)
    estimated_subsidies_chart_xlabels = map((lambda x: str(x)),
                                            estimated_subsidies_chart_xlabels)
    estimated_subsidies_chart.axes.label(
        str('|'.join(estimated_subsidies_chart_xlabels)))
    estimated_subsidies_chart.axes.label('|'.join(names))
    estimated_subsidies_chart.axes.style('000000')
    estimated_subsidies_chart.axes.style('000000')
    i = 0
    for x in estimated_subsidies:
        marker_text = 't $%.1f' % x
        estimated_subsidies_chart.marker(marker_text, '000000', 0, i, 10, -1)
        i = i + 1

    # subsidy rates chart
    subsidy_rates_normalized = _normalize_chart_range(subsidy_rates)
    subsidy_rate_chart = GChart('bhs', subsidy_rates_normalized.values())
    subsidy_rate_chart.size((500, 250))
    subsidy_rate_chart.color('|'.join(colors))
    subsidy_rate_chart.bar(18, 2, 0)
    subsidy_rate_chart.axes.type('xy')
    subsidy_rate_chart_xlabels = range(0,
                                       (_get_scale_bound(subsidy_rates) + 1),
                                       10)
    subsidy_rate_chart_xlabels = map((lambda x: str(x)),
                                     subsidy_rate_chart_xlabels)
    subsidy_rate_chart.axes.label(str('|'.join(subsidy_rate_chart_xlabels)))
    subsidy_rate_chart.axes.label('|'.join(names))
    subsidy_rate_chart.axes.style('000000')
    subsidy_rate_chart.axes.style('000000')
    i = 0
    for x in subsidy_rates:
        marker_text = 't %d%%' % x
        subsidy_rate_chart.marker(marker_text, '000000', 0, i, 10, -1)
        i = i + 1

    # amounts received chart
    amounts_received_normalized = _normalize_chart_range(amounts_received)
    amounts_received_chart = GChart('bhs',
                                    amounts_received_normalized.values())
    amounts_received_chart.size((500, 250))
    amounts_received_chart.color('|'.join(colors))
    amounts_received_chart.bar(18, 2, 0)
    amounts_received_chart.axes.type('xy')
    amounts_received_chart_xlabels = range(
        0, (_get_scale_bound(amounts_received) + 1), 10)
    amounts_received_chart_xlabels = map((lambda x: str(x)),
                                         amounts_received_chart_xlabels)
    amounts_received_chart.axes.label(
        str('|'.join(amounts_received_chart_xlabels)))
    amounts_received_chart.axes.label('|'.join(names))
    amounts_received_chart.axes.style('000000')
    amounts_received_chart.axes.style('000000')
    i = 0
    for x in amounts_received:
        marker_text = 't $%.1f' % x
        amounts_received_chart.marker(marker_text, '000000', 0, i, 10, -1)
        i = i + 1

    return render_to_response(
        'bailout/tarp_subsidy_table.html', {
            'estimated_subsidies_chart': estimated_subsidies_chart.img(),
            'subsidy_rate_chart': subsidy_rate_chart.img(),
            'amounts_received_chart': amounts_received_chart.img(),
            'estimated_subsidies': estimated_subsidies,
            'subsidy_rates': subsidy_rates,
            'amounts_received': amounts_received,
            'names': ' '.join(names),
            'colors': '|'.join(colors)
        },
        context_instance=RequestContext(request))