|
void CNTGraphCtrl::PlotElement(CDC *pDC)
{
// If there is no data available for plot then return .
if ( !nPlotIndex ) return ;
CPen *oldPen , *pen;
CBrush *oldBrush , *brush;
CPoint pt;
for(int i = 0 ; i < nElementCount ; i++) {
// Added by A.Hofmann (Modified)
//////////////////////////////////
// Check show state of the element
if ( mpElement[i].m_Type == 5 )
continue;
// Create the new pen as the color of serie
pen = new CPen(mpElement[i].m_Type, mpElement[i].m_Width, mpElement[i].m_Color);
oldPen = pDC->SelectObject(pen) ;
// Create the new brush as the color of serie
brush = new CBrush(mpElement[i].m_Color);
oldBrush = pDC->SelectObject(brush) ;
double x0,y0,x,y;
x0=mpElement[i].dValueX[0];
y0=mpElement[i].dValueY[0];
// calculate the corrdinate of ploting point.
pt = Corrdinate(x0,y0) ;
pDC->MoveTo(pt);
// Start plot all available data.
for(int index = 1 ; index <= mpElement[i].m_nCount ; index++)
{
x=mpElement[i].dValueX[index];
y=mpElement[i].dValueY[index];
double a,b;
a = (y0*x-y*x0)/(x-x0);
b = (y-y0)/(x-x0);
// Clip the ploting area if it exceed ranged .
if(x > dRangeX[MAX] ) {x = dRangeX[MAX]; y=a+b*x;}
if(x < dRangeX[MIN] ) {x = dRangeX[MIN]; y=a+b*x;}
if(y > dRangeY[MAX] ) {y = dRangeY[MAX]; x=(y-a)/b;}
if(y < dRangeY[MIN] ) {y = dRangeY[MIN]; x=(y-a)/b;}
pt = Corrdinate(x,y);
x0=x;
y0=y;
if (m_axisRect.PtInRect(pt)==FALSE)
{
if (m_axisRect.TopLeft().x > pt.x) pt.x = m_axisRect.TopLeft().x;
if (m_axisRect.TopLeft().y > pt.y) pt.y = m_axisRect.TopLeft().y;
if (m_axisRect.BottomRight().x < pt.x) pt.x = m_axisRect.BottomRight().x;
if (m_axisRect.BottomRight().y < pt.y) pt.y = m_axisRect.BottomRight().y;
}
//else
//{
pDC->MoveTo(pt);
if (mpElement[i].m_Type <=5) // Draw lines.
pDC->LineTo(pt);
else
pDC->MoveTo(pt) ;
int symsz = mpElement[i].m_Width;
if (symsz <= 0) symsz = 1;
CRect rect(pt.x-symsz,pt.y-symsz,pt.x+symsz,pt.y+symsz);
if (mpElement[i].m_Type == 6) // Draw dots.
pDC->Ellipse( rect );
if (mpElement[i].m_Type >= 7) // Draw rectangles.
{
CBrush aBrush(mpElement[i].m_Color);
pDC->FillRect (rect,&aBrush);
aBrush.DeleteObject();
}
//}
}
pDC->SelectObject(oldPen);
delete pen ;
pDC->SelectObject(oldBrush);
delete brush;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.