本文整理汇总了C#中NPlot.PhysicalAxis.WorldToPhysical方法的典型用法代码示例。如果您正苦于以下问题:C# PhysicalAxis.WorldToPhysical方法的具体用法?C# PhysicalAxis.WorldToPhysical怎么用?C# PhysicalAxis.WorldToPhysical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPlot.PhysicalAxis
的用法示例。
在下文中一共展示了PhysicalAxis.WorldToPhysical方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
/// <summary>
/// Draws the plot on a GDI+ surface against the provided x and y axes.
/// </summary>
/// <param name="g">The GDI+ surface on which to draw.</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public override void Draw( Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
{
SequenceAdapter data =
new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData );
TextDataAdapter textData =
new TextDataAdapter( this.DataSource, this.DataMember, this.TextData );
// first plot the marker
// we can do this cast, since the constructor accepts only this type!
for (int i=0; i<data.Count; ++i)
{
try
{
PointD pt = data[i];
if ( !Double.IsNaN(pt.X) && !Double.IsNaN(pt.Y) )
{
PointF xPos = xAxis.WorldToPhysical( pt.X, false);
PointF yPos = yAxis.WorldToPhysical( pt.Y, false);
Marker.Draw( g, (int)xPos.X, (int)yPos.Y );
if ( textData[i] != "" )
{
SizeF size = g.MeasureString( textData[i], this.Font );
switch (labelTextPosition_)
{
case LabelPositions.Above:
g.DrawString( textData[i], font_, Brushes.Black, new PointF(xPos.X-size.Width/2,yPos.Y-size.Height-Marker.Size*2/3));
break;
case LabelPositions.Below:
g.DrawString( textData[i], font_, Brushes.Black, new PointF(xPos.X-size.Width/2,yPos.Y+Marker.Size*2/3));
break;
case LabelPositions.Left:
g.DrawString( textData[i], font_, Brushes.Black, new PointF(xPos.X-size.Width-Marker.Size*2/3,yPos.Y-size.Height/2));
break;
case LabelPositions.Right:
g.DrawString( textData[i], font_, Brushes.Black, new PointF(xPos.X+Marker.Size*2/3,yPos.Y-size.Height/2));
break;
}
}
}
}
catch
{
throw new NPlotException("Error in TextPlot.Draw");
}
}
}
示例2: Draw
/// <summary>
/// Draws the point plot using the Drawing Context and x and y axes supplied
/// </summary>
/// <param name="ctx">The Drawing Context with which to draw.</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public virtual void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
{
SequenceAdapter data_ = new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData );
double leftCutoff_ = xAxis.PhysicalMin.X - marker.Size;
double rightCutoff_ = xAxis.PhysicalMax.X + marker.Size;
ctx.Save ();
ctx.SetColor (marker.LineColor);
ctx.SetLineWidth (marker.LineWidth);
for (int i=0; i<data_.Count; ++i) {
if (!Double.IsNaN(data_[i].X) && !Double.IsNaN(data_[i].Y)) {
Point xPos = xAxis.WorldToPhysical (data_[i].X, false);
if (xPos.X < leftCutoff_ || rightCutoff_ < xPos.X) {
continue;
}
Point yPos = yAxis.WorldToPhysical (data_[i].Y, false);
marker.Draw (ctx, xPos.X, yPos.Y);
if (marker.DropLine) {
Point yMin = new Point (data_[i].X, Math.Max (0.0, yAxis.Axis.WorldMin));
Point yStart = yAxis.WorldToPhysical (yMin.Y, false);
ctx.MoveTo (xPos.X, yStart.Y);
ctx.LineTo (xPos.X, yPos.Y);
ctx.Stroke ();
}
}
}
ctx.Restore ();
}
示例3: Draw
/// <summary>
/// Draws the arrow on a plot surface.
/// </summary>
/// <param name="g">graphics surface on which to draw</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw( System.Drawing.Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
{
if (this.To.X > xAxis.Axis.WorldMax || this.To.X < xAxis.Axis.WorldMin)
return;
if (this.To.Y > yAxis.Axis.WorldMax || this.To.Y < yAxis.Axis.WorldMin)
return;
double angle = this.angle_;
if (this.angle_ < 0.0)
{
int mul = -(int)(this.angle_ / 360.0) + 2;
angle = angle_ + 360.0 * (double)mul;
}
double normAngle = (double)angle % 360.0; // angle in range 0 -> 360.
Point toPoint = new Point(
(int)xAxis.WorldToPhysical( to_.X, true ).X,
(int)yAxis.WorldToPhysical( to_.Y, true ).Y );
float xDir = (float)Math.Cos( normAngle * 2.0 * Math.PI / 360.0 );
float yDir = (float)Math.Sin( normAngle * 2.0 * Math.PI / 360.0 );
toPoint.X += (int)(xDir*headOffset_);
toPoint.Y += (int)(yDir*headOffset_);
float xOff = physicalLength_ * xDir;
float yOff = physicalLength_ * yDir;
Point fromPoint = new Point(
(int)(toPoint.X + xOff),
(int)(toPoint.Y + yOff) );
g.DrawLine( pen_, toPoint, fromPoint );
Point[] head = new Point[3];
head[0] = toPoint;
xOff = headSize_ * (float)Math.Cos( (normAngle-headAngle_/2.0f) * 2.0 * Math.PI / 360.0 );
yOff = headSize_ * (float)Math.Sin( (normAngle-headAngle_/2.0f) * 2.0 * Math.PI / 360.0 );
head[1] = new Point(
(int)(toPoint.X + xOff),
(int)(toPoint.Y + yOff) );
float xOff2 = headSize_ * (float)Math.Cos( (normAngle+headAngle_/2.0f) * 2.0 * Math.PI / 360.0 );
float yOff2 = headSize_ * (float)Math.Sin( (normAngle+headAngle_/2.0f) * 2.0 * Math.PI / 360.0 );
head[2] = new Point(
(int)(toPoint.X + xOff2),
(int)(toPoint.Y + yOff2) );
g.FillPolygon( arrowBrush_, head );
SizeF textSize = g.MeasureString( text_, font_ );
SizeF halfSize = new SizeF( textSize.Width / 2.0f, textSize.Height / 2.0f );
float quadrantSlideLength = halfSize.Width + halfSize.Height;
float quadrantF = (float)normAngle / 90.0f; // integer part gives quadrant.
int quadrant = (int)quadrantF; // quadrant in.
float prop = quadrantF - (float)quadrant; // proportion of way through this qadrant.
float dist = prop * quadrantSlideLength; // distance along quarter of bounds rectangle.
// now find the offset from the middle of the text box that the
// rear end of the arrow should end at (reverse this to get position
// of text box with respect to rear end of arrow).
//
// There is almost certainly an elgant way of doing this involving
// trig functions to get all the signs right, but I'm about ready to
// drop off to sleep at the moment, so this blatent method will have
// to do.
PointF offsetFromMiddle = new PointF( 0.0f, 0.0f );
switch (quadrant)
{
case 0:
if (dist > halfSize.Height)
{
dist -= halfSize.Height;
offsetFromMiddle = new PointF( -halfSize.Width + dist, halfSize.Height );
}
else
{
offsetFromMiddle = new PointF( -halfSize.Width, - dist );
}
break;
case 1:
if (dist > halfSize.Width)
{
dist -= halfSize.Width;
//.........这里部分代码省略.........
示例4: CalculatePhysicalSeparation
/// <summary>
/// Calculates the physical (not world) separation between abscissa values.
/// </summary>
/// <param name="cd">Candle adapter containing data</param>
/// <param name="xAxis">Physical x axis the data is plotted against.</param>
/// <returns>physical separation between abscissa values.</returns>
private static float CalculatePhysicalSeparation( CandleDataAdapter cd, PhysicalAxis xAxis )
{
if (cd.Count > 1)
{
int xPos1 = (int)(xAxis.WorldToPhysical( ((PointOLHC)cd[0]).X, false )).X;
int xPos2 = (int)(xAxis.WorldToPhysical( ((PointOLHC)cd[1]).X, false )).X;
int minDist = xPos2 - xPos1;
if (cd.Count > 2)
{ // to be pretty sure we get the smallest gap.
int xPos3 = (int)(xAxis.WorldToPhysical(((PointOLHC)cd[2]).X, false)).X;
if (xPos3 - xPos2 < minDist)
{
minDist = xPos3 - xPos2;
}
if (cd.Count > 3)
{
int xPos4 = (int)(xAxis.WorldToPhysical(((PointOLHC)cd[3]).X, false)).X;
if (xPos4 - xPos3 < minDist)
{
minDist = xPos4 - xPos3;
}
}
}
return minDist;
}
return 0.0f;
}
示例5: Draw
/// <summary>
/// Draw on to the supplied graphics surface against the supplied axes.
/// </summary>
/// <param name="g">The graphics surface on which to draw.</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
/// <remarks>TODO: block positions may be off by a pixel or so. maybe. Re-think calculations</remarks>
public void Draw( Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
{
if ( data_==null || data_.GetLength(0) == 0 || data_.GetLength(1) == 0 )
{
return;
}
double worldWidth = xAxis.Axis.WorldMax - xAxis.Axis.WorldMin;
double numBlocksHorizontal = worldWidth / this.xStep_;
double worldHeight = yAxis.Axis.WorldMax - yAxis.Axis.WorldMin;
double numBlocksVertical = worldHeight / this.yStep_;
double physicalWidth = xAxis.PhysicalMax.X - xAxis.PhysicalMin.X;
double blockWidth = physicalWidth / numBlocksHorizontal;
bool wPositive = true;
if (blockWidth < 0.0)
{
wPositive = false;
}
blockWidth = Math.Abs(blockWidth)+1;
double physicalHeight = yAxis.PhysicalMax.Y - yAxis.PhysicalMin.Y;
double blockHeight = physicalHeight / numBlocksVertical;
bool hPositive = true;
if (blockHeight < 0.0)
{
hPositive = false;
}
blockHeight = Math.Abs(blockHeight)+1;
for (int i=0; i<data_.GetLength(0); ++i)
{
for (int j=0; j<data_.GetLength(1); ++j)
{
double wX = (double)j*this.xStep_ + xStart_;
double wY = (double)i*this.yStep_ + yStart_;
if ( !hPositive )
{
wY += yStep_;
}
if (!wPositive )
{
wX += xStep_;
}
if (this.center_)
{
wX -= this.xStep_/2.0;
wY -= this.yStep_/2.0;
}
Pen p = new Pen( this.Gradient.GetColor( (data_[i,j]-this.dataMin_)/(this.dataMax_-this.dataMin_) ) );
int x = (int)xAxis.WorldToPhysical(wX,false).X;
int y = (int)yAxis.WorldToPhysical(wY,false).Y;
g.FillRectangle( p.Brush,
x,
y,
(int)blockWidth,
(int)blockHeight);
//g.DrawRectangle(Pens.White,x,y,(int)blockWidth,(int)blockHeight);
}
}
}
示例6: Draw
/// <summary>
/// Renders the histogram.
/// </summary>
/// <param name="g">The Graphics surface on which to draw</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw( Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
{
SequenceAdapter data =
new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData );
float yoff;
for ( int i=0; i<data.Count; ++i )
{
// (1) determine the top left hand point of the bar (assuming not centered)
PointD p1 = data[i];
if ( double.IsNaN(p1.X) || double.IsNaN(p1.Y) )
continue;
// (2) determine the top right hand point of the bar (assuming not centered)
PointD p2;
if (i+1 != data.Count)
{
p2 = data[i+1];
if ( double.IsNaN(p2.X) || double.IsNaN(p2.Y) )
continue;
p2.Y = p1.Y;
}
else if (i != 0)
{
p2 = data[i-1];
if ( double.IsNaN(p2.X) || double.IsNaN(p2.Y) )
continue;
double offset = p1.X - p2.X;
p2.X = p1.X + offset;
p2.Y = p1.Y;
}
else
{
double offset = 1.0f;
p2.X = p1.X + offset;
p2.Y = p1.Y;
}
// (3) now account for plots this may be stacked on top of.
HistogramPlot currentPlot = this;
yoff = 0.0f;
double yval = 0.0f;
while (currentPlot.isStacked_)
{
SequenceAdapter stackedToData = new SequenceAdapter(
currentPlot.stackedTo_.DataSource,
currentPlot.stackedTo_.DataMember,
currentPlot.stackedTo_.OrdinateData,
currentPlot.stackedTo_.AbscissaData );
yval += stackedToData[i].Y;
yoff = yAxis.WorldToPhysical( yval, false ).Y;
p1.Y += stackedToData[i].Y;
p2.Y += stackedToData[i].Y;
currentPlot = currentPlot.stackedTo_;
}
// (4) now account for centering
if ( center_ )
{
double offset = ( p2.X - p1.X ) / 2.0f;
p1.X -= offset;
p2.X -= offset;
}
// (5) now account for BaseOffset (shift of bar sideways).
p1.X += baseOffset_;
p2.X += baseOffset_;
// (6) now get physical coordinates of top two points.
PointF xPos1 = xAxis.WorldToPhysical( p1.X, false );
PointF yPos1 = yAxis.WorldToPhysical( p1.Y, false );
PointF xPos2 = xAxis.WorldToPhysical( p2.X, false );
PointF yPos2 = yAxis.WorldToPhysical( p2.Y, false );
if (isStacked_)
{
currentPlot = this;
while (currentPlot.isStacked_)
{
currentPlot = currentPlot.stackedTo_;
}
this.baseWidth_ = currentPlot.baseWidth_;
}
float width = xPos2.X - xPos1.X;
float height;
if (isStacked_)
{
height = -yPos1.Y+yoff;
}
else
//.........这里部分代码省略.........
示例7: Draw
public void Draw(System.Drawing.Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis)
{
int physicalX = (int)xAxis.WorldToPhysical(x, false).X;
g.DrawLine(pen, new Point(physicalX, yAxis.PhysicalMin.Y), new Point(physicalX, yAxis.PhysicalMax.Y));
}
示例8: DrawGridLines
/// <summary>
/// Does all the work in drawing grid lines.
/// </summary>
/// <param name="ctx">The graphics context with which to draw</param>
/// <param name="axis">TODO</param>
/// <param name="orthogonalAxis">TODO</param>
/// <param name="a">the list of world values to draw grid lines at.</param>
/// <param name="horizontal">true if want horizontal lines, false otherwise.</param>
/// <param name="color">the color to draw the grid lines.</param>
private void DrawGridLines(Context ctx,
PhysicalAxis axis, PhysicalAxis orthogonalAxis,
System.Collections.ArrayList a, bool horizontal)
{
for (int i=0; i<a.Count; ++i) {
Point p1 = axis.WorldToPhysical ((double)a[i], true);
Point p2 = p1;
Point p3 = orthogonalAxis.PhysicalMax;
Point p4 = orthogonalAxis.PhysicalMin;
if (horizontal) {
p1.Y = p4.Y;
p2.Y = p3.Y;
}
else {
p1.X = p4.X;
p2.X = p3.X;
}
ctx.MoveTo (p1);
ctx.LineTo (p2);
// note: casting all drawing was necessary for sane display. why?
//g.DrawLine( p, (int)p1.X, (int)p1.Y, (int)p2.X, (int)p2.Y );
}
ctx.SetLineWidth (1);
ctx.SetColor (gridColor);
ctx.SetLineDash (0, gridDash);
ctx.Stroke ();
}
示例9: Draw
/// <summary>
/// Draws the marker on a plot surface.
/// </summary>
/// <param name="g">graphics surface on which to draw</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw( System.Drawing.Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
{
PointF point = new PointF(
xAxis.WorldToPhysical( x_, true ).X,
yAxis.WorldToPhysical( y_, true ).Y );
marker_.Draw( g, (int)point.X, (int)point.Y );
}
示例10: Draw
/// <summary>
/// Draws the candle plot with the specified Drawing Context and X,Y axes
/// </summary>
/// <param name="ctx">The Drawing Context with which to draw</param>
/// <param name="xAxis">The physical X-Axis to draw against</param>
/// <param name="yAxis">The physical Y-Axis to draw against</param>
public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
{
CandleDataAdapter cd = new CandleDataAdapter (DataSource, DataMember,
AbscissaData, OpenData, LowData, HighData, CloseData);
double offset = 0;
if (Centered) {
offset = CalculatePhysicalSeparation (cd,xAxis)/2;
}
double addAmount = StickWidth/2;
double stickWidth = StickWidth;
if (StickWidth == AutoScaleStickWidth) {
// default
addAmount = 2;
stickWidth = 4;
double minDist = CalculatePhysicalSeparation (cd, xAxis);
addAmount = minDist / 3;
stickWidth = addAmount * 2;
}
ctx.Save ();
ctx.SetLineWidth (1);
/*
// brant hyatt proposed.
if (Style == Styles.Stick)
{
p.Width = stickWidth;
addAmount = stickWidth + 2;
}
*/
for (int i=0; i<cd.Count; ++i) {
PointOLHC point = (PointOLHC)cd [i];
if ((!double.IsNaN (point.Open)) && (!double.IsNaN(point.High))
&& (!double.IsNaN (point.Low)) && (!double.IsNaN(point.Close))) {
double xPos = (xAxis.WorldToPhysical (point.X, false)).X;
if (xPos + offset + addAmount < xAxis.PhysicalMin.X || xAxis.PhysicalMax.X < xPos + offset - addAmount) {
continue;
}
double yLo = (yAxis.WorldToPhysical (point.Low, false)).Y;
double yHi = (yAxis.WorldToPhysical (point.High, false)).Y;
double yOpn = (yAxis.WorldToPhysical (point.Open, false)).Y;
double yCls = (yAxis.WorldToPhysical (point.Close,false)).Y;
if (Style == Styles.Stick) {
/*
// brant hyatt proposed.
if (i > 0)
{
if ( ((PointOLHC)cd[i]).Close > ((PointOLHC)cd[i-1]).Close)
{
p.Color = BullishColor;
}
else
{
p.Color = BearishColor;
}
}
*/
ctx.SetColor (Color);
ctx.MoveTo (xPos+offset, yLo);
ctx.LineTo (xPos+offset, yHi); // Low to High line
ctx.MoveTo (xPos-addAmount+offset, yOpn);
ctx.LineTo (xPos+offset, yOpn); // Open line
ctx.MoveTo (xPos+addAmount+offset, yCls);
ctx.LineTo (xPos+offset, yCls); // Close line
ctx.Stroke ();
}
else if (Style == Styles.Filled) {
ctx.MoveTo (xPos+offset, yLo);
ctx.LineTo (xPos+offset, yHi);
ctx.Stroke ();
if (yOpn > yCls) {
ctx.SetColor (BullishColor);
ctx.Rectangle (xPos-addAmount+offset, yCls, stickWidth, yOpn - yCls);
ctx.FillPreserve ();
ctx.SetColor (Color);
ctx.Stroke ();
}
else if (yOpn < yCls) {
ctx.SetColor (BearishColor);
ctx.Rectangle (xPos-addAmount+offset, yOpn, stickWidth, yCls - yOpn);
ctx.FillPreserve ();
ctx.SetColor (Color);
//.........这里部分代码省略.........
示例11: Draw
/// <summary>
/// Draws the histogram.
/// </summary>
/// <param name="ctx">The Drawing Context with which to draw</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
{
double yoff;
SequenceAdapter data = new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData);
ctx.Save ();
ctx.SetLineWidth (1);
for (int i=0; i<data.Count; ++i ) {
// (1) determine the top left hand point of the bar (assuming not centered)
Point p1 = data[i];
if (double.IsNaN(p1.X) || double.IsNaN(p1.Y)) {
continue;
}
// (2) determine the top right hand point of the bar (assuming not centered)
Point p2 = Point.Zero;;
if (i+1 != data.Count) {
p2 = data[i+1];
if (double.IsNaN(p2.X) || double.IsNaN(p2.Y)) {
continue;
}
p2.Y = p1.Y;
}
else if (i != 0) {
p2 = data[i-1];
if (double.IsNaN(p2.X) || double.IsNaN(p2.Y)) {
continue;
}
double offset = p1.X - p2.X;
p2.X = p1.X + offset;
p2.Y = p1.Y;
}
else {
double offset = 1.0;
p2.X = p1.X + offset;
p2.Y = p1.Y;
}
// (3) now account for plots this may be stacked on top of.
HistogramPlot currentPlot = this;
yoff = 0.0;
double yval = 0.0;
while (currentPlot.isStacked_) {
SequenceAdapter stackedToData = new SequenceAdapter (
currentPlot.stackedTo_.DataSource,
currentPlot.stackedTo_.DataMember,
currentPlot.stackedTo_.OrdinateData,
currentPlot.stackedTo_.AbscissaData );
yval += stackedToData[i].Y;
yoff = yAxis.WorldToPhysical (yval, false).Y;
p1.Y += stackedToData[i].Y;
p2.Y += stackedToData[i].Y;
currentPlot = currentPlot.stackedTo_;
}
// (4) now account for centering
if (center_) {
double offset = (p2.X - p1.X) / 2.0;
p1.X -= offset;
p2.X -= offset;
}
// (5) now account for BaseOffset (shift of bar sideways).
p1.X += baseOffset_;
p2.X += baseOffset_;
// (6) now get physical coordinates of top two points.
Point xPos1 = xAxis.WorldToPhysical (p1.X, false);
Point yPos1 = yAxis.WorldToPhysical (p1.Y, false);
Point xPos2 = xAxis.WorldToPhysical (p2.X, false);
if (isStacked_) {
currentPlot = this;
while (currentPlot.isStacked_) {
currentPlot = currentPlot.stackedTo_;
}
baseWidth_ = currentPlot.baseWidth_;
}
double width = xPos2.X - xPos1.X;
double height;
if (isStacked_) {
height = -yPos1.Y+yoff;
}
else {
height = -yPos1.Y+yAxis.PhysicalMin.Y;
}
double xoff = (1.0 - baseWidth_)/2.0*width;
Rectangle r = new Rectangle (xPos1.X+xoff, yPos1.Y, width-2*xoff, height);
//.........这里部分代码省略.........
示例12: Draw
/// <summary>
/// Draws the marker on a plot surface.
/// </summary>
/// <param name="ctx">The Drawing Context with which to draw</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
{
Point point = new Point (
xAxis.WorldToPhysical (x_, true).X,
yAxis.WorldToPhysical (y_, true ).Y);
marker_.Draw (ctx, point.X, point.Y );
}
示例13: Draw
/// <summary>
/// Draws the vertical line using the Context and the x and y axes specified
/// </summary>
/// <param name="ctx">The Context with which to draw.</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
{
double yMin = yAxis.PhysicalMin.Y;
double yMax = yAxis.PhysicalMax.Y;
yMin -= PixelIndent;
yMax += PixelIndent;
double length = Math.Abs (yMax - yMin);
double lengthDiff = length - length*LengthScale;
double indentAmount = lengthDiff/2;
yMin -= indentAmount;
yMax += indentAmount;
double xPos = xAxis.WorldToPhysical (AbscissaValue, false).X;
ctx.Save ();
ctx.SetLineWidth (1);
ctx.SetColor (Color);
ctx.MoveTo (xPos, yMin);
ctx.LineTo (xPos, yMax);
ctx.Stroke ();
ctx.Restore ();
// todo: clip and proper logic for flipped axis min max.
}
示例14: Draw
/// <summary>
/// Draws the horizontal line plot using the Context and the x and y axes specified
/// </summary>
/// <param name="ctx">The Context with which to draw.</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
{
double xMin = xAxis.PhysicalMin.X;
double xMax = xAxis.PhysicalMax.X;
xMin += pixelIndent_;
xMax -= pixelIndent_;
double length = Math.Abs (xMax - xMin);
double lengthDiff = length - length*scale_;
double indentAmount = lengthDiff/2;
xMin += indentAmount;
xMax -= indentAmount;
double yPos = yAxis.WorldToPhysical (value_, false).Y;
ctx.Save ();
ctx.SetLineWidth (1);
ctx.SetColor (color_);
ctx.MoveTo (xMin, yPos);
ctx.LineTo (xMax, yPos);
ctx.Stroke ();
ctx.Restore ();
// todo: clip and proper logic for flipped axis min max.
}
示例15: Draw
/// <summary>
/// Draws the step plot on a GDI+ surface against the provided x and y axes.
/// </summary>
/// <param name="g">The GDI+ surface on which to draw.</param>
/// <param name="xAxis">The X-Axis to draw against.</param>
/// <param name="yAxis">The Y-Axis to draw against.</param>
public virtual void Draw( Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
{
SequenceAdapter data =
new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData );
double leftCutoff = xAxis.PhysicalToWorld(xAxis.PhysicalMin, false);
double rightCutoff = xAxis.PhysicalToWorld(xAxis.PhysicalMax, false);
for (int i=0; i<data.Count; ++i)
{
PointD p1 = data[i];
if (Double.IsNaN(p1.X) || Double.IsNaN(p1.Y))
{
continue;
}
PointD p2;
PointD p3;
if (i+1 != data.Count)
{
p2 = data[i+1];
if (Double.IsNaN(p2.X) || Double.IsNaN(p2.Y))
{
continue;
}
p2.Y = p1.Y;
p3 = data[i+1];
}
else
{
// Check that we are not dealing with a DataSource of 1 point.
// This check is done here so it is only checked on the end
// condition and not for every point in the DataSource.
if (data.Count > 1)
{
p2 = data[i - 1];
}
else
{
// TODO: Once log4net is set up post a message to the user that a step-plot of 1 really does not make any sense.
p2 = p1;
}
double offset = p1.X - p2.X;
p2.X = p1.X + offset;
p2.Y = p1.Y;
p3 = p2;
}
if ( this.center_ )
{
double offset = ( p2.X - p1.X ) / 2.0f;
p1.X -= offset;
p2.X -= offset;
p3.X -= offset;
}
PointF xPos1 = xAxis.WorldToPhysical( p1.X, false );
PointF yPos1 = yAxis.WorldToPhysical( p1.Y, false );
PointF xPos2 = xAxis.WorldToPhysical( p2.X, false );
PointF yPos2 = yAxis.WorldToPhysical( p2.Y, false );
PointF xPos3 = xAxis.WorldToPhysical( p3.X, false );
PointF yPos3 = yAxis.WorldToPhysical( p3.Y, false );
// do horizontal clipping here, to speed up
if ((p1.X < leftCutoff && p2.X < leftCutoff && p3.X < leftCutoff) ||
(p1.X > rightCutoff && p2.X > rightCutoff && p3.X > rightCutoff))
{
continue;
}
if (!this.hideHorizontalSegments_)
{
if (scale_ != 1.0f)
{
float middle = (xPos2.X + xPos1.X) / 2.0f;
float width = xPos2.X - xPos1.X;
width *= this.scale_;
g.DrawLine( Pen, (int)(middle-width/2.0f), yPos1.Y, (int)(middle+width/2.0f), yPos2.Y );
}
else
{
g.DrawLine( Pen, xPos1.X, yPos1.Y, xPos2.X, yPos2.Y );
}
}
if (!this.hideVerticalSegments_)
{
g.DrawLine( Pen, xPos2.X, yPos2.Y, xPos3.X, yPos3.Y );
}
}
}