Exemplo n.º 1
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (Plotter2D == null)
            {
                return;
            }
            if (Collection == null)
            {
                return;
            }
            if (DataSource == null)
            {
                return;
            }
            if (Collection.Lines.Count == 0)
            {
                IsolineBuilder.DataSource   = DataSource;
                IsolineBuilder.MissingValue = MissingValue;
                Collection = IsolineBuilder.BuildIsoline();
            }

            IsolineCollection = Collection;

            var dc = drawingContext;
            var strokeThickness = StrokeThickness;
            var collection      = Collection;

            var bounds = DataRect.Empty;

            // determining content bounds
            foreach (LevelLine line in collection)
            {
                foreach (Point point in line.AllPoints)
                {
                    bounds.Union(point);
                }
            }

            Viewport2D.SetContentBounds(this, bounds);
            ViewportPanel.SetViewportBounds(this, bounds);

            if (bounds.IsEmpty)
            {
                return;
            }

            // custom transform with output set to renderSize of this control
            var transform = Plotter2D.Transform.WithRects(bounds, new Rect(RenderSize));

            // actual drawing of isolines
            RenderIsolineCollection(dc, strokeThickness, collection, transform);

            RenderLabels(dc, collection);
        }
 /// <summary>
 /// This method is called when data source changes.
 /// </summary>
 protected virtual void UpdateDataSource()
 {
     if (dataSource != null)
     {
         IsolineBuilder.DataSource = dataSource;
         collection = IsolineBuilder.Build();
     }
     else
     {
         collection = null;
     }
 }
Exemplo n.º 3
0
 protected override void UpdateDataSource()
 {
     if (DataSource != null)
     {
         IsolineBuilder.DataSource   = DataSource;
         IsolineBuilder.MissingValue = MissingValue;
         Collection = IsolineBuilder.BuildIsoline();
     }
     else
     {
         Collection = null;
     }
 }
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (Plotter2D == null)
            {
                return;
            }
            if (DataSource == null)
            {
                return;
            }

            var collection = (IsolineCollection)Parent.GetValue(IsolineCollectionProperty);

            if (collection == null)
            {
                return;
            }

            var bounds = ViewportPanel.GetViewportBounds(this);

            if (bounds.IsEmpty)
            {
                return;
            }

            var dc = drawingContext;
            var strokeThickness = StrokeThickness;

            var transform = Plotter2D.Transform.WithRects(bounds, new Rect(RenderSize));

            //dc.DrawRectangle(null, new Pen(Brushes.Green, 2), new Rect(RenderSize));

            var additionalLevels = GetAdditionalLevels(collection);

            IsolineBuilder.DataSource = DataSource;
            var additionalIsolineCollections = additionalLevels.Select(level =>
            {
                return(IsolineBuilder.BuildIsoline(level));
            });

            foreach (var additionalCollection in additionalIsolineCollections)
            {
                RenderIsolineCollection(dc, strokeThickness, additionalCollection, transform);
            }
        }
Exemplo n.º 5
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (Plotter2D == null)
            {
                return;
            }
            if (DataSource == null)
            {
                return;
            }
            if (Collection == null)
            {
                return;
            }
            if (Collection.Lines.Count == 0)
            {
                IsolineBuilder.DataSource = DataSource;
            }

            var    dc           = drawingContext;
            var    dataSource   = DataSource;
            var    localMinMax  = dataSource.GetMinMax();
            var    globalMinMax = dataSource.Range.Value;
            double lengthsRatio = globalMinMax.GetLength() / localMinMax.GetLength();

            if (lengthsRatio > 16)
            {
                double log    = Math.Round(Math.Log(lengthsRatio, 2));
                double number = 2 * Math.Pow(2, log);
                double delta  = globalMinMax.GetLength() / number;

                double start = Math.Floor((localMinMax.Min - globalMinMax.Min) / delta) * delta + globalMinMax.Min;
                double end   = localMinMax.Max;

                var transform       = Plotter2D.Transform;
                var strokeThickness = StrokeThickness;

                double x = start;
                while (x < end)
                {
                    var collection = IsolineBuilder.BuildIsoline(x);

                    foreach (LevelLine line in collection)
                    {
                        StreamGeometry lineGeometry = new StreamGeometry();
                        using (var context = lineGeometry.Open())
                        {
                            context.BeginFigure(line.StartPoint.ViewportToScreen(transform), false, false);
                            context.PolyLineTo(line.OtherPoints.ViewportToScreen(transform).ToArray(), true, true);
                        }
                        lineGeometry.Freeze();

                        var paletteRatio = (line.RealValue - globalMinMax.Min) / globalMinMax.GetLength();
                        Pen pen          = new Pen(new SolidColorBrush(Palette.GetColor(paletteRatio)), strokeThickness);

                        dc.DrawGeometry(null, pen, lineGeometry);
                    }

                    x += delta;
                }
            }
            //dc.DrawRectangle(Brushes.Green.MakeTransparent(0.3), null, new Rect(RenderSize));
        }