Exemplo n.º 1
0
        public static UIElement GetClosestItemContainerToPosition(ItemsControl itemsControl, Point point, Orientation orientation)
        {
            Type itemContainerType = ControlMethods.GetItemContainerType(itemsControl);

            if (itemContainerType == null)
            {
                return(null);
            }
            List <UIElement> containers = new List <UIElement>();
            LineGeometry     line;

            switch (orientation)
            {
            case Orientation.Horizontal:
                line = new LineGeometry(new Point(0d, point.Y), new Point(itemsControl.RenderSize.Width, point.Y));
                break;

            default:
                line = new LineGeometry(new Point(point.X, 0d), new Point(point.X, itemsControl.RenderSize.Height));
                break;
            }
            line.Freeze();
            VisualTreeHelper.HitTest(
                itemsControl,
                null,
                testResult =>
            {
                UIElement itemContainer = testResult.VisualHit.FindVisualTreeAncestor(itemContainerType) as UIElement;
                if (itemContainer != null && itemsControl.Equals(ItemsControl.ItemsControlFromItemContainer(itemContainer)))
                {
                    containers.Add(itemContainer);
                }
                return(HitTestResultBehavior.Continue);
            },
                new GeometryHitTestParameters(line)
                );
            switch (containers.Count)
            {
            case 0:
                return(null);

            case 1:
                return(containers[0]);
            }
            // Find closest item to the point clicked.
            UIElement closest         = null;
            double    closestDistance = double.MaxValue;

            foreach (UIElement container in containers)
            {
                Point  transform = container.TransformToAncestor(itemsControl).Transform(default(Point));
                double distance  = Math.Abs(orientation == Orientation.Horizontal ? point.X - transform.X : point.Y - transform.Y);
                if (distance < closestDistance)
                {
                    closest         = container;
                    closestDistance = distance;
                }
            }
            return(closest);
        }
Exemplo n.º 2
0
        private void UpdateGeometry(Point start, Point end)
        {
            var geometry = new LineGeometry(start, end);

            this.EdgePath.Data = geometry;
            geometry.Freeze();
        }
Exemplo n.º 3
0
        private static GeometryGroup CreatePathGeometry(TriangleMesh mesh)
        {
            var geometryGroup = new GeometryGroup();

            foreach (var e in mesh.Edges)
            {
                var p0           = 256 * e.Vertex0.Traits.Position;
                var p1           = 256 * e.Vertex1.Traits.Position;
                var lineGeometry = new LineGeometry(new Point(p0.X, p0.Y), new Point(p1.X, p1.Y));
                lineGeometry.Freeze();
                geometryGroup.Children.Add(lineGeometry);
            }
            foreach (var v in mesh.Vertices)//.Where(x => x.OnBoundary))
            {
                var p = new Point(256 * v.Traits.Position.X, 256 * v.Traits.Position.Y);
                //var elli = new EllipseGeometry(p, 2, 2);
                //geometryGroup.Children.Add(elli);

                /// text geometry & drawing
                var text         = new FormattedText(v.Index.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Tahoma"), 2, Brushes.Black);
                var textGeometry = text.BuildGeometry(p);
                textGeometry.Freeze();
                geometryGroup.Children.Add(textGeometry);
            }
            geometryGroup.Freeze();
            return(geometryGroup);
        }
Exemplo n.º 4
0
        private void AddARTCCs( )
        {
            foreach (ARTCC CurrentARTCC in MySector.ARTCCs)
            {
                FIX PreviousFIX = null;

                foreach (FIX CurrentFIX in CurrentARTCC.Fixes)
                {
                    if (PreviousFIX != null)
                    {
                        LineGeometry CurrentLine = new LineGeometry( );
                        CurrentLine.StartPoint = new Point(GetScaledLongitude(PreviousFIX.Longitude), GetScaledLatitude(PreviousFIX.Latitude));
                        CurrentLine.EndPoint   = new Point(GetScaledLongitude(CurrentFIX.Longitude), GetScaledLatitude(CurrentFIX.Latitude));
                        Path CurrentPath = new Path( );
                        CurrentPath.Stroke              = Brushes.Blue;
                        CurrentPath.StrokeThickness     = 0.1;
                        CurrentPath.SnapsToDevicePixels = true;
                        CurrentPath.Tag = String.Format("{0};{1};{2};{3};{4};{5};{6}", CurrentFIX.Name, "ARTCC", "LineGeometry", PreviousFIX.Longitude, PreviousFIX.Latitude, CurrentFIX.Longitude, CurrentFIX.Latitude);
                        CurrentLine.Freeze( );
                        CurrentPath.Data = CurrentLine;
                        cnvRadar.Children.Add(CurrentPath);
                    }

                    PreviousFIX = CurrentFIX;
                }
            }
        }
Exemplo n.º 5
0
        //根据LineHeights的多少画一段,然后可以重复利用这段,不必每次都计算坐标,和到LineHeights拿值
        private DrawingGroup DrawSingleSection()
        {
            var sectionGroup = new DrawingGroup();
            var renderHight  = Element.DesiredSize.Height;

            var selectedLineHeight = Element.GetSelectedLineHeight();

            var pen = CreatePen();

            // one graduations drawing
            for (var i = 0; i < Element.Graduations.Count; i++)
            {
                var graduation = Element.Graduations[i];
                if (graduation <= 0)
                {
                    continue;
                }

                var x    = i * Element.Interval;
                var line = new LineGeometry
                {
                    StartPoint = new Point(x, renderHight - graduation - selectedLineHeight),
                    EndPoint   = new Point(x, renderHight - selectedLineHeight)
                };
                line.Freeze();

                var geometryDrawing = new GeometryDrawing(null, pen, line);
                geometryDrawing.Freeze();

                sectionGroup.Children.Add(geometryDrawing);
            }
            return(sectionGroup);
        }
Exemplo n.º 6
0
        public void add_line(Point p1, Point p2)
        {
            LineGeometry line = new LineGeometry(p1, p2);

            line.Freeze();

            _geometryGroup.Children.Add(line);
        }
Exemplo n.º 7
0
        public void add_line(Point p1, Point p2)
        {
            LineGeometry line = new LineGeometry(p1, p2);

            line.Freeze();

            _geometryGroup_lines.Children.Add(line);
            _lines_is_dirt = true;
        }
Exemplo n.º 8
0
        private static LineGeometry CreateLine(Point start, Point end)
        {
            var line = new LineGeometry {
                StartPoint = start, EndPoint = end
            };

            line.Freeze();
            return(line);
        }
Exemplo n.º 9
0
        void CreateVisuals(ITextViewLine line)
        {
            var text = view.TextSnapshot.GetText(line.Start, line.Length);

            if (hasUsing == false)
            {
                UpdateUsing(text);
            }
            var regex = hasUsing == true ? usingColorRegex : colorRegex;

            var matches = regex.Matches(text);

            foreach (Match match in matches)
            {
                var mode = match.Groups["mode"].Value;

                Func <Match, Eto.Drawing.Color> translateColor;
                if (!colorMatching.TryGetValue(mode, out translateColor))
                {
                    continue;
                }

                var color = translateColor(match).ToWpf();
                if (color.A <= 0)
                {
                    continue;
                }

                var span     = new SnapshotSpan(view.TextSnapshot, line.Start + match.Index, match.Length);
                var geometry = view.TextViewLines.GetMarkerGeometry(span);
                if (geometry == null ||
                    !view.TextViewModel.IsPointInVisualBuffer(span.Start, PositionAffinity.Successor) ||
                    !view.TextViewModel.IsPointInVisualBuffer(span.End, PositionAffinity.Predecessor))
                {
                    continue;
                }

                var pen       = GetPen(color);
                var bounds    = geometry.Bounds;
                var underline = new LineGeometry(bounds.BottomLeft, bounds.BottomRight);
                underline.Freeze();
                var drawing = new GeometryDrawing(null, pen, underline);
                drawing.Freeze();

                var drawingImage = new DrawingImage(drawing);
                drawingImage.Freeze();

                var image = new Image();
                image.Source = drawingImage;

                Canvas.SetLeft(image, geometry.Bounds.Left);
                Canvas.SetTop(image, geometry.Bounds.Bottom - 2);

                layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, image, null);
            }
        }
Exemplo n.º 10
0
        protected Geometry GeometryFromAnnotation(Annotation annotation)
        {
            if (annotation == null || annotation.Points == null || annotation.Points.Count == 0)
            {
                return(null);
            }

            if (annotation.Points.Count == 1)
            {
                Point           p       = new Point(annotation.Points[0].X + this.Left, annotation.Points[0].Y + this.Top);
                EllipseGeometry ellipse = new EllipseGeometry(p, 3.0, 3.0);

                if (ellipse.CanFreeze)
                {
                    ellipse.Freeze();
                }

                return(ellipse);
            }
            else if (annotation.Points.Count == 2)
            {
                Point        p1   = new Point(annotation.Points[0].X + this.Left, annotation.Points[0].Y + this.Top);
                Point        p2   = new Point(annotation.Points[1].X + this.Left, annotation.Points[1].Y + this.Top);
                LineGeometry line = new LineGeometry(p1, p2);

                if (line.CanFreeze)
                {
                    line.Freeze();
                }

                return(line);
            }
            else
            {
                StreamGeometry streamGeometry = new StreamGeometry();
                using (StreamGeometryContext sgc = streamGeometry.Open())
                {
                    Point start = new Point(annotation.Points[0].X + this.Left, annotation.Points[0].Y + this.Top);

                    sgc.BeginFigure(start, true, true);

                    for (int i = 1; i < annotation.Points.Count; i++)
                    {
                        Point next = new Point(annotation.Points[i].X + this.Left, annotation.Points[i].Y + this.Top);
                        sgc.LineTo(next, true, true);
                    }
                }

                if (streamGeometry.CanFreeze)
                {
                    streamGeometry.Freeze();
                }

                return(streamGeometry);
            }
        }
Exemplo n.º 11
0
        protected override void Render(DrawingContext dc, DataSeries series, Plot plot, Axis xAxis, Axis yAxis, IList <DataSeries> sources)
        {
            if (series == null || plot == null || plot.Points == null || xAxis == null || yAxis == null)
            {
                return;
            }

            var xlong = xAxis.Extent;
            var ylong = yAxis.Extent;

            var lineStart = yAxis.StartPixelsPos;
            var lineEnd   = yAxis.StopPixelsPos;

            var points = plot.Points;

            foreach (var pt in points)
            {
                double x; // coordinates in pixels
                bool   isPtInsideArea;
                try
                {
                    x = xAxis.ToPixels(pt.X);
                    isPtInsideArea = (x >= 0.0 || x <= xlong);
                }
                catch (ArgumentException)
                {
                    continue;
                }

                if (isPtInsideArea)
                {
                    // Line Geometry
                    LineGeometry geometry = new LineGeometry();
                    geometry.StartPoint = new Point(x, lineStart);
                    geometry.EndPoint   = new Point(x, lineEnd);
                    geometry.Freeze();

                    // Clipping region
                    RectangleGeometry clip;
                    clip = new RectangleGeometry(new Rect(0, 0, xlong, ylong));
                    dc.PushClip(clip);
                    dc.DrawGeometry(Brushes.Transparent, series.Pen, geometry);
                }
            }
        }
Exemplo n.º 12
0
        public void RenderRowTick(int row, Brush brush, double thickness, double heightMultiplier, int blankRows)
        {
            LineGeometry line = new LineGeometry();

            line.StartPoint = new Point(Canvas.Width - 4, (MaximumVolumeRows + blankRows - row) * heightMultiplier);
            line.EndPoint   = new Point(Canvas.Width, (MaximumVolumeRows + blankRows - row) * heightMultiplier);
            line.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
            line.Freeze();

            Path path = new Path();

            path.Stroke              = brush;
            path.StrokeThickness     = thickness;
            path.SnapsToDevicePixels = false;

            path.Data = line;
            System.Windows.Controls.Canvas.SetZIndex(path, -1);
            this.Canvas.Children.Add(path);
        }
Exemplo n.º 13
0
        public Path CreateEdgeLine(DelaunayEdge edge)
        {
            if (this.edgesPaths == null)
            {
                this.edgesPaths = new Dictionary <DelaunayEdge, Path>();
            }

            if (!this.edgesPaths.ContainsKey(edge))
            {
                LineGeometry geometry = new LineGeometry(new Point(edge.Start.X, edge.Start.Y), new Point(edge.End.X, edge.End.Y));
                geometry.Freeze();
                Path path = new Path();
                path.Data             = geometry;
                path.StrokeThickness  = EdgeTickness;
                path.Stroke           = new SolidColorBrush(EdgeColor);
                this.edgesPaths[edge] = path;
            }
            return(this.edgesPaths[edge]);
        }
Exemplo n.º 14
0
        public Path CreateLineForMinSpanningTreeEdge(DelaunayEdge edge)
        {
            if (this.minimumSpanningTreePaths == null)
            {
                this.minimumSpanningTreePaths = new Dictionary <DelaunayEdge, Path>();
            }

            if (!this.minimumSpanningTreePaths.ContainsKey(edge))
            {
                LineGeometry geometry = new LineGeometry(new Point(edge.Start.X, edge.Start.Y), new Point(edge.End.X, edge.End.Y));
                geometry.Freeze();
                Path path = new Path();
                path.Data            = geometry;
                path.StrokeThickness = MinimumSpanningTreeTickness;
                path.Stroke          = new SolidColorBrush(Color.FromArgb(120, minimumSpanningTreeEdgeColor.A, minimumSpanningTreeEdgeColor.G, minimumSpanningTreeEdgeColor.B));
                this.minimumSpanningTreePaths[edge] = path;
            }
            return(this.minimumSpanningTreePaths[edge]);
        }
Exemplo n.º 15
0
        void RenderColumn(int seconds, Brush brush, double thickness, double widthMultiplier)
        {
            LineGeometry line = new LineGeometry();

            line.StartPoint = new Point(seconds * widthMultiplier, 0);
            line.EndPoint   = new Point(seconds * widthMultiplier, 4);
            line.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
            line.Freeze();

            Path path = new Path();

            path.Stroke              = brush;
            path.StrokeThickness     = thickness;
            path.SnapsToDevicePixels = false;

            path.Data = line;
            System.Windows.Controls.Canvas.SetZIndex(path, -1);
            this.Canvas.Children.Add(path);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
        private void UpdateGridVisual()
        {
            if (GridVisual != null && IsLoaded)
            {
                DrawingContext dc = GridVisual.RenderOpen();

                Matrix mtx       = PresentationSource.FromVisual(GridVisual).CompositionTarget.TransformToDevice;
                double dpiFactor = 1 / mtx.M11;
                double delt      = dpiFactor / 2;

                double xlen = PageSize.Width * PageScale;
                double ylen = PageSize.Height * PageScale;

                Brush brush    = new SolidColorBrush(GridColor);
                Pen   majorPen = new Pen(brush.CloneCurrentValue(), 1 * dpiFactor);
                brush.Opacity = 0.5;
                Pen minorPen = new Pen(brush.CloneCurrentValue(), 1 * dpiFactor);

                if (majorPen.CanFreeze)
                {
                    majorPen.Freeze();
                }
                if (minorPen.CanFreeze)
                {
                    minorPen.Freeze();
                }

                double border = 10 * PageScale;

                GuidelineSet guidelineSet = new GuidelineSet();
                guidelineSet.GuidelinesX.Add(0 - delt);
                //guidelineSet.GuidelinesX.Add(-border - delt);
                guidelineSet.GuidelinesX.Add(xlen - delt);
                //guidelineSet.GuidelinesX.Add(xlen + border * 2.0 - delt);

                guidelineSet.GuidelinesY.Add(0 - delt);
                //guidelineSet.GuidelinesY.Add(-border - delt);
                guidelineSet.GuidelinesY.Add(ylen - delt);
                //guidelineSet.GuidelinesY.Add(ylen + border * 2.0 - delt);

                dc.PushGuidelineSet(guidelineSet);
                dc.DrawRectangle(PageBackColor, majorPen, new Rect(-border, -border, xlen + border * 2.0, ylen + border * 2.0));
                dc.DrawRectangle(null, minorPen, new Rect(0, 0, xlen, ylen));
                dc.Pop();

                if (ShowGrid)
                {
                    LineGeometry lgx = new LineGeometry(new Point(0, 0), new Point(0, ylen));
                    LineGeometry lgy = new LineGeometry(new Point(0, 0), new Point(xlen, 0));
                    if (lgx.CanFreeze)
                    {
                        lgx.Freeze();
                    }
                    if (lgy.CanFreeze)
                    {
                        lgy.Freeze();
                    }


                    for (double x = 0; x <= PageSize.Width; x += GridSize)
                    {
                        GuidelineSet gridGuidelines = new GuidelineSet();
                        gridGuidelines.GuidelinesX.Add(x * PageScale - delt);

                        dc.PushGuidelineSet(gridGuidelines);
                        dc.PushTransform(new TranslateTransform(x * PageScale, 0));
                        dc.DrawGeometry(null, (x / GridSize) % 5 == 0 ? majorPen : minorPen, lgx);
                        dc.Pop();
                        dc.Pop();
                    }

                    for (double y = 0; y <= PageSize.Height; y += GridSize)
                    {
                        GuidelineSet gridGuidelines = new GuidelineSet();
                        gridGuidelines.GuidelinesY.Add(y * PageScale - delt);

                        dc.PushGuidelineSet(gridGuidelines);
                        dc.PushTransform(new TranslateTransform(0, y * PageScale));
                        dc.DrawGeometry(null, (y / GridSize) % 5 == 0 ? majorPen : minorPen, lgy);
                        dc.Pop();
                        dc.Pop();
                    }
                }

                dc.Close();
            }
        }
Exemplo n.º 19
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);
        }