Example #1
0
void Tree::display(CPaintDC& dc, int x, int y, int age)
{
	CBrush brushGreen(RGB(0, 255, 0));

	int d = 20 + (age/2);

	CRect rcEllipse(CPoint(x, y), CSize(d, d));
	CRgn rgnEllipse;

	rgnEllipse.CreateEllipticRgnIndirect(&rcEllipse);
	dc.FillRgn(&rgnEllipse, &brushGreen);
}
Example #2
0
void MyGraph::DrawSeriesLine(CDC& dc) const
{
	VALIDATE;
	ASSERT_VALID(&dc);
	_ASSERTE(!m_bStackedGraph);

	// Iterate the groups.
	CPoint ptLastLoc(0,0);
	int dataLastLoc(0);

	for (int nGroup = 0; nGroup < GetMaxSeriesSize(); nGroup++) {

		// How much space does each series get (includes inter series space)?
		int nSeriesSpace(0);

		if (m_saLegendLabels.GetSize()) {

			nSeriesSpace = (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)) /
				(int)m_olMyGraphSeries.GetCount();
		}
		else {
			nSeriesSpace = m_nXAxisWidth / (int)m_olMyGraphSeries.GetCount();
		}

		// Determine width of bars.
		int nMaxSeriesSize(GetMaxSeriesSize());
		nMaxSeriesSize = max(nMaxSeriesSize, 1);
		int nBarWidth(nSeriesSpace / nMaxSeriesSize);

		if (1 < m_olMyGraphSeries.GetCount()) {
			nBarWidth = (int) ((double) nBarWidth * INTERSERIES_PERCENT_USED);
		}

		// This is the width of the largest series (no inter series space).
		//int nMaxSeriesPlotSize(GetMaxSeriesSize() * nBarWidth);

		// Iterate the series.
		POSITION pos(m_olMyGraphSeries.GetHeadPosition());

		// Build objects.
		COLORREF crLine(m_dwaColors.GetAt(nGroup));
		CBrush br(crLine);
		CBrush* pBrushOld = dc.SelectObject(&br);
		ASSERT_VALID(pBrushOld);
		CPen penLine(PS_SOLID, 1, crLine);
		CPen* pPenOld = dc.SelectObject(&penLine);
		ASSERT_VALID(pPenOld);

		for (int nSeries = 0; nSeries < m_olMyGraphSeries.GetCount(); ++nSeries) {

			MyGraphSeries* pSeries = m_olMyGraphSeries.GetNext(pos);
			ASSERT_VALID(pSeries);

			// Get x and y location of center of ellipse.
			CPoint ptLoc(0,0);

			ptLoc.x = m_ptOrigin.x + (((nSeries + 1) * nSeriesSpace) -
				(nSeriesSpace / 2));

			int nMaxDataValue(GetMaxDataValue());
			nMaxDataValue = max(nMaxDataValue, 1);
			double dLineHeight(pSeries->GetData(nGroup) * m_nYAxisHeight /
				double(nMaxDataValue));

			ptLoc.y = (int) ((double) m_ptOrigin.y - dLineHeight);


			// Draw line back to last data member.
			if (nSeries > 0 && (pSeries->GetData(nGroup)!=0 || dataLastLoc != 0)) {

				dc.MoveTo(ptLastLoc.x, ptLastLoc.y - 1);
				VERIFY(dc.LineTo(ptLoc.x - 1, ptLoc.y - 1));
			}

			// Now draw ellipse.
			CRect rcEllipse(ptLoc.x - 3, ptLoc.y - 3, ptLoc.x + 3, ptLoc.y + 3);
			if(pSeries->GetData(nGroup)!=0){
				VERIFY(dc.Ellipse(rcEllipse));
			}
			if (m_olMyGraphSeries.GetCount() < 40)
			{
				pSeries->SetTipRegion(nGroup, rcEllipse);
			}

			// Save last pt and data
			ptLastLoc = ptLoc;
			dataLastLoc = pSeries->GetData(nGroup);
		}
		VERIFY(dc.SelectObject(pPenOld));
		penLine.DeleteObject();
		VERIFY(dc.SelectObject(pBrushOld));
		br.DeleteObject();
	}

	int nMaxDataValue = max(GetMaxDataValue(), 1);
	double barTop = m_ptOrigin.y - (double)m_nYAxisHeight *
		(GetAverageDataValue() / (double)nMaxDataValue);
	dc.MoveTo(m_ptOrigin.x, barTop);
	VERIFY(dc.LineTo(m_ptOrigin.x + (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)), barTop));
}