Changeset 2896 for trunk/python


Ignore:
Timestamp:
02/20/14 21:40:16 (10 years ago)
Author:
WataruKawasaki
Message:

New Development: Yes

JIRA Issue: Yes CAS-6216/6217

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: added new methods in sd.plotter2

Test Programs:

Put in Release Notes:

Module(s): sd

Description: arrows and annotation texts become available in sd.plotter2.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/plotter2.py

    r2895 r2896  
    4242    def get_vs(self):
    4343        """\
    44         returns viewsurface information as a dictionary.
     44        returns size and shape information on 'view surface' (a word used
     45        in PGPLOT, meaning the entire region of plotting) as a dictionary.
    4546        """
    4647        width = self._plotter.get_viewsurface_width()
     
    5960    def set_vs(self, width=None, unit=None, aspect=None):
    6061        """\
    61         set size/shape of graphic window or output file. ('vs' comes from
    62         'view surface' defined by PGPLOT)
     62        set size and shape of 'view surface', namely, the entire region
     63        of plotting including graphic window or output file. ('view
     64        surface' is a word used in PGPLOT)
    6365        Parameters:
    6466            width:  width of graphic window or output file.
     
    7577
    7678        Note:
    77             setting unit to 'cm', 'mm' or 'inch' results in the correct
    78             size when output device is X Window or PostScript, but not for
    79             the other cases (png). also, setting unit to 'pixel' works
    80             correctly only when output device is 'png'. this arises from
    81             the fixed size of pixel (=1/85 inch) defined in PGPLOT.
     79            setting unit to 'cm', 'mm' or 'inch' results in output with the
     80            correct size when output device is X Window or PostScript, but
     81            not for the other cases (png). also, setting unit to 'pixel'
     82            works correctly only when output device is 'png': this arises
     83            from PGPLOT's assumption on device resolution of 85 pixel/inch,
     84            though actual resolution will vary depending on device type.
     85            thus, for output with a correct size specified, users are
     86            recommended to use 'pixel' for 'png' output, and other units
     87            for 'xwindow' (the default) or PostScript output.
    8288        """
    8389        if width is None:
     
    512518    def set_xmask(self, xmin, xmax, color=None, fstyle=None, width=None, hsep=None, vpid=None):
    513519        """\
    514         add a rectangle which spans full y range.
     520        add a rectangle which spans the full y range.
    515521
    516522        Parameters:
     
    531537        if hsep   is None: hsep   = 1.0
    532538        if vpid   is None: vpid   = -1
     539       
    533540        coloridx = self.get_colorindex(color)
    534541        fstyleidx = self.get_fillstyleindex(fstyle)
     542       
    535543        self._plotter.set_mask_x(xmin, xmax, coloridx, fstyleidx, width, hsep, vpid)
     544
     545    def set_arrow(self, xtail, xhead, ytail, yhead, color=None, width=None, linestyle=None, headsize=None, headfs=None, headangle=None, headvent=None, vpid=None, arrowid=None):
     546        """\
     547        append an arrow or change existing arrow attributes.
     548
     549        Parameters:
     550            xtail:     x position of arrow tail
     551            xhead:     x position of arrow head
     552            ytail:     y position of arrow tail
     553            yhead:     y position of arrow head
     554            color:     color of arrow. see output of list_colornames().
     555                       default is "black".
     556            width:     width of arrow line and outline of arrow head.
     557                       default is 1.
     558            linestyle: line style. available styles can be listed via
     559                       list_linestyles().
     560            headsize:  size of arrow head. default is 1.0.
     561            headfs:    fill style of arrow head. see output of
     562                       list_arrowheadfillstyles(). default is "solid".
     563            headangle: acute angle of arrow head in unit of degree.
     564                       default is 45.0.
     565            headvent:  fraction of the triangular arrow-head that is
     566                       cut away from the back. 0.0 gives a triangular
     567                       wedge arrow head while 1.0 gives an open
     568                       '>'-shaped one. default is 0.3.
     569            vpid:      viewport id. when not given, the last viewport
     570                       will be the target.
     571            arrowid:   arrow id. when not given, the arrow having the
     572                       final arrow id for the specified viewport will
     573                       be the target.
     574        """
     575        if color     is None: color     = "black"
     576        if width     is None: width     = 1
     577        if linestyle is None: linestyle = "solid"
     578        if headsize  is None: headsize  = 1.0
     579        if headfs    is None: headfs    = "solid"
     580        if headangle is None: headangle = 45.0
     581        if headvent  is None: headvent  = 0.3
     582        if vpid      is None: vpid      = -1
     583        if arrowid   is None: arrowid   = -1
     584       
     585        coloridx = self.get_colorindex(color)
     586        linestyleidx = self.get_linestyleindex(linestyle)
     587        headfsidx = self.get_arrowheadfillstyleindex(headfs)
     588       
     589        self._plotter.set_arrow(xtail, xhead, ytail, yhead, coloridx, width, linestyleidx, headsize, headfsidx, headangle, headvent, vpid, arrowid)
     590
     591    def set_annotation(self, label, posx=None, posy=None, angle=None, fjust=None, size=None, style=None, color=None, bgcolor=None, vpid=None, annid=None):
     592        if posx    is None: posx    = 0.5
     593        if posy    is None: posy    = 0.5
     594        if angle   is None: angle   = 0.0
     595        if fjust   is None: fjust   = 0.5
     596        if size    is None: size    = 1.0
     597        if style   is None: style   = ""
     598        if color   is None: color   = "black"
     599        if bgcolor is None: bgcolor = "" # transparent
     600        if vpid    is None: vpid    = -1
     601        if annid   is None: annid   = -1
     602       
     603        coloridx = self.get_colorindex(color)
     604        bgcoloridx = self.get_colorindex(bgcolor) if (bgcolor.strip() != "") else bgcolor
     605       
     606        self._plotter.set_annotation(label, posx, posy, angle, fjust, size, style, coloridx, bgcoloridx, vpid, annid)
    536607
    537608    def set_xlabel(self, label, style=None, size=None, posx=None, posy=None, vpid=None):
     
    779850        print "------------------------------"
    780851
    781 """
    782     def set_annotation(self, label, posx=None, posy=None, angle=None, fjust=None, size=None, style=None, color=None, bgcolor=None, vpid=None):
    783         if posx    is None: posx    = -1.0
    784         if posy    is None: posy    = -1.0
    785         if angle   is None: angle   = 0.0
    786         if fjust   is None: fjust   = 0.5
    787         if size    is None: size    = 2.0
    788         if style   is None: style   = ""
    789         if color   is None: color   = 1 #default foreground colour (b)
    790         if bgcolor is None: bgcolor = 0 #default backgound colour (w)
    791         if vpid    is None: vpid    = -1
    792        
    793         coloridx = self.get_colorindex(color)
    794         bgcoloridx = self.get_colorindex(bgcolor)
    795         self._plotter.set_annotation(label, posx, posy, angle, fjust, size, style, coloridx, bgcoloridx, vpid)
    796 """
     852    @classmethod
     853    def get_arrowheadfillstyleindex(cls, fstyle):
     854        """\
     855        convert the given arrowhead fill style into style index used in PGPLOT.
     856        """
     857        style = fstyle.strip().lower()
     858        available_style = True
     859       
     860        if   style == "solid":   idx = 1
     861        elif style == "outline": idx = 2
     862        else: available_style = False
     863
     864        if (available_style):
     865            return idx
     866        else:
     867            raise ValueError("Unavailable fill style for arrow head.")
     868
     869    @classmethod
     870    def list_arrowheadfillstyles(cls):
     871        """\
     872        list the available fill styles for arrow head.
     873        """
     874        print "plotter2: arrow head fill style list ----"
     875        print "  (1) solid"
     876        print "  (2) outline"
     877        print "-----------------------------------------"
     878
Note: See TracChangeset for help on using the changeset viewer.