Example #1
0
def create_multi_xychart(title, labels, series_list, series_top, maxv=100):
    
#    labels = [labels[0]]
    series_list = [series_list[0]]
    
    # Create a XYChart object of size 540 x 375 pixels
    c = XYChart(900, 320)
    # Add a title to the chart using 18 pts Times Bold Italic font
    #c.addTitle("Average Weekly Network Load", "timesbi.ttf", 18)
    title = c.addTitle(utils.to_utf8(title), "simsun.ttc", 12)
    title.setMargin2(20, 0, 5, 30)
    
    color_list = BASE_COLOR
    
    # Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical
    # gradient color from light red (ffdddd) to dark red (880000) as background. Set
    # border and grid lines to white (ffffff).
    chart_width = 30 + 190 * len(labels)
    c.setPlotArea(50, 90, chart_width, 200, c.linearGradientColor(60, 40, 60, 280, 0xffffff,
    0xd8e2ec), -1, 0xffffff, 0xffffff)
    
    legendBox = c.addLegend(50, 16, 0, "simsun.ttc", 10)
    legendBox.setBackground(Transparent)
    #legendBox.setAlignment(TopCenter)
    legendBox.setHeight(30)
    
    # Set the x axis labels
    c.xAxis().setLabels([utils.to_utf8(label) for label in labels])
    
    # Draw the ticks between label positions (instead of at label positions)
    c.xAxis().setTickOffset(0.5)
    
    # Set axis label style to 8pts Arial Bold
    c.xAxis().setLabelStyle("simsun.ttc", 9)
    c.yAxis().setLabelStyle("simsun.ttc", 9)
    
    # Set axis line width to 2 pixels
    c.xAxis().setWidth(2)
    c.yAxis().setWidth(2)
    c.yAxis2().setWidth(1)
    
    # Add axis title
    c.yAxis().setTitle("得分/Score", "simsun.ttc", 9)
    
    c.yAxis().setLinearScale(0, maxv)
    
    # Add a multi-bar layer with 3 data sets and 4 pixels 3D depth
    #~ layer = c.addBarLayer2(Side, 1)
    layer = c.addBarLayer()
    layer.setBarGap(0.2)
    layer.setBarWidth(150, 48)

    for index, series in enumerate(series_list):
        layer.addDataSet(series['value'], color_list[index % len(color_list)], utils.to_utf8(series['name']))
    
    if series_top:
        legendBox.addKey2(2, utils.to_utf8(series_top['name']), 0xFF6900, 2)
        markLayer = c.addBoxWhiskerLayer(None, None, None, None, series_top['value'], -1, 0xFF6900)
        markLayer.setLineWidth(2)
        markLayer.setDataGap(0.1)
        markLayer.setDataLabelStyle("simsun.ttc", 9)
        markLayer.setDataLabelFormat("{value|1}")
    
    # Set bar border to transparent. Use soft lighting effect with light direction from
    # top.
    layer.setBorderColor(Transparent, softLighting(Top))
    #layer.setBorderColor(Transparent, barLighting(0.75, 2.0))
    
    layer.setAggregateLabelFormat("{value|1}")
    
    # output the chart
    return c.makeChart2(PNG)
Example #2
0
def create_simple_xychart(title, labels, data):
    # The colors for the bars
    colors = BASE_COLOR

    # Create a PieChart object of size 600 x 380 pixels.
    c = XYChart(380, 50 + 30 * len(labels))

    # Use the white on black palette, which means the default text and line colors are
    # white
    #~ c.setColors(whiteOnBlackPalette)

    # Use a vertical gradient color from blue (0000cc) to deep blue (000044) as
    # background. Use rounded corners of 30 pixels radius for the top-left and
    # bottom-right corners.
    c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight(), '0xEFF1F1', '0xDEE3E4')
        )
    #~ c.setRoundedFrame('0xffffff', 30, 0, 30, 0)

    # Add a title using 18 pts Times New Roman Bold Italic font. Add 6 pixels top and
    # bottom margins to the title.
    #title = c.addTitle(title, "simsun.ttc", 12)
    #title.setMargin2(0, 0, 6, 0)
    #title_height = 25
    title_height = 0

    # Add a separator line in white color just under the title
    #~ c.addLine(20, title.getHeight(), c.getWidth() - 21, title.getHeight(), '0xffffff')
    c.addLine(20, title_height, c.getWidth() - 21, title_height, '0xffffff')

    # Tentatively set the plotarea at (70, 80) and of 480 x 240 pixels in size. Use
    # transparent border and white grid lines
    c.setPlotArea(70, 70, 360, 30 + 30 * len(labels), -1, -1, Transparent, '0xffffff')

    # Swap the axis so that the bars are drawn horizontally
    c.swapXY()

    # Add a multi-color bar chart layer using the supplied data. Use bar gradient
    # lighting with the light intensity from 0.75 to 2.0
    layer = c.addBarLayer3(data, colors)
    #layer.setBorderColor(Transparent, barLighting(0.75, 2.0))
    layer.setBorderColor(Transparent, softLighting(Right))
    # Set the aggregate label format
    layer.setAggregateLabelFormat("{value|1}")

    # Set the aggregate label font to 8 point Arial Bold Italic
    layer.setAggregateLabelStyle("simsun.ttc", 8)



    # Set the labels on the x axis.
    c.xAxis().setLabels(labels)

    # Show the same scale on the left and right y-axes
    #c.syncYAxis()

    # Set the bottom y-axis title using 10pt Arial Bold font
    c.yAxis().setTitle("总得分 Total Score", "simsun.ttc", 9)

    # Set y-axes to transparent
    c.yAxis().setColors(Transparent)
    c.yAxis2().setColors(Transparent)

    # Disable ticks on the x-axis by setting the tick color to transparent
    c.xAxis().setTickColor(Transparent)

    # Set the label styles of all axes to 8pt Arial Bold font
    c.xAxis().setLabelStyle("simsun.ttc", 9)
    c.yAxis().setLabelStyle("simsun.ttc", 9)
    c.yAxis2().setLabelStyle("simsun.ttc", 9)
    
    c.yAxis().setLinearScale(0, 100)
    # Adjust the plot area size, such that the bounding box (inclusive of axes) is 30
    # pixels from the left edge, 25 pixels below the title, 50 pixels from the right
    # edge, and 25 pixels from the bottom edge.
    c.packPlotArea(20, title_height + 15, c.getWidth() - 30, c.getHeight() - 15)

    # Output the chart
    return c.makeChart2(PNG)
Example #3
0
def create_history_now_future_xychart(title, labels, series_list, series_top, maxv=100):
    
    top3, ytd, ave, future_score, point = get_ave_score(series_list)
    series_list.append(dict(name=u'2012 Top3 Ave', value=top3))
    series_list.append(dict(name=u'2012 YTD', value=ytd))
    series_list.append(dict(name=u'2011 Ave', value=ave))
    
    # Create a XYChart object of size 540 x 375 pixels
    c = XYChart(900, 320)
    # Add a title to the chart using 18 pts Times Bold Italic font
    #c.addTitle("Average Weekly Network Load", "timesbi.ttf", 18)
    title = c.addTitle(utils.to_utf8(title), "simsun.ttc", 12)
    title.setMargin2(20, 0, 10, 30)
    
    color_list = BASE_COLOR
    COLOR_BLUE = 0x0070C0
    COLOR_93 = 0x00B050
    COLOR_87 = 0xFFD600
    COLOR_TOP3_AVE = 0x595443
    COLOR_YTD = 0xFF0000
    COLOR_AVE = 0x5678A9
    
    # Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical
    # gradient color from light red (ffdddd) to dark red (880000) as background. Set
    # border and grid lines to white (ffffff).
    chart_width = 30 + 190 * len(labels) 
    c.setPlotArea(50, 90, chart_width, 200, c.linearGradientColor(60, 40, 60, 280, 0xffffff,
    0xd8e2ec), -1, 0xffffff, 0xffffff)
    
    legendBox = c.addLegend(50, 30, 0, "simsun.ttc", 10)
    legendBox.setBackground(Transparent)
    #legendBox.setAlignment(TopCenter)
    legendBox.setHeight(30)
    
    # Set the x axis labels
    c.xAxis().setLabels([utils.to_utf8(label) for label in labels])
    
    # Draw the ticks between label positions (instead of at label positions)
    c.xAxis().setTickOffset(0.5)
    
    # Set axis label style to 8pts Arial Bold
    c.xAxis().setLabelStyle("simsun.ttc", 9)
    c.yAxis().setLabelStyle("simsun.ttc", 9)
    
    # Set axis line width to 2 pixels
    c.xAxis().setWidth(2)
    c.yAxis().setWidth(2)
    c.yAxis2().setWidth(1)
    
    # Add axis title
    c.yAxis().setTitle("得分/Score", "simsun.ttc", 9)
    
    c.yAxis().setLinearScale(0, maxv)
    
    # Add a multi-bar layer with 3 data sets and 4 pixels 3D depth
    #~ layer = c.addBarLayer2(Side, 1)
    
    layer = c.addBarLayer()
    layer.setBarGap(0.1)
    layer.setBarWidth(170, 18)

    for index, series in enumerate(series_list):
        values = series['value']
        if len(values) > 1:
            color = COLOR_BLUE
        else:
            values.append(future_score)
            if point == 93:
                color = COLOR_93
            elif point == 87:
                color = COLOR_87
            else:
                color = COLOR_BLUE
        name = utils.to_utf8(series['name'])
        if name == u'2012 Top3 Ave':
            color = COLOR_TOP3_AVE
        if name == u'2012 YTD':
            color = COLOR_YTD
        if name == u'2011 Ave':
            color = COLOR_AVE
        #print values, color, name
        write_list = []
        for value in values:
            if value == -1 or value > 100:
                write_list.append(0)
            else:
                write_list.append(value)
        layer.addDataSet(write_list, color, name)
        for i, v in enumerate(values):
            if v == -1 or v > 100:
                if name in (u'2012 Top3 Ave',u'2012 YTD', u'2011 Ave'):
                    layer.addCustomGroupLabel(index, i, " ")
                else:
                    layer.addCustomGroupLabel(index, i, "N/A")
            else:
                layer.setAggregateLabelFormat("{value|1}")
                layer.setAggregateLabelStyle ('', 10, '0x0000', 0)
    
    yMark = c.yAxis().addMark(point, '0x800080', '%s' % point)
    yMark.setLineWidth(1)
    yMark.setAlignment(TopCenter)

    # Set bar border to transparent. Use soft lighting effect with light direction from
    # top.
    layer.setBorderColor(Transparent, softLighting(Top))
    #layer.setBorderColor(Transparent, barLighting(0.75, 2.0))
    
    #layer.setAggregateLabelFormat("{value|1}")
    
    # output the chart
    return c.makeChart2(PNG)
Example #4
0
def percent():
    # The data for the bar chart
    data = [40, 15, 53.2]
    
    # The labels for the bar chart
    labels = ["8月5日", "8月6日", "8月7日"]
    
    # Create a XYChart object of size 250 x 250 pixels
    c = XYChart(600, 400)
    c.addTitle('解析统计', FONT, 14)
    
    # Set the plotarea at (30, 20) and of size 200 x 200 pixels
    c.setPlotArea(80, 40, 500, 320)
    
    # Add a bar chart layer using the given data
    layer = c.addBarLayer(data, COLOR)
    layer.setAggregateLabelStyle(FONT, 12)
    layer.setAggregateLabelFormat("{value}%")
    
    # Set the labels on the x axis.
    c.xAxis().setLabels(labels)
#     c.xAxis().setLabelStep(1, 1)
    c.xAxis().setLabelStyle(FONT, 12)
    
    c.yAxis().setLinearScale(0, 100, 20)
    c.yAxis().setLabelFormat("{value}%")
    
    # Output the chart
    c.makeChart("/temp/chart/percent.png")
    print 'done~'
Example #5
0
 def CreateChartFromSamples(self,
                            width,
                            height,
                            dataX,
                            dataY,
                            dataZ,
                            rangeXY=None):
     startTime = blue.os.GetWallclockTime()
     if rangeXY:
         minX, minY, maxX, maxY = rangeXY
     else:
         minX = min(dataX)
         maxX = max(dataX)
         minY = min(dataY)
         maxY = max(dataY)
     maxZ = max(dataZ)
     minZ = min(dataZ)
     chart = XYChart(width, height)
     chart.setPlotArea(0, 0, width, height, Transparent, Transparent,
                       Transparent, Transparent, Transparent)
     layer = chart.addContourLayer(dataX, dataY, dataZ)
     chart.xAxis().setLinearScale(minX, maxX, NoValue)
     chart.xAxis().setColors(Transparent)
     chart.yAxis().setLinearScale(maxY, minY, NoValue)
     chart.yAxis().setColors(Transparent)
     colorAxis = layer.colorAxis()
     colorAxis.setColorGradient(
         True, [long(max(0, minZ)) << 24,
                long(min(255, maxZ)) << 24])
     layer.setSmoothInterpolation(True)
     layer.setContourColor(Transparent)
     self.LogInfo('CreateChartFromSamples width', width, 'height', height,
                  'render time',
                  float(blue.os.GetWallclockTime() - startTime) / const.SEC,
                  'seconds')
     return chart
Example #6
0
def multi_percent():
    # 数据与标签
    data1 = [40, 15, 53, 66, 23, 48, 71, 55, 31, 48, 94, 57]
    data2 = [50, 35, 64, 22, 17, 67, 84, 53, 20, 78, 94, 61]
    labels = ['08-05', '08-06', '08-07', '08-08', '08-09', '08-10', '08-11', '08-12', '08-13', '08-14', '08-15', '08-16']
    
    # 数据与标签
#     data1 = [40, 15, 53]
#     data2 = [50, 35, 64]
#     labels = ['08-05', '08-06', '08-07']
    
    # 图片大小
    c = XYChart(600, 400)
    c.addTitle('解析统计', FONT, 14)
    
    # 绘图位置及大小,背景及边框透明,设置网格线颜色
    c.setPlotArea(80, 40, 500, 320, Transparent, -1, Transparent, 0xcccccc)
    
    # 图例, (left, top, is_vertical?? , font, font_size)
    c.addLegend(170, 22, 0, FONT, 10).setBackground(Transparent)
    
    # 坐标轴颜色,标签字体
#     c.xAxis().setColors(Transparent)
    c.xAxis().setLabelStyle(FONT, 12)
    c.yAxis().setColors(Transparent)
    c.yAxis().setLabelStyle(FONT, 12)
    
    # 多个数据集
    layer = c.addBarLayer2(Side)
    layer.addDataSet(data1, COLOR, "流量Cache率")
    layer.addDataSet(data2, COLOR2, "访问数Cache率")
    
    # 柱子上显示数据,并设置透明边框,柱子颜色的“光强度”介于 0.8 和 1.3 之间
    layer.setAggregateLabelStyle(FONT, 10)
    layer.setAggregateLabelFormat("{value}%")
    layer.setBorderColor(Transparent, barLighting(0.8, 1.3))
    
    # X轴标签,最多显示7个标签
    c.xAxis().setLabels(labels)
    c.xAxis().setLabelStep(math.ceil(len(data1) / float(7)))
    
    # 顶部空白
    c.yAxis().setTopMargin(30)
    
    # 最小值,最大值,步进。标签格式
    c.yAxis().setLinearScale(0, 100, 20)
    c.yAxis().setLabelFormat("{value}%")
    
    # Output the chart
    c.makeChart("/temp/chart/multi_percent.png")
    print 'done~'
Example #7
0
def bar_label():
    # The data for the bar chart
    data = [85, 156, 179, 211, 123, 189, 166]
    
    # The labels for the bar chart
    labels = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
    
    # Create a XYChart object of size 600 x 360 pixels
    c = XYChart(600, 360)
    
    # Set the plotarea at (70, 20) and of size 500 x 300 pixels, with transparent background and border
    # and light grey (0xcccccc) horizontal grid lines
    c.setPlotArea(70, 20, 500, 300, Transparent, -1, Transparent, 0xcccccc)
    
    # Set the x and y axis stems to transparent and the label font to 12pt Arial
    c.xAxis().setColors(Transparent)
    c.xAxis().setLabelStyle(FONT, 12)
    c.yAxis().setColors(Transparent)
    c.yAxis().setLabelStyle(FONT, 12)
    
    # Add a blue (0x6699bb) bar chart layer using the given data
    layer = c.addBarLayer(data, COLOR)
    
    # Use bar gradient lighting with the light intensity from 0.8 to 1.3
    layer.setBorderColor(Transparent, barLighting(0.8, 1.3))
    
    # Set rounded corners for bars
#     layer.setRoundedCorners()
    
    # Display labela on top of bars using 12pt Arial font
    layer.setAggregateLabelStyle(FONT, 12)
    
    # Set the labels on the x axis.
    c.xAxis().setLabels(labels)
    
    # For the automatic y-axis labels, set the minimum spacing to 40 pixels.
    c.yAxis().setTickDensity(40)
    
    # Add a title to the y axis using dark grey (0x555555) 14pt Arial Bold font
    c.yAxis().setTitle("Y-Axis Title Placeholder", FONT, 14, 0x555555)
    
    # Output the chart
    c.makeChart("/temp/chart/barlabel.png")
    print 'done~'
Example #8
0
    def DoRewardChart_Thread(self, rewardID, size, icon):
        """This function is generating the reward graph for the incursion journal
        The image is build opon data from the reward system, which is cached with the policy never, None, None"""
        reward = self.GetRewardData(rewardID)
        maxRewardValue = 0
        minPlayerCount = 0
        maxPlayerCount = 0
        allSecurityBandTable = None
        lowSecurityBandTable = None
        highSecurityBandTable = None
        for rewardCriteria, rewardTables in reward.immediateRewards.iteritems(
        ):
            if not rewardTables:
                continue
            if rewardCriteria == const.rewardCriteriaAllSecurityBands:
                maxRewardValue = self.GetMaxRewardValue(
                    rewardTables, const.rewardTypeISK)
                minPlayerCount = self.GetMinRewardPlayerCount(rewardTables)
                maxPlayerCount = self.GetMaxRewardPlayerCount(rewardTables)
                allSecurityBandTable = rewardTables[0]
                break
            if rewardCriteria == const.rewardCriteriaHighSecurity:
                highSecurityBandTable = rewardTables[0]
            elif rewardCriteria == const.rewardCriteriaLowSecurity:
                lowSecurityBandTable = rewardTables[0]
            else:
                continue
            maxRewardValue = max(
                maxRewardValue,
                self.GetMaxRewardValue(rewardTables, const.rewardTypeISK))
            minPlayerCount = min(minPlayerCount,
                                 self.GetMinRewardPlayerCount(rewardTables))
            maxPlayerCount = max(maxPlayerCount,
                                 self.GetMaxRewardPlayerCount(rewardTables))

        scale = 1.0 / maxRewardValue
        majorTick = (maxPlayerCount - minPlayerCount) / 4
        data = []
        labels = []
        for x in xrange(minPlayerCount, maxPlayerCount + 1):
            if allSecurityBandTable is not None:
                quantity = self.GetQuantityForCount(allSecurityBandTable,
                                                    x) * scale
                data.append(quantity)
            else:
                quantityHigh = self.GetQuantityForCount(
                    highSecurityBandTable, x) * scale
                quantityLow = self.GetQuantityForCount(lowSecurityBandTable,
                                                       x) * scale
                data.append((quantityHigh, quantityLow))
            labels.append(str(x))

        chart = XYChart(size, size, BLACK, GRAY, False)
        chart.setPlotArea(PLOT_OFFSET, PLOT_OFFSET,
                          size - PLOT_OFFSET - PLOT_RIGHT_MARGIN,
                          size - PLOT_OFFSET - PLOT_BOTTOM_MARGIN, DARKGRAY,
                          -1, -1, GRAY, Transparent)
        if localization.util.GetLanguageID(
        ) == localization.const.LOCALE_SHORT_ENGLISH:
            font = 'arial.ttf'
            titleFont = 'arialbd.ttf'
        else:
            font = titleFont = uicore.font.GetFontDefault()
        chart.addLegend(LEGEND_OFFSET, LEGEND_OFFSET, 0, font,
                        8).setBackground(Transparent)
        legend = chart.getLegend()
        legend.setFontColor(WHITE)
        chart.addTitle(localization.GetByLabel('UI/Incursion/Reward/Title'),
                       titleFont, 12, WHITE).setBackground(Transparent)
        yAxis = chart.yAxis()
        yAxis.setTitle(
            localization.GetByLabel('UI/Incursion/Reward/PayoutMultiplier'),
            font, 10, WHITE)
        yAxis.setColors(GRAY, WHITE)
        yAxis.setLinearScale(0, 1.02, 0.5, 0.25)
        xAxis = chart.xAxis()
        xAxis.setLabels(labels)
        xAxis.setLabelStep(majorTick)
        xAxis.setColors(GRAY, WHITE)
        xAxis.setTitle(
            localization.GetByLabel('UI/Incursion/Reward/NumberPilots'), font,
            9, WHITE)
        layer = chart.addLineLayer2()
        layer.setLineWidth(1)
        if allSecurityBandTable is not None:
            layer.addDataSet(data, COLOR_HIGH_SEC,
                             localization.GetByLabel('UI/Common/Ratio'))
        else:
            dataHigh, dataLow = zip(*data)
            layer.addDataSet(dataHigh, COLOR_HIGH_SEC,
                             localization.GetByLabel('UI/Common/HighSec'))
            layer.addDataSet(dataLow, COLOR_NULL_SEC,
                             localization.GetByLabel('UI/Common/LowNullSec'))
        directory = os.path.normpath(
            os.path.join(blue.paths.ResolvePath(u'cache:/'), 'Pictures',
                         'Rewards'))
        if not os.path.exists(directory):
            os.makedirs(directory)
        pictureName = 'rewardchart2_%s_%d_%d.png' % (session.languageID, size,
                                                     rewardID)
        resPath = u'cache:/Pictures/Rewards/' + pictureName
        path = os.path.join(directory, pictureName)
        imageBuffer = chart.makeChart2(PNG)
        f = open(path, 'wb')
        f.write(imageBuffer)
        f.close()
        icon.LoadTexture(resPath)
        icon.SetRect(0, 0, size, size)
Example #9
0
def simple():
    # The data for the bar chart
    data = [850000000, 150000000, 790000000, 210000000, 530000000, 310000000, 220000000]
    
    # The labels for the bar chart
    labels = ["8月5日", "8月6日", "8月7日", "8月8日", "8月9日", '8月10日', '8月11日']
    
    # Create a XYChart object of size 250 x 250 pixels
    c = XYChart(600, 400)
    c.addTitle('解析统计', FONT, 14)
    
    # Set the plotarea at (30, 20) and of size 200 x 200 pixels
    c.setPlotArea(80, 40, 500, 320)
    
    # Add a bar chart layer using the given data
    layer = c.addBarLayer(data, COLOR)
    layer.setAggregateLabelStyle(FONT, 12)
    
    # Set the labels on the x axis.
    c.xAxis().setLabels(labels)
    c.xAxis().setLabelStep(2, 1)
    c.xAxis().setLabelStyle(FONT, 12)
    
    # Output the chart
    c.makeChart("/temp/chart/simple.png")
    print 'done~'
Example #10
0
 def CreateChartFromSamples(self, width, height, dataX, dataY, dataZ, rangeXY = None):
     startTime = blue.os.GetWallclockTime()
     if rangeXY:
         minX, minY, maxX, maxY = rangeXY
     else:
         minX = min(dataX)
         maxX = max(dataX)
         minY = min(dataY)
         maxY = max(dataY)
     maxZ = max(dataZ)
     minZ = min(dataZ)
     chart = XYChart(width, height)
     chart.setPlotArea(0, 0, width, height, Transparent, Transparent, Transparent, Transparent, Transparent)
     layer = chart.addContourLayer(dataX, dataY, dataZ)
     chart.xAxis().setLinearScale(minX, maxX, NoValue)
     chart.xAxis().setColors(Transparent)
     chart.yAxis().setLinearScale(maxY, minY, NoValue)
     chart.yAxis().setColors(Transparent)
     colorAxis = layer.colorAxis()
     colorAxis.setColorGradient(True, [long(max(0, minZ)) << 24, long(min(255, maxZ)) << 24])
     layer.setSmoothInterpolation(True)
     layer.setContourColor(Transparent)
     self.LogInfo('CreateChartFromSamples width', width, 'height', height, 'render time', float(blue.os.GetWallclockTime() - startTime) / const.SEC, 'seconds')
     return chart
Example #11
0
    def DoRewardChart_Thread(self, rewardID, size, icon):
        reward = self.GetRewardData(rewardID)
        maxRewardValue = 0
        minPlayerCount = 0
        maxPlayerCount = 0
        allSecurityBandTable = None
        lowSecurityBandTable = None
        highSecurityBandTable = None
        for rewardCriteria, rewardTables in reward.immediateRewards.iteritems():
            if not rewardTables:
                continue
            if rewardCriteria == const.rewardCriteriaAllSecurityBands:
                maxRewardValue = self.GetMaxRewardValue(rewardTables, const.rewardTypeISK)
                minPlayerCount = self.GetMinRewardPlayerCount(rewardTables)
                maxPlayerCount = self.GetMaxRewardPlayerCount(rewardTables)
                allSecurityBandTable = rewardTables[0]
                break
            if rewardCriteria == const.rewardCriteriaHighSecurity:
                highSecurityBandTable = rewardTables[0]
            elif rewardCriteria == const.rewardCriteriaLowSecurity:
                lowSecurityBandTable = rewardTables[0]
            else:
                continue
            maxRewardValue = max(maxRewardValue, self.GetMaxRewardValue(rewardTables, const.rewardTypeISK))
            minPlayerCount = min(minPlayerCount, self.GetMinRewardPlayerCount(rewardTables))
            maxPlayerCount = max(maxPlayerCount, self.GetMaxRewardPlayerCount(rewardTables))

        scale = 1.0 / maxRewardValue
        majorTick = (maxPlayerCount - minPlayerCount) / 4
        data = []
        labels = []
        for x in xrange(minPlayerCount, maxPlayerCount + 1):
            if allSecurityBandTable is not None:
                quantity = self.GetQuantityForCount(allSecurityBandTable, x) * scale
                data.append(quantity)
            else:
                quantityHigh = self.GetQuantityForCount(highSecurityBandTable, x) * scale
                quantityLow = self.GetQuantityForCount(lowSecurityBandTable, x) * scale
                data.append((quantityHigh, quantityLow))
            labels.append(str(x))

        chart = XYChart(size, size, BLACK, GRAY, False)
        chart.setPlotArea(PLOT_OFFSET, PLOT_OFFSET, size - PLOT_OFFSET - PLOT_RIGHT_MARGIN, size - PLOT_OFFSET - PLOT_BOTTOM_MARGIN, DARKGRAY, -1, -1, GRAY, Transparent)
        if localizationUtil.GetLanguageID() == localization.LOCALE_SHORT_ENGLISH:
            font = 'arial.ttf'
            titleFont = 'arialbd.ttf'
        else:
            font = titleFont = sm.GetService('font').GetFontDefault()
        chart.addLegend(LEGEND_OFFSET, LEGEND_OFFSET, 0, font, 8).setBackground(Transparent)
        legend = chart.getLegend()
        legend.setFontColor(WHITE)
        chart.addTitle(localization.GetByLabel('UI/Incursion/Reward/Title'), titleFont, 12, WHITE).setBackground(Transparent)
        yAxis = chart.yAxis()
        yAxis.setTitle(localization.GetByLabel('UI/Incursion/Reward/PayoutMultiplier'), font, 10, WHITE)
        yAxis.setColors(GRAY, WHITE)
        yAxis.setLinearScale(0, 1.02, 0.5, 0.25)
        xAxis = chart.xAxis()
        xAxis.setLabels(labels)
        xAxis.setLabelStep(majorTick)
        xAxis.setColors(GRAY, WHITE)
        xAxis.setTitle(localization.GetByLabel('UI/Incursion/Reward/NumberPilots'), font, 9, WHITE)
        layer = chart.addLineLayer2()
        layer.setLineWidth(1)
        if allSecurityBandTable is not None:
            layer.addDataSet(data, COLOR_HIGH_SEC, localization.GetByLabel('UI/Common/Ratio'))
        else:
            dataHigh, dataLow = zip(*data)
            layer.addDataSet(dataHigh, COLOR_HIGH_SEC, localization.GetByLabel('UI/Common/HighSec'))
            layer.addDataSet(dataLow, COLOR_NULL_SEC, localization.GetByLabel('UI/Common/LowNullSec'))
        directory = os.path.normpath(os.path.join(blue.paths.ResolvePath(u'cache:/'), 'Pictures', 'Rewards'))
        if not os.path.exists(directory):
            os.makedirs(directory)
        pictureName = 'rewardchart2_%s_%d_%d.png' % (session.languageID, size, rewardID)
        resPath = u'cache:/Pictures/Rewards/' + pictureName
        path = os.path.join(directory, pictureName)
        imageBuffer = chart.makeChart2(PNG)
        f = open(path, 'wb')
        f.write(imageBuffer)
        f.close()
        icon.LoadTexture(resPath)
        icon.SetRect(0, 0, size, size)
Example #12
0
def create_simple_xychart(title, labels, data):
    # The colors for the bars
    colors = BASE_COLOR

    # Create a PieChart object of size 600 x 380 pixels.
    c = XYChart(380, 50 + 30 * len(labels))

    # Use the white on black palette, which means the default text and line colors are
    # white
    #~ c.setColors(whiteOnBlackPalette)

    # Use a vertical gradient color from blue (0000cc) to deep blue (000044) as
    # background. Use rounded corners of 30 pixels radius for the top-left and
    # bottom-right corners.
    c.setBackground(
        c.linearGradientColor(0, 0, 0, c.getHeight(), '0xEFF1F1', '0xDEE3E4'))
    #~ c.setRoundedFrame('0xffffff', 30, 0, 30, 0)

    # Add a title using 18 pts Times New Roman Bold Italic font. Add 6 pixels top and
    # bottom margins to the title.
    #title = c.addTitle(title, "simsun.ttc", 12)
    #title.setMargin2(0, 0, 6, 0)
    #title_height = 25
    title_height = 0

    # Add a separator line in white color just under the title
    #~ c.addLine(20, title.getHeight(), c.getWidth() - 21, title.getHeight(), '0xffffff')
    c.addLine(20, title_height, c.getWidth() - 21, title_height, '0xffffff')

    # Tentatively set the plotarea at (70, 80) and of 480 x 240 pixels in size. Use
    # transparent border and white grid lines
    c.setPlotArea(70, 70, 360, 30 + 30 * len(labels), -1, -1, Transparent,
                  '0xffffff')

    # Swap the axis so that the bars are drawn horizontally
    c.swapXY()

    # Add a multi-color bar chart layer using the supplied data. Use bar gradient
    # lighting with the light intensity from 0.75 to 2.0
    layer = c.addBarLayer3(data, colors)
    #layer.setBorderColor(Transparent, barLighting(0.75, 2.0))
    layer.setBorderColor(Transparent, softLighting(Right))
    # Set the aggregate label format
    layer.setAggregateLabelFormat("{value|1}")

    # Set the aggregate label font to 8 point Arial Bold Italic
    layer.setAggregateLabelStyle("simsun.ttc", 8)

    # Set the labels on the x axis.
    c.xAxis().setLabels(labels)

    # Show the same scale on the left and right y-axes
    #c.syncYAxis()

    # Set the bottom y-axis title using 10pt Arial Bold font
    c.yAxis().setTitle("总得分 Total Score", "simsun.ttc", 9)

    # Set y-axes to transparent
    c.yAxis().setColors(Transparent)
    c.yAxis2().setColors(Transparent)

    # Disable ticks on the x-axis by setting the tick color to transparent
    c.xAxis().setTickColor(Transparent)

    # Set the label styles of all axes to 8pt Arial Bold font
    c.xAxis().setLabelStyle("simsun.ttc", 9)
    c.yAxis().setLabelStyle("simsun.ttc", 9)
    c.yAxis2().setLabelStyle("simsun.ttc", 9)

    c.yAxis().setLinearScale(0, 100)
    # Adjust the plot area size, such that the bounding box (inclusive of axes) is 30
    # pixels from the left edge, 25 pixels below the title, 50 pixels from the right
    # edge, and 25 pixels from the bottom edge.
    c.packPlotArea(20, title_height + 15,
                   c.getWidth() - 30,
                   c.getHeight() - 15)

    # Output the chart
    return c.makeChart2(PNG)
Example #13
0
def create_history_now_future_xychart(title,
                                      labels,
                                      series_list,
                                      series_top,
                                      maxv=100):

    top3, ytd, ave, future_score, point = get_ave_score(series_list)
    series_list.append(dict(name=u'2012 Top3 Ave', value=top3))
    series_list.append(dict(name=u'2012 YTD', value=ytd))
    series_list.append(dict(name=u'2011 Ave', value=ave))

    # Create a XYChart object of size 540 x 375 pixels
    c = XYChart(900, 320)
    # Add a title to the chart using 18 pts Times Bold Italic font
    #c.addTitle("Average Weekly Network Load", "timesbi.ttf", 18)
    title = c.addTitle(utils.to_utf8(title), "simsun.ttc", 12)
    title.setMargin2(20, 0, 10, 30)

    color_list = BASE_COLOR
    COLOR_BLUE = 0x0070C0
    COLOR_93 = 0x00B050
    COLOR_87 = 0xFFD600
    COLOR_TOP3_AVE = 0x595443
    COLOR_YTD = 0xFF0000
    COLOR_AVE = 0x5678A9

    # Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical
    # gradient color from light red (ffdddd) to dark red (880000) as background. Set
    # border and grid lines to white (ffffff).
    chart_width = 30 + 190 * len(labels)
    c.setPlotArea(50, 90, chart_width, 200,
                  c.linearGradientColor(60, 40, 60, 280, 0xffffff, 0xd8e2ec),
                  -1, 0xffffff, 0xffffff)

    legendBox = c.addLegend(50, 30, 0, "simsun.ttc", 10)
    legendBox.setBackground(Transparent)
    #legendBox.setAlignment(TopCenter)
    legendBox.setHeight(30)

    # Set the x axis labels
    c.xAxis().setLabels([utils.to_utf8(label) for label in labels])

    # Draw the ticks between label positions (instead of at label positions)
    c.xAxis().setTickOffset(0.5)

    # Set axis label style to 8pts Arial Bold
    c.xAxis().setLabelStyle("simsun.ttc", 9)
    c.yAxis().setLabelStyle("simsun.ttc", 9)

    # Set axis line width to 2 pixels
    c.xAxis().setWidth(2)
    c.yAxis().setWidth(2)
    c.yAxis2().setWidth(1)

    # Add axis title
    c.yAxis().setTitle("得分/Score", "simsun.ttc", 9)

    c.yAxis().setLinearScale(0, maxv)

    # Add a multi-bar layer with 3 data sets and 4 pixels 3D depth
    #~ layer = c.addBarLayer2(Side, 1)

    layer = c.addBarLayer()
    layer.setBarGap(0.1)
    layer.setBarWidth(170, 18)

    for index, series in enumerate(series_list):
        values = series['value']
        if len(values) > 1:
            color = COLOR_BLUE
        else:
            values.append(future_score)
            if point == 93:
                color = COLOR_93
            elif point == 87:
                color = COLOR_87
            else:
                color = COLOR_BLUE
        name = utils.to_utf8(series['name'])
        if name == u'2012 Top3 Ave':
            color = COLOR_TOP3_AVE
        if name == u'2012 YTD':
            color = COLOR_YTD
        if name == u'2011 Ave':
            color = COLOR_AVE
        #print values, color, name
        write_list = []
        for value in values:
            if value == -1 or value > 100:
                write_list.append(0)
            else:
                write_list.append(value)
        layer.addDataSet(write_list, color, name)
        for i, v in enumerate(values):
            if v == -1 or v > 100:
                if name in (u'2012 Top3 Ave', u'2012 YTD', u'2011 Ave'):
                    layer.addCustomGroupLabel(index, i, " ")
                else:
                    layer.addCustomGroupLabel(index, i, "N/A")
            else:
                layer.setAggregateLabelFormat("{value|1}")
                layer.setAggregateLabelStyle('', 10, '0x0000', 0)

    yMark = c.yAxis().addMark(point, '0x800080', '%s' % point)
    yMark.setLineWidth(1)
    yMark.setAlignment(TopCenter)

    # Set bar border to transparent. Use soft lighting effect with light direction from
    # top.
    layer.setBorderColor(Transparent, softLighting(Top))
    #layer.setBorderColor(Transparent, barLighting(0.75, 2.0))

    #layer.setAggregateLabelFormat("{value|1}")

    # output the chart
    return c.makeChart2(PNG)
Example #14
0
def create_multi_xychart(title, labels, series_list, series_top, maxv=100):

    #    labels = [labels[0]]
    series_list = [series_list[0]]

    # Create a XYChart object of size 540 x 375 pixels
    c = XYChart(900, 320)
    # Add a title to the chart using 18 pts Times Bold Italic font
    #c.addTitle("Average Weekly Network Load", "timesbi.ttf", 18)
    title = c.addTitle(utils.to_utf8(title), "simsun.ttc", 12)
    title.setMargin2(20, 0, 5, 30)

    color_list = BASE_COLOR

    # Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical
    # gradient color from light red (ffdddd) to dark red (880000) as background. Set
    # border and grid lines to white (ffffff).
    chart_width = 30 + 190 * len(labels)
    c.setPlotArea(50, 90, chart_width, 200,
                  c.linearGradientColor(60, 40, 60, 280, 0xffffff, 0xd8e2ec),
                  -1, 0xffffff, 0xffffff)

    legendBox = c.addLegend(50, 16, 0, "simsun.ttc", 10)
    legendBox.setBackground(Transparent)
    #legendBox.setAlignment(TopCenter)
    legendBox.setHeight(30)

    # Set the x axis labels
    c.xAxis().setLabels([utils.to_utf8(label) for label in labels])

    # Draw the ticks between label positions (instead of at label positions)
    c.xAxis().setTickOffset(0.5)

    # Set axis label style to 8pts Arial Bold
    c.xAxis().setLabelStyle("simsun.ttc", 9)
    c.yAxis().setLabelStyle("simsun.ttc", 9)

    # Set axis line width to 2 pixels
    c.xAxis().setWidth(2)
    c.yAxis().setWidth(2)
    c.yAxis2().setWidth(1)

    # Add axis title
    c.yAxis().setTitle("得分/Score", "simsun.ttc", 9)

    c.yAxis().setLinearScale(0, maxv)

    # Add a multi-bar layer with 3 data sets and 4 pixels 3D depth
    #~ layer = c.addBarLayer2(Side, 1)
    layer = c.addBarLayer()
    layer.setBarGap(0.2)
    layer.setBarWidth(150, 48)

    for index, series in enumerate(series_list):
        layer.addDataSet(series['value'], color_list[index % len(color_list)],
                         utils.to_utf8(series['name']))

    if series_top:
        legendBox.addKey2(2, utils.to_utf8(series_top['name']), 0xFF6900, 2)
        markLayer = c.addBoxWhiskerLayer(None, None, None, None,
                                         series_top['value'], -1, 0xFF6900)
        markLayer.setLineWidth(2)
        markLayer.setDataGap(0.1)
        markLayer.setDataLabelStyle("simsun.ttc", 9)
        markLayer.setDataLabelFormat("{value|1}")

    # Set bar border to transparent. Use soft lighting effect with light direction from
    # top.
    layer.setBorderColor(Transparent, softLighting(Top))
    #layer.setBorderColor(Transparent, barLighting(0.75, 2.0))

    layer.setAggregateLabelFormat("{value|1}")

    # output the chart
    return c.makeChart2(PNG)
Example #15
0
def simple():
    # The data for the area chart
    data = [30, 28, 40, 55, 75, 68, 54, 60, 50, 62, 75, 65, 75, 89, 60, 55, 53, 35, 50, 66, 56, 48, 52,
        65, 62]
    
    # The labels for the area chart
    labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
        "16", "17", "18", "19", "20", "21", "22", "23", "24"]
    
    # Create a XYChart object of size 250 x 250 pixels
    c = XYChart(250, 250)
    
    # Set the plotarea at (30, 20) and of size 200 x 200 pixels
    c.setPlotArea(30, 20, 200, 200)
    
    # Add an area chart layer using the given data
    c.addAreaLayer(data)
    
    # Set the labels on the x axis.
    c.xAxis().setLabels(labels)
    
    # Display 1 out of 3 labels on the x-axis.
    c.xAxis().setLabelStep(3)
    
    # Output the chart
    c.makeChart("/temp/chart/area_simple.png")
    
    print 'done'
Example #16
0
def custom():
    # The data for the area chart
    data = [30, 28, 40, 55, 75, 68, 54, 60, 50, 62, 75, 65, 75, 89, 60, 55, 53, 35, 50, 66, 56, 48, 52,
        65, 62, 28, 40, 55, 75, 68, 54, 28, 40, 55, 75, 68, 54]
    
    # The labels for the area chart
    d = datetime.datetime.now()
    labels = [(d + datetime.timedelta(minutes=5*i)).strftime('%m-%d %H:%M') for i in range(0, len(data))]
    
    c = XYChart(600, 400)
    c.addTitle('访问统计', FONT_SIMSUN, 14)
    c.setPlotArea(55, 40, 500, 320)
    
    c.addAreaLayer(data, 0x6699bb)
    c.xAxis().setLabels(labels)
    c.xAxis().setLabelStep(math.ceil(len(data) / float(8)))
    
    # Output the chart
    c.makeChart("/temp/chart/area_custom.png")
    
    print 'done'