📄 blockschart3d.cs
字号:
// Disclaimer and Copyright Information
// BlocksChart3D.cs :
//
// All rights reserved.
//
// Written by Pardesi Services, LLC
// Version 1.01
//
// Distribute freely, except: don't remove our name from the source or
// documentation (don't take credit for my work), mark your changes (don't
// get me blamed for your possible bugs), don't alter or remove this
// notice.
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, flames, etc. to
// softomatix@CommonComponent.com
///////////////////////////////////////////////////////////////////////////////
//
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
namespace CommonComponent.CommonChart
{
/// <summary>
///
/// </summary>
public class BlocksChart3D : CommonChart.BlocksChart2D
{
protected float m_fDepthFactor;
public BlocksChart3D()
{
this.m_GraphType = Type.BlocksGraph3D;
m_fDepthFactor = 0.02F;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
override protected bool DrawDataForVerticalAlignment()
{
// *********** NOTE **************************
// For now redirect the implementation to
// Horizontal alignment
// ********************************************
return this.DrawDataForHorizontalAlignment();
/*
try
{
ArrayList dataList = (ArrayList)this.m_obIslandList[0];
if (null == dataList || dataList.Count == 0)
{
Trace.WriteLine("There is no data list present in the array.");
return false;
}
int nCount = dataList.Count;
if (false == this.CalculateBarWidth(nCount))
{
Trace.WriteLine("Failed to calculate bar width");
return false;
}
if (false == this.CalculateBarHeightScale())
{
Trace.WriteLine("Failed to calculate the scale factor");
return false;
}
// Gemerate the random colors.
if (false == ColorUtil.GenerateRandomColors(nCount, out m_arrColors))
{
Trace.WriteLine("Failed to geenrate random color");
return false;
}
PointF pt = new PointF();
pt.X = (float)(this.m_ChartAxis.Origin.X);
pt.Y = this.m_ChartAxis.Origin.Y;
double nHeight = 0;
double nWidth = 0;
float fBlockCount = 0.0F;
float fPartialBlock = 0.0F;
int nCompleteBlocks = 0;
double diff = m_dEqualBarWidth - m_dDrawBarWidth;
for (int i = 0; i < nCount; i++)
{
Color fillColor = (Color)this.m_arrColors[i];
SolidBrush obBrush = new SolidBrush(fillColor);
GraphDataObject obData = (GraphDataObject)dataList[i];
if (null != obData)
{
// Calculate number of blocks that will be needed to display the data.
fBlockCount = (float)(obData.Y/this.BlockUnit);
nCompleteBlocks = (int)Math.Round((double)fBlockCount);
fPartialBlock = fBlockCount - nCompleteBlocks;
// First draw complete blocks
for (int nCmp = 0; nCmp < nCompleteBlocks; nCmp++)
{
}
// Draw partial block.
pt.Y = (float)(this.m_ChartAxis.Origin.Y - ((i+1) * this.m_dEqualBarWidth) + diff);
// First draw the front rectangle.
nHeight = this.m_dDrawBarWidth;
nWidth = (obData.Y * this.m_dBarHeightScale);
this.DrawBar(this.m_obGraphics, (int)pt.X, (int)pt.Y, (float)nWidth, (float)nHeight, 0.0, fillColor);
}
obBrush.Dispose();
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
return false;
}
return true;
*/
}
/// <summary>
///
/// </summary>
/// <returns></returns>
override protected bool DrawDataForHorizontalAlignment()
{
//TODO: For now we will process only first array of data list. Later
// on implementation needs to take into account that there may
// be more than one list.
if (false == this.CalculateBarHeightScale())
{
Trace.WriteLine("Failed to calculate the scale factor");
return false;
}
float fBlockCount = 0.0F;
float fPartialBlock = 0.0F;
int nCompleteBlocks = 0;
double ptX = 0.0;
double ptY = 0.0;
double dThickness = this.m_iYAxisSpan * m_fDepthFactor;
int nHeight = 0;
int nWidth = 0;
int nLeftX = 0;
int nLeftY = 0;
int nCompleteBlockHeight = 0;
int nCmp = 0;
for (int nIdx = 0; nIdx < this.m_obDataIslandNodes.Count; nIdx++)
{
ArrayList obIslandDataList = (ArrayList)this.m_obIslandList[nIdx];
int nCount = obIslandDataList.Count;
//int nStartX = (int)(this.m_ChartAxis.Origin.X);
int nStartX = (int)(this.m_ChartAxis.Origin.X + + m_fIslandSpacing/2.0F);
for (int i = 0; i < nCount; i++)
{
Color fillColor = (Color)this.m_arrColors[i];
GraphDataObject obData = (GraphDataObject)obIslandDataList[i];
if (null != obData)
{
// Calculate number of blocks that will be needed to display the data.
fBlockCount = (float)(obData.Y/this.BlockUnit);
nCompleteBlocks = (int)fBlockCount;
fPartialBlock = fBlockCount - nCompleteBlocks;
nCompleteBlockHeight = (int)(this.BlockUnit * this.m_dBarHeightScale);
nHeight = nCompleteBlockHeight;
nWidth = (int)this.m_dDrawBarWidth;
//nLeftX = (int)(this.m_ChartAxis.Origin.X + (i * this.m_dEqualBarWidth));
nLeftX = (int)(nStartX + nIdx*(this.m_fIslandWidth + this.m_fIslandSpacing) + i * this.m_dEqualBarWidth);
// First draw complete blocks
for (nCmp = 0; nCmp < nCompleteBlocks; nCmp++)
{
nLeftY = this.m_ChartAxis.Origin.Y - (nCmp*(nHeight+this.BlocksBuffer) + nHeight);
this.DrawBar(this.m_obGraphics, nLeftX, nLeftY, nWidth, nHeight, dThickness, fillColor);
}
// Draw partial block.
nHeight = (int)(this.BlockUnit * fPartialBlock * this.m_dBarHeightScale);
if (nCmp > 0)
{
nLeftY = this.m_ChartAxis.Origin.Y - (nCmp*(nCompleteBlockHeight + this.BlocksBuffer) + nHeight);
}
else
{
nLeftY = this.m_ChartAxis.Origin.Y - nHeight;
}
this.DrawBar(this.m_obGraphics, nLeftX, nLeftY, nWidth, nHeight, dThickness, fillColor);
// Draw the ticker.
/*
this.DrawChartTicker(this.m_obGraphics, nLeftX, nLeftY+nHeight, nWidth, nHeight, 3,
this.m_LegendsList[i], this.m_TickerTextDirection, this.GraphAlignment, this.m_TickColor);
*/
}
}
// Draw Island legend.
if (this.DrawXAxisLegend)
{
ptX = (nStartX + nIdx*(this.m_fIslandWidth + this.m_fIslandSpacing));
ptY = this.m_ChartAxis.Origin.Y;
this.DrawIslandLegendText(m_obGraphics, this.m_XTickFont, ptX, ptY, this.m_fIslandDrawWidth,
m_IslandLegendsList[nIdx], this.GraphAlignment, this.m_TickColor);
}
}
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
override protected bool DrawAxisLabels()
{
return true;
}
/// <summary>
///
/// </summary>
/// <param name="iLeftX"></param>
/// <param name="iLeftY"></param>
/// <param name="iWidth"></param>
/// <param name="iHeight"></param>
/// <param name="dThickness"></param>
/// <param name="faceColor"></param>
/// <returns></returns>
override protected bool DrawBar(Graphics obGraphics, int iLeftX, int iLeftY, float iWidth, float iHeight, double dThickness, Color faceColor)
{
SolidBrush faceBrush = null;
SolidBrush leftBrush = null;
SolidBrush topBrush = null;
SolidBrush baseBrush = null;
SolidBrush backBrush = null;
SolidBrush rightBrush = null;
PointF [] faceRect = null;
PointF [] leftRect = null;
PointF [] topRect = null;
PointF [] baseRect = null;
PointF [] backRect = null;
PointF [] rightRect = null;
try
{
faceBrush = new SolidBrush(faceColor);
leftBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, -2));
topBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, 30));
baseBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, -5));
backBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, -10));
rightBrush = new SolidBrush(ColorUtil.GetDarkColor(faceColor, -20));
faceRect = new PointF[4];
leftRect = new PointF[4];
topRect = new PointF[4];
baseRect = new PointF[4];
backRect = new PointF[4];
rightRect = new PointF[4];
faceRect[0].X = iLeftX;
faceRect[0].Y = iLeftY;
faceRect[1].X = faceRect[0].X + iWidth;
faceRect[1].Y = faceRect[0].Y;
faceRect[2].X = faceRect[1].X;
faceRect[2].Y = faceRect[1].Y + iHeight;
faceRect[3].X = faceRect[2].X - iWidth;
faceRect[3].Y = faceRect[2].Y;
rightRect[0].X = faceRect[1].X;
rightRect[0].Y = faceRect[1].Y;
rightRect[1].X = (float)(rightRect[0].X + dThickness);
rightRect[1].Y = (float)(rightRect[0].Y - dThickness);
rightRect[2].X = rightRect[1].X;
rightRect[2].Y = rightRect[1].Y + iHeight;
rightRect[3].X = rightRect[0].X;
rightRect[3].Y = rightRect[0].Y + iHeight;
leftRect[0].X = faceRect[0].X;
leftRect[0].Y = faceRect[0].Y;
leftRect[1].X = (float)(leftRect[0].X + dThickness);
leftRect[1].Y = (float)(leftRect[0].Y - dThickness);
leftRect[2].X = leftRect[1].X;
leftRect[2].Y = leftRect[1].Y + iHeight;
leftRect[3].X = leftRect[0].X;
leftRect[3].Y = leftRect[0].Y + iHeight;
backRect[0].X = leftRect[1].X;
backRect[0].Y = leftRect[1].Y;
backRect[1].X = rightRect[1].X;
backRect[1].Y = rightRect[1].Y;
backRect[2].X = rightRect[2].X;
backRect[2].Y = rightRect[2].Y;
backRect[3].X = leftRect[2].X;
backRect[3].Y = leftRect[2].Y;
baseRect[0].X = faceRect[0].X;
baseRect[0].Y = faceRect[0].Y;
baseRect[1].X = faceRect[1].X;
baseRect[1].Y = faceRect[1].Y;
baseRect[2].X = rightRect[1].X;
baseRect[2].Y = rightRect[1].Y;
baseRect[3].X = leftRect[1].X;
baseRect[3].Y = leftRect[1].Y;
topRect[0].X = faceRect[3].X;
topRect[0].Y = faceRect[3].Y;
topRect[1].X = faceRect[2].X;
topRect[1].Y = faceRect[2].Y;
topRect[2].X = backRect[2].X;
topRect[2].Y = backRect[2].Y;
topRect[3].X = backRect[3].X;
topRect[3].Y = backRect[3].Y;
obGraphics.FillPolygon(baseBrush, baseRect);
obGraphics.FillPolygon(leftBrush, leftRect);
obGraphics.FillPolygon(backBrush, backRect);
obGraphics.FillPolygon(faceBrush, faceRect);
obGraphics.FillPolygon(rightBrush, rightRect);
obGraphics.FillPolygon(topBrush, topRect);
}
finally
{
if (null != faceBrush)
{
faceBrush.Dispose();
}
if (null != topBrush)
{
topBrush.Dispose();
}
if (null != baseBrush)
{
baseBrush.Dispose();
}
if (null != leftBrush)
{
faceBrush.Dispose();
}
if (null != backBrush)
{
backBrush.Dispose();
}
if (null != rightBrush)
{
rightBrush.Dispose();
}
faceBrush = null;
leftBrush = null;
topBrush = null;
baseBrush = null;
backBrush = null;
rightBrush = null;
}
return true;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
override protected bool DrawAxisForHorizontalAlignment(bool bDrawGrid)
{
Pen obPen = null;
Pen obGridPen = null;
int iThickness = (int)(this.m_iYAxisSpan * m_fDepthFactor);
Point x1, x11;
Point x2, x22;
Point y1, y11;
Point y2, y22;
try
{
CalculateBarHeightScale();
x1 = new Point(this.m_ChartAxis.X1.X, this.m_ChartAxis.X1.Y);
x2 = new Point(this.m_ChartAxis.X2.X, this.m_ChartAxis.X2.Y);
y1 = new Point(this.m_ChartAxis.Y1.X, this.m_ChartAxis.Y1.Y);
y2 = new Point(this.m_ChartAxis.Y2.X, this.m_ChartAxis.Y2.Y);
obPen = new Pen(new SolidBrush(Color.Black));
this.m_obGraphics.DrawLine(obPen, x1, x2);
this.m_obGraphics.DrawLine(obPen, y1, y2);
// Translate all four points to draw the axis at depth.
x11 = x1 + new Size(iThickness, -iThickness);
x22 = x2 + new Size(iThickness, -iThickness);
y11 = y1 + new Size(iThickness, -iThickness);
y22 = y2 + new Size(iThickness, -iThickness);
string strVal = "";
// Draw the grid lines now.
if (this.BlockUnit > 0)
{
SizeF rectText;
PointF pt1 = new PointF();
PointF pt2 = new PointF();
PointF pt3 = new PointF();
obGridPen = new Pen(GridColor);
int nCompleteBlockHeight = (int)(this.BlockUnit * this.m_dBarHeightScale);
for (int i = 0; i <= this.m_iMaxBlocks; i++)
{
pt1.X = y2.X;
//pt1.Y = (float)(y2.Y - (i * this.BlockUnit) * this.m_dBarHeightScale);
pt1.Y = (float)(this.m_ChartAxis.X1.Y - (i*(nCompleteBlockHeight + this.BlocksBuffer)));
if (pt1.Y < this.m_ChartAxis.Y1.Y)
{
pt1.Y = this.m_ChartAxis.Y1.Y;
}
pt2.X = pt1.X + iThickness;
pt2.Y = pt1.Y - iThickness;
pt3.X = pt2.X + this.m_iXAxisSpan;
pt3.Y = pt2.Y;
if (HasGridLines && bDrawGrid)
{
this.m_obGraphics.DrawLine(obGridPen, pt1, pt2);
this.m_obGraphics.DrawLine(obGridPen, pt2, pt3);
}
strVal = (MinYValue + (i * this.BlockUnit)).ToString();
rectText = this.m_obGraphics.MeasureString(strVal, this.m_YTickFont);
pt1.X = pt1.X - (rectText.Width + 2);
this.m_obGraphics.DrawString(strVal, this.m_YTickFont, new SolidBrush(this.m_TitleColor), pt1);
}
}
// Draw Rest of the lines.
this.m_obGraphics.DrawRectangle(obPen, x11.X, y11.Y, this.m_iXAxisSpan, this.m_iYAxisSpan);
this.m_obGraphics.DrawLine(obPen, y1, y11);
this.m_obGraphics.DrawLine(obPen, y2, y22);
this.m_obGraphics.DrawLine(obPen, x1, x11);
this.m_obGraphics.DrawLine(obPen, x2, x22);
this.m_obGraphics.DrawLine(obPen, x11, x22);
}
finally
{
if (obPen != null)
{
obPen.Dispose();
}
}
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -