Ejemplo n.º 1
0
    def generateGraphs(self, x, y):
        (x1, y1, Width, Height) = self._getGraphRegion(x, y)
        #Draw Axes
        yVAxis = YValueAxis()
        #If we got numeric X vals, we use a ValueAxis, otherwise CategoryAxis.
        if len(self.x_vals) > 0:
            if isinstance(self.x_vals[0], str):
                xVAxis = XCategoryAxis()
            else:
                xVAxis = XValueAxis()
        else:
            return -1
        
        (y_min, y_max, y_step) = self.getValueAxisScale(yVAxis, [self.y_vals])

        if y_min == -1 and y_min == -1 and y_step == -1:
            return -1
        
        (self.valueMin, self.valueMax, self.valueStep) = (y_min, y_max, y_step)
        
        (SizeXaxis, SizeYaxis) = self.getSizes()
        #lot of ugliness in here to get the split chart working :|
        if self.betweenSplitsF == True:
            if self.numSplits == 0:
                self.tmpYVal = SizeYaxis
            else:
                SizeYaxis = self.tmpYVal
        if self.numSplits > 0:
            xVAxis.visibleLabels = False
            xVAxis.visibleTicks = False
        X_start_pos = x1 - x + SizeYaxis
        X_width = Width - SizeYaxis - 10
        if self.betweenSplitsF == True:
            if self.numSplits > 0:
                Y_start_pos = y1 - y + SizeXaxis + (self.numSplits *
                        self.height) - (self.numSplits * 15)
            else:
                Y_start_pos = y1 - y + SizeXaxis + (self.numSplits *
                        self.height)
            Y_height = Height - SizeXaxis + 40
        else:
            Y_start_pos = y1 - y + SizeXaxis + (self.numSplits *
                    self.height)
            Y_height = Height - SizeXaxis
        xVAxis.setPosition(X_start_pos, Y_start_pos, X_width)
        if isinstance(xVAxis, XValueAxis):
            dataList = []
            dataTuple =  reduce(lambda a,b: a + (b,), self.x_vals, ())
            dataList.append(dataTuple)
            xVAxis.configure(dataList)
            xVAxis.labelTextFormat = '%0.' + '%d' % self.xAxisDigits + 'f'
        else:
            dataList = []
            zerodata = [0 for val in self.x_vals]
            dataTuple =  reduce(lambda a,b: a + (b,), zerodata, ())
            dataList.append(dataTuple)
            xVAxis.configure(dataList)
            xVAxis.categoryNames = self.x_vals
            #Ugly hack for setting the labels.dy. Empirical: If there are more than 5 
            #chars, dy = -35 fits fine (assuming the angle would be > 75,when we have 
            #so long val)
            maxLen = 0
            for val in self.x_vals:
                valLen = len(val)
                if valLen > maxLen:
                    maxLen = valLen
            if maxLen > 5:
                xVAxis.labels.dy = -35
                           
        xVAxis.labels.fontName = 'Helvetica'
        xVAxis.labels.fontSize = 7
        xVAxis.labels.angle = self.xValsDisplayAngle
        drawLegendF = False
        if len(self.legendList) > 0:
            drawLegendF = True
        drawLabelF = False
        lblCounts = len(self.x_vals) * len(self.y_vals)
        if lblCounts <= 30 and self.displayDataLbls == True:
            drawLabelF = True
        if len(self.x_vals) == 1:
            drawLabelF = True            
        #hack to increase chart height to include legend and labels
        total_height = 0
        legendHeight = 0
        if drawLegendF == True:
            #Kludge: We enchroach the space needed for legends by bringing down the 
            #y value by 28 (in drawOn()), we use that space here
            legendHeight = Y_height + 28
        graph_height = Y_height
        yVAxis.setPosition(X_start_pos, Y_start_pos, Y_height)
        yVAxis.valueMin = y_min
        yVAxis.valueMax = y_max    
        yVAxis.valueStep = y_step
        yVAxis.labels.fontName = 'Helvetica'
        yVAxis.labels.fontSize = 7
        yVAxis.labelTextFormat = '%0.' + '%d' % self.yAxisDigits + 'f'
        yVAxis.configure(self.y_vals)
        #will later sync the yVAxis as the ValueAxis of the graph
        self.drawing.add(xVAxis)
        if self.numSplits == 0:
            tmp = self.height
            self.height = self.origHeight
            self._drawLabels(self.title, self.x_label, self.y_label)
            self.height = tmp
        for graphtype in self.graphList:
            #Draw only one set of Legends/Labels for any dataset,
            #even if there are multiple charts drawn for the same dataset
            if self.labelsDrawnF == True and self.numSplits == 0:
                drawLabelF = False
            if self.legendsDrawnF == True and self.numSplits == 0:
                drawLegendF = False
            if graphtype == 'Bar':
                GraphObj = VerticalBarChart()
                GraphObj.valueAxis = yVAxis
                self.drawGraph(GraphObj, X_start_pos, Y_start_pos, X_width,
                        graph_height, drawLabelF, drawLegendF, legendHeight)
            if graphtype == 'Line':
                GraphObj = HorizontalLineChart()
                GraphObj.valueAxis = yVAxis
                self.drawGraph(GraphObj, X_start_pos, Y_start_pos, X_width,
                        graph_height, drawLabelF, drawLegendF, legendHeight)