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
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()
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()
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()
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()
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
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"
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"