예제 #1
0
 /// <summary>
 /// Fill the background of the <see cref="RectangleF"/> area, using the
 /// fill type from this <see cref="Fill"/>.
 /// </summary>
 /// <param name="g">
 /// A graphic device object to be drawn into.  This is normally e.Graphics from the
 /// PaintEventArgs argument to the Paint() method.
 /// </param>
 /// <param name="rect">The <see cref="RectangleF"/> struct specifying the area
 /// to be filled</param>
 /// <param name="pt">The data value to be used in case it's a
 /// <see cref="FillType.GradientByX" />, <see cref="FillType.GradientByY" />, or
 /// <see cref="FillType.GradientByZ" /> <see cref="FillType" />.</param>
 public void Draw( Graphics g, RectangleF rect, PointPair pt )
 {
     if ( this.IsVisible )
     {
         using ( Brush brush = this.MakeBrush( rect, pt ) )
         {
             g.FillRectangle( brush, rect );
         }
     }
 }
예제 #2
0
파일: Bar.cs 프로젝트: nic0lae/mathtoolbelt
        /// <summary>
        /// Draw the <see cref="Bar"/> to the specified <see cref="Graphics"/> device
        /// at the specified location.  This routine draws a single bar.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="left">The x position of the left side of the bar in
        /// pixel units</param>
        /// <param name="right">The x position of the right side of the bar in
        /// pixel units</param>
        /// <param name="top">The y position of the top of the bar in
        /// pixel units</param>
        /// <param name="bottom">The y position of the bottom of the bar in
        /// pixel units</param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This
        /// scaling factor is calculated by the <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor
        /// represents a linear multiple to be applied to font sizes, symbol sizes, etc.
        /// </param>
        /// <param name="fullFrame">true to draw the bottom portion of the border around the
        /// bar (this is for legend entries)</param> 
        /// <param name="dataValue">The data value to be used for a value-based
        /// color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.</param>
        /// <param name="isSelected">Indicates that the <see cref="Bar" /> should be drawn
        /// with attributes from the <see cref="Selection" /> class.
        /// </param>
        public void Draw( Graphics g, GraphPane pane, float left, float right, float top,
							float bottom, float scaleFactor, bool fullFrame, bool isSelected,
							PointPair dataValue )
        {
            // Do a sanity check to make sure the top < bottom.  If not, reverse them
            if ( top > bottom )
            {
                float junk = top;
                top = bottom;
                bottom = junk;
            }

            // Do a sanity check to make sure the left < right.  If not, reverse them
            if ( left > right )
            {
                float junk = right;
                right = left;
                left = junk;
            }

            if ( top < -10000 )
                top = -10000;
            else if ( top > 10000 )
                top = 10000;
            if ( left < -10000 )
                left = -10000;
            else if ( left > 10000 )
                left = 10000;
            if ( right < -10000 )
                right = -10000;
            else if ( right > 10000 )
                right = 10000;
            if ( bottom < -10000 )
                bottom = -10000;
            else if ( bottom > 10000 )
                bottom = 10000;

            // Make a rectangle for the bar and draw it
            RectangleF rect = new RectangleF( left, top, right - left, bottom - top );

            Draw( g, pane, rect, scaleFactor, fullFrame, isSelected, dataValue );
        }
예제 #3
0
파일: Bar.cs 프로젝트: nic0lae/mathtoolbelt
        /// <summary>
        /// Draw the <see cref="Bar"/> to the specified <see cref="Graphics"/> device
        /// at the specified location.  This routine draws a single bar.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="rect">The rectangle (pixels) to contain the bar</param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This
        /// scaling factor is calculated by the <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor
        /// represents a linear multiple to be applied to font sizes, symbol sizes, etc.
        /// </param>
        /// <param name="fullFrame">true to draw the bottom portion of the border around the
        /// bar (this is for legend entries)</param> 
        /// <param name="dataValue">The data value to be used for a value-based
        /// color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.</param>
        /// <param name="isSelected">Indicates that the <see cref="Bar" /> should be drawn
        /// with attributes from the <see cref="Selection" /> class.
        /// </param>
        public void Draw( Graphics g, GraphPane pane, RectangleF rect, float scaleFactor,
							bool fullFrame, bool isSelected, PointPair dataValue )
        {
            if ( isSelected )
            {
                Selection.Fill.Draw( g, rect, dataValue );
                Selection.Border.Draw( g, pane, scaleFactor, rect );
            }
            else
            {
                _fill.Draw( g, rect, dataValue );
                _border.Draw( g, pane, scaleFactor, rect );
            }
        }
예제 #4
0
        /// <summary>
        /// This method just handles the case where one or more of the coordinates are outrageous,
        /// or GDI+ threw an exception.  This method attempts to correct the outrageous coordinates by
        /// interpolating them to a point (along the original line) that lies at the edge of the ChartRect
        /// so that GDI+ will handle it properly.  GDI+ will throw an exception, or just plot the data
        /// incorrectly if the coordinates are too large (empirically, this appears to be when the
        /// coordinate value is greater than 5,000,000 or less than -5,000,000).  Although you typically
        /// would not see coordinates like this, if you repeatedly zoom in on a ZedGraphControl, eventually
        /// all your points will be way outside the bounds of the plot.
        /// </summary>
        private void InterpolatePoint( Graphics g, GraphPane pane, CurveItem curve, PointPair lastPt,
						float scaleFactor, Pen pen, float lastX, float lastY, float tmpX, float tmpY )
        {
            try
            {
                RectangleF chartRect = pane.Chart._rect;
                // try to interpolate values
                bool lastIn = chartRect.Contains( lastX, lastY );
                bool curIn = chartRect.Contains( tmpX, tmpY );

                // If both points are outside the ChartRect, make a new point that is on the LastX/Y
                // side of the ChartRect, and fall through to the code that handles lastIn == true
                if ( !lastIn )
                {
                    float newX, newY;

                    if ( Math.Abs( lastX ) > Math.Abs( lastY ) )
                    {
                        newX = lastX < 0 ? chartRect.Left : chartRect.Right;
                        newY = lastY + ( tmpY - lastY ) * ( newX - lastX ) / ( tmpX - lastX );
                    }
                    else
                    {
                        newY = lastY < 0 ? chartRect.Top : chartRect.Bottom;
                        newX = lastX + ( tmpX - lastX ) * ( newY - lastY ) / ( tmpY - lastY );
                    }

                    lastX = newX;
                    lastY = newY;
                }

                if ( !curIn )
                {
                    float newX, newY;

                    if ( Math.Abs( tmpX ) > Math.Abs( tmpY ) )
                    {
                        newX = tmpX < 0 ? chartRect.Left : chartRect.Right;
                        newY = tmpY + ( lastY - tmpY ) * ( newX - tmpX ) / ( lastX - tmpX );
                    }
                    else
                    {
                        newY = tmpY < 0 ? chartRect.Top : chartRect.Bottom;
                        newX = tmpX + ( lastX - tmpX ) * ( newY - tmpY ) / ( lastY - tmpY );
                    }

                    tmpX = newX;
                    tmpY = newY;
                }

                /*
                if ( this.StepType == StepType.ForwardStep )
                {
                    g.DrawLine( pen, lastX, lastY, tmpX, lastY );
                    g.DrawLine( pen, tmpX, lastY, tmpX, tmpY );
                }
                else if ( this.StepType == StepType.RearwardStep )
                {
                    g.DrawLine( pen, lastX, lastY, lastX, tmpY );
                    g.DrawLine( pen, lastX, tmpY, tmpX, tmpY );
                }
                else 		// non-step
                    g.DrawLine( pen, lastX, lastY, tmpX, tmpY );
                */
                if ( !curve.IsSelected && this._gradientFill.IsGradientValueType )
                {
                    using ( Pen tPen = GetPen( pane, scaleFactor, lastPt ) )
                    {
                        if ( this.StepType == StepType.NonStep )
                        {
                            g.DrawLine( tPen, lastX, lastY, tmpX, tmpY );
                        }
                        else if ( this.StepType == StepType.ForwardStep )
                        {
                            g.DrawLine( tPen, lastX, lastY, tmpX, lastY );
                            g.DrawLine( tPen, tmpX, lastY, tmpX, tmpY );
                        }
                        else if ( this.StepType == StepType.RearwardStep )
                        {
                            g.DrawLine( tPen, lastX, lastY, lastX, tmpY );
                            g.DrawLine( tPen, lastX, tmpY, tmpX, tmpY );
                        }
                        else if ( this.StepType == StepType.ForwardSegment )
                        {
                            g.DrawLine( tPen, lastX, lastY, tmpX, lastY );
                        }
                        else
                        {
                            g.DrawLine( tPen, lastX, tmpY, tmpX, tmpY );
                        }
                    }
                }
                else
                {
                    if ( this.StepType == StepType.NonStep )
                    {
                        g.DrawLine( pen, lastX, lastY, tmpX, tmpY );
                    }
                    else if ( this.StepType == StepType.ForwardStep )
                    {
                        g.DrawLine( pen, lastX, lastY, tmpX, lastY );
                        g.DrawLine( pen, tmpX, lastY, tmpX, tmpY );
                    }
                    else if ( this.StepType == StepType.RearwardStep )
                    {
                        g.DrawLine( pen, lastX, lastY, lastX, tmpY );
                        g.DrawLine( pen, lastX, tmpY, tmpX, tmpY );
                    }
                    else if ( this.StepType == StepType.ForwardSegment )
                    {
                        g.DrawLine( pen, lastX, lastY, tmpX, lastY );
                    }
                    else if ( this.StepType == StepType.RearwardSegment )
                    {
                        g.DrawLine( pen, lastX, tmpY, tmpX, tmpY );
                    }
                }

            }

            catch { }
        }
예제 #5
0
        /// <summary>
        /// Constructs a buffer with a copy of the items within the provided
        /// <see cref="IPointList" />.
        /// The <see cref="Capacity" /> is set to the length of the provided list.
        /// </summary>
        /// <param name="rhs">The <see cref="IPointList" /> to be copied.</param>
        public RollingPointPairList( IPointList rhs )
        {
            _mBuffer = new PointPair[rhs.Count];

            for ( int i = 0; i < rhs.Count; i++ )
            {
                _mBuffer[i] = new PointPair( rhs[i] );
            }

            _headIdx = rhs.Count - 1;
            _tailIdx = 0;
        }
        private void HandleEditDrag( Point mousePt )
        {
            // get the scale values that correspond to the current point
            double curX, curY;
            _dragPane.ReverseTransform( mousePt, _dragCurve.IsX2Axis, _dragCurve.IsY2Axis,
                    _dragCurve.YAxisIndex, out curX, out curY );
            double startX, startY;
            _dragPane.ReverseTransform( _dragStartPt, _dragCurve.IsX2Axis, _dragCurve.IsY2Axis,
                    _dragCurve.YAxisIndex, out startX, out startY );

            // calculate the new scale values for the point
            PointPair newPt = new PointPair( _dragStartPair );

            Scale xScale = _dragCurve.GetXAxis( _dragPane )._scale;
            if ( _isEnableHEdit )
                newPt.X = xScale.DeLinearize( xScale.Linearize( newPt.X ) +
                            xScale.Linearize( curX ) - xScale.Linearize( startX ) );

            Scale yScale = _dragCurve.GetYAxis( _dragPane )._scale;
            if ( _isEnableVEdit )
                newPt.Y = yScale.DeLinearize( yScale.Linearize( newPt.Y ) +
                            yScale.Linearize( curY ) - yScale.Linearize( startY ) );

            // save the data back to the point list
            IPointListEdit list = _dragCurve.Points as IPointListEdit;
            if ( list != null )
                list[_dragIndex] = newPt;

            // force a redraw
            Refresh();
        }
예제 #7
0
        /// <summary>
        /// Draw the <see cref="ErrorBar"/> to the specified <see cref="Graphics"/>
        /// device at the specified location.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="isXBase">boolean value that indicates if the "base" axis for this
        /// <see cref="ErrorBar"/> is the X axis.  True for an <see cref="XAxis"/> base,
        /// false for a <see cref="YAxis"/> or <see cref="Y2Axis"/> base.</param>
        /// <param name="pixBase">The independent axis position of the center of the error bar in
        /// pixel units</param>
        /// <param name="pixValue">The dependent axis position of the top of the error bar in
        /// pixel units</param>
        /// <param name="pixLowValue">The dependent axis position of the bottom of the error bar in
        /// pixel units</param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This
        /// scaling factor is calculated by the <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor
        /// represents a linear multiple to be applied to font sizes, symbol sizes, etc.</param>
        /// <param name="pen">A pen with attributes of <see cref="Color"/> and
        /// <see cref="PenWidth"/> for this <see cref="ErrorBar"/></param>
        /// <param name="dataValue">The data value to be used for a value-based
        /// color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.</param>
        /// <param name="isSelected">Indicates that the <see cref="ErrorBar" /> should be drawn
        /// with attributes from the <see cref="Selection" /> class.
        /// </param>
        public void Draw( Graphics g, GraphPane pane, bool isXBase,
								float pixBase, float pixValue,
								float pixLowValue, float scaleFactor, Pen pen, bool isSelected,
								PointPair dataValue )
        {
            if ( isXBase )
            {
                g.DrawLine( pen, pixBase, pixValue, pixBase, pixLowValue );
                _symbol.DrawSymbol( g, pane, (int)pixBase, (int)pixValue,
                            scaleFactor, isSelected, dataValue );
                _symbol.DrawSymbol( g, pane, (int)pixBase, (int)pixLowValue,
                            scaleFactor, isSelected, dataValue );
            }
            else
            {
                g.DrawLine( pen, pixValue, pixBase, pixLowValue, pixBase );
                _symbol.DrawSymbol( g, pane, (int)pixValue, (int)pixBase,
                            scaleFactor, isSelected, dataValue );
                _symbol.DrawSymbol( g, pane, (int)pixLowValue, (int)pixBase,
                            scaleFactor, isSelected, dataValue );
            }
        }
예제 #8
0
 /// <summary>
 /// Indexer: get the Sample instance at the specified ordinal position in the list
 /// </summary>
 /// <param name="index">The ordinal position in the list of samples</param>
 /// <returns>Returns a <see cref="PointPair" /> instance containing the
 /// data specified by <see cref="XType" /> and <see cref="YType" />
 /// </returns>
 public PointPair this[int index]
 {
     get
     {
         PointPair pt = new PointPair();
         Sample sample = (Sample) list[index];
         pt.X = GetValue( sample, XType );
         pt.Y = GetValue( sample, YType );
         return pt;
     }
 }
예제 #9
0
        /// <summary>
        /// Draw all the <see cref="OHLCBar"/>'s to the specified <see cref="Graphics"/>
        /// device as a candlestick at each defined point.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="curve">A <see cref="OHLCBarItem"/> object representing the
        /// <see cref="OHLCBar"/>'s to be drawn.</param>
        /// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent)
        /// axis for the <see cref="OHLCBar"/></param>
        /// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent)
        /// axis for the <see cref="OHLCBar"/></param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        public void Draw(Graphics g, GraphPane pane, OHLCBarItem curve,
                         Axis baseAxis, Axis valueAxis, float scaleFactor)
        {
            //ValueHandler valueHandler = new ValueHandler( pane, false );

            float pixBase, pixHigh, pixLow, pixOpen, pixClose;

            if (curve.Points != null)
            {
                //float halfSize = _size * scaleFactor;
                float halfSize = GetBarWidth(pane, baseAxis, scaleFactor);

                using (Pen pen = !curve.IsSelected ? new Pen(_color, _width) :
                                 new Pen(Selection.Border.Color, Selection.Border.Width))
//				using ( Pen pen = new Pen( _color, _penWidth ) )
                {
                    // Loop over each defined point
                    for (int i = 0; i < curve.Points.Count; i++)
                    {
                        PointPair pt    = curve.Points[i];
                        double    date  = pt.X;
                        double    high  = pt.Y;
                        double    low   = pt.Z;
                        double    open  = PointPair.Missing;
                        double    close = PointPair.Missing;
                        if (pt is StockPt)
                        {
                            open  = (pt as StockPt).Open;
                            close = (pt as StockPt).Close;
                        }

                        // Any value set to double max is invalid and should be skipped
                        // This is used for calculated values that are out of range, divide
                        //   by zero, etc.
                        // Also, any value <= zero on a log scale is invalid

                        if (!curve.Points[i].IsInvalid3D &&
                            (date > 0 || !baseAxis._scale.IsLog) &&
                            ((high > 0 && low > 0) || !valueAxis._scale.IsLog))
                        {
                            pixBase = (int)(baseAxis.Scale.Transform(curve.IsOverrideOrdinal, i, date) + 0.5);
                            //pixBase = baseAxis.Scale.Transform( curve.IsOverrideOrdinal, i, date );
                            pixHigh = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, high);
                            pixLow  = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, low);
                            if (PointPair.IsValueInvalid(open))
                            {
                                pixOpen = Single.MaxValue;
                            }
                            else
                            {
                                pixOpen = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, open);
                            }

                            if (PointPair.IsValueInvalid(close))
                            {
                                pixClose = Single.MaxValue;
                            }
                            else
                            {
                                pixClose = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, close);
                            }

                            if (!curve.IsSelected && this._gradientFill.IsGradientValueType)
                            {
                                using (Pen tPen = GetPen(pane, scaleFactor, pt))
                                    Draw(g, pane, baseAxis is XAxis || baseAxis is X2Axis,
                                         pixBase, pixHigh, pixLow, pixOpen,
                                         pixClose, halfSize, tPen);
                            }
                            else
                            {
                                Draw(g, pane, baseAxis is XAxis || baseAxis is X2Axis,
                                     pixBase, pixHigh, pixLow, pixOpen,
                                     pixClose, halfSize, pen);
                            }
                        }
                    }
                }
            }
        }
예제 #10
0
 /// <summary>
 /// The StockPt copy constructor.
 /// </summary>
 /// <param name="rhs">The basis for the copy.</param>
 public StockPt( PointPair rhs )
     : base(rhs)
 {
     if ( rhs is StockPt )
     {
         StockPt pt = rhs as StockPt;
         this.Open = pt.Open;
         this.Close = pt.Close;
         this.Vol = pt.Vol;
         this.ColorValue = rhs.ColorValue;
     }
     else
     {
         this.Open = PointPair.Missing;
         this.Close = PointPair.Missing;
         this.Vol = PointPair.Missing;
         this.ColorValue = PointPair.Missing;
     }
 }
예제 #11
0
        /// <summary>
        /// Draw the <see cref="JapaneseCandleStick"/> to the specified <see cref="Graphics"/>
        /// device at the specified location.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="isXBase">boolean value that indicates if the "base" axis for this
        /// <see cref="JapaneseCandleStick"/> is the X axis.  True for an <see cref="XAxis"/> base,
        /// false for a <see cref="YAxis"/> or <see cref="Y2Axis"/> base.</param>
        /// <param name="pixBase">The independent axis position of the center of the candlestick in
        /// pixel units</param>
        /// <param name="pixHigh">The high value position of the candlestick in
        /// pixel units</param>
        /// <param name="pixLow">The low value position of the candlestick in
        /// pixel units</param>
        /// <param name="pixOpen">The opening value position of the candlestick in
        /// pixel units</param>
        /// <param name="pixClose">The closing value position of the candlestick in
        /// pixel units</param>
        /// <param name="halfSize">The scaled width of one-half of a bar, in pixels</param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This
        /// scaling factor is calculated by the <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor
        /// represents a linear multiple to be applied to font sizes, symbol sizes, etc.</param>
        /// <param name="pen">A pen with the <see cref="Color"/> attribute for this
        /// <see cref="JapaneseCandleStick"/></param>
        /// <param name="fill">
        /// The <see cref="Fill" /> instance to be used for filling this
        /// <see cref="JapaneseCandleStick" />
        /// </param>
        /// <param name="border">The <see cref="Border" /> instance to be used for drawing the
        /// border around the <see cref="JapaneseCandleStick" /> filled box</param>
        /// <param name="pt">The <see cref="PointPair" /> to be used for determining the
        /// <see cref="Fill" />, just in case it's a <see cref="FillType.GradientByX" />,
        /// <see cref="FillType.GradientByY" />, or
        /// <see cref="FillType.GradientByZ" /> <see cref="FillType" /></param>
        public void Draw( Graphics g, GraphPane pane, bool isXBase,
								float pixBase, float pixHigh, float pixLow,
								float pixOpen, float pixClose, float halfSize,
								float scaleFactor, Pen pen, Fill fill, Border border, PointPair pt )
        {
            //float halfSize = (int) ( _size * scaleFactor / 2.0f + 0.5f );

            if ( pixBase != PointPair.Missing && Math.Abs( pixLow ) < 1000000 &&
                        Math.Abs( pixHigh ) < 1000000)
            {
                RectangleF rect;
                if ( isXBase )
                {
                    rect = new RectangleF( pixBase - halfSize, Math.Min( pixOpen, pixClose ),
                                halfSize * 2.0f, Math.Abs( pixOpen - pixClose ) );

                    g.DrawLine( pen, pixBase, pixHigh, pixBase, pixLow );
                }
                else
                {
                    rect = new RectangleF( Math.Min( pixOpen, pixClose ), pixBase - halfSize,
                                Math.Abs( pixOpen - pixClose ), halfSize * 2.0f );

                    g.DrawLine( pen, pixHigh, pixBase, pixLow, pixBase );
                }

                if ( _isOpenCloseVisible && Math.Abs( pixOpen ) < 1000000 &&
                            Math.Abs( pixClose ) < 1000000 )
                {
                    if ( rect.Width == 0 )
                        rect.Width = 1;
                    if ( rect.Height == 0 )
                        rect.Height = 1;

                    fill.Draw( g, rect, pt );
                    border.Draw( g, pane, scaleFactor, rect );
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Add a set of points to the <see cref="RollingPointPairList"/> from
        /// three arrays of type double.
        /// If the X or Y array is null, then a set of ordinal values is automatically
        /// generated in its place (see <see cref="AxisType.Ordinal"/>.
        /// If the <see paramref="z"/> value
        /// is null, then it is set to zero.
        /// If the arrays are of different size, then the larger array prevails and the
        /// smaller array is padded with <see cref="PointPairBase.Missing"/> values.
        /// </summary>
        /// <param name="x">A double[] array of X values</param>
        /// <param name="y">A double[] array of Y values</param>
        /// <param name="z">A double[] array of Z values</param>
        public void Add( double[] x, double[] y, double[] z )
        {
            int len = 0;

            if ( x != null )
                len = x.Length;
            if ( y != null && y.Length > len )
                len = y.Length;
            if ( z != null && z.Length > len )
                len = z.Length;

            for ( int i = 0; i < len; i++ )
            {
                PointPair point = new PointPair();

                if ( x == null )
                    point.X = (double)i + 1.0;
                else if ( i < x.Length )
                    point.X = x[i];
                else
                    point.X = PointPair.Missing;

                if ( y == null )
                    point.Y = (double)i + 1.0;
                else if ( i < y.Length )
                    point.Y = y[i];
                else
                    point.Y = PointPair.Missing;

                if ( z == null )
                    point.Z = (double)i + 1.0;
                else if ( i < z.Length )
                    point.Z = z[i];
                else
                    point.Z = PointPair.Missing;

                Add( point );
            }
        }
예제 #13
0
        /// <summary>
        /// Add a set of values onto the head of the queue,
        /// overwriting old values if the buffer is full.
        /// </summary>
        /// <remarks>
        /// This method is much more efficient that the <see cref="Add(PointPair)">Add(PointPair)</see>
        /// method, since it does not require that a new PointPair instance be provided.
        /// If the buffer already contains a <see cref="PointPair"/> at the head position,
        /// then the x, y, z, and tag values will be copied into the existing PointPair.
        /// Otherwise, a new PointPair instance must be created.
        /// In this way, each PointPair position in the rolling list will only be allocated one time.
        /// To truly be memory efficient, the <see cref="Remove" />, <see cref="RemoveAt" />,
        /// and <see cref="Pop" /> methods should be avoided.  Also, the <paramref name="tag"/> property
        /// for this method should be null, since it is a reference type.
        /// </remarks>
        /// <param name="x">The X value</param>
        /// <param name="y">The Y value</param>
        /// <param name="z">The Z value</param>
        /// <param name="tag">The Tag value for the PointPair</param>
        public void Add( double x, double y, double z, object tag )
        {
            // advance the rolling list
            GetNextIndex();

            if ( _mBuffer[_headIdx] == null )
                _mBuffer[_headIdx] = new PointPair( x, y, z, tag );
            else
            {
                _mBuffer[_headIdx].X = x;
                _mBuffer[_headIdx].Y = y;
                _mBuffer[_headIdx].Z = z;
                _mBuffer[_headIdx].Tag = tag;
            }
        }
예제 #14
0
 /// <summary>
 /// Add a <see cref="PointPair"/> onto the head of the queue,
 /// overwriting old values if the buffer is full.
 /// </summary>
 /// <param name="item">The <see cref="PointPair" /> to be added.</param>
 public void Add( PointPair item )
 {
     _mBuffer[ GetNextIndex() ] = item;
 }
예제 #15
0
        /// <summary>
        /// Create a fill brush using current properties.  This method will construct a brush based on the
        /// settings of <see cref="ZedGraph.Fill.Type"/>, <see cref="ZedGraph.Fill.Color"/>
        /// and <see cref="ZedGraph.Fill.Brush"/>.  If
        /// <see cref="ZedGraph.Fill.Type"/> is set to <see cref="ZedGraph.FillType.Brush"/> and
        /// <see cref="ZedGraph.Fill.Brush"/>
        /// is null, then a <see cref="LinearGradientBrush"/> will be created between the colors of
        /// <see cref="System.Drawing.Color.White"/> and <see cref="ZedGraph.Fill.Color"/>.
        /// </summary>
        /// <param name="rect">A rectangle that bounds the object to be filled.  This determines
        /// the start and end of the gradient fill.</param>
        /// <param name="dataValue">The data value to be used for a value-based
        /// color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.</param>
        /// <returns>A <see cref="System.Drawing.Brush"/> class representing the fill brush</returns>
        public Brush MakeBrush( RectangleF rect, PointPair dataValue )
        {
            // get a brush
            if ( this.IsVisible && ( !_color.IsEmpty || _brush != null ) )
            {
                if ( rect.Height < 1.0F )
                    rect.Height = 1.0F;
                if ( rect.Width < 1.0F )
                    rect.Width = 1.0F;

                //Brush	brush;
                if ( _type == FillType.Brush )
                {
                    return ScaleBrush( rect, _brush, _isScaled );
                }
                else if ( IsGradientValueType )
                {
                    if ( dataValue != null )
                    {
                        if ( !_secondaryValueGradientColor.IsEmpty )
                        {
                            // Go ahead and create a new Fill so we can do all the scaling, etc.,
                            // that is associated with a gradient
                            Fill tmpFill = new Fill( _secondaryValueGradientColor,
                                    GetGradientColor( dataValue ), _angle );
                            return tmpFill.MakeBrush( rect );
                        }
                        else
                            return new SolidBrush( GetGradientColor( dataValue ) );
                    }
                    else if ( _rangeDefault != double.MaxValue )
                    {
                        if ( !_secondaryValueGradientColor.IsEmpty )
                        {
                            // Go ahead and create a new Fill so we can do all the scaling, etc.,
                            // that is associated with a gradient
                            Fill tmpFill = new Fill( _secondaryValueGradientColor,
                                    GetGradientColor( _rangeDefault ), _angle );
                            return tmpFill.MakeBrush( rect );
                        }
                        else
                            return new SolidBrush( GetGradientColor( _rangeDefault ) );
                    }
                    else
                        return ScaleBrush( rect, _brush, true );
                }
                else
                    return new SolidBrush( _color );
            }

            // Always return a suitable default
            return new SolidBrush( Color.White );
        }
예제 #16
0
        /// <summary>
        /// The PointPair copy constructor.
        /// </summary>
        /// <param name="rhs">The basis for the copy.</param>
        public PointPair( PointPair rhs )
            : base(rhs)
        {
            this.Z = rhs.Z;

            if ( rhs.Tag is ICloneable )
                this.Tag = ((ICloneable) rhs.Tag).Clone();
            else
                this.Tag = rhs.Tag;
        }
예제 #17
0
        internal Color GetGradientColor( PointPair dataValue )
        {
            double val;

            if ( dataValue == null )
                val = _rangeDefault;
            else if ( _type == FillType.GradientByColorValue )
                val = dataValue.ColorValue;
            else if ( _type == FillType.GradientByZ )
                val = dataValue.Z;
            else if ( _type == FillType.GradientByY )
                val = dataValue.Y;
            else
                val = dataValue.X;

            return GetGradientColor( val );
        }
예제 #18
0
        /// <summary>
        /// Create a <see cref="Pen" /> object based on the properties of this
        /// <see cref="LineBase" />.
        /// </summary>
        /// <param name="pane">The owner <see cref="GraphPane" /> of this
        /// <see cref="LineBase" />.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="dataValue">The data value to be used for a value-based
        /// color gradient.  This is only applicable if <see cref="Fill.Type">GradientFill.Type</see>
        /// is one of <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/>, <see cref="FillType.GradientByZ"/>,
        /// or <see cref="FillType.GradientByColorValue" />.
        /// </param>
        /// <returns>A <see cref="Pen" /> object with the properties of this <see cref="LineBase" />
        /// </returns>
        public Pen GetPen( PaneBase pane, float scaleFactor, PointPair dataValue )
        {
            Color color = _color;
            if ( _gradientFill.IsGradientValueType )
                color = _gradientFill.GetGradientColor( dataValue );

            Pen pen = new Pen( color,
                        pane.ScaledPenWidth( _width, scaleFactor ) );

            pen.DashStyle = _style;

            if ( _style == DashStyle.Custom )
            {
                if ( _dashOff > 1e-10 && _dashOn > 1e-10 )
                {
                    pen.DashStyle = DashStyle.Custom;
                    float[] pattern = new float[2];
                    pattern[0] = _dashOn;
                    pattern[1] = _dashOff;
                    pen.DashPattern = pattern;
                }
                else
                    pen.DashStyle = DashStyle.Solid;
            }

            return pen;
        }
예제 #19
0
        /// <summary> 
        /// Indexer to access the specified <see cref="PointPair"/> object by 
        /// its ordinal position in the list. 
        /// </summary> 
        /// <param name="index">The ordinal position (zero-based) of the 
        /// <see cref="PointPair"/> object to be accessed.</param> 
        /// <value>A <see cref="PointPair"/> object reference.</value> 
        public PointPair this[int index]
        {
            get
            {
                if ( index < 0 || index >= _bindingSource.Count )
                    throw new System.ArgumentOutOfRangeException( "Error: Index out of range" );

                object row = _bindingSource[index];

                double x = GetDouble( row, _xDataMember, index );
                double y = GetDouble( row, _yDataMember, index );
                double z = GetDouble( row, _zDataMember, index );
                object tag = GetObject( row, _tagDataMember );

                PointPair pt = new PointPair( x, y, z );
                pt.Tag = tag;
                return pt;
            }
        }
예제 #20
0
        /// <summary>
        /// Add a <see cref="PointPair"/> object to the collection at the end of the list.
        /// </summary>
        /// <param name="point">The <see cref="PointPair"/> object to be added</param>
        public void Add(PointPair point)
        {
//			throw new ArgumentException( "Error: Only the StockPt type can be added to StockPointList" +
//				".  An ordinary PointPair is not allowed" );
            base.Add(new StockPt(point));
        }
예제 #21
0
        /// <summary>
        /// Add a <see cref="PointPair"/> object to the end of the points collection for this curve.
        /// </summary>
        /// <remarks>
        /// This method will only work if the <see cref="IPointList" /> instance reference
        /// at <see cref="Points" /> supports the <see cref="IPointListEdit" /> interface.
        /// Otherwise, it does nothing.
        /// </remarks>
        /// <param name="point">A reference to the <see cref="PointPair"/> object to
        /// be added</param>
        public void AddPoint( PointPair point )
        {
            if ( _points == null )
                this.Points = new PointPairList();

            if ( _points is IPointListEdit )
                ( _points as IPointListEdit ).Add( point );
            else
                throw new NotImplementedException();
        }
예제 #22
0
        /// <summary>
        /// Draw the <see cref="Symbol"/> to the specified <see cref="Graphics"/> device
        /// at the specified location.  This routine draws a single symbol.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="x">The x position of the center of the symbol in
        /// pixel units</param>
        /// <param name="y">The y position of the center of the symbol in
        /// pixel units</param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This
        /// scaling factor is calculated by the <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor
        /// represents a linear multiple to be applied to font sizes, symbol sizes, etc.
        /// </param>
        /// <param name="dataValue">The data value to be used for a value-based
        /// color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.</param>
        /// <param name="isSelected">Indicates that the <see cref="Symbol" /> should be drawn
        /// with attributes from the <see cref="Selection" /> class.
        /// </param>
        public void DrawSymbol( Graphics g, GraphPane pane, int x, int y,
							float scaleFactor, bool isSelected, PointPair dataValue )
        {
            Symbol source = this;
            if ( isSelected )
                source = Selection.Symbol;

            // Only draw if the symbol is visible
            if (	_isVisible &&
                    this.Type != SymbolType.None &&
                    x < 100000 && x > -100000 &&
                    y < 100000 && y > -100000 )
            {
                SmoothingMode sModeSave = g.SmoothingMode;
                if ( _isAntiAlias )
                    g.SmoothingMode = SmoothingMode.HighQuality;

                using ( Pen pen = _border.GetPen( pane, scaleFactor, dataValue ) )
                using ( GraphicsPath path = this.MakePath( g, scaleFactor ) )
                using ( Brush brush = this.Fill.MakeBrush( path.GetBounds(), dataValue ) )
                {
                    DrawSymbol( g, x, y, path, pen, brush );
                }

                g.SmoothingMode = sModeSave;
            }
        }
예제 #23
0
        /// <summary>
        /// Draw the this <see cref="CurveItem"/> to the specified <see cref="Graphics"/>
        /// device.  The format (stair-step or line) of the curve is
        /// defined by the <see cref="StepType"/> property.  The routine
        /// only draws the line segments; the symbols are drawn by the
        /// <see cref="Symbol.Draw"/> method.  This method
        /// is normally only called by the Draw method of the
        /// <see cref="CurveItem"/> object
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="curve">A <see cref="LineItem"/> representing this
        /// curve.</param>
        public void DrawCurveOriginal( Graphics g, GraphPane pane,
										  CurveItem curve, float scaleFactor )
        {
            Line source = this;
            if ( curve.IsSelected )
                source = Selection.Line;

            float tmpX, tmpY,
                    lastX = float.MaxValue,
                    lastY = float.MaxValue;
            double curX, curY, lowVal;
            PointPair curPt, lastPt = new PointPair();

            bool lastBad = true;
            IPointList points = curve.Points;
            ValueHandler valueHandler = new ValueHandler( pane, false );
            Axis yAxis = curve.GetYAxis( pane );
            Axis xAxis = curve.GetXAxis( pane );

            bool xIsLog = xAxis._scale.IsLog;
            bool yIsLog = yAxis._scale.IsLog;

            float minX = pane.Chart.Rect.Left;
            float maxX = pane.Chart.Rect.Right;
            float minY = pane.Chart.Rect.Top;
            float maxY = pane.Chart.Rect.Bottom;

            using ( Pen pen = source.GetPen( pane, scaleFactor ) )
            {
                if ( points != null && !_color.IsEmpty && this.IsVisible )
                {
                    //bool lastOut = false;
                    bool isOut;

                    // Loop over each point in the curve
                    for ( int i = 0; i < points.Count; i++ )
                    {
                        curPt = points[i];
                        if ( pane.LineType == LineType.Stack )
                        {
                            if ( !valueHandler.GetValues( curve, i, out curX, out lowVal, out curY ) )
                            {
                                curX = PointPair.Missing;
                                curY = PointPair.Missing;
                            }
                        }
                        else
                        {
                            curX = curPt.X;
                            curY = curPt.Y;
                        }

                        // Any value set to double max is invalid and should be skipped
                        // This is used for calculated values that are out of range, divide
                        //   by zero, etc.
                        // Also, any value <= zero on a log scale is invalid
                        if ( curX == PointPair.Missing ||
                                curY == PointPair.Missing ||
                                System.Double.IsNaN( curX ) ||
                                System.Double.IsNaN( curY ) ||
                                System.Double.IsInfinity( curX ) ||
                                System.Double.IsInfinity( curY ) ||
                                ( xIsLog && curX <= 0.0 ) ||
                                ( yIsLog && curY <= 0.0 ) )
                        {
                            // If the point is invalid, then make a linebreak only if IsIgnoreMissing is false
                            // LastX and LastY are always the last valid point, so this works out
                            lastBad = lastBad || !pane.IsIgnoreMissing;
                            isOut = true;
                        }
                        else
                        {
                            // Transform the current point from user scale units to
                            // screen coordinates
                            tmpX = xAxis.Scale.Transform( curve.IsOverrideOrdinal, i, curX );
                            tmpY = yAxis.Scale.Transform( curve.IsOverrideOrdinal, i, curY );
                            isOut = ( tmpX < minX && lastX < minX ) || ( tmpX > maxX && lastX > maxX ) ||
                                ( tmpY < minY && lastY < minY ) || ( tmpY > maxY && lastY > maxY );

                            if ( !lastBad )
                            {
                                try
                                {
                                    // GDI+ plots the data wrong and/or throws an exception for
                                    // outrageous coordinates, so we do a sanity check here
                                    if ( lastX > 5000000 || lastX < -5000000 ||
                                            lastY > 5000000 || lastY < -5000000 ||
                                            tmpX > 5000000 || tmpX < -5000000 ||
                                            tmpY > 5000000 || tmpY < -5000000 )
                                        InterpolatePoint( g, pane, curve, lastPt, scaleFactor, pen,
                                                        lastX, lastY, tmpX, tmpY );
                                    else if ( !isOut )
                                    {
                                        if ( !curve.IsSelected && this._gradientFill.IsGradientValueType )
                                        {
                                            using ( Pen tPen = GetPen( pane, scaleFactor, lastPt ) )
                                            {
                                                if ( this.StepType == StepType.NonStep )
                                                {
                                                    g.DrawLine( tPen, lastX, lastY, tmpX, tmpY );
                                                }
                                                else if ( this.StepType == StepType.ForwardStep )
                                                {
                                                    g.DrawLine( tPen, lastX, lastY, tmpX, lastY );
                                                    g.DrawLine( tPen, tmpX, lastY, tmpX, tmpY );
                                                }
                                                else if ( this.StepType == StepType.RearwardStep )
                                                {
                                                    g.DrawLine( tPen, lastX, lastY, lastX, tmpY );
                                                    g.DrawLine( tPen, lastX, tmpY, tmpX, tmpY );
                                                }
                                                else if ( this.StepType == StepType.ForwardSegment )
                                                {
                                                    g.DrawLine( tPen, lastX, lastY, tmpX, lastY );
                                                }
                                                else
                                                {
                                                    g.DrawLine( tPen, lastX, tmpY, tmpX, tmpY );
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if ( this.StepType == StepType.NonStep )
                                            {
                                                g.DrawLine( pen, lastX, lastY, tmpX, tmpY );
                                            }
                                            else if ( this.StepType == StepType.ForwardStep )
                                            {
                                                g.DrawLine( pen, lastX, lastY, tmpX, lastY );
                                                g.DrawLine( pen, tmpX, lastY, tmpX, tmpY );
                                            }
                                            else if ( this.StepType == StepType.RearwardStep )
                                            {
                                                g.DrawLine( pen, lastX, lastY, lastX, tmpY );
                                                g.DrawLine( pen, lastX, tmpY, tmpX, tmpY );
                                            }
                                            else if ( this.StepType == StepType.ForwardSegment )
                                            {
                                                g.DrawLine( pen, lastX, lastY, tmpX, lastY );
                                            }
                                            else if ( this.StepType == StepType.RearwardSegment )
                                            {
                                                g.DrawLine( pen, lastX, tmpY, tmpX, tmpY );
                                            }
                                        }
                                    }

                                }
                                catch
                                {
                                    InterpolatePoint( g, pane, curve, lastPt, scaleFactor, pen,
                                                lastX, lastY, tmpX, tmpY );
                                }

                            }

                            lastPt = curPt;
                            lastX = tmpX;
                            lastY = tmpY;
                            lastBad = false;
                            //lastOut = isOut;
                        }
                    }
                }
            }
        }
예제 #24
0
        /// <summary>
        /// Constructs an empty buffer with the specified capacity.  Pre-allocates space
        /// for all PointPair's in the list if <paramref name="preLoad"/> is true.
        /// </summary>
        /// <param name="capacity">Number of elements in the rolling list.  This number
        /// cannot be changed once the RollingPointPairList is constructed.</param>
        /// <param name="preLoad">true to pre-allocate all PointPair instances in
        /// the list, false otherwise.  Note that in order to be memory efficient,
        /// the <see cref="Add(double,double,double)"/> method should be used to add
        /// data.  Avoid the <see cref="Add(PointPair)"/> method.
        /// </param>
        /// <seealso cref="Add(double,double,double)"/>
        public RollingPointPairList( int capacity, bool preLoad )
        {
            _mBuffer = new PointPair[capacity];
            _headIdx = _tailIdx = -1;

            if ( preLoad )
                for ( int i = 0; i < capacity; i++ )
                    _mBuffer[i] = new PointPair();
        }