Changeset 2896
- Timestamp:
- 02/20/14 21:40:16 (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/plotter2.py
r2895 r2896 42 42 def get_vs(self): 43 43 """\ 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. 45 46 """ 46 47 width = self._plotter.get_viewsurface_width() … … 59 60 def set_vs(self, width=None, unit=None, aspect=None): 60 61 """\ 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) 63 65 Parameters: 64 66 width: width of graphic window or output file. … … 75 77 76 78 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. 82 88 """ 83 89 if width is None: … … 512 518 def set_xmask(self, xmin, xmax, color=None, fstyle=None, width=None, hsep=None, vpid=None): 513 519 """\ 514 add a rectangle which spans full y range.520 add a rectangle which spans the full y range. 515 521 516 522 Parameters: … … 531 537 if hsep is None: hsep = 1.0 532 538 if vpid is None: vpid = -1 539 533 540 coloridx = self.get_colorindex(color) 534 541 fstyleidx = self.get_fillstyleindex(fstyle) 542 535 543 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) 536 607 537 608 def set_xlabel(self, label, style=None, size=None, posx=None, posy=None, vpid=None): … … 779 850 print "------------------------------" 780 851 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 2 2 3 3 namespace asap { 4 5 Plotter2AnnotationInfo::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 16 Plotter2AnnotationInfo::~Plotter2AnnotationInfo() { 17 } 18 19 Plotter2ArrowInfo::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 33 Plotter2ArrowInfo::~Plotter2ArrowInfo() { 34 } 4 35 5 36 Plotter2RectInfo::Plotter2RectInfo() { … … 71 102 vData.clear(); 72 103 vRect.clear(); 104 vArro.clear(); 105 vAnno.clear(); 73 106 74 107 labelXString = ""; … … 104 137 Plotter2ViewportInfo::~Plotter2ViewportInfo() { 105 138 vData.clear(); 139 vRect.clear(); 140 vArro.clear(); 141 vAnno.clear(); 106 142 } 107 143 … … 353 389 354 390 void 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 } 355 394 Plotter2ViewportInfo* vi = &vInfo[id]; 356 395 … … 365 404 void Plotter2::showViewport(const int inVpid) { 366 405 int vpid = inVpid; 406 if (vpid >= (int)vInfo.size()) { 407 return; 408 } 367 409 if (vpid < 0) { 368 410 vpid = vInfo.size() - 1; … … 378 420 void Plotter2::hideViewport(const int inVpid) { 379 421 int vpid = inVpid; 422 if (vpid >= (int)vInfo.size()) { 423 return; 424 } 380 425 if (vpid < 0) { 381 426 vpid = vInfo.size() - 1; … … 536 581 void Plotter2::setRangeX(const float xmin, const float xmax, const int inVpid) { 537 582 int vpid = inVpid; 583 if (vpid >= (int)vInfo.size()) { 584 return; 585 } 538 586 if (vpid < 0) { 539 587 vpid = vInfo.size() - 1; … … 553 601 void Plotter2::setRangeY(const float ymin, const float ymax, const int inVpid) { 554 602 int vpid = inVpid; 603 if (vpid >= (int)vInfo.size()) { 604 return; 605 } 555 606 if (vpid < 0) { 556 607 vpid = vInfo.size() - 1; … … 570 621 std::vector<float> Plotter2::getRangeX(const int inVpid) { 571 622 int vpid = inVpid; 623 if (vpid >= (int)vInfo.size()) { 624 exit(0); 625 } 572 626 if (vpid < 0) { 573 627 vpid = vInfo.size() - 1; … … 582 636 std::vector<float> Plotter2::getRangeY(const int inVpid) { 583 637 int vpid = inVpid; 638 if (vpid >= (int)vInfo.size()) { 639 exit(0); 640 } 584 641 if (vpid < 0) { 585 642 vpid = vInfo.size() - 1; … … 599 656 void Plotter2::setAutoRangeX(const int inVpid) { 600 657 int vpid = inVpid; 658 if (vpid >= (int)vInfo.size()) { 659 exit(0); 660 } 601 661 if (vpid < 0) { 602 662 vpid = vInfo.size() - 1; … … 614 674 void Plotter2::setAutoRangeY(const int inVpid) { 615 675 int vpid = inVpid; 676 if (vpid >= (int)vInfo.size()) { 677 exit(0); 678 } 616 679 if (vpid < 0) { 617 680 vpid = vInfo.size() - 1; … … 629 692 void Plotter2::setFontSizeDef(const float size, const int inVpid) { 630 693 int vpid = inVpid; 694 if (vpid >= (int)vInfo.size()) { 695 exit(0); 696 } 631 697 if (vpid < 0) { 632 698 vpid = vInfo.size() - 1; … … 644 710 void Plotter2::setTicksX(const float interval, const int num, const int inVpid) { 645 711 int vpid = inVpid; 712 if (vpid >= (int)vInfo.size()) { 713 exit(0); 714 } 646 715 if (vpid < 0) { 647 716 vpid = vInfo.size() - 1; … … 661 730 void Plotter2::setTicksY(const float interval, const int num, const int inVpid) { 662 731 int vpid = inVpid; 732 if (vpid >= (int)vInfo.size()) { 733 exit(0); 734 } 663 735 if (vpid < 0) { 664 736 vpid = vInfo.size() - 1; … … 683 755 void Plotter2::setAutoTicksX(const int inVpid) { 684 756 int vpid = inVpid; 757 if (vpid >= (int)vInfo.size()) { 758 exit(0); 759 } 685 760 if (vpid < 0) { 686 761 vpid = vInfo.size() - 1; … … 698 773 void Plotter2::setAutoTicksY(const int inVpid) { 699 774 int vpid = inVpid; 775 if (vpid >= (int)vInfo.size()) { 776 exit(0); 777 } 700 778 if (vpid < 0) { 701 779 vpid = vInfo.size() - 1; … … 713 791 void Plotter2::setNumIntervalX(const float interval, const int inVpid) { 714 792 int vpid = inVpid; 793 if (vpid >= (int)vInfo.size()) { 794 exit(0); 795 } 715 796 if (vpid < 0) { 716 797 vpid = vInfo.size() - 1; … … 728 809 void Plotter2::setNumIntervalY(const float interval, const int inVpid) { 729 810 int vpid = inVpid; 811 if (vpid >= (int)vInfo.size()) { 812 exit(0); 813 } 730 814 if (vpid < 0) { 731 815 vpid = vInfo.size() - 1; … … 743 827 void Plotter2::setNumLocationX(const std::string& side, const int inVpid) { 744 828 int vpid = inVpid; 829 if (vpid >= (int)vInfo.size()) { 830 exit(0); 831 } 745 832 if (vpid < 0) { 746 833 vpid = vInfo.size() - 1; … … 758 845 void Plotter2::setNumLocationY(const std::string& side, const int inVpid) { 759 846 int vpid = inVpid; 847 if (vpid >= (int)vInfo.size()) { 848 exit(0); 849 } 760 850 if (vpid < 0) { 761 851 vpid = vInfo.size() - 1; … … 773 863 void Plotter2::setData(const std::vector<float>& xdata, const std::vector<float>& ydata, const int inVpid, const int inDataid) { 774 864 int vpid = inVpid; 865 if (vpid >= (int)vInfo.size()) { 866 exit(0); 867 } 775 868 if (vpid < 0) { 776 869 vpid = vInfo.size() - 1; … … 789 882 vi->vData.push_back(di); 790 883 dataid = vi->vData.size() - 1; 884 } else if (dataid >= (int)vi->vData.size()) { 885 exit(0); 791 886 } 792 887 … … 796 891 void Plotter2::setLine(const int color, const int width, const int style, const int inVpid, const int inDataid) { 797 892 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]; 806 906 807 907 int dataid = inDataid; 808 908 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; 817 920 } 818 921 819 922 void Plotter2::showLine(const int inVpid, const int inDataid) { 820 923 int vpid = inVpid; 924 if (vpid >= (int)vInfo.size()) { 925 exit(0); 926 } 821 927 if (vpid < 0) { 822 928 vpid = vInfo.size() - 1; … … 827 933 828 934 int dataid = inDataid; 935 if (dataid >= (int)vInfo[vpid].vData.size()) { 936 exit(0); 937 } 829 938 if (dataid < 0) { 830 939 dataid = vInfo[vpid].vData.size() - 1; … … 840 949 void Plotter2::hideLine(const int inVpid, const int inDataid) { 841 950 int vpid = inVpid; 951 if (vpid >= (int)vInfo.size()) { 952 exit(0); 953 } 842 954 if (vpid < 0) { 843 955 vpid = vInfo.size() - 1; … … 848 960 849 961 int dataid = inDataid; 962 if (dataid >= (int)vInfo[vpid].vData.size()) { 963 exit(0); 964 } 850 965 if (dataid < 0) { 851 966 dataid = vInfo[vpid].vData.size() - 1; … … 861 976 void Plotter2::setPoint(const int type, const float size, const int color, const int inVpid, const int inDataid) { 862 977 int vpid = inVpid; 978 if (vpid >= (int)vInfo.size()) { 979 exit(0); 980 } 863 981 if (vpid < 0) { 864 982 vpid = vInfo.size() - 1; … … 871 989 872 990 int dataid = inDataid; 991 if (dataid >= (int)vInfo[vpid].vData.size()) { 992 exit(0); 993 } 873 994 if (dataid < 0) { 874 995 dataid = vInfo[vpid].vData.size() - 1; … … 884 1005 void Plotter2::showPoint(const int inVpid, const int inDataid) { 885 1006 int vpid = inVpid; 1007 if (vpid >= (int)vInfo.size()) { 1008 exit(0); 1009 } 886 1010 if (vpid < 0) { 887 1011 vpid = vInfo.size() - 1; … … 892 1016 893 1017 int dataid = inDataid; 1018 if (dataid >= (int)vInfo[vpid].vData.size()) { 1019 exit(0); 1020 } 894 1021 if (dataid < 0) { 895 1022 dataid = vInfo[vpid].vData.size() - 1; … … 905 1032 void Plotter2::hidePoint(const int inVpid, const int inDataid) { 906 1033 int vpid = inVpid; 1034 if (vpid >= (int)vInfo.size()) { 1035 exit(0); 1036 } 907 1037 if (vpid < 0) { 908 1038 vpid = vInfo.size() - 1; … … 913 1043 914 1044 int dataid = inDataid; 1045 if (dataid >= (int)vInfo[vpid].vData.size()) { 1046 exit(0); 1047 } 915 1048 if (dataid < 0) { 916 1049 dataid = vInfo[vpid].vData.size() - 1; … … 926 1059 void Plotter2::setMaskX(const float xmin, const float xmax, const int color, const int fill, const int width, const float hsep, const int inVpid) { 927 1060 int vpid = inVpid; 1061 if (vpid >= (int)vInfo.size()) { 1062 exit(0); 1063 } 928 1064 if (vpid < 0) { 929 1065 vpid = vInfo.size() - 1; … … 953 1089 } 954 1090 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]; 1091 void 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 1135 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, 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]; 967 1161 968 1162 std::string styleString; … … 976 1170 styleString = "\\fs"; 977 1171 } 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 1183 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) { 1184 int vpid = inVpid; 1185 if (vpid >= (int)vInfo.size()) { 1186 exit(0); 1187 } 1001 1188 if (vpid < 0) { 1002 1189 vpid = vInfo.size() - 1; … … 1020 1207 styleString = "\\fs"; 1021 1208 } 1022 vi->label YString = styleString + label;1209 vi->labelXString = styleString + label; 1023 1210 1024 1211 float posx = inPosx; 1025 1212 if (posx < 0.0) { 1026 posx = 0. 35*vi->vpPosXMin;1027 } 1028 vi->label YPosX = posx;1213 posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax); 1214 } 1215 vi->labelXPosX = posx; 1029 1216 1030 1217 float posy = inPosy; 1031 1218 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 1230 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) { 1231 int vpid = inVpid; 1232 if (vpid >= (int)vInfo.size()) { 1233 exit(0); 1234 } 1045 1235 if (vpid < 0) { 1046 1236 vpid = vInfo.size() - 1; … … 1064 1254 styleString = "\\fs"; 1065 1255 } 1066 vi-> titleString = styleString + label;1256 vi->labelYString = styleString + label; 1067 1257 1068 1258 float posx = inPosx; 1069 1259 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; 1073 1263 1074 1264 float posy = inPosy; 1075 1265 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 1277 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) { 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]; 1111 1292 1112 1293 std::string styleString; … … 1120 1301 styleString = "\\fs"; 1121 1302 } 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 1324 void 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 } 1134 1339 1135 1340 void Plotter2::close() { … … 1140 1345 } 1141 1346 1347 void 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 1142 1357 void Plotter2::plot() { 1143 1358 open(); … … 1154 1369 1155 1370 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); 1163 1372 1164 1373 // setup viewport … … 1175 1384 // data 1176 1385 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); 1183 1387 1184 1388 Plotter2DataInfo di = vi.vData[j]; … … 1221 1425 // masks 1222 1426 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); 1230 1428 1231 1429 Plotter2RectInfo ri = vi.vRect[j]; … … 1247 1445 } 1248 1446 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); 1256 1473 1257 1474 cpgbox("BCTS", vi.majorTickIntervalX, vi.nMinorTickWithinMajorTicksX, 1258 1475 "BCTSV", vi.majorTickIntervalY, vi.nMinorTickWithinMajorTicksY); 1259 1476 1260 // viewport outline, ticks and number labels1477 // viewport numberings 1261 1478 std::string numformatx, numformaty; 1262 1479 if (vi.numLocationX == "b") { -
trunk/src/Plotter2.h
r2895 r2896 10 10 11 11 namespace asap { 12 13 class Plotter2AnnotationInfo { 14 public: 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 28 class Plotter2ArrowInfo { 29 public: 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 }; 12 46 13 47 class Plotter2RectInfo { … … 101 135 // rectangles 102 136 std::vector<Plotter2RectInfo> vRect; 137 138 // arrows 139 std::vector<Plotter2ArrowInfo> vArro; 140 141 //annotations 142 std::vector<Plotter2AnnotationInfo> vAnno; 103 143 104 144 // x-label … … 198 238 void hidePoint(const int inVpid, const int inDataid); 199 239 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); 200 242 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); 201 243 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); 202 244 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); 203 245 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);205 246 void plot(); 206 247 private: … … 215 256 void open(); 216 257 void close(); 258 void resetAttributes(const Plotter2ViewportInfo& vi); 217 259 }; 218 260 -
trunk/src/python_Plotter2.cpp
r2895 r2896 81 81 .def("hide_point",&Plotter2::hidePoint) 82 82 .def("set_mask_x",&Plotter2::setMaskX) 83 .def("set_arrow",&Plotter2::setArrow) 84 .def("set_annotation",&Plotter2::setAnnotation) 83 85 .def("set_label_x",&Plotter2::setLabelX) 84 86 .def("set_label_y",&Plotter2::setLabelY) 85 87 .def("set_title",&Plotter2::setTitle) 86 88 .def("set_vpbgcolor",&Plotter2::setViewportBackgroundColor) 87 //.def("set_annotation",&Plotter2::setAnnotation)88 89 89 90 .def("plot",&Plotter2::plot)
Note:
See TracChangeset
for help on using the changeset viewer.