Ejemplo n.º 1
0
 def save_style(self, style):
     current_obj = self.style_editor.textObject
     style = str(style)
     if style == current_obj.name:
         to_name = current_obj.To_name
         to_src = "default"
         tt_name = current_obj.Tt_name
         tt_src = "default"
     else:
         to_name = style
         to_src = current_obj.To_name
         tt_name = style
         tt_src = current_obj.Tt_name
     try:
         to = vcs.gettextorientation(to_name)
     except ValueError:
         to = vcs.createtextorientation(name=to_name, source=to_src)
     try:
         tt = vcs.gettexttable(tt_name)
     except ValueError:
         tt = vcs.createtexttable(name=tt_name, source=tt_src)
     get_textstyles().updated(tt_name)
     self.current_member.texttable = tt
     self.current_member.textorientation = to
     self.current_member = None
     self.sync()
     self.labelUpdated.emit()
Ejemplo n.º 2
0
    def __init__(self, interactor, label, dp, configurator):
        self.label = label
        self.display = dp
        super(LabelEditor, self).__init__(interactor, label, configurator)

        self.toolbar = vcs.vtk_ui.Toolbar(
            self.interactor,
            "%s Options" %
            label.member)
        template = vcs.gettemplate(dp.template)

        self.actor = get_actor(self.label, self.display)

        tprop = self.actor.GetTextProperty()
        self.real_bg = tprop.GetBackgroundColor()
        self.real_bg_opacity = tprop.GetBackgroundOpacity()

        tprop.SetBackgroundColor(contrasting_color(*tprop.GetColor()))
        tprop.SetBackgroundOpacity(.85)

        text_types_name = template.name + "_" + label.member

        try:
            self.tt = vcs.gettexttable(text_types_name)
            self.to = vcs.gettextorientation(text_types_name)
        except ValueError:
            self.tt = vcs.createtexttable(text_types_name, label.texttable)
            self.to = vcs.createtextorientation(
                text_types_name,
                label.textorientation)

        self.height_button = self.toolbar.add_slider_button(
            self.to.height,
            1,
            100,
            "Height",
            update=self.update_height)

        halign = self.toolbar.add_button(
            ["Left Align", "Center Align", "Right Align"], action=self.halign)
        valign = self.toolbar.add_button(
            ["Top Align", "Half Align", "Bottom Align"], action=self.valign)

        halign.set_state(self.to.halign)
        valign.set_state(__valign_map__[self.to.valign])

        self.angle_button = self.toolbar.add_slider_button(
            self.to.angle,
            0,
            360,
            "Angle",
            update=self.update_angle)

        self.picker = None
        self.toolbar.add_button(["Change Color"], action=self.change_color)
        self.toolbar.show()
        self.label.texttable = self.tt.name
        self.label.textorientation = self.to.name
Ejemplo n.º 3
0
    def get_el(self, name):
        tt = vcs.gettexttable(name)
        to = vcs.gettextorientation(name)

        for tc in vcs.listelements("textcombined"):
            tc = vcs.gettextcombined(tc)
            if tc.To_name == name and tc.Tt_name == name:
                return tc
        tc = vcs.createtextcombined()
        tc.Tt = tt
        tc.To = to
        return tc
Ejemplo n.º 4
0
    def get_el(self, name):
        tt = vcs.gettexttable(name)
        to = vcs.gettextorientation(name)

        for tc in vcs.listelements("textcombined"):
            tc = vcs.gettextcombined(tc)
            if tc.To_name == name and tc.Tt_name == name:
                return tc
        tc = vcs.createtextcombined()
        tc.Tt = tt
        tc.To = to
        return tc
Ejemplo n.º 5
0
    def __init__(self, interactor, label, dp, configurator):
        self.label = label
        self.display = dp
        super(LabelEditor, self).__init__(interactor, label, configurator)

        self.toolbar = vcs.vtk_ui.Toolbar(self.interactor,
                                          "%s Options" % label.member)
        template = vcs.gettemplate(dp.template)

        self.actor = get_actor(self.label, self.display)

        tprop = self.actor.GetTextProperty()
        self.real_bg = tprop.GetBackgroundColor()
        self.real_bg_opacity = tprop.GetBackgroundOpacity()

        tprop.SetBackgroundColor(contrasting_color(*tprop.GetColor()))
        tprop.SetBackgroundOpacity(.85)

        text_types_name = template.name + "_" + label.member

        try:
            self.tt = vcs.gettexttable(text_types_name)
            self.to = vcs.gettextorientation(text_types_name)
        except ValueError:
            self.tt = vcs.createtexttable(text_types_name, label.texttable)
            self.to = vcs.createtextorientation(text_types_name,
                                                label.textorientation)

        self.height_button = self.toolbar.add_slider_button(
            self.to.height, 1, 100, "Height", update=self.update_height)

        halign = self.toolbar.add_button(
            ["Left Align", "Center Align", "Right Align"], action=self.halign)
        valign = self.toolbar.add_button(
            ["Top Align", "Half Align", "Bottom Align"], action=self.valign)

        halign.set_state(self.to.halign)
        valign.set_state(__valign_map__[self.to.valign])

        self.angle_button = self.toolbar.add_slider_button(
            self.to.angle, 0, 360, "Angle", update=self.update_angle)

        self.picker = None
        self.toolbar.add_button(["Change Color"], action=self.change_color)
        # Adds itself to self.toolbar automatically
        FontEditor(self.toolbar,
                   self.set_font,
                   current_font=vcs.getfontname(self.tt.font))
        self.toolbar.show()
        self.label.texttable = self.tt.name
        self.label.textorientation = self.to.name
Ejemplo n.º 6
0
    def __init__(self, interactor, label, dp, configurator):
        self.label = label
        self.display = dp
        super(LabelEditor, self).__init__(interactor, label, configurator)

        self.toolbar = vcs.vtk_ui.Toolbar(self.interactor,
                                          "%s Options" % label.member)
        template = vcs.gettemplate(dp.template)

        self.actor = get_actor(self.label, self.display)

        text_types_name = template.name + "_" + label.member

        try:
            self.tt = vcs.gettexttable(text_types_name)
            self.to = vcs.gettextorientation(text_types_name)
        except ValueError:
            self.tt = vcs.createtexttable(text_types_name, label.texttable)
            self.to = vcs.createtextorientation(text_types_name,
                                                label.textorientation)

        self.height_button = self.toolbar.add_slider_button(
            self.to.height, 1, 100, "Height", update=self.update_height)

        halign = self.toolbar.add_button(
            ["Left Align", "Center Align", "Right Align"], action=self.halign)
        valign = self.toolbar.add_button(
            ["Top Align", "Half Align", "Bottom Align"], action=self.valign)

        halign.set_state(self.to.halign)
        valign.set_state(__valign_map__[self.to.valign])

        self.angle_button = self.toolbar.add_slider_button(
            self.to.angle, 0, 360, "Angle", update=self.update_angle)

        font_editor = FontEditor(self.toolbar, self.set_font,
                                 vcs.elements["fontNumber"][self.tt.font])

        self.picker = None
        self.toolbar.add_button(["Change Color"], action=self.change_color)
        self.toolbar.show()
        self.label.texttable = self.tt.name
        self.label.textorientation = self.to.name
Ejemplo n.º 7
0
    def __init__(self, interactor, label, dp, configurator):
        self.label = label
        self.display = dp
        super(LabelEditor, self).__init__(interactor, label, configurator)

        self.toolbar = vcs.vtk_ui.Toolbar(self.interactor, "%s Options" % label.member)
        template = vcs.gettemplate(dp.template)

        self.actor = get_actor(self.label, self.display)


        text_types_name = template.name + "_" + label.member

        try:
            self.tt = vcs.gettexttable(text_types_name)
            self.to = vcs.gettextorientation(text_types_name)
        except ValueError:
            self.tt = vcs.createtexttable(text_types_name, label.texttable)
            self.to = vcs.createtextorientation(text_types_name, label.textorientation)

        self.height_button = self.toolbar.add_slider_button(self.to.height, 1, 100, "Height", update=self.update_height)

        halign = self.toolbar.add_button(["Left Align", "Center Align", "Right Align"], action=self.halign)
        valign = self.toolbar.add_button(["Top Align", "Half Align", "Bottom Align"], action=self.valign)

        halign.set_state(self.to.halign)
        valign.set_state(__valign_map__[self.to.valign])

        self.angle_button = self.toolbar.add_slider_button(self.to.angle, 0, 360, "Angle", update=self.update_angle)

        font_editor = FontEditor(self.toolbar, self.set_font, vcs.elements["fontNumber"][self.tt.font])

        self.picker = None
        self.toolbar.add_button(["Change Color"], action=self.change_color)
        self.toolbar.show()
        self.label.texttable = self.tt.name
        self.label.textorientation = self.to.name
Ejemplo n.º 8
0
def build_templates(canvas=None, graphicMethodStrings=None, overlay=None, rows=1, columns=1,
                    mainTemplateOptions=None, templateOptionsArray=None, templateNameArray=None,
                    legendDirection='vertical', forceAspectRatio=False, onlyData=False, disableLegend=False):
    """
    This function generates and adjusts the templates needed to plot the diagnostic plots.
    """

    #debug:
    # debugInfoFunc(graphicMethodStrings, overlay, rows, columns,
    #               mainTemplateOptions, templateOptionsArray, templateNameArray,
    #               legendDirection, forceAspectRatio, onlyData)

    if rows == 0 or columns == 0:
        raise ValueError("One must enter a size bigger than zero for rows and columns.")
        exit(0)

    if ((graphicMethodStrings == None) or (mainTemplateOptions == None)) or ((overlay == None) or (canvas == None)):
        return (None, None)

    graphicMethodObjects = []
    
    for i in range(len(graphicMethodStrings)):  # make sure the graphics method exists
        if (graphicMethodStrings[i] == 'isofill') and ('uvwg' not in canvas.listelements('isofill')) :
            graphicMethodObjects.append(
                canvas.createisofill('uvwg_' + (str(random.random())[2:]), 'default')
            )
            
        if (graphicMethodStrings[i] == 'isoline') and ('uvwg' not in canvas.listelements('isoline')) :
            graphicMethodObjects.append(
                canvas.createisoline('uvwg_' + (str(random.random())[2:]), 'default')
            )
            
        if (graphicMethodStrings[i] == 'boxfill') and ('uvwg' not in canvas.listelements('boxfill')) :
            graphicMethodObjects.append(
                canvas.createisoline('uvwg_' + (str(random.random())[2:]), 'default')
            )
            
        if (graphicMethodStrings[i] == 'yxvsx') and ('uvwg' not in canvas.listelements('yxvsx')) :
            graphicMethodObjects.append(
                canvas.createyxvsx('uvwg_' + (str(random.random())[2:]), 'default')
            )
            if overlay[i] == 0:
                graphicMethodObjects[i].linewidth = 1.5
            else:
                graphicMethodObjects[i].linewidth = 2.0
                graphicMethodObjects[i].linetype = 'dash'
                graphicMethodObjects[i].linecolor = 242
                
        if (graphicMethodStrings[i] == 'vector') and ('uvwg' not in canvas.listelements('vector')) :
            graphicMethodObjects.append(
                canvas.createvector('uvwg_' + (str(random.random())[2:]), 'default')
            )
            ## kludge because new vectors seem to have HUGE arrows
            graphicMethodObjects[-1].scale=.03
            
        if (graphicMethodStrings[i] == 'scatter') and ('uvwg' not in canvas.listelements('scatter')) :
            graphicMethodObjects.append(
                canvas.createscatter('uvwg_' + (str(random.random())[2:]), 'default')
            )
            if overlay[i] == 0:
                graphicMethodObjects[i].markersize = 8
            else:
                graphicMethodObjects[i].linewidth = 2.0
                graphicMethodObjects[i].linecolor = 242
                graphicMethodObjects[i].markersize = 1
                
        if (graphicMethodStrings[i] == 'taylordiagram'):
            td = canvas.createtaylordiagram('taylor_' + (str(random.random())[2:]), 'default')
            graphicMethodObjects.append( td )
            #graphicMethodObjects[i].addMarker()
            #graphicMethodObjects[i].Marker.size = 8

    # if rows > columns:
    #     canvas.portrait()
    # else:
    #     canvas.landscape()

    # Creates EzTemplate
    M = EzTemplate.Multi(rows=rows, columns=columns)

    # Set EzTemplate Options
    M.legend.direction = legendDirection  # default='horizontal'

    # Font size auto-scale
    scaleFactor = gaussian(float(max(rows, columns))/10.0, 0.1, 0.45)

    # Title size auto-scale
    if (rows == columns) and (rows ==1):
        titleScaleFactor = 1.3*scaleFactor
    else:
        titleScaleFactor = linear(float(max(rows, columns)))

    # Get from yxvsx_merra_tas.py
    # Set conversion factor to multiply font height coordinates by
    #  to obtain the value in normalized coordinates.  This is set
    #  by trial-and-error:
    fontht2norm  = 0.0007
    
    dx = calcdx(M, rows, columns)
    dy = calcdy(M, rows, columns)

    # Aspect Ratio:
    if forceAspectRatio:        
        if dx > 2*dy:
            while calcdx(M, rows, columns) > 2*dy:
                M.margins.left  += 0.01
                M.margins.right += 0.01
        elif 2*dy > dx:
            while 2*calcdy(M, rows, columns) > dx:
                M.margins.top    += 0.01
                M.margins.bottom += 0.01
                
    # Adjusts margins and vertical spaces to
    # handle title-data or title-(out of box) problems
    if mainTemplateOptions.title:        
        y1_row0 = calcy1(M, 0, dy, 0.0)
        y1_row1 = calcy1(M, 1, dy, 0.0)
        y2_row1 = calcy2(y1_row1, dy, 0.0)

        title_height = 14 * fontht2norm  # 14 is the default font size
        
        if rows > 1:
            Mt         = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)        
            Mt.margins = M.margins
            Mt.spacing = M.spacing
            
            # Avoiding overlay of titles and xnames:
            templateAbove = Mt.get(row=0, column=0, legend='local', font=False)
            templateBelow = Mt.get(row=1, column=0, legend='local', font=False)
            titleBelowY2  = title_height + templateBelow.title.y                                   
            xnameAboveY   = templateAbove.xname.y
            
            del templateAbove
            del templateBelow
            
            titleAbove_Y = 0.0
            while (titleBelowY2 > xnameAboveY):
                Mt.spacing.vertical  += 0.01
                templateBelow         = Mt.get(row=1, column=0, legend='local', font=False)
                templateAbove         = Mt.get(row=0, column=0, legend='local', font=False)
                titleBelowY2          = title_height + templateBelow.title.y
                xnameAboveY           = templateAbove.xname.y
                titleAbove_Y          = templateAbove.title.y
                del templateAbove
                del templateBelow
                                                    
            # Avoiding titles out of bounds
            titleAboveY2 = title_height + titleAbove_Y
            while titleAboveY2 > 1.0:
                Mt.margins.top     += 0.01
                Mt.margins.bottom  += 0.01
                templateAbove       = Mt.get(row=0, column=0, legend='local')
                titleAboveY2        = title_height + templateAbove.title.y
                del templateAbove

            M.spacing = Mt.spacing
            M.margins = Mt.margins
            del Mt
            
        elif rows == 1:
            title_height = 60 * fontht2norm  # one plot per page has a different scale
            Mt         = EzTemplate.Multi(rows=rows, columns=columns)
            Mt.margins = M.margins
            Mt.spacing = M.spacing
            tt         = Mt.get(row=0, column=0, legend='local')
            tt.scalefont(scaleFactor)
            titley2 = title_height * scaleFactor + tt.title.y
            del tt

            # Avoiding titles out of bounds
            while titley2 > 1.0:
                Mt.margins.top    += 0.01
                Mt.margins.bottom += 0.01
                tt      = Mt.get(row=0, column=0, legend='local')
                titley2 = title_height * scaleFactor + tt.title.y
                del tt
                           
            M.margins = Mt.margins 
            M.spacing = Mt.spacing
            del Mt
    # Adjusts the Xname position related to out of page problems
    if mainTemplateOptions.xname:
        Mt         = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)        
        Mt.margins = M.margins
        Mt.spacing = M.spacing

        tt = None
        if rows > 1 :
            tt = Mt.get(row=rows-1, column=0, legend='local')
        else:
            tt = Mt.get(row=0, column=0, legend='local')

        xnameY = tt.xname.y
        del tt
       
        # 0.004 was found by trying-error procedure
        while xnameY < 0.004:
            Mt.margins.top    += 0.01
            Mt.margins.bottom += 0.01
            if rows > 1 :
                tt = Mt.get(row=rows-1, column=0, legend='local')
            else:
                tt = Mt.get(row=0, column=0, legend='local')
            xnameY = tt.xname.y
            del tt
            #print "xnameY = ", xnameY

        M.margins.top    = Mt.margins.top 
        M.margins.bottom = Mt.margins.bottom
        del Mt
        
    # Adjust the xname position related to other plots in the same page
    if mainTemplateOptions.xname:
        y1_row0 = calcy1(M, 0, dy, 0.0)
        y1_row1 = calcy1(M, 1, dy, 0.0)
        y2_row1 = calcy2(y1_row1, dy, 0.0)

        if rows > 1:
            Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)        
            Mt.margins.top        = M.margins.top
            Mt.margins.bottom     = M.margins.bottom
            Mt.spacing.vertical   = M.spacing.vertical
            Mt.spacing.horizontal = M.spacing.horizontal
            
            tt     = Mt.get(row=0, column=0, legend='local')
            xnameY = tt.xname.y
            del tt

            # Avoiding overlay of xnames and data
            while  xnameY < (y2_row1 + 0.01*y2_row1):
                Mt.spacing.vertical += 0.01
                dy      = calcdy(Mt, rows, columns)
                y1_row1 = calcy1(Mt, 1, dy, 0.0)
                y2_row1 = calcy2(y1_row1, dy, 0.0)
                #print "dy = {0}, y1_row1 = {1}, y2_row1 = {2}".format(dy, y1_row1, y2_row1)

            M.spacing.vertical = Mt.spacing.vertical
            del Mt 

    # Adjusts the Ylabel1 position related to out of page problems
    if mainTemplateOptions.ylabel1:
        Mt         = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)        
        Mt.margins = M.margins
        Mt.spacing = M.spacing

        tt = Mt.get(row=0, column=0, legend='local', font=False)
        ylabel1X = tt.ylabel1.x
        del tt
                
        while ylabel1X < 0.0:
            Mt.margins.left  += 0.01
            Mt.margins.right += 0.01
            tt       = Mt.get(row=0, column=0, legend='local')
            ylabel1X = tt.ylabel1.x
            del tt

        M.margins = Mt.margins 
        M.spacing = Mt.spacing        
        del Mt

    # Adjusts the Yname position related to out of page problems
    # if mainTemplateOptions.yname:
    #     Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)
    #     Mt.legend.direction = legendDirection
    #     Mt.margins          = M.margins
    #     Mt.spacing          = M.spacing

    #     tt = Mt.get(row=0, column=0, legend='local')
    #     ynamex = tt.yname.x
        
    #     while ynamex < 0.0:
    #         Mt.margins.left  *= 1.01
    #         Mt.margins.right *= 1.01
    #         tt     = Mt.get(row=0, column=0, legend='local')
    #         ynamex = tt.yname.x

    #     M.margins.left  = Mt.margins.left 
    #     M.margins.right = Mt.margins.right

    # Adjusts yname position related to the page margins
    if mainTemplateOptions.yname:
        Mt         = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)
        Mt.spacing = M.spacing
        Mt.margins = M.margins
        tt = Mt.get(row=0, column=0, legend='local', font=False)

        while tt.yname.x < 0.0015:
            Mt.margins.left += 0.05
            del tt
            tt = Mt.get(row=0, column=0, legend='local', font=False)
        del tt             
        
        M.margins = Mt.margins 
        M.spacing = Mt.spacing
        del Mt

    # Adjusts the Yname position related to other plots in the same page
    if mainTemplateOptions.yname and (columns > 1):
        Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)
        Mt.legend.direction = legendDirection
        Mt.margins          = M.margins
        Mt.spacing          = M.spacing

        tt = Mt.get(row=0, column=0, legend='local')
        # takes legend changes in effect...
        delta = float(tt.data.x2 - tt.data.x1)
        posx2 = tt.legend.x1 + 0.09*delta

        if posx2 > 1.0:
            posx2 = tt.legend.x1 + 0.05*delta
        legendx2 = posx2
        
        del tt        
        tt2 = Mt.get(row=0, column=1, legend='local')
        ynamex = tt2.yname.x
        del tt2

        while ynamex < legendx2:
            Mt.spacing.horizontal += 0.01
            tt = Mt.get(row=0, column=0, legend='local')
            # takes legend changes in effect...
            delta = float(tt.data.x2 - tt.data.x1)
            posx2 = tt.legend.x1 + 0.09*delta
            if posx2 > 1.0:
                posx2    = tt.legend.x1 + 0.05*delta
                legendx2 = posx2
        
            tt2    = Mt.get(row=0, column=1, legend='local')
            ynamex = tt2.yname.x
            del tt
            del tt2

        #M.spacing.horizontal = Mt.spacing.horizontal
        M.margins = Mt.margins
        M.spacing = Mt.spacing
        del Mt
 
    # Adjusts legend position
    if mainTemplateOptions.legend:
        Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)
        Mt.legend.direction = legendDirection
        Mt.margins          = M.margins
        Mt.spacing          = M.spacing
        
        tt = Mt.get(row=0, column=0, legend='local', font=False)
        # takes legend changes in effect...
        delta = float(tt.data.x2 - tt.data.x1)
        
        if legendDirection == 'vertical':
                posx2 = tt.legend.x1 + 0.09*delta
                if posx2 > 1.0:
                    posx2 = tt.legend.x1 + 0.05*delta
                legendx2 = posx2

                while legendx2 > 0.955:
                    Mt.margins.left  += 0.01
                    Mt.margins.right += 0.01
                    del tt
                    tt = Mt.get(row=0, column=0, legend='local', font=False)
                    # takes legend changes in effect...
                    delta = float(tt.data.x2 - tt.data.x1)
                    posx2 = tt.legend.x1 + 0.09*delta
                    if posx2 > 1.0:
                        posx2 = tt.legend.x1 + 0.06*delta
                    legendx2 = posx2
        elif legendDirection == 'horizontal':
            # Fix bug where ynames and values are out of bound in display but not in value.
            Mt.margins.left += 0.025
            while tt.ylabel1.x < 0.0015:
                Mt.margins.left += 0.1
                del tt
                tt = Mt.get(row=0, column=0, legend='local', font=False)
            
        M.margins.left  = Mt.margins.left
        M.margins.right = Mt.margins.right
        del Mt

    # Adjusts vertical spacing if Mean is enabled and the aspect-ration is being forced:
    if mainTemplateOptions.mean and forceAspectRatio:
        Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)        
        Mt.margins.top        = M.margins.top
        Mt.margins.bottom     = M.margins.bottom
        Mt.spacing.vertical   = M.spacing.vertical
        Mt.spacing.horizontal = M.spacing.horizontal
        
        tt = Mt.get(row=0, column=0, legend='local')
        tt.scalefont(scaleFactor)
        tt.mean.x                = tt.title.x
        mean_orientation         = vcs.gettextorientation(tt.mean.textorientation)
        mean_orientation.halign  = "center"
        mean_orientation.valign  = "top"
        mean_orientation.height *= scaleFactor*0.7
        tt.mean.textorientation  = mean_orientation
        mean_orientation = None
        # 0.009 was found empirically
        if math.fabs(tt.mean.y - tt.data.y2) < 0.009:
            while math.fabs(tt.mean.y - tt.data.y2) < 0.009:
                Mt.margins.top    += 0.01
                Mt.margins.bottom += 0.01
                del tt
                tt = Mt.get(row=0, column=0, legend='local')
                tt.scalefont(scaleFactor)

            M.margins.top    = Mt.margins.top 
            M.margins.bottom = Mt.margins.bottom
            del Mt
        else:
            del tt

    ######################
    # Generating Templates
    
    finalTemplates = []
    
    for i in range(len(graphicMethodStrings)):
        if (len(overlay) > 1) and (overlay[i] == 1):
            lastTemplate = finalTemplates[-1]
            cpLastTemplate = canvas.createtemplate(lastTemplate.name+'_overlay', lastTemplate.name)
            # Avoiding legend overlaping.
            cpLastTemplate.legend.y1 += 0.01
            setTemplateOptions(cpLastTemplate, templateOptionsArray[i])
            finalTemplates.append(cpLastTemplate)
            continue
        
        # Template name
        #if (templateNameArray is not None) and (len(templateNameArray) > i):
        #    M.template = templateNameArray[i]
        
        if (templateNameArray is not None) and (len(templateNameArray) > i):         
            template = M.get(legend='local',tname=templateNameArray[i])
        else:
            template = M.get(legend='local')

        # scale fonts
        template.scalefont(scaleFactor)

        if mainTemplateOptions.title:
            # Align title
            delta                          = template.data.x2 - template.data.x1
            template.title.x               = template.data.x1 + float(delta)/2.0
            if rows == 1:
                template.title.y              *= 0.99
            title_orientation              = vcs.createtextorientation()
            title_orientation.halign       = "center"
            title_orientation.height      *= titleScaleFactor # 100 * deltaY  # default = 14
            template.title.textorientation = title_orientation
            title_orientation = None
            
        if mainTemplateOptions.dataname:
            template.dataname.x               = template.data.x1
            template.dataname.y               = template.data.y2 + 0.01
            dataname_orientation              = vcs.gettextorientation(template.dataname.textorientation)
            dataname_orientation.height      *= 0.98
            template.dataname.textorientation = dataname_orientation
            dataname_orientation = None
            
        if mainTemplateOptions.legend:
            if legendDirection == 'vertical':
                template.legend.offset += 0.0095
                # Adjusting legend position
                delta = template.data.x2 - template.data.x1
                posx2 = template.legend.x1 + 0.08*delta
                if posx2 > 1.0:
                    posx2 = template.legend.x1 + 0.05*delta
                template.legend.x2 = posx2
            elif legendDirection == 'horizontal':
                # Adjusting legend position
                template.legend.x1 = template.data.x1
                template.legend.x2 = template.data.x2
                deltaL = template.legend.y2 - template.legend.y1
                template.legend.y2 = template.xname.y - 0.03
                template.legend.y1 = template.legend.y2 - deltaL - 0.01
          
        if mainTemplateOptions.mean:
            # Align Mean
            template.mean.x               = template.title.x
            if rows == 1:
                template.mean.y              *= 0.99
            mean_orientation              = vcs.createtextorientation()
            mean_orientation.halign       = "center"
            #mean_orientation.valign       = "top"
            if (rows == columns) and (rows ==1):
                mean_orientation.height      *= scaleFactor*0.88
            else:
                mean_orientation.height      *= scaleFactor*0.65
            template.mean.textorientation = mean_orientation
            mean_orientation = None

        if mainTemplateOptions.xname:
            #template.xname.y              *= 1.01
            xname_orientation              = vcs.gettextorientation(template.xname.textorientation)
            xname_orientation.halign       = "center"
            #xname_orientation.valign       = "bottom"
            xname_orientation.height      *= 0.85
            template.xname.textorientation = xname_orientation
            xname_orientation = None

        if mainTemplateOptions.yname:
            #template.yname.y              *= 1.01
            yname_orientation              = vcs.gettextorientation(template.yname.textorientation)
            yname_orientation.halign       = "center"
            #yname_orientation.valign       = "top"
            yname_orientation.height      *= 0.85
            template.yname.textorientation = yname_orientation
            yname_orientation = None

        if mainTemplateOptions.xlabel1:
            #template.xlabel1.y              *= 1.01
            xlabel1_orientation              = vcs.gettextorientation(template.xlabel1.textorientation)
            #xlabel1_orientation.halign       = "center"
            #xlabel1_orientation.valign       = "bottom"
            xlabel1_orientation.height      *= 0.85
            template.xlabel1.textorientation = xlabel1_orientation
            xlabel1_orientation = None

        if mainTemplateOptions.ylabel1:
            #template.ylabel1.y              *= 1.01
            ylabel1_orientation              = vcs.gettextorientation(template.ylabel1.textorientation)
            #ylabel1_orientation.halign       = "center"
            #ylabel1_orientation.valign       = "bottom"
            ylabel1_orientation.height      *= 0.85
            template.ylabel1.textorientation = ylabel1_orientation
            ylabel1_orientation = None

        if mainTemplateOptions.units:
            template.units.x = template.data.x2 - (5*14*fontht2norm) # 5 charactes
            if mainTemplateOptions.mean:
                template.units.y = template.mean.y
            else:
                template.units.y = template.data.y2 + 0.01
            units_orientation              = vcs.gettextorientation(template.units.textorientation)
            units_orientation.halign       = "left"
            #units_orientation.valign       = "bottom"
            units_orientation.height      *= 0.85
            template.units.textorientation = units_orientation
            units_orientation = None

        if mainTemplateOptions.min:
            template.min.x = template.legend.x1

        if mainTemplateOptions.max:
            minTo          = canvas.gettextorientation(template.min.textorientation)
            minheight      = minTo.height * fontht2norm
            minTo = None
            template.max.x = template.legend.x1
            if (rows == columns) and (rows ==1):
                template.max.y = template.min.y - 1.55*minheight
            else:
                template.max.y = template.min.y - 1.35*minheight 

        if onlyData:
            dudTemplate = TemplateOptions()
            dudTemplate.setAllFalse()
            dudTemplate.data = True
            setTemplateOptions(template, dudTemplate)
        else:
            if (templateOptionsArray is not None) and (len(templateOptionsArray) > i):
                setTemplateOptions(template, templateOptionsArray[i])
            else:
                setTemplateOptions(template, mainTemplateOptions)    

        if disableLegend == True:
            template.legend.priority = 0
                
        finalTemplates.append(template)        

    return (graphicMethodObjects, finalTemplates)
Ejemplo n.º 9
0
def build_templates(canvas=None,
                    graphicMethodStrings=None,
                    overlay=None,
                    rows=1,
                    columns=1,
                    mainTemplateOptions=None,
                    templateOptionsArray=None,
                    templateNameArray=None,
                    legendDirection='vertical',
                    forceAspectRatio=False,
                    onlyData=False,
                    disableLegend=False):
    """
    This function generates and adjusts the templates needed to plot the diagnostic plots.
    """

    #debug:
    # debugInfoFunc(graphicMethodStrings, overlay, rows, columns,
    #               mainTemplateOptions, templateOptionsArray, templateNameArray,
    #               legendDirection, forceAspectRatio, onlyData)

    if rows == 0 or columns == 0:
        raise ValueError(
            "One must enter a size bigger than zero for rows and columns.")
        exit(0)

    if ((graphicMethodStrings == None) or
        (mainTemplateOptions == None)) or ((overlay == None) or
                                           (canvas == None)):
        return (None, None)

    graphicMethodObjects = []

    for i in range(
            len(graphicMethodStrings)):  # make sure the graphics method exists
        if (graphicMethodStrings[i]
                == 'isofill') and ('uvwg'
                                   not in canvas.listelements('isofill')):
            graphicMethodObjects.append(
                canvas.createisofill('uvwg_' + (str(random.random())[2:]),
                                     'default'))

        if (graphicMethodStrings[i]
                == 'isoline') and ('uvwg'
                                   not in canvas.listelements('isoline')):
            graphicMethodObjects.append(
                canvas.createisoline('uvwg_' + (str(random.random())[2:]),
                                     'default'))

        if (graphicMethodStrings[i]
                == 'boxfill') and ('uvwg'
                                   not in canvas.listelements('boxfill')):
            graphicMethodObjects.append(
                canvas.createisoline('uvwg_' + (str(random.random())[2:]),
                                     'default'))

        if (graphicMethodStrings[i]
                == 'yxvsx') and ('uvwg' not in canvas.listelements('yxvsx')):
            graphicMethodObjects.append(
                canvas.createyxvsx('uvwg_' + (str(random.random())[2:]),
                                   'default'))
            if overlay[i] == 0:
                graphicMethodObjects[i].linewidth = 1.5
            else:
                graphicMethodObjects[i].linewidth = 2.0
                graphicMethodObjects[i].line = 'dash'
                graphicMethodObjects[i].linecolor = 242

        if (graphicMethodStrings[i]
                == 'vector') and ('uvwg' not in canvas.listelements('vector')):
            graphicMethodObjects.append(
                canvas.createvector('uvwg_' + (str(random.random())[2:]),
                                    'default'))

        if (graphicMethodStrings[i]
                == 'scatter') and ('uvwg'
                                   not in canvas.listelements('scatter')):
            graphicMethodObjects.append(
                canvas.createscatter('uvwg_' + (str(random.random())[2:]),
                                     'default'))
            if overlay[i] == 0:
                graphicMethodObjects[i].markersize = 8
            else:
                graphicMethodObjects[i].linewidth = 2.0
                graphicMethodObjects[i].linecolor = 242
                graphicMethodObjects[i].markersize = 1

        if (graphicMethodStrings[i] == 'taylordiagram'):
            td = canvas.createtaylordiagram(
                'taylor_' + (str(random.random())[2:]), 'default')
            graphicMethodObjects.append(td)
            #graphicMethodObjects[i].addMarker()
            #graphicMethodObjects[i].Marker.size = 8

    # if rows > columns:
    #     canvas.portrait()
    # else:
    #     canvas.landscape()

    # Creates EzTemplate
    M = EzTemplate.Multi(rows=rows, columns=columns)

    # Set EzTemplate Options
    M.legend.direction = legendDirection  # default='horizontal'

    # Font size auto-scale
    scaleFactor = gaussian(float(max(rows, columns)) / 10.0, 0.1, 0.45)

    # Title size auto-scale
    if (rows == columns) and (rows == 1):
        titleScaleFactor = 1.3 * scaleFactor
    else:
        titleScaleFactor = linear(float(max(rows, columns)))

    # Get from yxvsx_merra_tas.py
    # Set conversion factor to multiply font height coordinates by
    #  to obtain the value in normalized coordinates.  This is set
    #  by trial-and-error:
    fontht2norm = 0.0007

    dx = calcdx(M, rows, columns)
    dy = calcdy(M, rows, columns)

    # Aspect Ratio:
    if forceAspectRatio:
        if dx > 2 * dy:
            while calcdx(M, rows, columns) > 2 * dy:
                M.margins.left += 0.01
                M.margins.right += 0.01
        elif 2 * dy > dx:
            while 2 * calcdy(M, rows, columns) > dx:
                M.margins.top += 0.01
                M.margins.bottom += 0.01

    # Adjusts margins and vertical spaces to
    # handle title-data or title-(out of box) problems
    if mainTemplateOptions.title:
        y1_row0 = calcy1(M, 0, dy, 0.0)
        y1_row1 = calcy1(M, 1, dy, 0.0)
        y2_row1 = calcy2(y1_row1, dy, 0.0)

        title_height = 14 * fontht2norm  # 14 is the default font size

        if rows > 1:
            Mt = EzTemplate.Multi(rows=rows,
                                  columns=columns,
                                  legend_direction=legendDirection)
            Mt.margins = M.margins
            Mt.spacing = M.spacing

            # Avoiding overlay of titles and xnames:
            templateAbove = Mt.get(row=0, column=0, legend='local', font=False)
            templateBelow = Mt.get(row=1, column=0, legend='local', font=False)
            titleBelowY2 = title_height + templateBelow.title.y

            while titleBelowY2 > templateAbove.xname.y:
                Mt.spacing.vertical += 0.01
                templateBelow = Mt.get(row=1,
                                       column=0,
                                       legend='local',
                                       font=False)
                templateAbove = Mt.get(row=0,
                                       column=0,
                                       legend='local',
                                       font=False)
                titleBelowY2 = title_height + templateBelow.title.y

            # Avoiding titles out of bounds
            titleAboveY2 = title_height + templateAbove.title.y
            while titleAboveY2 > 1.0:
                Mt.margins.top += 0.01
                Mt.margins.bottom += 0.01
                templateAbove = Mt.get(row=0, column=0, legend='local')
                titleAboveY2 = title_height + templateAbove.title.y

            M.spacing = Mt.spacing
            M.margins = Mt.margins

        elif rows == 1:
            title_height = 60 * fontht2norm  # one plot per page has a different scale
            Mt = EzTemplate.Multi(rows=rows, columns=columns)
            Mt.margins = M.margins
            Mt.spacing = M.spacing
            tt = Mt.get(row=0, column=0, legend='local')
            tt.scalefont(scaleFactor)
            titley2 = title_height * scaleFactor + tt.title.y

            # Avoiding titles out of bounds
            while titley2 > 1.0:
                Mt.margins.top += 0.01
                Mt.margins.bottom += 0.01
                tt = Mt.get(row=0, column=0, legend='local')
                titley2 = title_height * scaleFactor + tt.title.y

            M.margins = Mt.margins
            M.spacing = Mt.spacing

    # Adjusts the Xname position related to out of page problems
    if mainTemplateOptions.xname:
        Mt = EzTemplate.Multi(rows=rows,
                              columns=columns,
                              legend_direction=legendDirection)
        Mt.margins = M.margins
        Mt.spacing = M.spacing

        tt = None
        if rows > 1:
            tt = Mt.get(row=rows - 1, column=0, legend='local')
        else:
            tt = Mt.get(row=0, column=0, legend='local')

        xnameY = tt.xname.y

        # 0.004 was found by trying-error procedure
        while xnameY < 0.004:
            Mt.margins.top += 0.01
            Mt.margins.bottom += 0.01
            if rows > 1:
                tt = Mt.get(row=rows - 1, column=0, legend='local')
            else:
                tt = Mt.get(row=0, column=0, legend='local')
            xnameY = tt.xname.y
            #print "xnameY = ", xnameY

        M.margins.top = Mt.margins.top
        M.margins.bottom = Mt.margins.bottom

    # Adjust the xname position related to other plots in the same page
    if mainTemplateOptions.xname:
        y1_row0 = calcy1(M, 0, dy, 0.0)
        y1_row1 = calcy1(M, 1, dy, 0.0)
        y2_row1 = calcy2(y1_row1, dy, 0.0)

        if rows > 1:
            Mt = EzTemplate.Multi(rows=rows,
                                  columns=columns,
                                  legend_direction=legendDirection)
            Mt.margins.top = M.margins.top
            Mt.margins.bottom = M.margins.bottom
            Mt.spacing.vertical = M.spacing.vertical
            Mt.spacing.horizontal = M.spacing.horizontal

            tt = Mt.get(row=0, column=0, legend='local')
            xnameY = tt.xname.y

            # Avoiding overlay of xnames and data
            while xnameY < (y2_row1 + 0.01 * y2_row1):
                Mt.spacing.vertical += 0.01
                dy = calcdy(Mt, rows, columns)
                y1_row1 = calcy1(Mt, 1, dy, 0.0)
                y2_row1 = calcy2(y1_row1, dy, 0.0)
                #print "dy = {0}, y1_row1 = {1}, y2_row1 = {2}".format(dy, y1_row1, y2_row1)

            M.spacing.vertical = Mt.spacing.vertical

    # Adjusts the Ylabel1 position related to out of page problems
    if mainTemplateOptions.ylabel1:
        Mt = EzTemplate.Multi(rows=rows,
                              columns=columns,
                              legend_direction=legendDirection)
        Mt.margins = M.margins
        Mt.spacing = M.spacing

        tt = Mt.get(row=0, column=0, legend='local', font=False)
        ylabel1X = tt.ylabel1.x

        while ylabel1X < 0.0:
            Mt.margins.left += 0.01
            Mt.margins.right += 0.01
            tt = Mt.get(row=0, column=0, legend='local')
            ylabel1X = tt.ylabel1.x

        M.margins = Mt.margins
        M.spacing = Mt.spacing

    # Adjusts the Yname position related to out of page problems
    # if mainTemplateOptions.yname:
    #     Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection)
    #     Mt.legend.direction = legendDirection
    #     Mt.margins          = M.margins
    #     Mt.spacing          = M.spacing

    #     tt = Mt.get(row=0, column=0, legend='local')
    #     ynamex = tt.yname.x

    #     while ynamex < 0.0:
    #         Mt.margins.left  *= 1.01
    #         Mt.margins.right *= 1.01
    #         tt     = Mt.get(row=0, column=0, legend='local')
    #         ynamex = tt.yname.x

    #     M.margins.left  = Mt.margins.left
    #     M.margins.right = Mt.margins.right

    # Adjusts yname position related to the page margins
    if mainTemplateOptions.yname:
        Mt = EzTemplate.Multi(rows=rows,
                              columns=columns,
                              legend_direction=legendDirection)
        Mt.spacing = M.spacing
        Mt.margins = M.margins
        tt = Mt.get(row=0, column=0, legend='local', font=False)

        while tt.yname.x < 0.0015:
            Mt.margins.left += 0.05
            tt = Mt.get(row=0, column=0, legend='local', font=False)

        M.margins = Mt.margins
        M.spacing = Mt.spacing

    # Adjusts the Yname position related to other plots in the same page
    if mainTemplateOptions.yname and (columns > 1):
        Mt = EzTemplate.Multi(rows=rows,
                              columns=columns,
                              legend_direction=legendDirection)
        Mt.legend.direction = legendDirection
        Mt.margins = M.margins
        Mt.spacing = M.spacing

        tt = Mt.get(row=0, column=0, legend='local')
        # takes legend changes in effect...
        delta = float(tt.data.x2 - tt.data.x1)
        posx2 = tt.legend.x1 + 0.09 * delta
        if posx2 > 1.0:
            posx2 = tt.legend.x1 + 0.05 * delta
        legendx2 = posx2

        tt2 = Mt.get(row=0, column=1, legend='local')
        ynamex = tt2.yname.x

        while ynamex < legendx2:
            Mt.spacing.horizontal += 0.01
            tt = Mt.get(row=0, column=0, legend='local')
            # takes legend changes in effect...
            delta = float(tt.data.x2 - tt.data.x1)
            posx2 = tt.legend.x1 + 0.09 * delta
            if posx2 > 1.0:
                posx2 = tt.legend.x1 + 0.05 * delta
                legendx2 = posx2

            tt2 = Mt.get(row=0, column=1, legend='local')
            ynamex = tt2.yname.x

        #M.spacing.horizontal = Mt.spacing.horizontal
        M.margins = Mt.margins
        M.spacing = Mt.spacing

    # Adjusts legend position
    if mainTemplateOptions.legend:
        Mt = EzTemplate.Multi(rows=rows,
                              columns=columns,
                              legend_direction=legendDirection)
        Mt.legend.direction = legendDirection
        Mt.margins = M.margins
        Mt.spacing = M.spacing

        tt = Mt.get(row=0, column=0, legend='local', font=False)
        # takes legend changes in effect...
        delta = float(tt.data.x2 - tt.data.x1)

        if legendDirection == 'vertical':
            posx2 = tt.legend.x1 + 0.09 * delta
            if posx2 > 1.0:
                posx2 = tt.legend.x1 + 0.05 * delta
            legendx2 = posx2

            while legendx2 > 0.96:
                Mt.margins.left += 0.02
                Mt.margins.right += 0.02
                tt = Mt.get(row=0, column=0, legend='local', font=False)
                # takes legend changes in effect...
                delta = float(tt.data.x2 - tt.data.x1)
                posx2 = tt.legend.x1 + 0.09 * delta
                if posx2 > 1.0:
                    posx2 = tt.legend.x1 + 0.06 * delta
                legendx2 = posx2
        elif legendDirection == 'horizontal':
            # Fix bug where ynames and values are out of bound in display but not in value.
            Mt.margins.left += 0.025
            while tt.ylabel1.x < 0.0015:
                Mt.margins.left += 0.1
                tt = Mt.get(row=0, column=0, legend='local', font=False)

        M.margins.left = Mt.margins.left
        M.margins.right = Mt.margins.right

    # Adjusts vertical spacing if Mean is enabled and the aspect-ration is being forced:
    if mainTemplateOptions.mean and forceAspectRatio:
        Mt = EzTemplate.Multi(rows=rows,
                              columns=columns,
                              legend_direction=legendDirection)
        Mt.margins.top = M.margins.top
        Mt.margins.bottom = M.margins.bottom
        Mt.spacing.vertical = M.spacing.vertical
        Mt.spacing.horizontal = M.spacing.horizontal

        tt = Mt.get(row=0, column=0, legend='local')
        tt.scalefont(scaleFactor)
        tt.mean.x = tt.title.x
        mean_orientation = vcs.gettextorientation(tt.mean.textorientation)
        mean_orientation.halign = "center"
        mean_orientation.valign = "top"
        mean_orientation.height *= scaleFactor * 0.7
        tt.mean.textorientation = mean_orientation

        # 0.009 was found empirically
        if math.fabs(tt.mean.y - tt.data.y2) < 0.009:
            while math.fabs(tt.mean.y - tt.data.y2) < 0.009:
                Mt.margins.top += 0.01
                Mt.margins.bottom += 0.01
                tt = Mt.get(row=0, column=0, legend='local')
                tt.scalefont(scaleFactor)

            M.margins.top = Mt.margins.top
            M.margins.bottom = Mt.margins.bottom

    ######################
    # Generating Templates

    finalTemplates = []

    for i in range(len(graphicMethodStrings)):
        if (len(overlay) > 1) and (overlay[i] == 1):
            lastTemplate = finalTemplates[-1]
            cpLastTemplate = canvas.createtemplate(
                lastTemplate.name + '_overlay', lastTemplate.name)
            # Avoiding legend overlaping.
            cpLastTemplate.legend.y1 += 0.01
            setTemplateOptions(cpLastTemplate, templateOptionsArray[i])
            finalTemplates.append(cpLastTemplate)
            continue

        # Template name
        #if (templateNameArray is not None) and (len(templateNameArray) > i):
        #    M.template = templateNameArray[i]

        # Legend into plot area
        template = M.get(legend='local')

        # scale fonts
        template.scalefont(scaleFactor)

        if mainTemplateOptions.title:
            # Align title
            delta = template.data.x2 - template.data.x1
            template.title.x = template.data.x1 + float(delta) / 2.0
            if rows == 1:
                template.title.y *= 0.99
            title_orientation = vcs.createtextorientation()
            title_orientation.halign = "center"
            title_orientation.height *= titleScaleFactor  # 100 * deltaY  # default = 14
            template.title.textorientation = title_orientation

        if mainTemplateOptions.dataname:
            template.dataname.x = template.data.x1
            template.dataname.y = template.data.y2 + 0.01
            dataname_orientation = vcs.gettextorientation(
                template.dataname.textorientation)
            dataname_orientation.height *= 0.98
            template.dataname.textorientation = dataname_orientation

        if mainTemplateOptions.legend:
            if legendDirection == 'vertical':
                # Adjusting legend position
                delta = template.data.x2 - template.data.x1
                posx2 = template.legend.x1 + 0.08 * delta
                if posx2 > 1.0:
                    posx2 = template.legend.x1 + 0.05 * delta
                template.legend.x2 = posx2
            elif legendDirection == 'horizontal':
                # Adjusting legend position
                template.legend.x1 = template.data.x1
                template.legend.x2 = template.data.x2
                deltaL = template.legend.y2 - template.legend.y1
                template.legend.y2 = template.xname.y - 0.03
                template.legend.y1 = template.legend.y2 - deltaL - 0.01

        if mainTemplateOptions.mean:
            # Align Mean
            template.mean.x = template.title.x
            if rows == 1:
                template.mean.y *= 0.99
            mean_orientation = vcs.createtextorientation()
            mean_orientation.halign = "center"
            #mean_orientation.valign       = "top"
            if (rows == columns) and (rows == 1):
                mean_orientation.height *= scaleFactor * 0.88
            else:
                mean_orientation.height *= scaleFactor * 0.65
            template.mean.textorientation = mean_orientation

        if mainTemplateOptions.xname:
            #template.xname.y              *= 1.01
            xname_orientation = vcs.gettextorientation(
                template.xname.textorientation)
            xname_orientation.halign = "center"
            #xname_orientation.valign       = "bottom"
            xname_orientation.height *= 0.85
            template.xname.textorientation = xname_orientation

        if mainTemplateOptions.yname:
            #template.yname.y              *= 1.01
            yname_orientation = vcs.gettextorientation(
                template.yname.textorientation)
            yname_orientation.halign = "center"
            #yname_orientation.valign       = "top"
            yname_orientation.height *= 0.85
            template.yname.textorientation = yname_orientation

        if mainTemplateOptions.xlabel1:
            #template.xlabel1.y              *= 1.01
            xlabel1_orientation = vcs.gettextorientation(
                template.xlabel1.textorientation)
            #xlabel1_orientation.halign       = "center"
            #xlabel1_orientation.valign       = "bottom"
            xlabel1_orientation.height *= 0.85
            template.xlabel1.textorientation = xlabel1_orientation

        if mainTemplateOptions.ylabel1:
            #template.ylabel1.y              *= 1.01
            ylabel1_orientation = vcs.gettextorientation(
                template.ylabel1.textorientation)
            #ylabel1_orientation.halign       = "center"
            #ylabel1_orientation.valign       = "bottom"
            ylabel1_orientation.height *= 0.85
            template.ylabel1.textorientation = ylabel1_orientation

        if mainTemplateOptions.units:
            template.units.x = template.data.x2 - (5 * 14 * fontht2norm
                                                   )  # 5 charactes
            if mainTemplateOptions.mean:
                template.units.y = template.mean.y
            else:
                template.units.y = template.data.y2 + 0.01
            units_orientation = vcs.gettextorientation(
                template.units.textorientation)
            units_orientation.halign = "left"
            #units_orientation.valign       = "bottom"
            units_orientation.height *= 0.85
            template.units.textorientation = units_orientation

        if mainTemplateOptions.min:
            template.min.x = template.legend.x1

        if mainTemplateOptions.max:
            minTo = canvas.gettextorientation(template.min.textorientation)
            minheight = minTo.height * fontht2norm
            template.max.x = template.legend.x1
            if (rows == columns) and (rows == 1):
                template.max.y = template.min.y - 1.55 * minheight
            else:
                template.max.y = template.min.y - 1.35 * minheight

        if onlyData:
            dudTemplate = TemplateOptions()
            dudTemplate.setAllFalse()
            dudTemplate.data = True
            setTemplateOptions(template, dudTemplate)
        else:
            if (templateOptionsArray
                    is not None) and (len(templateOptionsArray) > i):
                setTemplateOptions(template, templateOptionsArray[i])
            else:
                setTemplateOptions(template, mainTemplateOptions)

        if disableLegend == True:
            template.legend.priority = 0

        finalTemplates.append(template)

    return (graphicMethodObjects, finalTemplates)
Ejemplo n.º 10
0
    def generateTemplate(self):
        template = vcs.createtemplate()
        # Now sets all the things for the template...
        # Sets a bunch of template attributes to off
        for att in [
            'line1', 'line2', 'line3', 'line4',
            'box2', 'box3', 'box4',
            'min', 'max', 'mean',
            'xtic1', 'xtic2',
            'ytic1', 'ytic2',
            'xvalue', 'yvalue', 'zvalue', 'tvalue',
            'xunits', 'yunits', 'zunits', 'tunits',
            'source', 'title', 'dataname',
        ]:
            a = getattr(template, att)
            setattr(a, 'priority', 0)
        for att in [
            'xname', 'yname',
        ]:
            a = getattr(template, att)
            setattr(a, 'priority', 0)

        template.data.x1 = self.PLOT_SETTINGS.x1
        template.data.x2 = self.PLOT_SETTINGS.x2
        template.data.y1 = self.PLOT_SETTINGS.y1
        template.data.y2 = self.PLOT_SETTINGS.y2
        template.box1.x1 = self.PLOT_SETTINGS.x1
        template.box1.x2 = self.PLOT_SETTINGS.x2
        template.box1.y1 = self.PLOT_SETTINGS.y1
        template.box1.y2 = self.PLOT_SETTINGS.y2
        template.xname.y = self.PLOT_SETTINGS.y2 + .02
        template.yname.x = self.PLOT_SETTINGS.x2 + .01
        template.xlabel1.y = self.PLOT_SETTINGS.y1
        template.xlabel2.y = self.PLOT_SETTINGS.y2
        template.xlabel1.texttable = self.PLOT_SETTINGS.tictable
        template.xlabel2.texttable = self.PLOT_SETTINGS.tictable
        template.xlabel1.textorientation = \
            self.PLOT_SETTINGS.xticorientation
        template.xlabel2.textorientation = \
            self.PLOT_SETTINGS.xticorientation
        template.ylabel1.x = self.PLOT_SETTINGS.x1
        template.ylabel2.x = self.PLOT_SETTINGS.x2
        template.ylabel1.texttable = self.PLOT_SETTINGS.tictable
        template.ylabel2.texttable = self.PLOT_SETTINGS.tictable
        template.ylabel1.textorientation = \
            self.PLOT_SETTINGS.yticorientation
        template.ylabel2.textorientation = \
            self.PLOT_SETTINGS.yticorientation

        if self.PLOT_SETTINGS.xtic1.y1 is not None:
            template.xtic1.y1 = self.PLOT_SETTINGS.xtic1.y1
            template.xtic1.priority = 1
        if self.PLOT_SETTINGS.xtic1.y2 is not None:
            template.xtic1.y2 = self.PLOT_SETTINGS.xtic1.y2
            template.xtic1.priority = 1
        if self.PLOT_SETTINGS.xtic2.y1 is not None:
            template.xtic2.y1 = self.PLOT_SETTINGS.xtic2.y1
            template.xtic2.priority = 1
        if self.PLOT_SETTINGS.xtic2.y2 is not None:
            template.xtic2.y2 = self.PLOT_SETTINGS.xtic2.y2
            template.xtic2.priority = 1
        if self.PLOT_SETTINGS.ytic1.x1 is not None:
            template.ytic1.x1 = self.PLOT_SETTINGS.ytic1.x1
            template.ytic1.priority = 1
        if self.PLOT_SETTINGS.ytic1.x2 is not None:
            template.ytic1.x2 = self.PLOT_SETTINGS.ytic1.x2
            template.ytic1.priority = 1
        if self.PLOT_SETTINGS.ytic2.x1 is not None:
            template.ytic2.priority = 1
            template.ytic2.x1 = self.PLOT_SETTINGS.ytic2.x1
        if self.PLOT_SETTINGS.ytic2.x2 is not None:
            template.ytic2.priority = 1
            template.ytic2.x2 = self.PLOT_SETTINGS.ytic2.x2
        template.legend.x1 = self.PLOT_SETTINGS.legend.x1
        template.legend.x2 = self.PLOT_SETTINGS.legend.x2
        template.legend.y1 = self.PLOT_SETTINGS.legend.y1
        template.legend.y2 = self.PLOT_SETTINGS.legend.y2
        try:
            tmp = vcs.createtextorientation('crap22')
        except Exception:
            tmp = vcs.gettextorientation('crap22')
        tmp.height = 12
        # tmp.halign = 'center'
        # template.legend.texttable = tmp
        template.legend.textorientation = tmp
        return template
Ejemplo n.º 11
0
def textorientation(name):
    try:
        obj = vcs.gettextorientation(str(name))
    except:
        abort(404)
    return jsonify(vcs.utils.dumpToDict(obj)[0])
Ejemplo n.º 12
0
 def testScaleFontsTemplate(self):
     t = vcs.createtemplate()
     sz = vcs.gettextorientation(t.legend.textorientation).height
     t.scalefont(5.)
     sz2 = vcs.gettextorientation(t.legend.textorientation).height
     self.assertEqual(sz * 5., sz2)
Ejemplo n.º 13
0
    def generateTemplate(self):
        template = vcs.createtemplate()
        # Now sets all the things for the template...
        # Sets a bunch of template attributes to off
        for att in [
                "line1",
                "line2",
                "line3",
                "line4",
                "box2",
                "box3",
                "box4",
                "min",
                "max",
                "mean",
                "xtic1",
                "xtic2",
                "ytic1",
                "ytic2",
                "xvalue",
                "yvalue",
                "zvalue",
                "tvalue",
                "xunits",
                "yunits",
                "zunits",
                "tunits",
                "source",
                "title",
                "dataname",
        ]:
            a = getattr(template, att)
            setattr(a, "priority", 0)
        for att in [
                "xname",
                "yname",
        ]:
            a = getattr(template, att)
            setattr(a, "priority", 0)

        template.data.x1 = self.PLOT_SETTINGS.x1
        template.data.x2 = self.PLOT_SETTINGS.x2
        template.data.y1 = self.PLOT_SETTINGS.y1
        template.data.y2 = self.PLOT_SETTINGS.y2
        template.box1.x1 = self.PLOT_SETTINGS.x1
        template.box1.x2 = self.PLOT_SETTINGS.x2
        template.box1.y1 = self.PLOT_SETTINGS.y1
        template.box1.y2 = self.PLOT_SETTINGS.y2
        template.xname.y = self.PLOT_SETTINGS.y2 + 0.02
        template.yname.x = self.PLOT_SETTINGS.x2 + 0.01
        template.xlabel1.y = self.PLOT_SETTINGS.y1
        template.xlabel2.y = self.PLOT_SETTINGS.y2
        template.xlabel1.texttable = self.PLOT_SETTINGS.tictable
        template.xlabel2.texttable = self.PLOT_SETTINGS.tictable
        template.xlabel1.textorientation = self.PLOT_SETTINGS.xticorientation
        template.xlabel2.textorientation = self.PLOT_SETTINGS.xticorientation
        template.ylabel1.x = self.PLOT_SETTINGS.x1
        template.ylabel2.x = self.PLOT_SETTINGS.x2
        template.ylabel1.texttable = self.PLOT_SETTINGS.tictable
        template.ylabel2.texttable = self.PLOT_SETTINGS.tictable
        template.ylabel1.textorientation = self.PLOT_SETTINGS.yticorientation
        template.ylabel2.textorientation = self.PLOT_SETTINGS.yticorientation

        if self.PLOT_SETTINGS.xtic1.y1 is not None:
            template.xtic1.y1 = self.PLOT_SETTINGS.xtic1.y1
            template.xtic1.priority = 1
        if self.PLOT_SETTINGS.xtic1.y2 is not None:
            template.xtic1.y2 = self.PLOT_SETTINGS.xtic1.y2
            template.xtic1.priority = 1
        if self.PLOT_SETTINGS.xtic2.y1 is not None:
            template.xmintic2.y1 = self.PLOT_SETTINGS.xtic2.y1
            template.xmintic2.priority = 1
        if self.PLOT_SETTINGS.xtic2.y2 is not None:
            template.xmintic2.y2 = self.PLOT_SETTINGS.xtic2.y2
            template.xmintic2.priority = 1
        if self.PLOT_SETTINGS.ytic1.x1 is not None:
            template.ytic1.x1 = self.PLOT_SETTINGS.ytic1.x1
            template.ytic1.priority = 1
        if self.PLOT_SETTINGS.ytic1.x2 is not None:
            template.ytic1.x2 = self.PLOT_SETTINGS.ytic1.x2
            template.ytic1.priority = 1
        if self.PLOT_SETTINGS.ytic2.x1 is not None:
            template.ymintic2.priority = 1
            template.ymintic2.x1 = self.PLOT_SETTINGS.ytic2.x1
        if self.PLOT_SETTINGS.ytic2.x2 is not None:
            template.ymintic2.priority = 1
            template.ymintic2.x2 = self.PLOT_SETTINGS.ytic2.x2
        template.legend.x1 = self.PLOT_SETTINGS.legend.x1
        template.legend.x2 = self.PLOT_SETTINGS.legend.x2
        template.legend.y1 = self.PLOT_SETTINGS.legend.y1
        template.legend.y2 = self.PLOT_SETTINGS.legend.y2
        try:
            tmp = vcs.createtextorientation("crap22")
        except Exception:
            tmp = vcs.gettextorientation("crap22")
        tmp.height = 12
        # tmp.halign = 'center'
        # template.legend.texttable = tmp
        template.legend.textorientation = tmp
        return template