📄 graph.cpp
字号:
tmpSeries = (CGraphSeries*)graphSeries->GetNext(pos);
tickXLocation = xApexPoint - (xAxisWidth / 2) + ((x * seriesSpace) - (seriesSpace / 2));
pDC->MoveTo(tickXLocation,yApexPoint - 3);
pDC->LineTo(tickXLocation,yApexPoint + 3);
if(!inRedraw)
{
//draw tick label
CString tickLabel;
tickLabel = tmpSeries->GetLabel();
if(!xAxisAlign) //horizontal
{
CFont xFont;
xFont.CreateFont(xTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&xFont);
pDC->TextOut(tickXLocation - ((tickLabel.GetLength() * 8) / 2), yApexPoint + (yAxisHeight / 2) + 8, tickLabel);
pDC->SelectObject(pOldFont);
}
else
{
CFont sideFont2;
sideFont2.CreateFont(xTickFontSize, 0, (xAxisAlign * 10), 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&sideFont2);
pDC->GetTextMetrics(&tm);
charWidth = tm.tmAveCharWidth;
if(xAxisAlign < 180)
pDC->TextOut(tickXLocation - 8, yApexPoint + (yAxisHeight / 2) + 8 + (xAxisLabelLength * charWidth), tickLabel);
else
pDC->TextOut(tickXLocation + 2, yApexPoint + (yAxisHeight / 2) + 8, tickLabel);
pDC->SelectObject(pOldFont);
}
}
rightXTick = tickXLocation;
}
if((graphSeries->GetCount() % 2) > 0)
{
tmpSeries = (CGraphSeries*)graphSeries->GetNext(pos);
tickXLocation = xApexPoint;
pDC->MoveTo(tickXLocation,yApexPoint - 3);
pDC->LineTo(tickXLocation,yApexPoint + 3);
if(!inRedraw)
{
//draw tick label
CString tickLabel;
tickLabel = tmpSeries->GetLabel();
if(!xAxisAlign) //horizontal
{
CFont xFont;
xFont.CreateFont(xTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&xFont);
pDC->TextOut(tickXLocation - ((tickLabel.GetLength() * 8) / 2), yApexPoint + (yAxisHeight / 2) + 8, tickLabel);
pDC->SelectObject(pOldFont);
}
else
{
CFont sideFont2;
sideFont2.CreateFont(xTickFontSize, 0, (xAxisAlign * 10), 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&sideFont2);
pDC->GetTextMetrics(&tm);
charWidth = tm.tmAveCharWidth;
if(xAxisAlign < 180)
pDC->TextOut(tickXLocation - 8, yApexPoint + (yAxisHeight / 2) + 8 + (xAxisLabelLength * charWidth), tickLabel);
else
pDC->TextOut(tickXLocation + 2, yApexPoint + (yAxisHeight / 2) + 8, tickLabel);
pDC->SelectObject(pOldFont);
}
}
rightXTick = tickXLocation;
x++;
}
for(; x <= graphSeries->GetCount(); x++)
{
tmpSeries = (CGraphSeries*)graphSeries->GetNext(pos);
tickXLocation = xApexPoint - (xAxisWidth / 2) + ((x * seriesSpace) - (seriesSpace / 2));
pDC->MoveTo(tickXLocation,yApexPoint - 3);
pDC->LineTo(tickXLocation,yApexPoint + 3);
if(!inRedraw)
{
//draw tick label
CString tickLabel;
tickLabel = tmpSeries->GetLabel();
if(!xAxisAlign) //horizontal
{
CFont xFont;
xFont.CreateFont(xTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&xFont);
pDC->TextOut(tickXLocation - ((tickLabel.GetLength() * 8) / 2), yApexPoint + (yAxisHeight / 2) + 8, tickLabel);
pDC->SelectObject(pOldFont);
}
else
{
CFont sideFont2;
sideFont2.CreateFont(xTickFontSize, 0, (xAxisAlign * 10), 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&sideFont2);
pDC->GetTextMetrics(&tm);
charWidth = tm.tmAveCharWidth;
if(xAxisAlign < 180)
pDC->TextOut(tickXLocation - 8, yApexPoint + (yAxisHeight / 2) + 8 + (xAxisLabelLength * charWidth), tickLabel);
else
pDC->TextOut(tickXLocation + 2, yApexPoint + (yAxisHeight / 2) + 8, tickLabel);
pDC->SelectObject(pOldFont);
}
}
rightXTick = tickXLocation;
}
}
else
{
//scatter graphs will use the same tick marking on both axis lines
seriesSpace = (xAxisWidth - 20) / numTicks;
for(x = 1; x <= numTicks / 2; x++)
{
tickXLocation = xApexPoint - (xAxisWidth / 2) + (x * seriesSpace);
//draw tick mark
pDC->MoveTo(tickXLocation, yApexPoint + (yAxisHeight / 2) - 3);
pDC->LineTo(tickXLocation, yApexPoint + (yAxisHeight / 2) + 3);
if(!inRedraw)
{
//draw tick label
CString tickLabel;
tickLabel.Format("%d", x * tickSpace);
CFont xFont;
xFont.CreateFont(xTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&xFont);
pDC->GetTextMetrics(&tm);
charWidth = tm.tmAveCharWidth;
pDC->TextOut(tickXLocation - (tickLabel.GetLength() * charWidth / 2), yApexPoint + 8, tickLabel);
}
rightXTick = tickXLocation;
pDC->SelectObject(pOldFont);
}
//draw the 0
for(; x <= numTicks; x++)
{
tickXLocation = xApexPoint - (xAxisWidth / 2) + (x * seriesSpace);
//draw tick mark
pDC->MoveTo(tickXLocation, yApexPoint + (yAxisHeight / 2) - 3);
pDC->LineTo(tickXLocation, yApexPoint + (yAxisHeight / 2) + 3);
if(!inRedraw)
{
//draw tick label
CString tickLabel;
tickLabel.Format("%d", x * tickSpace);
CFont xFont;
xFont.CreateFont(xTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&xFont);
pDC->GetTextMetrics(&tm);
charWidth = tm.tmAveCharWidth;
pDC->TextOut(tickXLocation - (tickLabel.GetLength() * charWidth / 2), yApexPoint + 8, tickLabel);
}
rightXTick = tickXLocation;
pDC->SelectObject(pOldFont);
}
}
break;
}
}
else
{
//reverse above stuff and treat as horizontal graph
switch(graphQuadType)
{
case 1 :
pDC->TextOut(10, (yApexPoint - (yAxisHeight / 2)) + (axisYLabel.GetLength() / 2), axisXLabel);
pDC->SelectObject(&axisFont);
pDC->GetTextMetrics(&tm);
charWidth = tm.tmAveCharWidth;
labelHeight = tm.tmHeight + 10;
if(axisYLabel.GetLength() == 0)
labelHeight = 0;
pDC->TextOut(xApexPoint + (xAxisWidth / 2) - ((axisXLabel.GetLength() / 2) * charWidth), maxHeight - 5 - 6, axisYLabel);
pDC->SelectObject(pOldFont);
//to allow scalability (height may be less than tickRange)
tickScale = 0.00;
//draw y axis ticks
if(graphType != SCATTER_GRAPH)
{
tickScale = (yAxisHeight - 10) / seriesSize;
POSITION pos;
pos = graphSeries->GetHeadPosition();
CGraphSeries* tmpSeries;
for(y = 1; y <= graphSeries->GetCount(); y++)
{
tmpSeries = (CGraphSeries*)graphSeries->GetNext(pos);
seriesSpace = yAxisHeight / graphSeries->GetCount();
tickYLocation = yApexPoint - ((y * seriesSpace) - (seriesSpace / 2));
//draw tick mark
pDC->MoveTo(xApexPoint - 3, tickYLocation);
pDC->LineTo(xApexPoint + 3, tickYLocation);
if(!inRedraw)
{
//draw tick label
CString tickLabel;
tickLabel = tmpSeries->GetLabel();
CFont yFont;
yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FIXED_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&yFont);
charWidth = tm.tmAveCharWidth;
pDC->TextOut(xApexPoint - (xAxisLabelLength * charWidth) - 5, tickYLocation - (tm.tmHeight / 2), tickLabel);
}
topYTick = tickYLocation;
pDC->SelectObject(pOldFont);
}
}
else
{
//scatter graphs will use the same tick marking on both axis lines
for(y = 1; y <= numTicks; y++)
{
tickScale = (yAxisHeight - 10) / numTicks;
tickYLocation = yApexPoint - (int)(y * tickScale);
//draw tick mark
pDC->MoveTo(xApexPoint - 3, tickYLocation);
pDC->LineTo(xApexPoint + 3, tickYLocation);
if(!inRedraw)
{
//draw tick label
CString tickLabel;
tickLabel.Format("%d", y * tickSpace);
CFont yFont;
yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&yFont);
pDC->TextOut(xApexPoint - 10 - (tickLabel.GetLength() * (yTickFontSize / 2)), tickYLocation - 6, tickLabel);
}
topYTick = tickYLocation;
pDC->SelectObject(pOldFont);
}
}
//draw X axis tick marks
tickScale = (xAxisWidth - 10) / numTicks;
for(x = 1; x <= numTicks; x++)
{
tickXLocation = xApexPoint + (int)(x * tickScale);
pDC->MoveTo(tickXLocation,yApexPoint - 3);
pDC->LineTo(tickXLocation,yApexPoint + 3);
if(!inRedraw)
{
if(graphHasGridLines)
{
//draw grid lines
COLORREF gridLineColor;
gridLineColor = DARK_GREY;
CPen gridPen (PS_SOLID, 1, gridLineColor);
CPen* pOldPen;
pOldPen = pDC->SelectObject(&gridPen);
pDC->MoveTo(tickXLocation, yApexPoint);
pDC->LineTo(tickXLocation, yApexPoint - yAxisHeight);
pDC->SelectObject(pOldPen);
}
//draw tick label
CString tickLabel;
tickLabel.Format("%d", minTick + (x * tickSpace));
if(!xAxisAlign) //horizontal
{
CFont xFont;
xFont.CreateFont(xTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&xFont);
charWidth = tm.tmAveCharWidth;
pDC->TextOut(tickXLocation - ((tickLabel.GetLength() * charWidth) / 2), yApexPoint + 8, tickLabel);
pDC->SelectObject(pOldFont);
}
else
{
CFont sideFont2;
sideFont2.CreateFont(xTickFontSize, 0, (xAxisAlign * 10), 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&sideFont2);
pDC->GetTextMetrics(&tm);
charWidth = tm.tmAveCharWidth;
if(xAxisAlign < 180)
pDC->TextOut(tickXLocation - 8, yApexPoint + 8 + (xAxisLabelLength * charWidth), tickLabel);
else
pDC->TextOut(tickXLocation + 2, yApexPoint + 8, tickLabel);
pDC->SelectObject(pOldFont);
}
}
rightXTick = tickXLocation;
}
break;
case 2 :
pDC->TextOut(10, (yApexPoint - (yAxisHeight / 2)) + (axisYLabel.GetLength() / 2), axisXLabel);
pDC->SelectObject(&axisFont);
pDC->GetTextMetrics(&tm);
charWidth = tm.tmAveCharWidth;
labelHeight = tm.tmHeight + 10;
if(axisYLabel.GetLength() == 0)
labelHeight = 0;
pDC->TextOut(xApexPoint - ((axisXLabel.GetLength() / 2) * charWidth), maxHeight - 5 - 6, axisYLabel);
pDC->SelectObject(pOldFont);
//to allow scalability (height may be less than tickRange)
tickScale = 0.00;
seriesSpace = yAxisHeight / graphSeries->GetCount();
//draw y axis ticks
if(graphType != SCATTER_GRAPH)
{
tickScale = (yAxisHeight - 10) / seriesSize;
POSITION pos;
pos = graphSeries->GetHeadPosition();
CGraphSeries* tmpSeries;
for(y = 1; y <= graphSeries->GetCount(); y++)
{
tmpSeries = (CGraphSeries*)graphSeries->GetNext(pos);
tickYLocation = yApexPoint - ((y * seriesSpace) - (seriesSpace / 2));
//draw tick mark
pDC->MoveTo(xApexPoint - 3, tickYLocation);
pDC->LineTo(xApexPoint + 3, tickYLocation);
if(!inRedraw)
{
//draw tick label
CString tickLabel;
tickLabel = tmpSeries->GetLabel();
CFont yFont;
yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FIXED_PITCH | FF_ROMAN,"Arial");
pDC->SelectObject(&yFont);
charWidth = tm.tmAveCharWidth;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -