INT_PTR CXTPChartControl::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{

	ASSERT_VALID(this);
	ASSERT(::IsWindow(m_hWnd));

	// check child windows first by calling CControlBar
	INT_PTR nHit = CWnd::OnToolHitTest(point, pTI);
	if (nHit != -1)
		return nHit;


	CXTPChartSeriesPoint* pSeriesPoint = DYNAMIC_DOWNCAST(CXTPChartSeriesPoint, HitTest(point));

	if (pSeriesPoint)
	{
		nHit = (INT_PTR)pSeriesPoint;

		CString strTip = pSeriesPoint->GetTooltipText();
		if (strTip.GetLength() == 0)
			return -1;

		CRect rc;
		GetClientRect(rc);

		CXTPToolTipContext::FillInToolInfo(pTI, m_hWnd, rc, nHit, strTip);

		return nHit;
	}
	return -1;
}
void CXTPChartPyramidSeriesView::CalculateValues()
{
	double dSum = 0;
	int i;

	for (i = 0; i < m_pPointsView->GetCount(); i++)
	{
		CXTPChartPyramidSeriesPointView* pPointView = (CXTPChartPyramidSeriesPointView*)m_pPointsView->GetAt(i);

		CXTPChartSeriesPoint* pPoint = pPointView->GetPoint();

		double dValue = pPoint->GetValue(0);

		dSum += dValue;
	}

	if (dSum == 0)
		dSum = 1;

	for (i = 0; i < m_pPointsView->GetCount(); i++)
	{
		CXTPChartPyramidSeriesPointView* pPointView = (CXTPChartPyramidSeriesPointView*)m_pPointsView->GetAt(i);

		CXTPChartSeriesPoint* pPoint = pPointView->GetPoint();

		double dValue = pPoint->GetValue(0);

		pPointView->m_dValue = dValue >= 0 ? dValue / dSum : 0;
	}
}
CXTPChartDeviceCommand* CXTPChartHighLowSeriesPointView::CreateDeviceCommand(CXTPChartDeviceContext* pDC)
{
	UNREFERENCED_PARAMETER(pDC);

	CPoint pointOpen = GetScreenPoint(chartOpen).Round();
	CPoint pointClose = GetScreenPoint(chartClose).Round();

	CPoint pointLow = GetScreenPoint(chartLow).Round();
	CPoint pointHight = GetScreenPoint(chartHigh).Round();

	BOOL bUpColor = TRUE;


	CXTPChartSeriesPoint* pPrevPoint = m_pPoint->GetPreviousPoint();
	if (pPrevPoint)
	{
		if (pPrevPoint->GetValue(chartClose) > m_pPoint->GetValue(chartClose))
		{
			bUpColor = FALSE;
		}
	}

	CXTPChartHighLowSeriesView* pView = (CXTPChartHighLowSeriesView*)GetSeriesView();

	CXTPChartAxisView* pAxisView = pView->GetAxisViewX();
	CXTPChartHighLowSeriesStyle* pStyle = (CXTPChartHighLowSeriesStyle*)GetSeriesView()->GetStyle();

	int nWidth = (int)(pAxisView->DistanceToPoint(1) * 0.5);
	if (nWidth < 5)
		nWidth = 5;

	int nLineThickness = pStyle->GetLineThickness();

	nWidth = (nWidth & ~1) + nLineThickness * 3;

	CXTPChartDeviceCommand* pCommand = new CXTPChartHitTestElementCommand(m_pPoint);

	CXTPChartColor color = bUpColor ? pStyle->GetUpColor() : pStyle->GetDownColor();


	pCommand->AddChildCommand(new CXTPChartSolidLineDeviceCommand(
		CXTPChartPointF(pointHight), CXTPChartPointF(pointLow), color, nLineThickness));

	pCommand->AddChildCommand(new CXTPChartSolidLineDeviceCommand(
		CXTPChartPointF(pointOpen), CXTPChartPointF((float)(pointOpen.x - nWidth / 2), (float)pointOpen.y), color, nLineThickness));

	pCommand->AddChildCommand(new CXTPChartSolidLineDeviceCommand(
		CXTPChartPointF(pointClose), CXTPChartPointF((float)(pointClose.x + nWidth / 2), (float)pointClose.y), color, nLineThickness));


	return pCommand;
}