Esempio n. 1
0
        /// <summary>
        /// Used internally to draw symbol.
        /// </summary>
        internal static void DrawSymbol(Graphics g, GraphPane pane, SymbolType type,
                                        int x, int y, float size,
                                        bool isVisible, Fill fill, Border border, float scaleFactor,
                                        bool isAntiAlias, IPointPair dataValue)
        {
            // Only draw if the symbol is visible
            if (!isVisible || type == SymbolType.None || Math.Abs(x) >= 100000 || Math.Abs(y) >= 100000)
            {
                return;
            }

            var sModeSave = g.SmoothingMode;

            if (isAntiAlias)
            {
                g.SmoothingMode = SmoothingMode.HighQuality;
            }

            using (var pen = border.GetPen(pane, scaleFactor, dataValue))
                using (var path = MakePath(g, type, scaleFactor, size))
                    using (var brush = fill.MakeBrush(path.GetBounds(), dataValue))
                        drawSymbol(g, x, y, path, pen, brush, type, fill, border);

            g.SmoothingMode = sModeSave;
        }
Esempio n. 2
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(IPointPair item)
        {
            if (_headIdx == -1)
            {                   // buffer is currently empty.
                _headIdx = _tailIdx = 0;
            }
            else
            {
                // Determine the index to write to.
                if (++_headIdx == _mBuffer.Length)
                {                       // Wrap around.
                    _headIdx = 0;
                }

                if (_headIdx == _tailIdx)
                {                       // Buffer overflow. Increment tailIdx.
                    if (++_tailIdx == _mBuffer.Length)
                    {                   // Wrap around.
                        _tailIdx = 0;
                    }
                }
            }

            _mBuffer[_headIdx] = item;
        }
Esempio n. 3
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, IPointPair dataValue)
        {
            var color = Color;

            if (GradientFill.IsGradientValueType)
            {
                color = GradientFill.GetGradientColor(dataValue);
            }

            var pen = new Pen(color, pane.ScaledPenWidth(Width, scaleFactor))
            {
                DashStyle = Style
            };

            if (Style != DashStyle.Custom)
            {
                return(pen);
            }

            if (DashOff <= 1e-10 || DashOn <= 1e-10)
            {
                pen.DashStyle = DashStyle.Solid;
            }
            else
            {
                pen.DashStyle   = DashStyle.Custom;
                pen.DashPattern = new[] { DashOn, DashOff };
            }

            return(pen);
        }
Esempio n. 4
0
        protected override void BeforeDraw(Graphics g, GraphPane pane,
                                           Axis valueAxis, CurveItem curve, IPointPair pt,
                                           float pixBase, float pixHigh, float pixLow, float halfSize)
        {
            var p = pt as ICandleClusteredVolume;

            if (p?.Volumes != null)
            {
                //using (var backBrush = new SolidBrush(Default.ClusterBaseColor))
                //  g.FillRectangle(backBrush, pixBase - halfSize, pixHigh, halfSize*2, pixLow - pixHigh);

                //var prevPricePix = pixLow;

                var halfClustStep = ClusterStep / 2;

                foreach (var v in p.Volumes)
                {
                    var low          = Math.Max(p.Low, v.Price - halfClustStep);
                    var high         = Math.Min(p.High, v.Price + halfClustStep);
                    var fromPricePix = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, 0, low);
                    var toPricePix   = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, 0, high);
                    var height       = Math.Abs(toPricePix - fromPricePix);
                    var color        = getVolumeColor(v.VolSell + v.VolBuy);

                    if (color != Default.ClusterBaseColor)
                    {
                        using (var brush = new SolidBrush(color))
                            g.FillRectangle(brush, pixBase - halfSize / 2, toPricePix, halfSize, height);
                    }
                }
            }

            base.BeforeDraw(g, pane, valueAxis, curve, pt, pixBase, pixHigh, pixLow, halfSize);
        }
Esempio n. 5
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, IPointPair dataValue)
        {
            var source = isSelected ? Selection.Symbol : this;

            DrawSymbol(g, pane, Type, x, y, Size, IsVisible, source.Fill, source.Border,
                       scaleFactor, IsAntiAlias, dataValue);
        }
Esempio n. 6
0
        private static bool IsVisible(GraphPane pane, LineItem lineItem, IPointPair point)
        {
            var xScale = lineItem.GetXAxis(pane).Scale;
            var yScale = lineItem.GetYAxis(pane).Scale;
            var visible = point.X > xScale.Min && point.X <xScale.Max && point.Y> yScale.Min && point.Y < yScale.Max;

            return(visible);
        }
        /// <summary>
        /// Append a data point to the collection
        /// </summary>
        /// <param name="pt">The <see cref="PointPair" /> value to append</param>
        public void Add(IPointPair pt)
        {
            DataPoint dp = new DataPoint();

            dp.X = pt.X;
            dp.Y = pt.Y;
            Add(dp);
        }
        /// <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="barIndex">index of bar which will be drawn.</param>
        public void Draw(Graphics g, GraphPane pane, float left, float right, float top,
                         float bottom, float scaleFactor, bool fullFrame,
                         IPointPair dataValue, int barIndex)
        {
            // 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, dataValue, barIndex);
        }
Esempio n. 9
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, IPointPair pt)
 {
     if (this.IsVisible)
     {
         using (Brush brush = this.MakeBrush(rect, pt))
         {
             g.FillRectangle(brush, rect);
             //brush.Dispose();
         }
     }
 }
Esempio n. 10
0
 /// <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, IPointPair 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);
     }
 }
        /// <summary>
        /// Determine the coords for the rectangle associated with a specified point for
        /// this <see cref="CurveItem" />
        /// </summary>
        /// <param name="pane">The <see cref="GraphPane" /> to which this curve belongs</param>
        /// <param name="i">The index of the point of interest</param>
        /// <param name="coords">A list of coordinates that represents the "rect" for
        /// this point (used in an html AREA tag)</param>
        /// <returns>true if it's a valid point, false otherwise</returns>
        override public bool GetCoords(GraphPane pane, int i, out string coords)
        {
            coords = string.Empty;

            if (i < 0 || i >= _points.Count)
            {
                return(false);
            }

            Axis valueAxis = ValueAxis(pane);
            Axis baseAxis  = BaseAxis(pane);

            float halfSize = _stick.Size * pane.CalcScaleFactor();

            IPointPair pt   = _points[i];
            double     date = pt.X;
            double     high = pt.Y;
            double     low  = pt.Z;

            if (!pt.IsInvalid3D &&
                (date > 0 || !baseAxis._scale.IsLog) &&
                ((high > 0 && low > 0) || !valueAxis._scale.IsLog))
            {
                float pixBase, pixHigh, pixLow;
                pixBase = baseAxis.Scale.Transform(_isOverrideOrdinal, i, date);
                pixHigh = valueAxis.Scale.Transform(_isOverrideOrdinal, i, high);
                pixLow  = valueAxis.Scale.Transform(_isOverrideOrdinal, i, low);

                // Calculate the pixel location for the side of the bar (on the base axis)
                float pixSide = pixBase - halfSize;

                // Draw the bar
                if (baseAxis is XAxis)
                {
                    coords = String.Format("{0:f0},{1:f0},{2:f0},{3:f0}",
                                           pixSide, pixLow,
                                           pixSide + halfSize * 2, pixHigh);
                }
                else
                {
                    coords = String.Format("{0:f0},{1:f0},{2:f0},{3:f0}",
                                           pixLow, pixSide,
                                           pixHigh, pixSide + halfSize * 2);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 12
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>
        internal 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, IPointPair pt,
                           float dotHalfSize)
        {
            //float halfSize = (int) ( _size * scaleFactor / 2.0f + 0.5f );

            if (pixBase == PointPair.Missing || Math.Abs(pixLow) >= 1000000 ||
                Math.Abs(pixHigh) >= 1000000)
            {
                return;
            }
            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)
            {
                return;
            }

            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);

            DrawHighLowDots(g, isXBase, pixBase, pixHigh, pixLow, dotHalfSize);
        }
Esempio n. 13
0
        /// <summary>
        /// The PointPair copy constructor.
        /// </summary>
        /// <param name="rhs">The basis for the copy.</param>
        public PointPair(IPointPair rhs)
        {
            this.X = rhs.X;
            this.Y = rhs.Y;
            this.Z = rhs.Z;

            if (rhs.Tag is ICloneable)
            {
                this.Tag = ((ICloneable)rhs.Tag).Clone();
            }
            else
            {
                this.Tag = rhs.Tag;
            }
        }
Esempio n. 14
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(IPointPair point)
 {
     if (!(point is IOHLC))
     {
         throw new ArgumentException("Only points of StockPt type can be added to StockPointList!");
     }
     if ((point is IStockPt))
     {
         base.Add((T)((IStockPt)point).Clone());
     }
     else
     {
         base.Add((T)point.Clone());
     }
 }
        /// <summary>
        /// Determine the minimum increment between individual points to be used for
        /// calculating a bar size that fits without overlapping
        /// </summary>
        /// <param name="list">The <see cref="IPointList" /> list of points for the bar
        /// of interest</param>
        /// <param name="baseAxis">The base axis for the bar</param>
        /// <returns>The minimum increment between bars along the base axis</returns>
        internal static double GetMinStepSize(IPointList list, Axis baseAxis)
        {
            double minStep = Double.MaxValue;

            if (list.Count <= 0 || baseAxis._scale.IsAnyOrdinal)
            {
                return(1.0);
            }

            IPointPair lastPt = list[0];

            for (int i = 1; i < list.Count; i++)
            {
                IPointPair pt = list[i];
                if (!pt.IsInvalid || !lastPt.IsInvalid)
                {
                    double step;
                    if (baseAxis is XAxis)
                    {
                        step = pt.X - lastPt.X;
                    }
                    else
                    {
                        step = pt.Y - lastPt.Y;
                    }

                    if (step > 0 && step < minStep)
                    {
                        minStep = step;
                    }
                }

                lastPt = pt;
            }

            double range = baseAxis.Scale._maxLinearized - baseAxis.Scale._minLinearized;

            if (range <= 0)
            {
                minStep = 1.0;
            }
            else if (minStep <= 0 || minStep < 0.001 * range || minStep > range)
            {
                minStep = 0.1 * range;
            }

            return(minStep);
        }
        /// <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(IPointPair point)
        {
            if (_points == null)
            {
                this.Points = new PointPairList();
            }

            if (_points is IPointListEdit)
            {
                (_points as IPointListEdit).Add(point);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 17
0
        public static bool PtInPolygon(PointF[] points, IPointPair pt)
        {
            int  i, j;
            bool rc = false;

            for (i = 0, j = points.Length - 1; i < points.Length; j = i++)
            {
                if (((points[i].Y > pt.Y) != (points[j].Y > pt.Y)) &&
                    (pt.X < (points[j].X - points[i].X) * (pt.Y - points[i].Y) / (points[j].Y - points[i].Y) + points[i].X))
                {
                    rc = !rc;
                }
            }

            return(rc);
        }
Esempio n. 18
0
        public static bool PtInPolygon2(PointF[] points, IPointPair p)
        {
            bool result = false;

            for (int i = 0; i < points.Length - 1; i++)
            {
                if ((((points[i + 1].Y <= p.Y) && (p.Y < points[i].Y)) ||
                     ((points[i].Y <= p.Y) && (p.Y < points[i + 1].Y))
                     ) &&
                    (p.X < (points[i].X - points[i + 1].X) * (p.Y - points[i + 1].Y) / (points[i].Y - points[i + 1].Y) + points[i + 1].X))
                {
                    result = !result;
                }
            }
            return(result);
        }
Esempio n. 19
0
 /// <summary>
 /// The StockPt copy constructor.
 /// </summary>
 /// <param name="rhs">The basis for the copy.</param>
 public StockPt(IPointPair rhs)
     : base(rhs)
 {
     if (rhs is StockPt)
     {
         StockPt pt = rhs as StockPt;
         this.Open  = pt.Open;
         this.Close = pt.Close;
         this.Vol   = pt.Vol;
     }
     else
     {
         this.Open  = PointPair.Missing;
         this.Close = PointPair.Missing;
         this.Vol   = PointPair.Missing;
     }
 }
Esempio n. 20
0
        private Color GetGradientColor(IPointPair dataValue)
        {
            double val;

            if (_type == FillType.GradientByZ)
            {
                val = dataValue.Z;
            }
            else if (_type == FillType.GradientByY)
            {
                val = dataValue.Y;
            }
            else
            {
                val = dataValue.X;
            }

            return(GetGradientColor(val));
        }
Esempio n. 21
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, IPointPair 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.IsPenWidthScaled, scaleFactor, rect);
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        /// The PointPairBase copy constructor.
        /// </summary>
        /// <param name="rhs">The basis for the copy.</param>
        public PointPairBase(IPointPair rhs)
        {
            this.X = rhs.X;
            this.Y = rhs.Y;

            var r = rhs as PointPairBase;

            if (r == null)
            {
                return;
            }

            this.ID              = r.ID;
            this.IsVisible       = r.IsVisible;
            this.IsFiltered      = r.IsFiltered;
            this.PointColor      = r.PointColor;
            this.PointSymbolType = r.PointSymbolType;
            this.IsSelectable    = r.IsSelectable;
        }
Esempio n. 23
0
 protected static void GetOHLC(IPointPair pt, out double date, out double o,
                               out double h, out double l, out double c)
 {
     date = pt.X;
     if (pt is IOHLC)
     {
         var p = (IOHLC)pt;
         o = p.Open;
         h = p.High;
         l = p.Low;
         c = p.Close;
     }
     else
     {
         o = PointPair.Missing;
         h = pt.Y;
         l = pt.Z;
         c = PointPair.Missing;
     }
 }
Esempio n. 24
0
 /// <summary>
 /// The StockPt copy constructor.
 /// </summary>
 /// <param name="rhs">The basis for the copy.</param>
 public StockPt(IPointPair rhs) : base(rhs)
 {
     if (rhs is IOHLCV)
     {
         var pt = rhs as IOHLCV;
         Open       = pt.Open;
         VolBuy     = pt.VolBuy;
         VolSell    = pt.VolSell;
         High       = pt.High;
         ColorValue = ((StockPt)rhs).ColorValue;
     }
     else
     {
         Open       = PointPair.Missing;
         High       = PointPair.Missing;
         VolBuy     = 0;
         VolSell    = 0;
         ColorValue = PointPair.Missing;
     }
 }
        /// <summary>
        /// Determine the coords for the rectangle associated with a specified point for
        /// this <see cref="CurveItem" />
        /// </summary>
        /// <param name="pane">The <see cref="GraphPane" /> to which this curve belongs</param>
        /// <param name="i">The index of the point of interest</param>
        /// <param name="coords">A list of coordinates that represents the "rect" for
        /// this point (used in an html AREA tag)</param>
        /// <returns>true if it's a valid point, false otherwise</returns>
        override public bool GetCoords(GraphPane pane, int i, out string coords)
        {
            coords = string.Empty;

            if (i < 0 || i >= _points.Count)
            {
                return(false);
            }

            IPointPair pt = _points[i];

            if (pt.IsInvalid)
            {
                return(false);
            }

            double       x, y, z;
            ValueHandler valueHandler = new ValueHandler(pane, false);

            valueHandler.GetValues(this, i, out x, out z, out y);

            Axis yAxis = GetYAxis(pane);

            PointF pixPt = new PointF(pane.XAxis.Scale.Transform(_isOverrideOrdinal, i, x),
                                      yAxis.Scale.Transform(_isOverrideOrdinal, i, y));

            if (!pane.Chart.Rect.Contains(pixPt))
            {
                return(false);
            }

//			float halfSize = _symbol.Size * pane.CalcScaleFactor();
            float halfSize = 1 * pane.CalcScaleFactor();

            coords = String.Format("{0:f0},{1:f0},{2:f0},{3:f0}",
                                   pixPt.X - halfSize, pixPt.Y - halfSize,
                                   pixPt.X + halfSize, pixPt.Y + halfSize);

            return(true);
        }
Esempio n. 26
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,
                  IPointPair 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);
     }
 }
Esempio n. 27
0
        /// <summary>
        /// Pop an item off the head of the queue.
        /// </summary>
        /// <returns>The popped item. Throws an exception if the buffer was empty.</returns>
        public IPointPair Pop()
        {
            if (_tailIdx == -1)
            {                   // buffer is currently empty.
                throw new InvalidOperationException("buffer is empty.");
            }

            IPointPair o = _mBuffer[_headIdx];

            if (_tailIdx == _headIdx)
            {                   // The buffer is now empty.
                _headIdx = _tailIdx = -1;
                return(o);
            }

            if (--_headIdx == -1)
            {                   // Wrap around.
                _headIdx = _mBuffer.Length - 1;
            }

            return(o);
        }
        /// <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>
        public void DrawSymbol(Graphics g, GraphPane pane, float x, float y,
                               float scaleFactor, IPointPair dataValue)
        {
            // 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;
                }

                Pen          pen   = _border.MakePen(pane.IsPenWidthScaled, scaleFactor);
                GraphicsPath path  = this.MakePath(g, scaleFactor, false, 1);
                Brush        brush = this.Fill.MakeBrush(path.GetBounds(), dataValue);

                DrawSymbol(g, x, y, path, pen, brush);

                g.SmoothingMode = sModeSave;
            }
        }
        /// <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="barIndex">index of bar which will be drawn.</param>
        public void Draw(Graphics g, GraphPane pane, RectangleF rect, float scaleFactor,
                         bool fullFrame, IPointPair dataValue,
                         // BioRad addition 7.9.2007
                         int barIndex
                         // end BioRad
                         )
        {
            _fill.Draw(g, rect, dataValue);

            // Fill the Bar
            //if ( this.fill.IsVisible )
            //{
            //	// just avoid height/width being less than 0.1 so GDI+ doesn't cry
            //	Brush brush = this.fill.MakeBrush( _rect, dataValue );
            //	g.FillRectangle( brush, rect );
            //	brush.Dispose();
            //}

            // Border the Bar
            //if ( !this.border.Color.IsEmpty )

            // BioRad Change from
            // _border.Draw(g, pane.IsPenWidthScaled, scaleFactor, rect);
            // BioRad Change to
            bool isHighlighted = _highlightedBarIndexes.Contains(barIndex);

            _border.Draw(g, pane.IsPenWidthScaled, scaleFactor, rect, isHighlighted);
            // end BioRad

            // BioRad addition 7.9.2007
            if (barIndex >= 0)
            {
                _barRectangles[barIndex] = rect;
            }
            // end BioRad
        }
Esempio n. 30
0
 /// <summary>
 /// Add a <see cref="StockPt"/> object to the collection at the end of the list.
 /// </summary>
 /// <param name="point">The <see cref="StockPt"/> object to
 /// be added</param>
 public void Add(IPointPair point)
 {
     base.Add(new StockPt(point));
 }