Changeset 2896 for trunk


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.


Location:
trunk
Files:
4 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
  • trunk/src/Plotter2.cpp

    r2895 r2896  
    22
    33namespace asap {
     4
     5Plotter2AnnotationInfo::Plotter2AnnotationInfo() {
     6    text = "";
     7    posx = 0.0;
     8    posy = 0.0;
     9    angle = 0.0;
     10    fjust = 0.0;
     11    size = 1.0;
     12    color = 1;    // black
     13    bgcolor = -1; // transparent
     14}
     15
     16Plotter2AnnotationInfo::~Plotter2AnnotationInfo() {
     17}
     18
     19Plotter2ArrowInfo::Plotter2ArrowInfo() {
     20    xhead = 1.0;
     21    xtail = 0.0;
     22    yhead = 1.0;
     23    ytail = 0.0;
     24    color = 1;         // black
     25    width = 1;
     26    lineStyle = 1;     // solid line
     27    headSize = 1.0;
     28    headFillStyle = 1; // solid
     29    headAngle = 45.0;
     30    headVent = 0.3;
     31}
     32
     33Plotter2ArrowInfo::~Plotter2ArrowInfo() {
     34}
    435
    536Plotter2RectInfo::Plotter2RectInfo() {
     
    71102    vData.clear();
    72103    vRect.clear();
     104    vArro.clear();
     105    vAnno.clear();
    73106
    74107    labelXString = "";
     
    104137Plotter2ViewportInfo::~Plotter2ViewportInfo() {
    105138    vData.clear();
     139    vRect.clear();
     140    vArro.clear();
     141    vAnno.clear();
    106142}
    107143
     
    353389
    354390void Plotter2::setViewport(const float xmin, const float xmax, const float ymin, const float ymax, const int id) {
     391  if (id >= (int)vInfo.size()) {
     392      return;
     393    }
    355394    Plotter2ViewportInfo* vi = &vInfo[id];
    356395
     
    365404void Plotter2::showViewport(const int inVpid) {
    366405    int vpid = inVpid;
     406    if (vpid >= (int)vInfo.size()) {
     407        return;
     408    }
    367409    if (vpid < 0) {
    368410        vpid = vInfo.size() - 1;
     
    378420void Plotter2::hideViewport(const int inVpid) {
    379421    int vpid = inVpid;
     422    if (vpid >= (int)vInfo.size()) {
     423        return;
     424    }
    380425    if (vpid < 0) {
    381426        vpid = vInfo.size() - 1;
     
    536581void Plotter2::setRangeX(const float xmin, const float xmax, const int inVpid) {
    537582    int vpid = inVpid;
     583    if (vpid >= (int)vInfo.size()) {
     584        return;
     585    }
    538586    if (vpid < 0) {
    539587        vpid = vInfo.size() - 1;
     
    553601void Plotter2::setRangeY(const float ymin, const float ymax, const int inVpid) {
    554602    int vpid = inVpid;
     603    if (vpid >= (int)vInfo.size()) {
     604        return;
     605    }
    555606    if (vpid < 0) {
    556607        vpid = vInfo.size() - 1;
     
    570621std::vector<float> Plotter2::getRangeX(const int inVpid) {
    571622    int vpid = inVpid;
     623    if (vpid >= (int)vInfo.size()) {
     624        exit(0);
     625    }
    572626    if (vpid < 0) {
    573627        vpid = vInfo.size() - 1;
     
    582636std::vector<float> Plotter2::getRangeY(const int inVpid) {
    583637    int vpid = inVpid;
     638    if (vpid >= (int)vInfo.size()) {
     639        exit(0);
     640    }
    584641    if (vpid < 0) {
    585642        vpid = vInfo.size() - 1;
     
    599656void Plotter2::setAutoRangeX(const int inVpid) {
    600657    int vpid = inVpid;
     658    if (vpid >= (int)vInfo.size()) {
     659        exit(0);
     660    }
    601661    if (vpid < 0) {
    602662        vpid = vInfo.size() - 1;
     
    614674void Plotter2::setAutoRangeY(const int inVpid) {
    615675    int vpid = inVpid;
     676    if (vpid >= (int)vInfo.size()) {
     677        exit(0);
     678    }
    616679    if (vpid < 0) {
    617680        vpid = vInfo.size() - 1;
     
    629692void Plotter2::setFontSizeDef(const float size, const int inVpid) {
    630693    int vpid = inVpid;
     694    if (vpid >= (int)vInfo.size()) {
     695        exit(0);
     696    }
    631697    if (vpid < 0) {
    632698        vpid = vInfo.size() - 1;
     
    644710void Plotter2::setTicksX(const float interval, const int num, const int inVpid) {
    645711    int vpid = inVpid;
     712    if (vpid >= (int)vInfo.size()) {
     713        exit(0);
     714    }
    646715    if (vpid < 0) {
    647716        vpid = vInfo.size() - 1;
     
    661730void Plotter2::setTicksY(const float interval, const int num, const int inVpid) {
    662731    int vpid = inVpid;
     732    if (vpid >= (int)vInfo.size()) {
     733        exit(0);
     734    }
    663735    if (vpid < 0) {
    664736        vpid = vInfo.size() - 1;
     
    683755void Plotter2::setAutoTicksX(const int inVpid) {
    684756    int vpid = inVpid;
     757    if (vpid >= (int)vInfo.size()) {
     758        exit(0);
     759    }
    685760    if (vpid < 0) {
    686761        vpid = vInfo.size() - 1;
     
    698773void Plotter2::setAutoTicksY(const int inVpid) {
    699774    int vpid = inVpid;
     775    if (vpid >= (int)vInfo.size()) {
     776        exit(0);
     777    }
    700778    if (vpid < 0) {
    701779        vpid = vInfo.size() - 1;
     
    713791void Plotter2::setNumIntervalX(const float interval, const int inVpid) {
    714792    int vpid = inVpid;
     793    if (vpid >= (int)vInfo.size()) {
     794        exit(0);
     795    }
    715796    if (vpid < 0) {
    716797        vpid = vInfo.size() - 1;
     
    728809void Plotter2::setNumIntervalY(const float interval, const int inVpid) {
    729810    int vpid = inVpid;
     811    if (vpid >= (int)vInfo.size()) {
     812        exit(0);
     813    }
    730814    if (vpid < 0) {
    731815        vpid = vInfo.size() - 1;
     
    743827void Plotter2::setNumLocationX(const std::string& side, const int inVpid) {
    744828    int vpid = inVpid;
     829    if (vpid >= (int)vInfo.size()) {
     830        exit(0);
     831    }
    745832    if (vpid < 0) {
    746833        vpid = vInfo.size() - 1;
     
    758845void Plotter2::setNumLocationY(const std::string& side, const int inVpid) {
    759846    int vpid = inVpid;
     847    if (vpid >= (int)vInfo.size()) {
     848        exit(0);
     849    }
    760850    if (vpid < 0) {
    761851        vpid = vInfo.size() - 1;
     
    773863void Plotter2::setData(const std::vector<float>& xdata, const std::vector<float>& ydata, const int inVpid, const int inDataid) {
    774864    int vpid = inVpid;
     865    if (vpid >= (int)vInfo.size()) {
     866        exit(0);
     867    }
    775868    if (vpid < 0) {
    776869        vpid = vInfo.size() - 1;
     
    789882        vi->vData.push_back(di);
    790883        dataid = vi->vData.size() - 1;
     884    } else if (dataid >= (int)vi->vData.size()) {
     885        exit(0);
    791886    }
    792887
     
    796891void Plotter2::setLine(const int color, const int width, const int style, const int inVpid, const int inDataid) {
    797892    int vpid = inVpid;
    798     if (vpid < 0) {
    799         vpid = vInfo.size() - 1;
    800     }
    801     if (vpid < 0) {
    802         Plotter2ViewportInfo vi;
    803         vInfo.push_back(vi);
    804         vpid = 0;
    805     }
     893    if (vpid >= (int)vInfo.size()) {
     894        exit(0);
     895    }
     896    if (vpid < 0) {
     897        vpid = vInfo.size() - 1;
     898    }
     899    if (vpid < 0) {
     900        Plotter2ViewportInfo vi;
     901        vInfo.push_back(vi);
     902        vpid = 0;
     903    }
     904
     905    Plotter2ViewportInfo* vi = &vInfo[vpid];
    806906
    807907    int dataid = inDataid;
    808908    if (dataid < 0) {
    809         dataid = vInfo[vpid].vData.size() - 1;
    810     }
    811 
    812     Plotter2ViewportInfo* vi = &vInfo[vpid];
    813     vi->vData[dataid].drawLine  = true;
    814     vi->vData[dataid].lineColor = color;
    815     vi->vData[dataid].lineWidth = width;
    816     vi->vData[dataid].lineStyle = style;
     909        dataid = vi->vData.size() - 1;
     910    } else if (dataid >= (int)vi->vData.size()) {
     911        exit(0);
     912    }
     913
     914    Plotter2DataInfo* di = &vi->vData[dataid];
     915    di->drawLine  = true;
     916    di->lineColor = color;
     917    di->lineWidth = width;
     918    di->lineStyle = style;
     919    //vi->vData[dataid].lineStyle = style;
    817920}
    818921
    819922void Plotter2::showLine(const int inVpid, const int inDataid) {
    820923    int vpid = inVpid;
     924    if (vpid >= (int)vInfo.size()) {
     925        exit(0);
     926    }
    821927    if (vpid < 0) {
    822928        vpid = vInfo.size() - 1;
     
    827933
    828934    int dataid = inDataid;
     935    if (dataid >= (int)vInfo[vpid].vData.size()) {
     936        exit(0);
     937    }
    829938    if (dataid < 0) {
    830939        dataid = vInfo[vpid].vData.size() - 1;
     
    840949void Plotter2::hideLine(const int inVpid, const int inDataid) {
    841950    int vpid = inVpid;
     951    if (vpid >= (int)vInfo.size()) {
     952        exit(0);
     953    }
    842954    if (vpid < 0) {
    843955        vpid = vInfo.size() - 1;
     
    848960
    849961    int dataid = inDataid;
     962    if (dataid >= (int)vInfo[vpid].vData.size()) {
     963        exit(0);
     964    }
    850965    if (dataid < 0) {
    851966        dataid = vInfo[vpid].vData.size() - 1;
     
    861976void Plotter2::setPoint(const int type, const float size, const int color, const int inVpid, const int inDataid) {
    862977    int vpid = inVpid;
     978    if (vpid >= (int)vInfo.size()) {
     979        exit(0);
     980    }
    863981    if (vpid < 0) {
    864982        vpid = vInfo.size() - 1;
     
    871989
    872990    int dataid = inDataid;
     991    if (dataid >= (int)vInfo[vpid].vData.size()) {
     992        exit(0);
     993    }
    873994    if (dataid < 0) {
    874995        dataid = vInfo[vpid].vData.size() - 1;
     
    8841005void Plotter2::showPoint(const int inVpid, const int inDataid) {
    8851006    int vpid = inVpid;
     1007    if (vpid >= (int)vInfo.size()) {
     1008        exit(0);
     1009    }
    8861010    if (vpid < 0) {
    8871011        vpid = vInfo.size() - 1;
     
    8921016
    8931017    int dataid = inDataid;
     1018    if (dataid >= (int)vInfo[vpid].vData.size()) {
     1019        exit(0);
     1020    }
    8941021    if (dataid < 0) {
    8951022        dataid = vInfo[vpid].vData.size() - 1;
     
    9051032void Plotter2::hidePoint(const int inVpid, const int inDataid) {
    9061033    int vpid = inVpid;
     1034    if (vpid >= (int)vInfo.size()) {
     1035        exit(0);
     1036    }
    9071037    if (vpid < 0) {
    9081038        vpid = vInfo.size() - 1;
     
    9131043
    9141044    int dataid = inDataid;
     1045    if (dataid >= (int)vInfo[vpid].vData.size()) {
     1046        exit(0);
     1047    }
    9151048    if (dataid < 0) {
    9161049        dataid = vInfo[vpid].vData.size() - 1;
     
    9261059void Plotter2::setMaskX(const float xmin, const float xmax, const int color, const int fill, const int width, const float hsep, const int inVpid) {
    9271060    int vpid = inVpid;
     1061    if (vpid >= (int)vInfo.size()) {
     1062        exit(0);
     1063    }
    9281064    if (vpid < 0) {
    9291065        vpid = vInfo.size() - 1;
     
    9531089}
    9541090
    955 void Plotter2::setLabelX(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
    956     int vpid = inVpid;
    957     if (vpid < 0) {
    958         vpid = vInfo.size() - 1;
    959     }
    960     if (vpid < 0) {
    961         Plotter2ViewportInfo vi;
    962         vInfo.push_back(vi);
    963         vpid = 0;
    964     }
    965 
    966     Plotter2ViewportInfo* vi = &vInfo[vpid];
     1091void Plotter2::setArrow(const float xtail, const float xhead, const float ytail,
     1092                          const float yhead, const int color, const int width,
     1093                          const int lineStyle, const float headSize,
     1094                          const int headFillStyle, const float headAngle,
     1095                          const float headVent, const int inVpid, const int inArrowid) {
     1096    int vpid = inVpid;
     1097    if (vpid >= (int)vInfo.size()) {
     1098        exit(0);
     1099    }
     1100    if (vpid < 0) {
     1101        vpid = vInfo.size() - 1;
     1102    }
     1103    if (vpid < 0) {
     1104        Plotter2ViewportInfo vi;
     1105        vInfo.push_back(vi);
     1106        vpid = 0;
     1107    }
     1108
     1109    Plotter2ViewportInfo* vi = &vInfo[vpid];
     1110
     1111    int arrowid = inArrowid;
     1112    if (arrowid < 0) {
     1113        Plotter2ArrowInfo ai;
     1114        vi->vArro.push_back(ai);
     1115        arrowid = vi->vArro.size() - 1;
     1116    } else if (arrowid >= (int)vi->vArro.size()) {
     1117        exit(0);
     1118    }
     1119
     1120    Plotter2ArrowInfo* ai = &vi->vArro[arrowid];
     1121
     1122    ai->xhead = xhead;
     1123    ai->xtail = xtail;
     1124    ai->yhead = yhead;
     1125    ai->ytail = ytail;
     1126    ai->color = color;
     1127    ai->width = width;
     1128    ai->lineStyle = lineStyle;
     1129    ai->headSize = headSize;
     1130    ai->headFillStyle = headFillStyle;
     1131    ai->headAngle = headAngle;
     1132    ai->headVent = headVent;
     1133}
     1134
     1135void Plotter2::setAnnotation(const std::string& label, const float posx, const float posy, const float angle, const float fjust, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid, const int inAnnid) {
     1136    int vpid = inVpid;
     1137    if (vpid >= (int)vInfo.size()) {
     1138        exit(0);
     1139    }
     1140    if (vpid < 0) {
     1141        vpid = vInfo.size() - 1;
     1142    }
     1143    if (vpid < 0) {
     1144        Plotter2ViewportInfo vi;
     1145        vInfo.push_back(vi);
     1146        vpid = 0;
     1147    }
     1148
     1149    Plotter2ViewportInfo* vi = &vInfo[vpid];
     1150
     1151    int annotationid = inAnnid;
     1152    if (annotationid < 0) {
     1153        Plotter2AnnotationInfo ai;
     1154        vi->vAnno.push_back(ai);
     1155        annotationid = vi->vAnno.size() - 1;
     1156    } else if (annotationid >= (int)vi->vAnno.size()) {
     1157        exit(0);
     1158    }
     1159
     1160    Plotter2AnnotationInfo* ai = &vi->vAnno[annotationid];
    9671161
    9681162    std::string styleString;
     
    9761170      styleString = "\\fs";
    9771171    }
    978     vi->labelXString = styleString + label;
    979 
    980     float posx = inPosx;
    981     if (posx < 0.0) {
    982         posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
    983     }
    984     vi->labelXPosX   = posx;
    985 
    986     float posy = inPosy;
    987     if (posy < 0.0) {
    988         posy = 0.35*vi->vpPosYMin;
    989     }
    990     vi->labelXPosY   = posy;
    991 
    992     vi->labelXAngle  = 0.0;
    993     vi->labelXFJust  = 0.5;
    994     vi->labelXSize   = size;
    995     vi->labelXColor  = color;
    996     vi->labelXBColor = bgcolor;
    997 }
    998 
    999 void Plotter2::setLabelY(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
    1000     int vpid = inVpid;
     1172
     1173    ai->text = styleString + label;
     1174    ai->posx = posx;
     1175    ai->posy = posy;
     1176    ai->angle = angle;
     1177    ai->fjust = fjust;
     1178    ai->size = size;
     1179    ai->color = color;
     1180    ai->bgcolor = bgcolor;
     1181}
     1182
     1183void Plotter2::setLabelX(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
     1184    int vpid = inVpid;
     1185    if (vpid >= (int)vInfo.size()) {
     1186        exit(0);
     1187    }
    10011188    if (vpid < 0) {
    10021189        vpid = vInfo.size() - 1;
     
    10201207      styleString = "\\fs";
    10211208    }
    1022     vi->labelYString = styleString + label;
     1209    vi->labelXString = styleString + label;
    10231210
    10241211    float posx = inPosx;
    10251212    if (posx < 0.0) {
    1026         posx = 0.35*vi->vpPosXMin;
    1027     }
    1028     vi->labelYPosX   = posx;
     1213        posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
     1214    }
     1215    vi->labelXPosX   = posx;
    10291216
    10301217    float posy = inPosy;
    10311218    if (posy < 0.0) {
    1032         posy = 0.5*(vi->vpPosYMin + vi->vpPosYMax);
    1033     }
    1034     vi->labelYPosY   = posy;
    1035 
    1036     vi->labelYAngle  = 90.0;
    1037     vi->labelYFJust  = 0.5;
    1038     vi->labelYSize   = size;
    1039     vi->labelYColor  = color;
    1040     vi->labelYBColor = bgcolor;
    1041 }
    1042 
    1043 void Plotter2::setTitle(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
    1044     int vpid = inVpid;
     1219        posy = 0.35*vi->vpPosYMin;
     1220    }
     1221    vi->labelXPosY   = posy;
     1222
     1223    vi->labelXAngle  = 0.0;
     1224    vi->labelXFJust  = 0.5;
     1225    vi->labelXSize   = size;
     1226    vi->labelXColor  = color;
     1227    vi->labelXBColor = bgcolor;
     1228}
     1229
     1230void Plotter2::setLabelY(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
     1231    int vpid = inVpid;
     1232    if (vpid >= (int)vInfo.size()) {
     1233        exit(0);
     1234    }
    10451235    if (vpid < 0) {
    10461236        vpid = vInfo.size() - 1;
     
    10641254      styleString = "\\fs";
    10651255    }
    1066     vi->titleString = styleString + label;
     1256    vi->labelYString = styleString + label;
    10671257
    10681258    float posx = inPosx;
    10691259    if (posx < 0.0) {
    1070         posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
    1071     }
    1072     vi->titlePosX   = posx;
     1260        posx = 0.35*vi->vpPosXMin;
     1261    }
     1262    vi->labelYPosX   = posx;
    10731263
    10741264    float posy = inPosy;
    10751265    if (posy < 0.0) {
    1076         posy = vi->vpPosYMax + 0.25*(1.0 - vi->vpPosYMax);
    1077     }
    1078     vi->titlePosY   = posy;
    1079 
    1080     vi->titleAngle  = 0.0;
    1081     vi->titleFJust  = 0.5;
    1082     vi->titleSize   = size;
    1083     vi->titleColor  = color;
    1084     vi->titleBColor = bgcolor;
    1085 }
    1086 
    1087 void Plotter2::setViewportBackgroundColor(const int bgcolor, const int inVpid) {
    1088     int vpid = inVpid;
    1089     if (vpid < 0) {
    1090         vpid = vInfo.size() - 1;
    1091     }
    1092     if (vpid < 0) {
    1093         exit(0);
    1094     }
    1095 
    1096     Plotter2ViewportInfo* vi = &vInfo[vpid];
    1097     vi->vpBColor = bgcolor;
    1098 }
    1099 
    1100 /*
    1101 void Plotter2::setAnnotation(const std::string& label, const float posx, const float posy, const float angle, const float fjust, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
    1102     int vpid = inVpid;
    1103     if (vpid < 0) {
    1104         vpid = vInfo.size() - 1;
    1105     }
    1106     if (vpid < 0) {
    1107         Plotter2ViewportInfo vi;
    1108         vInfo.push_back(vi);
    1109         vpid = 0;
    1110     }
     1266        posy = 0.5*(vi->vpPosYMin + vi->vpPosYMax);
     1267    }
     1268    vi->labelYPosY   = posy;
     1269
     1270    vi->labelYAngle  = 90.0;
     1271    vi->labelYFJust  = 0.5;
     1272    vi->labelYSize   = size;
     1273    vi->labelYColor  = color;
     1274    vi->labelYBColor = bgcolor;
     1275}
     1276
     1277void Plotter2::setTitle(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
     1278    int vpid = inVpid;
     1279    if (vpid >= (int)vInfo.size()) {
     1280        exit(0);
     1281    }
     1282    if (vpid < 0) {
     1283        vpid = vInfo.size() - 1;
     1284    }
     1285    if (vpid < 0) {
     1286        Plotter2ViewportInfo vi;
     1287        vInfo.push_back(vi);
     1288        vpid = 0;
     1289    }
     1290
     1291    Plotter2ViewportInfo* vi = &vInfo[vpid];
    11111292
    11121293    std::string styleString;
     
    11201301      styleString = "\\fs";
    11211302    }
    1122 
    1123     Plotter2ViewportInfo* vi = &vInfo[vpid];
    1124     //vi->titleString = styleString + label;
    1125     //vi->titlePosX   = posx;
    1126     //vi->titlePosY   = posy;
    1127     //vi->titleAngle  = angle;
    1128     //vi->titleFJust  = fjust;
    1129     //vi->titleSize   = size;
    1130     //vi->titleColor  = color;
    1131     //vi->titleBColor = bgcolor;
    1132 }
    1133 */
     1303    vi->titleString = styleString + label;
     1304
     1305    float posx = inPosx;
     1306    if (posx < 0.0) {
     1307        posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
     1308    }
     1309    vi->titlePosX   = posx;
     1310
     1311    float posy = inPosy;
     1312    if (posy < 0.0) {
     1313        posy = vi->vpPosYMax + 0.25*(1.0 - vi->vpPosYMax);
     1314    }
     1315    vi->titlePosY   = posy;
     1316
     1317    vi->titleAngle  = 0.0;
     1318    vi->titleFJust  = 0.5;
     1319    vi->titleSize   = size;
     1320    vi->titleColor  = color;
     1321    vi->titleBColor = bgcolor;
     1322}
     1323
     1324void Plotter2::setViewportBackgroundColor(const int bgcolor, const int inVpid) {
     1325    int vpid = inVpid;
     1326    if (vpid >= (int)vInfo.size()) {
     1327        exit(0);
     1328    }
     1329    if (vpid < 0) {
     1330        vpid = vInfo.size() - 1;
     1331    }
     1332    if (vpid < 0) {
     1333        exit(0);
     1334    }
     1335
     1336    Plotter2ViewportInfo* vi = &vInfo[vpid];
     1337    vi->vpBColor = bgcolor;
     1338}
    11341339
    11351340void Plotter2::close() {
     
    11401345}
    11411346
     1347void Plotter2::resetAttributes(const Plotter2ViewportInfo& vi) {
     1348    cpgstbg(0); // reset background colour to the initial one (white)
     1349    cpgsci(1);  // reset foreground colour to the initial one (black)
     1350    cpgsls(1);  // reset line style to solid
     1351    cpgslw(1);  // reset line width to 1
     1352    cpgscf(1);  // reset font style to normal
     1353    cpgsch(vi.fontSizeDef);// reset font size
     1354    cpgsfs(1);  // reset fill style (solid)
     1355}
     1356
    11421357void Plotter2::plot() {
    11431358    open();
     
    11541369
    11551370        if (vi.showViewport) {
    1156             cpgstbg(0); // reset background colour to the initial one (white)
    1157             cpgsci(1);  // reset foreground colour to the initial one (black)
    1158             cpgsls(1);  // reset line style to solid
    1159             cpgslw(1);  // reset line width to 1
    1160             cpgscf(1);  // reset font style to normal
    1161             cpgsch(vi.fontSizeDef);// reset font size
    1162             cpgsfs(1);  // reset fill style (solid)
     1371            resetAttributes(vi);
    11631372
    11641373            // setup viewport
     
    11751384            // data
    11761385            for (unsigned int j = 0; j < vi.vData.size(); ++j) {
    1177                 cpgstbg(0); // reset background colour to the initial one (white)
    1178                 cpgsci(1);  // reset foreground colour to the initial one (black)
    1179                 cpgsls(1);  // reset line style to solid
    1180                 cpgslw(1);  // reset line width to 1
    1181                 cpgscf(1);  // reset font style to normal
    1182                 cpgsch(vi.fontSizeDef);// reset font size
     1386                resetAttributes(vi);
    11831387
    11841388                Plotter2DataInfo di = vi.vData[j];
     
    12211425            // masks
    12221426            for (unsigned int j = 0; j < vi.vRect.size(); ++j) {
    1223                 cpgstbg(0); // reset background colour to the initial one (white)
    1224                 cpgsci(1);  // reset foreground colour to the initial one (black)
    1225                 cpgsls(1);  // reset line style to solid
    1226                 cpgslw(1);  // reset line width to 1
    1227                 cpgscf(1);  // reset font style to normal
    1228                 cpgsch(vi.fontSizeDef);// reset font size
    1229                 cpgsfs(1);  // reset fill style (solid)
     1427                resetAttributes(vi);
    12301428
    12311429                Plotter2RectInfo ri = vi.vRect[j];
     
    12471445            }
    12481446
    1249             cpgstbg(0); // reset background colour to the initial one (white)
    1250             cpgsci(1);  // reset foreground colour to the initial one (black)
    1251             cpgsls(1);  // reset line style to solid
    1252             cpgslw(1);  // reset line width to 1
    1253             cpgscf(1);  // reset font style to normal
    1254             cpgsch(vi.fontSizeDef);// reset font size
    1255             cpgsfs(1);  // reset fill style (solid)
     1447            // arrows
     1448            for (unsigned int j = 0; j < vi.vArro.size(); ++j) {
     1449                resetAttributes(vi);
     1450
     1451                Plotter2ArrowInfo ai = vi.vArro[j];
     1452                cpgsci(ai.color);
     1453                cpgslw(ai.width);
     1454                cpgsls(ai.lineStyle);
     1455                cpgsch(ai.headSize);
     1456                cpgsah(ai.headFillStyle, ai.headAngle, ai.headVent);
     1457                cpgarro(ai.xtail, ai.ytail, ai.xhead, ai.yhead);
     1458            }
     1459
     1460            // annotations
     1461            for (unsigned int j = 0; j < vi.vAnno.size(); ++j) {
     1462                resetAttributes(vi);
     1463
     1464                Plotter2AnnotationInfo ai = vi.vAnno[j];
     1465                cpgsch(ai.size);
     1466                cpgsci(ai.color);
     1467                cpgstbg(ai.bgcolor);
     1468                cpgptxt(ai.posx, ai.posy, ai.angle, ai.fjust, ai.text.c_str());
     1469            }
     1470
     1471            // viewport outline and ticks
     1472            resetAttributes(vi);
    12561473
    12571474            cpgbox("BCTS",  vi.majorTickIntervalX, vi.nMinorTickWithinMajorTicksX,
    12581475                   "BCTSV", vi.majorTickIntervalY, vi.nMinorTickWithinMajorTicksY);
    12591476
    1260             // viewport outline, ticks and number labels
     1477            // viewport numberings
    12611478            std::string numformatx, numformaty;
    12621479            if (vi.numLocationX == "b") {
  • trunk/src/Plotter2.h

    r2895 r2896  
    1010
    1111namespace asap {
     12
     13class Plotter2AnnotationInfo {
     14public:
     15    Plotter2AnnotationInfo();
     16    ~Plotter2AnnotationInfo();
     17
     18    std::string text;
     19    float posx;
     20    float posy;
     21    float angle;
     22    float fjust;
     23    float size;
     24    int color;
     25    int bgcolor;
     26};
     27
     28class Plotter2ArrowInfo {
     29public:
     30    Plotter2ArrowInfo();
     31    ~Plotter2ArrowInfo();
     32
     33    float xhead;
     34    float xtail;
     35    float yhead;
     36    float ytail;
     37
     38    int color;
     39    int width;
     40    int lineStyle;
     41    float headSize;
     42    int headFillStyle;
     43    float headAngle;
     44    float headVent;
     45};
    1246
    1347class Plotter2RectInfo {
     
    101135    // rectangles
    102136    std::vector<Plotter2RectInfo> vRect;
     137
     138    // arrows
     139    std::vector<Plotter2ArrowInfo> vArro;
     140
     141    //annotations
     142    std::vector<Plotter2AnnotationInfo> vAnno;
    103143
    104144    // x-label
     
    198238    void hidePoint(const int inVpid, const int inDataid);
    199239    void setMaskX(const float xmin, const float xmax, const int color, const int fill, const int width, const float hsep, const int inVpid);
     240    void setArrow(const float xtail, const float xhead, const float ytail, const float yhead, const int color, const int width, const int lineStyle, const float headSize, const int headFillStyle, const float headAngle, const float headVent, const int inVpid, const int inArrowid);
     241    void setAnnotation(const std::string& label, const float posx, const float posy, const float angle, const float fjust, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid, const int inAnnid);
    200242    void setLabelX(const std::string& label, const float posx, const float posy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid);
    201243    void setLabelY(const std::string& label, const float posx, const float posy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid);
    202244    void setTitle(const std::string& label, const float posx, const float posy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid);
    203245    void setViewportBackgroundColor(const int bgcolor, const int inVpid);
    204     //void setAnnotation(const std::string& label, const float posx, const float posy, const float angle, const float fjust, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid);
    205246    void plot();
    206247private:
     
    215256    void open();
    216257    void close();
     258    void resetAttributes(const Plotter2ViewportInfo& vi);
    217259};
    218260
  • trunk/src/python_Plotter2.cpp

    r2895 r2896  
    8181         .def("hide_point",&Plotter2::hidePoint)
    8282         .def("set_mask_x",&Plotter2::setMaskX)
     83         .def("set_arrow",&Plotter2::setArrow)
     84         .def("set_annotation",&Plotter2::setAnnotation)
    8385         .def("set_label_x",&Plotter2::setLabelX)
    8486         .def("set_label_y",&Plotter2::setLabelY)
    8587         .def("set_title",&Plotter2::setTitle)
    8688         .def("set_vpbgcolor",&Plotter2::setViewportBackgroundColor)
    87          //.def("set_annotation",&Plotter2::setAnnotation)
    8889
    8990         .def("plot",&Plotter2::plot)
Note: See TracChangeset for help on using the changeset viewer.