Ejemplo n.º 1
0
        private void TryCasheResources(IRenderContext2D context)
        {
            _strokePen = _strokePen ?? context.CreatePen(Stroke, AntiAliasing, (float)StrokeThickness, Opacity);

            _gainFillBrush = _gainFillBrush ?? context.CreateBrush(GainMarkerFill);
            _lossFillBrush = _lossFillBrush ?? context.CreateBrush(LossMarkerFill);
        }
        /// <summary>
        /// Draws the series using the <see cref="IRenderContext2D" /> and the <see cref="IRenderPassData" /> passed in
        /// </summary>
        /// <param name="renderContext">The render context. This is a graphics object which has methods to draw lines, quads and polygons to the screen</param>
        /// <param name="renderPassData">The render pass data. Contains a resampled
        /// <see cref="IPointSeries" />, the
        /// <see cref="IndexRange" /> of points on the screen
        /// and the current YAxis and XAxis
        /// <see cref="ICoordinateCalculator{T}" /> to convert data-points to screen points</param>
        protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
        {
            base.Draw(renderContext, renderPassData);

            // Get the data from RenderPassData. See CustomRenderableSeries article which describes PointSeries relationship to DataSeries
            if (renderPassData.PointSeries.Count == 0)
            {
                return;
            }

            // Convert to Spline Series
            _splineSeries = ComputeSplineSeries(renderPassData.PointSeries, IsSplineEnabled, UpSampleFactor);

            // Get the coordinates of the first dataPoint
            var point = GetCoordinatesFor(_splineSeries[0].X, _splineSeries[0].Y);

            // Create a pen to draw the spline line. Make sure you dispose it!
            using (var linePen = renderContext.CreatePen(this.Stroke, this.AntiAliasing, this.StrokeThickness))
            {
                // Create a line drawing context. Make sure you dispose it!
                // NOTE: You can create mutliple line drawing contexts to draw segments if you want
                //       You can also call renderContext.DrawLine() and renderContext.DrawLines(), but the lineDrawingContext is higher performance
                using (var lineDrawingContext = renderContext.BeginLine(linePen, point.X, point.Y))
                {
                    for (int i = 1; i < _splineSeries.Count; i++)
                    {
                        point = GetCoordinatesFor(_splineSeries[i].X, _splineSeries[i].Y);

                        lineDrawingContext.MoveTo(point.X, point.Y);
                    }
                }
            }

            DrawPointMarkers(renderContext, renderPassData.PointSeries);
        }
Ejemplo n.º 3
0
        protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
        {
            var xcal        = renderPassData.XCoordinateCalculator;
            var ycal        = renderPassData.YCoordinateCalculator;
            var surf        = GetParentSurface();
            var xrange      = surf.XAxis.VisibleRange.AsDoubleRange();
            var yrange      = surf.YAxis.VisibleRange.AsDoubleRange();
            var area        = new Rect(xrange.Min, yrange.Min, xrange.Diff, yrange.Diff);
            var pixTakeCare = 3;
            var pixSizeX    = (TReal)Math.Abs(xcal.GetDataValue(pixTakeCare) - xcal.GetDataValue(0.0));
            var pixSizeY    = (TReal)Math.Abs(ycal.GetDataValue(0.0) - ycal.GetDataValue(pixTakeCare));
            var found       = DataSeries.FindInArea(area, pixSizeX, pixSizeY);
            var brush       = renderContext.CreateBrush(new SolidColorBrush(Colors.BlueViolet));
            var pen         = renderContext.CreatePen(Colors.Black, false, 1);

            foreach (var rect in found)
            {
                DrawRectangle(renderContext, pen, brush, xcal, ycal, (TReal)rect.X, (TReal)rect.Y, (TReal)rect.Width, (TReal)rect.Height);
            }
            brush.Dispose();
            pen.Dispose();

            var sdbg = DataSeries as Series4;
            //sdbg.DrawNodes(renderContext, xcal, ycal, area, pixSizeX, pixSizeY);
        }
        private void CustomDraw(IRenderContext2D renderContext, IRenderPassData renderPassData)
        {
            var dataPointSeries = renderPassData.PointSeries as Point2DSeries;

            foreach (var pt in ptList)
            {
                System.Windows.Media.Color ptColor = System.Windows.Media.Color.FromArgb(pt.Color.A, pt.Color.R, pt.Color.G, pt.Color.B);

                var ptRefLocal = GetRenderingPoint(new Point(pt.Pt.X, pt.Pt.Y));

                /// Create a pen to draw. Make sure you dispose it!
                using (var ptPen = renderContext.CreatePen(ptColor, this.AntiAliasing, (float)1))
                {
                    using (var ptBrush = renderContext.CreateBrush(new SolidColorBrush(ptColor)))
                    {
                        renderContext.DrawEllipse(ptPen, ptBrush, ptRefLocal, pt.Width, pt.Width);

                        //using (var lineDrawingContext = renderContext.BeginLine(linePen, initialPoint.X, initialPoint.Y))
                        //    {
                        //        lineDrawingContext.MoveTo(endPoint.X, endPoint.Y);
                        //        lineDrawingContext.End();
                        //    }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void CustomDraw(IRenderContext2D renderContext)
        {
            foreach (var p in polygonList)
            {
                Polygon polygon = p.Value.polygon;

                if (polygon.Points.Count > 0)
                {
                    Point initialPoint = GetRenderingPoint(polygon.Points[0]);

                    System.Windows.Media.Color backgroundColor = System.Windows.Media.Color.FromArgb(p.Value.backgroundColor.A, p.Value.backgroundColor.R, p.Value.backgroundColor.G, p.Value.backgroundColor.B);

                    using (var brush = renderContext.CreateBrush(backgroundColor))
                    {
                        //IEnumerable<Point> points; // define your points
                        renderContext.FillPolygon(brush, GetRenderingPoints(polygon.Points));
                    }

                    //// Create a pen to draw. Make sure you dispose it!
                    System.Windows.Media.Color borderColor = System.Windows.Media.Color.FromArgb(p.Value.borderColor.A, p.Value.borderColor.R, p.Value.borderColor.G, p.Value.borderColor.B);

                    using (var linePen = renderContext.CreatePen(borderColor, this.AntiAliasing, p.Value.borderWidth, p.Value.borderOpacity, p.Value.borderDashPattern))
                    {
                        using (var lineDrawingContext = renderContext.BeginLine(linePen, initialPoint.X, initialPoint.Y))
                        {
                            for (int i = 1; i < polygon.Points.Count; i++)
                            {
                                lineDrawingContext.MoveTo(GetRenderingPoint(polygon.Points[i]).X, GetRenderingPoint(polygon.Points[i]).Y);
                            }
                            lineDrawingContext.End();
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void DrawNodes(IRenderContext2D renderContext, ICoordinateCalculator <double> xc, ICoordinateCalculator <double> yc, Rect area, float pixSizeX, float pixSizeY)
        {
            var pen   = renderContext.CreatePen(Colors.Brown, false, 1);
            var nodes = FindNodesWithDecimation(area, pixSizeX, pixSizeY);

            foreach (var node in nodes)
            {
                var p1 = new Point(xc.GetCoordinate(node.HorizontalRange.Min), yc.GetCoordinate(node.VerticalRange.Min));
                var p2 = new Point(xc.GetCoordinate(node.HorizontalRange.Max), yc.GetCoordinate(node.VerticalRange.Max));
                renderContext.DrawQuad(pen, p1, p2);
            }
            pen.Dispose();
        }
        private void CustomDraw(IRenderContext2D renderContext)
        {
            foreach (var s in segmentList)
            {
                Point initialPoint = GetRenderingPoint(new Point(s.Segment.X1, s.Segment.Y1));
                Point endPoint     = GetRenderingPoint(new Point(s.Segment.X2, s.Segment.Y2));
                System.Windows.Media.Color segmentColor = System.Windows.Media.Color.FromArgb(s.Color.A, s.Color.R, s.Color.G, s.Color.B);

                /// Create a pen to draw. Make sure you dispose it!
                using (var linePen = renderContext.CreatePen(segmentColor, this.AntiAliasing, (float)s.Width, s.Opacity, s.DashPattern))
                {
                    using (var lineDrawingContext = renderContext.BeginLine(linePen, initialPoint.X, initialPoint.Y))
                    {
                        lineDrawingContext.MoveTo(endPoint.X, endPoint.Y);
                        lineDrawingContext.End();
                    }
                }
            }
        }
Ejemplo n.º 8
0
        protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
        {
            base.Draw(renderContext, renderPassData);

            // Create a line drawing context. Make sure you dispose it!
            // NOTE: You can create mutliple line drawing contexts to draw segments if you want
            //       You can also call renderContext.DrawLine() and renderContext.DrawLines(), but the lineDrawingContext is higher performance
            foreach (var p in polygonList)
            {
                Polygon polygon = p.Value.polygon;

                if (polygon.Points.Count > 0)
                {
                    Point initialPoint = GetRenderingPoint(polygon.Points[0]);

                    System.Windows.Media.Color backgroundColor = System.Windows.Media.Color.FromArgb(p.Value.backgroundColor.A, p.Value.backgroundColor.R, p.Value.backgroundColor.G, p.Value.backgroundColor.B);

                    using (var brush = renderContext.CreateBrush(backgroundColor))
                    {
                        //IEnumerable<Point> points; // define your points
                        renderContext.FillPolygon(brush, GetRenderingPoints(polygon.Points));
                    }

                    //// Create a pen to draw. Make sure you dispose it!
                    System.Windows.Media.Color borderColor = System.Windows.Media.Color.FromArgb(p.Value.borderColor.A, p.Value.borderColor.R, p.Value.borderColor.G, p.Value.borderColor.B);

                    using (var linePen = renderContext.CreatePen(borderColor, this.AntiAliasing, p.Value.borderWidth, p.Value.borderOpacity, p.Value.borderDashPattern))
                    {
                        using (var lineDrawingContext = renderContext.BeginLine(linePen, initialPoint.X, initialPoint.Y))
                        {
                            for (int i = 1; i < polygon.Points.Count; i++)
                            {
                                lineDrawingContext.MoveTo(GetRenderingPoint(polygon.Points[i]).X, GetRenderingPoint(polygon.Points[i]).Y);
                            }
                            lineDrawingContext.End();
                        }
                    }
                }
            }
        }
 protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
 {
     var xcal = renderPassData.XCoordinateCalculator;
     var ycal = renderPassData.YCoordinateCalculator;
     var surf = GetParentSurface();
     var xrange = surf.XAxis.VisibleRange.AsDoubleRange();
     var yrange = surf.YAxis.VisibleRange.AsDoubleRange();
     var area = new Rect(xrange.Min, yrange.Min, xrange.Diff, yrange.Diff);
     var found = DataSeries.FindInArea(area);
     var brush = renderContext.CreateBrush(new SolidColorBrush(Colors.BlueViolet));
     var pen = renderContext.CreatePen(Colors.Black, false, 1);
     foreach (var index in found)
     {
         var xv = DataSeries.XValues[index];
         var yv = DataSeries.YValues[index];
         var wv = DataSeries.WidthValues[index];
         var hv = DataSeries.HeightValues[index];
         DrawRectangle(renderContext, pen, brush, xcal, ycal, xv, yv, wv, hv);
     }
     brush.Dispose();
     pen.Dispose();
 }
        protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
        {
            var xcal   = renderPassData.XCoordinateCalculator;
            var ycal   = renderPassData.YCoordinateCalculator;
            var surf   = GetParentSurface();
            var xrange = surf.XAxis.VisibleRange.AsDoubleRange();
            var yrange = surf.YAxis.VisibleRange.AsDoubleRange();
            var area   = new Rect(xrange.Min, yrange.Min, xrange.Diff, yrange.Diff);
            var found  = DataSeries.FindInArea(area);
            var brush  = renderContext.CreateBrush(new SolidColorBrush(Colors.BlueViolet));
            var pen    = renderContext.CreatePen(Colors.Black, false, 1);

            foreach (var index in found)
            {
                var xv = DataSeries.XValues[index];
                var yv = DataSeries.YValues[index];
                var wv = DataSeries.WidthValues[index];
                var hv = DataSeries.HeightValues[index];
                DrawRectangle(renderContext, pen, brush, xcal, ycal, xv, yv, wv, hv);
            }
            brush.Dispose();
            pen.Dispose();
        }
Ejemplo n.º 11
0
        public override void Draw(IRenderContext2D context, IEnumerable <Point> centers)
        {
            var fill   = context.CreateBrush(Fill);
            var stroke = context.CreatePen(Stroke, AntiAliasing, (float)StrokeThickness);

            float width2  = (float)(Width * 0.5);
            float height2 = (float)(Height * 0.5);

            foreach (var center in centers)
            {
                double top    = center.Y - height2;
                double bottom = center.Y + height2;
                double left   = center.X - width2;
                double right  = center.X + width2;

                var diamondPoints = new[]
                {
                    // Points drawn like this:
                    //
                    //      x0      (x4 in same location as x0)
                    //
                    // x3        x1
                    //
                    //      x2

                    new Point(center.X, top),    // x0
                    new Point(right, center.Y),  // x1
                    new Point(center.X, bottom), // x2
                    new Point(left, center.Y),   // x3
                    new Point(center.X, top),    // x4 == x0
                };

                context.FillPolygon(fill, diamondPoints);
                context.DrawLines(stroke, diamondPoints);
            }
        }
        protected override void Draw(IRenderContext2D renderContext, IRenderPassData renderPassData)
        {
            var xcal = renderPassData.XCoordinateCalculator;
            var ycal = renderPassData.YCoordinateCalculator;
            var surf = GetParentSurface();
            var xrange = surf.XAxis.VisibleRange.AsDoubleRange();
            var yrange = surf.YAxis.VisibleRange.AsDoubleRange();
            var area = new Rect(xrange.Min, yrange.Min, xrange.Diff, yrange.Diff);
            var pixTakeCare = 3;
            var pixSizeX = (TReal)Math.Abs(xcal.GetDataValue(pixTakeCare) - xcal.GetDataValue(0.0));
            var pixSizeY = (TReal)Math.Abs(ycal.GetDataValue(0.0) - ycal.GetDataValue(pixTakeCare));
            var found = DataSeries.FindInArea(area, pixSizeX, pixSizeY);
            var brush = renderContext.CreateBrush(new SolidColorBrush(Colors.BlueViolet));
            var pen = renderContext.CreatePen(Colors.Black, false, 1);
            foreach (var rect in found)
            {
                DrawRectangle(renderContext, pen, brush, xcal, ycal, (TReal)rect.X, (TReal)rect.Y, (TReal)rect.Width, (TReal)rect.Height);
            }
            brush.Dispose();
            pen.Dispose();

            var sdbg = DataSeries as Series4;
            //sdbg.DrawNodes(renderContext, xcal, ycal, area, pixSizeX, pixSizeY);
        }