Ejemplo n.º 1
0
def _pie_graph(env, factor, query=None, title=None):
    """
    Create a pie graph of the number of tickets as a function of the factor.
    factor is a name of a field by which the tickets are counted.
    query can be None or any Trac query by which the data will be collected.
    """
    ticket_stats = _get_pie_graph_stats(env, factor, query)

    pie_values = []
    for factor_value, number_of_tickets in ticket_stats.iteritems():
        pie_values.append(pie_value(number_of_tickets, label=(factor_value, None, "13")))

    plot = Pie(start_angle=35, animate=True, values=pie_values, colours=COLOURS, label_colour="#432BAF")
    plot.set_tooltip("#label# - #val# tickets (#percent#)")

    chart_div_id = _create_chart_div_id()
    on_click_function_name = "on_click_%s" % (chart_div_id,)
    plot.set_on_click(on_click_function_name)

    if not title:
        title = "Tickets per %s" % (factor,)

    chart = _create_chart(title, plot)

    on_click_html = _create_pie_graph_on_click_html(env, ticket_stats, factor, query, on_click_function_name)

    return chart, chart_div_id, on_click_html
Ejemplo n.º 2
0
	def pie(self):
		plot = Pie(start_angle = 35, animate = True, values = [2, 3, pie_value(6.5, ('hello (6.5)', '#FF33C9', 24))], colours = ['#D01F3C', '#356AA0', '#C79810'], label_colour = '#432BAF')
		plot.set_tooltip('#val# of #total#<br>#percent# of 100%')
		plot.set_gradient_fill(True)
		plot.set_on_click('plot1')
		plot.set_no_labels(False)
		
		chart = openFlashChart.template("Pie chart")
		chart.add_element(plot)
		
		return chart.encode()
Ejemplo n.º 3
0
    def pie(self):
        plot = Pie(
            start_angle=35,
            animate=True,
            values=[2, 3, pie_value(6.5, ('hello (6.5)', '#FF33C9', 24))],
            colours=['#D01F3C', '#356AA0', '#C79810'],
            label_colour='#432BAF')
        plot.set_tooltip('#val# of #total#<br>#percent# of 100%')
        plot.set_gradient_fill(True)
        plot.set_on_click('plot1')
        plot.set_no_labels(False)

        chart = openFlashChart.template("Pie chart")
        chart.add_element(plot)

        return chart.encode()
Ejemplo n.º 4
0
def get_chart(request,style,date_start,date_end):
    raw_data = get_chart_vars(request,date_start,date_end)
    var1 = []
    var2 = []
    dates = []
    if raw_data['variable1'] != None:
        var_legend = raw_data['variable1_name']
        for items in raw_data['variable1']:
            var1.append(int(items[1]))
            dates.append(str(items[0]))
    if raw_data['variable2'] != None:
        var_legend = raw_data['variable2_name']
        for items in raw_data['variable2']:
            var2.append(int(items[1]))	
    chart = openFlashChart.template('')
    chart.set_bg_colour(colour='#ffffff')
    if len(var1) > 0:
        range_y1_min = round(min(var1)*0.95,0)
        range_y1_max = round(max(var1)*1.05,0)
        range_y1_steps = round(round(max(var1)*1.05,0)/10,0)
    else:
        range_y1_min = 0
        range_y1_max = 0
        range_y1_steps = 0
    if len(var2) > 0:
        range_y2_min = round(min(var2)*0.95,0)
        range_y2_max = round(max(var2)*1.05,0)
        range_y2_steps = round(round(max(var2)*1.05,0)/10,0)
    else:
        range_y2_min = 0
        range_y2_max = 0
        range_y2_steps = 0
    chart.set_y_axis(min = range_y1_min, max = range_y1_max, steps = range_y1_steps)
    chart.set_x_axis(labels = {'labels':dates, 'rotate':'vertical'})
    if style == 'lines':
        plot1 = Line(text = raw_data['variable1_name'], fontsize = 20, values = var1)
        plot2 = Line(text = raw_data['variable2_name'], fontsize = 20, values = var2)
        plot2['axis'] = "right"
        plot2.set_colour('#54b928')
        chart.set_y_axis_right(min = range_y2_min, max = range_y2_max, steps = range_y2_steps)
        if request.GET.get('onevar',None) == None:
            chart.add_element(plot2)
    elif style == 'pie':
        plot1 = Pie(text = raw_data['variable1_name'], fontsize = 20, values = var1, colours = ['#4f8dbc','#54b928'])
    elif style == 'columns':
        plot1 = Bar_Filled(text = raw_data['variable1_name'], fontsize = 20, values = var1)
        plot2 = Bar_Filled(text = raw_data['variable2_name'], fontsize = 20, values = var2)
        plot2['axis'] = "right"
        plot2.set_colour('#54b928')		
        chart.set_y_axis_right(min = range_y2_min, max = range_y2_max, steps = range_y2_steps)
        if request.GET.get('onevar',None) == None:
            chart.add_element(plot2)
    plot1.set_colour('#4f8dbc')
    chart.add_element(plot1)
    return HttpResponse(chart.encode())
Ejemplo n.º 5
0
def _pie_graph(env, factor, query=None, title=None):
    """
    Create a pie graph of the number of tickets as a function of the factor.
    factor is a name of a field by which the tickets are counted.
    query can be None or any Trac query by which the data will be collected.
    """
    ticket_stats = _get_pie_graph_stats(env, factor, query)

    pie_values = []
    for factor_value, number_of_tickets in ticket_stats.iteritems():
        pie_values.append(
            pie_value(
                number_of_tickets,
                label=(factor_value, None, '13'),
            ))

    plot = Pie(start_angle=35,
               animate=True,
               values=pie_values,
               colours=COLOURS,
               label_colour='#432BAF')
    plot.set_tooltip('#label# - #val# tickets (#percent#)')

    chart_div_id = _create_chart_div_id()
    on_click_function_name = 'on_click_%s' % (chart_div_id, )
    plot.set_on_click(on_click_function_name)

    if not title:
        title = "Tickets per %s" % (factor, )

    chart = _create_chart(title, plot)

    on_click_html = _create_pie_graph_on_click_html(env, ticket_stats, factor,
                                                    query,
                                                    on_click_function_name)

    return chart, chart_div_id, on_click_html
Ejemplo n.º 6
0
def getjsondata(context, records=10, type=None):
    site_encoding = context.plone_utils.getSiteEncoding()
    strpath = "/".join(context.getPhysicalPath())
    portal = context.portal_url.getPortalObject()

    try:
        from ubify.policy.config import contentroot_details
        rootid = contentroot_details['id']
        objRoot = getattr(portal, rootid)
        if context == objRoot:
            strpath = "/".join(portal.getPhysicalPath())
        else:
            strpath = "/".join(context.getPhysicalPath())
    except AttributeError:
        strpath = "/".join(context.getPhysicalPath())

    if type is None:
        raise "No chart type was passed"
    elif type.lower() == "topcontributors":
        chart = template('')
        plot = HBar()
        results = getTopContributors(context, strpath)[:records]
        results.sort(lambda x, y: cmp(x['count'], y['count']), reverse=True)
        objvalues = [k['count'] for k in results if k['count'] > 0]

        users = [j['userid'] for j in results if j['count'] > 0]
        users.reverse()

        xlabels = x_axis_labels()
        xlabels.set_colour("#666666")
        chartsteps = 1.0
        if len(objvalues) > 0:
            chartsteps = getchartsteps(objvalues[-1], objvalues[0])
        chart.set_x_axis(offset=False,
                         labels=xlabels,
                         steps=chartsteps,
                         colour="#cccccc",
                         grid_colour="#f1f1f1")
        chart.set_y_axis(offset=True,
                         labels=users,
                         colour="#666666",
                         grid_colour="#f1f1f1")

        for val in objvalues:
            plot.append_values(
                hbar_value((0, val),
                           tooltip='#right# contributions',
                           colour='#4092D8'))
        chart.add_element(plot)
        chart.set_tooltip(
            stroke=1,
            colour="#1f1f1f",
            bg_colour="#292929",
            title_style="font-size:12px;color:#ffffff;font-weight:bold",
            body_style="font-size:12px;color:#ffffff",
            behaviour="hover")

        chart.set_bg_colour("#FFFFFF")
        return chart.encode()

    elif type.lower() == "topcommenters":
        chart = template('')
        plot = HBar()
        results = getTopCommenter(context, strpath)[:records]
        results.sort(lambda x, y: cmp(x['count'], y['count']), reverse=True)
        objvalues = [k['count'] for k in results if k['count'] > 0]

        users = [j['userid'] for j in results if j['count'] > 0]
        users.reverse()

        xlabels = x_axis_labels()
        xlabels.set_colour("#666666")
        chartsteps = 1.0
        if len(objvalues) > 0:
            chartsteps = getchartsteps(objvalues[-1], objvalues[0])
        chart.set_x_axis(offset=False,
                         labels=xlabels,
                         steps=chartsteps,
                         colour="#cccccc",
                         grid_colour="#f1f1f1")
        chart.set_y_axis(offset=True,
                         labels=users,
                         colour="#666666",
                         grid_colour="#f1f1f1")

        for val in objvalues:
            plot.append_values(
                hbar_value((0, val),
                           tooltip='#right# comments',
                           colour='#57AC0B'))
        chart.add_element(plot)
        chart.set_tooltip(
            stroke=1,
            colour="#1f1f1f",
            bg_colour="#292929",
            title_style="font-size:12px;color:#ffffff;font-weight:bold",
            body_style="font-size:12px;color:#ffffff",
            behaviour="hover")

        chart.set_bg_colour("#FFFFFF")
        return chart.encode()

    elif type.lower() == "contentstats":
        #For pie chart
        results = [
            k for k in getContentItemsCount(context, strpath) if k['count'] > 0
        ]
        results.sort(lambda x, y: cmp(x['count'], y['count']), reverse=True)

        chart = template('')
        plot = Pie(start_angle=35,
                   animate=True,
                   values=[
                       pie_value(val=k['count'], label=(k['id'], None, None))
                       for k in results
                   ],
                   colours=[
                       '#4092D8',
                       '#57AC0B',
                       '#CC0000',
                       '#862DFF',
                       '#FF6600',
                       '#00FFF6',
                       '#FF37D2',
                       '#5251ff',
                       '#F0EA80',
                       '#abff00',
                   ],
                   label_colour='#666666')
        plot.set_tooltip('#label#: #val# of #total#<br>#percent# of 100%')
        plot.set_gradient_fill(True)
        plot.set_no_labels(False)

        chart.add_element(plot)
        chart.set_tooltip(
            stroke=1,
            colour="#1f1f1f",
            bg_colour="#292929",
            title_style="font-size:12px;color:#ffffff;font-weight:bold",
            body_style="font-size:12px;color:#ffffff",
            behaviour="hover")
        chart.set_bg_colour("#FFFFFF")
        return chart.encode()

    else:
        raise "Unknown chart type was passed"
Ejemplo n.º 7
0
	def pie(self,search_result,title):
		plot = Pie(start_angle = 35, animate = True,  label_colour = '#432BAF')
		values = []
		colours = []
		count = 0
		for row in search_result:
			count+=1
			values.append(pie_value(int(row[1]),(row[0],None,None)))
			colours.append(colorArr[count/len(colorArr)])
		if not search_result:
			values.append(pie_value(1,("None",None,None)))
			colours.append(colorArr[count/len(colorArr)])
		plot.set_values(values=values)
		plot.colours = colours
		plot.set_tooltip('#val# of #total#<br>#percent# of 100%')
		plot.set_gradient_fill(True)
		plot.set_on_click('plot1')
		plot.set_no_labels(False)

		chart = openFlashChart.template(u''+title+'')
		chart.add_element(plot)

		return chart.encode()
Ejemplo n.º 8
0
    def pie(self, search_result, title):
        plot = Pie(start_angle=35, animate=True, label_colour='#432BAF')
        values = []
        colours = []
        count = 0
        for row in search_result:
            count += 1
            values.append(pie_value(int(row[1]), (row[0], None, None)))
            colours.append(colorArr[count / len(colorArr)])
        if not search_result:
            values.append(pie_value(1, ("None", None, None)))
            colours.append(colorArr[count / len(colorArr)])
        plot.set_values(values=values)
        plot.colours = colours
        plot.set_tooltip('#val# of #total#<br>#percent# of 100%')
        plot.set_gradient_fill(True)
        plot.set_on_click('plot1')
        plot.set_no_labels(False)

        chart = openFlashChart.template(u'' + title + '')
        chart.add_element(plot)

        return chart.encode()