void Plotter2::resetAttributes(const Plotter2ViewportInfo& vi) { cpgstbg(0); // reset background colour to the initial one (white) cpgsci(1); // reset foreground colour to the initial one (black) cpgsls(1); // reset line style to solid cpgslw(1); // reset line width to 1 cpgscf(1); // reset font style to normal cpgsch(vi.fontSizeDef);// reset font size cpgsfs(1); // reset fill style (solid) }
void Plotter2::plot() { open(); if ((width > 0.0) && (aspect > 0.0)) { cpgpap(width, aspect); } cpgscr(0, 1.0, 1.0, 1.0); // set background color white cpgscr(1, 0.0, 0.0, 0.0); // set foreground color black for (unsigned int i = 0; i < vInfo.size(); ++i) { Plotter2ViewportInfo vi = vInfo[i]; if (vi.showViewport) { resetAttributes(vi); // setup viewport cpgsvp(vi.vpPosXMin, vi.vpPosXMax, vi.vpPosYMin, vi.vpPosYMax); cpgswin(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax); // background color (default is transparent) if (vi.vpBColor >= 0) { cpgsci(vi.vpBColor); cpgrect(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax); cpgsci(1); // reset foreground colour to the initial one (black) } // data for (unsigned int j = 0; j < vi.vData.size(); ++j) { resetAttributes(vi); Plotter2DataInfo di = vi.vData[j]; std::vector<float> vxdata = di.xData; int ndata = vxdata.size(); float* pxdata = new float[ndata]; float* pydata = new float[ndata]; for (int k = 0; k < ndata; ++k) { pxdata[k] = di.xData[k]; pydata[k] = di.yData[k]; } if (di.drawLine) { cpgsls(di.lineStyle); cpgslw(di.lineWidth); int colorIdx = di.lineColor; if (colorIdx < 0) { colorIdx = (j + 1) % 15 + 1; } cpgsci(colorIdx); cpgline(ndata, pxdata, pydata); } if (di.drawMarker) { cpgsch(di.markerSize); cpgsci(di.markerColor); cpgpt(ndata, pxdata, pydata, di.markerType); } delete [] pxdata; delete [] pydata; } //calculate y-range of xmasks std::vector<float> yrange = vi.getRangeY(); float yexcess = 0.1*(yrange[1] - yrange[0]); float xmaskymin = yrange[0] - yexcess; float xmaskymax = yrange[1] + yexcess; // masks for (unsigned int j = 0; j < vi.vRect.size(); ++j) { resetAttributes(vi); Plotter2RectInfo ri = vi.vRect[j]; cpgsci(ri.color); cpgsfs(ri.fill); cpgslw(ri.width); cpgshs(45.0, ri.hsep, 0.0); float* mxdata = new float[4]; float* mydata = new float[4]; mxdata[0] = ri.xmin; mxdata[1] = ri.xmax; mxdata[2] = ri.xmax; mxdata[3] = ri.xmin; mydata[0] = xmaskymin; mydata[1] = xmaskymin; mydata[2] = xmaskymax; mydata[3] = xmaskymax; cpgpoly(4, mxdata, mydata); } // arrows for (unsigned int j = 0; j < vi.vArro.size(); ++j) { resetAttributes(vi); Plotter2ArrowInfo ai = vi.vArro[j]; cpgsci(ai.color); cpgslw(ai.width); cpgsls(ai.lineStyle); cpgsch(ai.headSize); cpgsah(ai.headFillStyle, ai.headAngle, ai.headVent); cpgarro(ai.xtail, ai.ytail, ai.xhead, ai.yhead); } // arbitrary texts for (unsigned int j = 0; j < vi.vText.size(); ++j) { resetAttributes(vi); Plotter2TextInfo ti = vi.vText[j]; cpgsch(ti.size); cpgsci(ti.color); cpgstbg(ti.bgcolor); cpgptxt(ti.posx, ti.posy, ti.angle, ti.fjust, ti.text.c_str()); } // viewport outline and ticks resetAttributes(vi); cpgbox("BCTS", vi.majorTickIntervalX, vi.nMinorTickWithinMajorTicksX, "BCTSV", vi.majorTickIntervalY, vi.nMinorTickWithinMajorTicksY); // viewport numberings std::string numformatx, numformaty; if (vi.numLocationX == "b") { numformatx = "N"; } else if (vi.numLocationX == "t") { numformatx = "M"; } else if (vi.numLocationX == "") { numformatx = ""; } if (vi.numLocationY == "l") { numformaty = "NV"; } else if (vi.numLocationY == "r") { numformaty = "MV"; } else if (vi.numLocationY == "") { numformaty = ""; } cpgbox(numformatx.c_str(), vi.majorTickIntervalX * vi.nMajorTickWithinTickNumsX, 0, numformaty.c_str(), vi.majorTickIntervalY * vi.nMajorTickWithinTickNumsY, 0); float xpos, ypos; // x-label vi.getWorldCoordByWindowCoord(vi.labelXPosX, vi.labelXPosY, &xpos, &ypos); cpgsch(vi.labelXSize); cpgsci(vi.labelXColor); cpgstbg(vi.labelXBColor); //outside viewports, works ONLY with /xwindow cpgptxt(xpos, ypos, vi.labelXAngle, vi.labelXFJust, vi.labelXString.c_str()); // y-label vi.getWorldCoordByWindowCoord(vi.labelYPosX, vi.labelYPosY, &xpos, &ypos); cpgsch(vi.labelYSize); cpgsci(vi.labelYColor); cpgstbg(vi.labelYBColor); //outside viewports, works ONLY with /xwindow cpgptxt(xpos, ypos, vi.labelYAngle, vi.labelYFJust, vi.labelYString.c_str()); // title vi.getWorldCoordByWindowCoord(vi.titlePosX, vi.titlePosY, &xpos, &ypos); cpgsch(vi.titleSize); cpgsci(vi.titleColor); cpgstbg(vi.titleBColor); //outside viewports, works ONLY with /xwindow cpgptxt(xpos, ypos, vi.titleAngle, vi.titleFJust, vi.titleString.c_str()); } } close(); }
/* set text background color index */ static void _pgstbg (int *i) { cpgstbg (*i); }