Esempio n. 1
0
        public void DrawExtraData(ChartControl chartSource, IDrawingContext dc)
        {
            var dataSource = chartSource.MainCollection;

            if (dataSource == null)
            {
                return;
            }

            var items = dataSource.Items;

            int iStart = dataSource.FirstVisibleItemIndex;
            int count  = dataSource.VisiableItemCount;

            IPen pen = DrawingObjectFactory.CreatePen(Forground, 1);

            var xMid = dataSource.ItemXDistance / 2;

            startY        = -1;
            internalIndex = -1;
            XRItems       = null;
            for (int i = iStart; i < iStart + count; i++)
            {
                var item = dataSource.Items[i];
                if (item.ExtraData == null)
                {
                    continue;
                }

                var xhHistory = item.ExtraData.Get(ExtraDataNames.XRName) as ExitRight;
                if (xhHistory != null)
                {
                    var x = dataSource.GetItemPositionX(i, ChartItemCollection.ValueName);

                    if (startY == -1)
                    {
                        startY  = dataSource.ChartRegion.Bottom - height;
                        XRItems = new List <XRItem>();
                    }
                    XRItems.Add(new XRItem()
                    {
                        X       = x,
                        Index   = i,
                        toolTip = xhHistory.ToString()
                    });

                    x = PointSnapper.SnapValue(x + xMid);

                    var point1 = new Point(x, dataSource.ChartRegion.Bottom);
                    var point2 = new Point(x, dataSource.ChartRegion.Bottom - 2);

                    dc.DrawLine(pen, point1, point2);

                    point1 = new Point(x, dataSource.ChartRegion.Bottom - 5);

                    dc.DrawEllipse(Forground, null, point1, radius, radius);
                }
            }
        }
Esempio n. 2
0
        private void DrawDenseChart(IDrawingContext dc)
        {
            int i = -1;

            do
            {
                i++;
            } while (i < points.Length && !IsPointValid(points[i]));

            GeometryGroup groupRaise = new GeometryGroup(), groupFall = new GeometryGroup();

            Point  p1   = new Point(ChartItemCollection.valueNA, ChartItemCollection.valueNA);
            Point  p2   = new Point(ChartItemCollection.valueNA, ChartItemCollection.valueNA);
            double open = ChartItemCollection.valueNA;
            double close = open;

            List <Point> PtList = new List <Point>();

            double halfItemWidth = ItemXDistance / 2;

            int iStart = i;


            for (; i < points.Length; i++)
            {
                if (!IsPointValid(points[i]))
                {
                    continue;
                }

                var x  = points[i].X;
                var yC = points[i].Y;
                var yH = verticalLines[i].YHigh;
                var yL = verticalLines[i].YLow;
                var yO = verticalLines[i].YOpen;

                GeometryGroup group = null;

                var xMid = PointSnapper.SnapValue(x + halfItemWidth);

                if (p1.X != xMid)
                {
                    if (i != iStart)
                    {
                        if (p1.Y == p2.Y)
                        {
                            p2.Y++;
                        }

                        bool isRaise = close <= open;

                        if (isRaise)
                        {
                            group = groupRaise;
                        }
                        else
                        {
                            group = groupFall;
                        }

                        LineGeometry line1 = new LineGeometry()
                        {
                            StartPoint = p1,
                            EndPoint   = p2
                        };
#if USINGCANVAS
#else
                        line1.Freeze();
#endif
                        group.Children.Add(line1);
                    }

                    open  = yO;
                    close = yC;
                    p1.X  = p2.X = xMid;
                    p1.Y  = PointSnapper.SnapValue(yH);
                    p2.Y  = PointSnapper.SnapValue(yL);
                }
                else
                {
                    var YH = PointSnapper.SnapValue(yH);
                    if (YH < p1.Y)
                    {
                        p1.Y = YH;
                    }
                    var YL = PointSnapper.SnapValue(yL);
                    if (YL > p2.Y)
                    {
                        p2.Y = YL;
                    }
                    close = yC;
                }
            }
#if USINGCANVAS
#else
            groupRaise.Freeze();
            groupFall.Freeze();
#endif
            dc.DrawGeometry(null, lineRaisePen, groupRaise);
            dc.DrawGeometry(null, lineFallPen, groupFall);
        }
Esempio n. 3
0
        private void DrawBar(IDrawingContext dc)
        {
            int i = -1;

            do
            {
                i++;
            } while (!IsPointValid(points[i]));

            GeometryGroup groupRaise = new GeometryGroup(), groupFall = new GeometryGroup();

            Point        p1     = new Point();
            Point        p2     = new Point();
            List <Point> PtList = new List <Point>();

            double halfItemWidth = ItemXDistance / 2;

            for (; i < points.Length; i++)
            {
                if (!IsPointValid(points[i]))
                {
                    continue;
                }

                var x = points[i].X;
                var y = points[i].Y;

                GeometryGroup group = null;

                bool isRaise = (Items[iStartPosition + i] as VolumnItem).IsRaise;
                if (isRaise)
                {
                    group = groupRaise;
                }
                else
                {
                    group = groupFall;
                }

                if (ItemXDistance >= 3 && volumnItemStyle == VolumnItemStyle.Fat)
                {
                    p1.X = PointSnapper.SnapValue(x);
                    p1.Y = PointSnapper.SnapValue(y);
                    p2.X = PointSnapper.SnapValue(x + ItemXDistance) - 1;
                    p2.Y = collectRect.Bottom;

                    RectangleGeometry rect = new RectangleGeometry()
                    {
                        Rect = new Rect(p1, p2)
                    };
#if USINGCANVAS
#else
                    rect.Freeze();
#endif
                    group.Children.Add(rect);
                }
                else
                {
                    p1.X = p2.X = PointSnapper.SnapValue(x + halfItemWidth);
                    p1.Y = PointSnapper.SnapValue(y);
                    p2.Y = collectRect.Bottom;
                    LineGeometry line1 = new LineGeometry()
                    {
                        StartPoint = p1,
                        EndPoint   = p2
                    };
#if USINGCANVAS
#else
                    line1.Freeze();
#endif

                    group.Children.Add(line1);
                }
            }

#if USINGCANVAS
#else
            (RaisePen as DrawingPen).Freeze();
            (FallPen as DrawingPen).Freeze();
            groupRaise.Freeze();
            groupFall.Freeze();
#endif

            dc.DrawGeometry(null, RaisePen, groupRaise);
            dc.DrawGeometry(FallPen.Brush, FallPen, groupFall);
        }
Esempio n. 4
0
        /// <summary>
        /// <see cref="ChartItemCollection.Draw(IDrawingContext)"/>
        /// </summary>
        public override void Draw(IDrawingContext dc)
        {
            if (points == null || !points.Any())
            {
                return;
            }

            if (ItemStyle == StockItemStyle.Linear)
            {
                base.Draw(dc);
                return;
            }

            double halfItemWidth = ItemXDistance / 2;

            if (halfItemWidth + ItemXSpan < 1)
            {
                DrawDenseChart(dc);
                return;
            }

            int i = -1;

            do
            {
                i++;
            } while (i < points.Length && !IsPointValid(points[i]));

            GeometryGroup groupLineRaise = new GeometryGroup(), groupLineFall = new GeometryGroup();
            GeometryGroup groupRectRaise = new GeometryGroup(), groupRectFall = new GeometryGroup();

            Point        p1 = new Point();
            Point        p2 = new Point();
            List <Point> PtList = new List <Point>();

            for (; i < points.Length; i++)
            {
                if (!IsPointValid(points[i]))
                {
                    continue;
                }
                var  x       = points[i].X;
                var  yC      = points[i].Y;
                var  yH      = verticalLines[i].YHigh;
                var  yL      = verticalLines[i].YLow;
                var  yO      = verticalLines[i].YOpen;
                bool isRaise = yC <= yO;
                if (yC == yO)
                {
                    isRaise = Items[i + iStartPosition].ValueChange >= 0;
                }
                GeometryGroup groupLine, groupRect = null;

                var xMid = PointSnapper.SnapValue(x + halfItemWidth);
                if (ItemStyle == StockItemStyle.Candle)
                {
                    if (ItemXDistance >= 3)
                    {
                        p1.X = p2.X = xMid;
                        p1.Y = PointSnapper.SnapValue(yH);

                        double yNext = 0;
                        if (isRaise)
                        {
                            p2.Y      = PointSnapper.SnapValue(yC);
                            groupLine = groupLineRaise;
                            groupRect = groupRectRaise;
                            yNext     = PointSnapper.SnapValue(yO);
                        }
                        else
                        {
                            p2.Y      = PointSnapper.SnapValue(yO);
                            groupLine = groupLineFall;
                            groupRect = groupRectFall;
                            yNext     = PointSnapper.SnapValue(yC);
                        }

                        if (p1.Y != p2.Y)
                        {
                            LineGeometry line1 = new LineGeometry()
                            {
                                StartPoint = p1,
                                EndPoint   = p2
                            };

#if USINGCANVAS
#else
                            line1.Freeze();
#endif
                            groupLine.Children.Add(line1);
                        }

                        p1.X = PointSnapper.SnapValue(x);
                        p1.Y = p2.Y;
                        p2.X = PointSnapper.SnapValue(x + ItemXDistance) - 1;
                        p2.Y = yNext;

                        if (p1.Y == p2.Y)
                        {
                            LineGeometry rLine = new LineGeometry()
                            {
                                StartPoint = p1,
                                EndPoint   = p2
                            };
#if USINGCANVAS
#else
                            rLine.Freeze();
#endif
                            groupLine.Children.Add(rLine);
                        }
                        else
                        {
                            RectangleGeometry rect = new RectangleGeometry()
                            {
                                Rect = new Rect(p1, p2)
                            };
#if USINGCANVAS
#else
                            rect.Freeze();
#endif
                            groupRect.Children.Add(rect);
                        }


                        p1.X = p2.X = xMid;
                        p1.Y = yNext;
                        p2.Y = PointSnapper.SnapValue(yL);

                        if (p1.Y != p2.Y)
                        {
                            LineGeometry line2 = new LineGeometry()
                            {
                                StartPoint = p1,
                                EndPoint   = p2
                            };
#if USINGCANVAS
#else
                            line2.Freeze();
#endif
                            groupLine.Children.Add(line2);
                        }
                    }
                    else
                    {
                        if (isRaise)
                        {
                            groupLine = groupLineRaise;
                        }
                        else
                        {
                            groupLine = groupLineFall;
                        }


                        p1.X = p2.X = xMid;
                        p1.Y = PointSnapper.SnapValue(yH);
                        p2.Y = PointSnapper.SnapValue(yL);
                        if (p1.Y == p2.Y)
                        {
                            p2.Y++;
                        }

                        LineGeometry line1 = new LineGeometry
                        {
                            StartPoint = p1,
                            EndPoint   = p2
                        };
#if USINGCANVAS
#else
                        line1.Freeze();
#endif
                        groupLine.Children.Add(line1);
                    }
                }
                else
                {
                    if (isRaise)
                    {
                        groupLine = groupLineRaise;
                    }
                    else
                    {
                        groupLine = groupLineFall;
                    }

                    p1.X = p2.X = xMid;
                    p1.Y = PointSnapper.SnapValue(yH);
                    p2.Y = PointSnapper.SnapValue(yL);
                    if (p1.Y == p2.Y)
                    {
                        p2.Y++;
                    }

                    LineGeometry line1 = new LineGeometry()
                    {
                        StartPoint = p1,
                        EndPoint   = p2
                    };

#if USINGCANVAS
#else
                    line1.Freeze();
#endif
                    groupLine.Children.Add(line1);

                    p1.X = PointSnapper.SnapValue(x);
                    p1.Y = p2.Y = PointSnapper.SnapValue(yO);
                    p2.X = xMid;

                    if (p1.X != p2.X)
                    {
                        LineGeometry line2 = new LineGeometry()
                        {
                            StartPoint = p1,
                            EndPoint   = p2
                        };
#if USINGCANVAS
#else
                        line2.Freeze();
#endif
                        groupLine.Children.Add(line2);
                    }


                    p1.X = p2.X;
                    p1.Y = p2.Y = PointSnapper.SnapValue(yC);
                    p2.X = PointSnapper.SnapValue(x + ItemXDistance);
                    if (p1.X != p2.X)
                    {
                        LineGeometry line3 = new LineGeometry()
                        {
                            StartPoint = p1,
                            EndPoint   = p2
                        };
#if USINGCANVAS
#else
                        line3.Freeze();
#endif
                        groupLine.Children.Add(line3);
                    }
                }
            }

#if USINGCANVAS
#else
            groupLineRaise.Freeze();
            groupLineFall.Freeze();
            groupRectRaise.Freeze();
            groupRectFall.Freeze();
#endif
            dc.DrawGeometry(null, lineRaisePen, groupLineRaise);
            dc.DrawGeometry(null, lineFallPen, groupLineFall);
            dc.DrawGeometry(null, rectRaisePen, groupRectRaise);
            dc.DrawGeometry(rectFallPen.Brush, rectFallPen, groupRectFall);
        }