Exemple #1
0
	def hbar(self):
		months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
	
		plot = HBar(colour = '#86BBEF')
		plot.set_tooltip('Months: #val#')
		plot.append_values(hbar_value((0, 4), colour = '#909090'))
		plot.append_values(hbar_value((4, 8), colour = '#909009'))
		plot.append_values(hbar_value((8, 11), tooltip = '#left# to #right#<br>%s to %s (#val# months)' %(months[8], months[11])))
		
		chart = openFlashChart.template("HBar chart")
		chart.set_x_axis(offset = False, labels = x_axis_labels(labels = months))
		chart.set_y_axis(offset = True, labels = ['one', 'two', 'three'])
		chart.add_element(plot)
		
		return chart.encode()
Exemple #2
0
    def hbar(self):
        months = [
            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
            'Oct', 'Nov', 'Dec'
        ]

        plot = HBar(colour='#86BBEF')
        plot.set_tooltip('Months: #val#')
        plot.append_values(hbar_value((0, 4), colour='#909090'))
        plot.append_values(hbar_value((4, 8), colour='#909009'))
        plot.append_values(
            hbar_value((8, 11),
                       tooltip='#left# to #right#<br>%s to %s (#val# months)' %
                       (months[8], months[11])))

        chart = openFlashChart.template("HBar chart")
        chart.set_x_axis(offset=False, labels=x_axis_labels(labels=months))
        chart.set_y_axis(offset=True, labels=['one', 'two', 'three'])
        chart.add_element(plot)

        return chart.encode()
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"
Exemple #4
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"