Ejemplo n.º 1
0
        /// <summary>
        /// Renders the series on the specified render context.
        /// </summary>
        /// <param name="rc">The rendering context.</param>
        /// <param name="model">The model.</param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            var p0            = this.Transform(this.XAxis.ActualMinimum, this.YAxis.ActualMinimum);
            var p1            = this.Transform(this.XAxis.ActualMaximum, this.YAxis.ActualMaximum);
            var w             = (int)(p1.X - p0.X);
            var h             = (int)(p0.Y - p1.Y);
            int maxIterations = (int)this.ColorAxis.ActualMaximum + 1;
            var pixels        = new OxyColor[h, w];

            ParallelFor(
                0,
                h,
                i =>
            {
                double y = this.YAxis.ActualMinimum
                           + ((double)i / (h - 1) * (this.YAxis.ActualMaximum - this.YAxis.ActualMinimum));
                for (int j = 0; j < w; j++)
                {
                    double x = this.XAxis.ActualMinimum
                               + ((double)j / (w - 1)
                                  * (this.XAxis.ActualMaximum - this.XAxis.ActualMinimum));
                    var iterations = Solve(x, y, maxIterations);
                    pixels[i, j]   = this.ColorAxis.GetColor((double)iterations);
                }
            });

            var bitmap = OxyImage.PngFromArgb(pixels);

            //TEST  rc.DrawImage(bitmap, p0.X, p1.Y, p1.X - p0.X, p0.Y - p1.Y, 1, true);
            RenderingExtensions.DrawImage(rc, bitmap, p0.X, p1.Y, p1.X - p0.X, p0.Y - p1.Y, 1, true);
        }
Ejemplo n.º 2
0
        public void GetParentRenderingIdsForRendering_WhenPlaceholderIsNotDynamic_ReturnsEmptyEnumerable()
        {
            var parents = RenderingExtensions.GetParentRenderingIdsForRendering(Keys.PlaceholderKey);

            parents.Should().NotBeNull();
            parents.Should().BeEmpty();
        }
Ejemplo n.º 3
0
        public ModelSpawn(string directory, BinaryReader reader)
        {
            if (reader.BaseStream.Position == reader.BaseStream.Length)
            {
                return;
            }

            var flags = reader.ReadInt32();

            reader.BaseStream.Position += 2 + 4;

            var position = reader.Read <Vector3>();

            position.X -= 32 * 533.333313f;
            position.Y -= 32 * 533.333313f;

            var rotation       = reader.Read <Vector3>();
            var rotationMatrix = RenderingExtensions.FromEulerAngles(rotation.Z * MathHelper.Pi / 180.0f,
                                                                     rotation.X * MathHelper.Pi / 180.0f,
                                                                     rotation.Y * MathHelper.Pi / 180.0f);

            var translationMatrix = Matrix4.CreateTranslation(position);
            var scaleMatrix       = Matrix4.CreateScale(reader.ReadSingle());

            PositionMatrix = rotationMatrix * scaleMatrix * translationMatrix;

            if ((flags & 0x4) != 0)
            {
                reader.BaseStream.Position += 4 * 6; // BBox
            }
            var nameLength = reader.ReadInt32();

            ModelName = string.Intern(System.Text.Encoding.UTF8.GetString(reader.ReadBytes(nameLength)));
        }
Ejemplo n.º 4
0
        public override string ProvideText(string text, double width, FontFamily font, double fontSize, Thickness padding)
        {
            var renderstr = text;

            width -= 10;
            if (TrimIndex >= renderstr.Length)
            {
                return(renderstr);
            }
            if (width <= 40)
            {
                return(renderstr);
            }
            var fixedprefix = text.Substring(0, TrimIndex);
            var suffix      = text.Substring(TrimIndex);
            var ellipse     = "...";


            var renderSize = RenderingExtensions.EstimateLabelRenderSize(font, fontSize, padding, renderstr);

            if (renderSize.Width > width)
            {
                do
                {
                    suffix     = suffix.Substring(1);
                    renderstr  = fixedprefix + ellipse + suffix;
                    renderSize = RenderingExtensions.EstimateLabelRenderSize(font, fontSize, padding, renderstr);
                } while (renderSize.Width > width && renderstr.Length > 2);
            }

            return(renderstr);
        }
Ejemplo n.º 5
0
        public void GetParentRenderingIdsForRendering_WhenPlaceholderIsNested_ReturnsCorrectParents(string originalKey, params string[] expectedParents)
        {
            var parents = RenderingExtensions.GetParentRenderingIdsForRendering(originalKey);

            parents.Should().NotBeNull();
            parents.Should().NotBeEmpty();
            parents.Should().BeEquivalentTo(expectedParents);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// If the Rendering expects a Datasource and it is Null or Empty, return the Blank View.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="rendering"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        private string GetPath(Database database, Rendering rendering, string path)
        {
            if (!RenderingExtensions.RequiresDatasource(rendering.RenderingItem) ||
                RenderingExtensions.DatasourceExists(database, rendering.DataSource))
            {
                return(path);
            }

            Log.Warn($"EXPERIENCE EDITOR - Datasource needs set on the View Rendering: {rendering.RenderingItem.DisplayName}, Path: {rendering.Item.Paths.FullPath}, ID: {rendering.Item.ID}.", this);
            return(ExperienceEditorConstants.Views.BlankViewPath);
        }
Ejemplo n.º 7
0
        protected IMarker GetMarker(Rendering rendering)
        {
            // If the Rendering's Datasource Template field is empty, we assume that it does not need a Datasource to function.
            if (!RenderingExtensions.RequiresDatasource(rendering.RenderingItem))
            {
                return(null);
            }

            // If the rendering has a valid Datasource, do not add the Wrapper otherwise add it.
            return(Context.ContentDatabase.GetItem(rendering.DataSource) == null
                ? new DatasourceRenderingMarker(RenderingContext.Current, rendering.RenderingItem.DisplayName)
                : null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Renders the series on the specified rendering context.
        /// </summary>
        /// <param name="rc">The rendering context.</param>
        /// <param name="model">The owner plot model.</param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            if (Points.Count == 0)
            {
                return;
            }

            if (Points.Count % 2 != 0)
            {
                throw new InvalidOperationException("The number of points should be even.");
            }

            if (this.XAxis == null || this.YAxis == null)
            {
                throw new InvalidOperationException("Axis has not been defined.");
            }

            var clippingRect = GetClippingRect();

            IList <ScreenPoint> screenPoints =
                //TEST  Points.Select<IDataPoint, ScreenPoint>(this.Transform).ToList();
                Alt.EnumerableHelper.ToList(Alt.EnumerableHelper.Select <IDataPoint, ScreenPoint>(Points, this.Transform));

            var verticalLines = new List <ScreenPoint>();

            for (int i = 0; i < screenPoints.Count; i += 2)
            {
                if (screenPoints[i].DistanceToSquared(screenPoints[i + 1]) < this.StrokeThickness)
                {
                    screenPoints[i]     = new ScreenPoint(screenPoints[i].X - (this.StrokeThickness * 0.5), screenPoints[i].Y);
                    screenPoints[i + 1] = new ScreenPoint(screenPoints[i].X + (this.StrokeThickness * 0.5), screenPoints[i].Y);
                }

                if (this.ShowVerticals && i > 0 && Math.Abs(screenPoints[i - 1].X - screenPoints[i].X) < this.Epsilon)
                {
                    verticalLines.Add(screenPoints[i - 1]);
                    verticalLines.Add(screenPoints[i]);
                }
            }

            //TEST  rc.DrawClippedLineSegments(screenPoints, clippingRect, this.ActualColor, this.StrokeThickness, this.LineStyle, this.LineJoin, false);
            RenderingExtensions.DrawClippedLineSegments(rc, screenPoints, clippingRect, this.ActualColor, this.StrokeThickness, this.LineStyle, this.LineJoin, false);

            //TEST  rc.DrawClippedLineSegments(verticalLines, clippingRect, this.ActualColor, this.StrokeThickness / 3, LineStyle.Dash, this.LineJoin, false);
            RenderingExtensions.DrawClippedLineSegments(rc, verticalLines, clippingRect, this.ActualColor, this.StrokeThickness / 3, LineStyle.Dash, this.LineJoin, false);

            //TEST  rc.DrawMarkers(screenPoints, clippingRect, this.MarkerType, null, this.MarkerSize, this.MarkerFill, this.MarkerStroke, this.MarkerStrokeThickness);
            RenderingExtensions.DrawMarkers(rc, screenPoints, clippingRect, this.MarkerType, null, this.MarkerSize, this.MarkerFill, this.MarkerStroke, this.MarkerStrokeThickness);
        }
Ejemplo n.º 9
0
        public ModelSpawn(string directory, BinaryReader reader)
        {
            Valid = false;
            if (reader.BaseStream.Position == reader.BaseStream.Length)
            {
                return;
            }

            Valid = true;
            Flags = reader.ReadUInt32();
            AdtID = reader.ReadUInt16();
            ID    = reader.ReadUInt32();

            var position = reader.Read <Vector3>();

            position.X -= 32 * 533.333313f;
            position.Y -= 32 * 533.333313f;

            var rotation = reader.Read <Vector3>();
            /// THIS IS OK. IF IT IS BECOMING WRONG, SWAP ROT.Z AND ROT.X
            var rotationMatrix = RenderingExtensions.FromEulerAngles(rotation.Z * MathHelper.Pi / 180.0f,
                                                                     rotation.X * MathHelper.Pi / 180.0f,
                                                                     rotation.Y * MathHelper.Pi / 180.0f);

            var translationMatrix = Matrix4.CreateTranslation(position);
            var scaleMatrix       = Matrix4.CreateScale(reader.ReadSingle());

            PositionMatrix = rotationMatrix * scaleMatrix * translationMatrix;

            if (HasBoundingBox)
            {
                BoundingBoxLow  = reader.Read <Vector3>();
                BoundingBoxHigh = reader.Read <Vector3>();
            }

            var nameLength = reader.ReadInt32();

            Name = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(nameLength));

            Model = WorldModelCache.OpenInstance(directory, Name);
            foreach (var model in Model.GroupModels)
            {
                model.AddInstance(PositionMatrix);
            }
        }
        public override void Process(GetRendererArgs args)
        {
            var rendering = args.Rendering;
            var database  = Sitecore.Context.Database;

            if (!database.Name.Equals("core") && RenderingExtensions.RequiresDatasource(rendering.RenderingItem) &&
                !RenderingExtensions.DatasourceExists(database, rendering.DataSource) &&
                !rendering.RenderingType.Equals("Layout"))
            {
                // Return Blank View if the Rendering Requires a Datasource and the Datasource doesn't exist.
                args.Result = this.GetRenderer(rendering, args);

                // Log for funzies
                Log.Warn($"EXPERIENCE EDITOR - Datasource needs set on the Controller Rendering: {rendering.RenderingItem.DisplayName}, Path: {rendering.Item.Paths.FullPath}, ID: {rendering.Item.ID}.", this);
                return;
            }

            base.Process(args);
        }
Ejemplo n.º 11
0
        public override string ProvideText(string text, double width, FontFamily font, double fontSize, Thickness padding)
        {
            var renderstr = text;

            var ellipse     = "...";
            var ellipseSize = RenderingExtensions.EstimateLabelRenderSize(font, fontSize, padding, ellipse);

            var renderSize = RenderingExtensions.EstimateLabelRenderSize(font, fontSize, padding, renderstr);

            if (renderSize.Width > width)
            {
                do
                {
                    renderstr  = renderstr.Substring(1);
                    renderSize = RenderingExtensions.EstimateLabelRenderSize(font, fontSize, padding, renderstr);
                } while (renderSize.Width > width - ellipseSize.Width && renderstr.Length > 2);
                return(ellipse + renderstr);
            }

            return(renderstr);
        }
Ejemplo n.º 12
0
        public Size PredictRenderSizeAllocation(string text, double relativeToFontSize)
        {
            var textFontSize = relativeToFontSize * RelativeFontSize;

            if (textFontSize <= 0)
            {
                return(new Size(0, 0));
            }

            var renderSize = RenderingExtensions.EstimateTextRenderSize(FontFamily, textFontSize, Padding, text);

            if (TextRotation == TextRotation.None)
            {
                return(renderSize);
            }

            //var largest = renderSize.Largest();
            //return new Size(largest, largest);

            return(new Size(renderSize.Height, renderSize.Width));
        }
Ejemplo n.º 13
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var str       = values[0].RequireType <string>();
            var renderstr = str;

            var targetControl   = values[1].RequireType <Control>();
            var relativeControl = values[2].RequireType <Control>();
            var fallbackWidth   = System.Convert.ToDouble(parameter);

            var ellipse     = "...";
            var ellipseSize = RenderingExtensions.EstimateLabelRenderSize(targetControl.FontFamily, targetControl.FontSize, ellipse);

            var targetWidth = relativeControl.ActualWidth - ellipseSize.Width - 10;

            if (!targetControl.IsLoaded || targetWidth < 1)
            {
                targetWidth = fallbackWidth;
                //targetControl.MouseDown += (s, e) =>
                //{
                //	s.RequireType<ContentControl>().GetBindingExpression(ContentControl.ContentProperty)?.UpdateTarget();
                //	//targetControl.Width = (double)Convert(values, targetType, parameter, culture);
                //};
            }

            var renderSize = RenderingExtensions.EstimateLabelRenderSize(targetControl.FontFamily, targetControl.FontSize, renderstr);

            if (renderSize.Width > targetWidth)
            {
                do
                {
                    renderstr  = renderstr.Substring(1);
                    renderSize = RenderingExtensions.EstimateLabelRenderSize(targetControl.FontFamily, targetControl.FontSize, renderstr);
                } while (renderSize.Width > targetWidth && renderstr.Length > 2);
                return(ellipse + renderstr);
            }

            return(renderstr);
        }
Ejemplo n.º 14
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            PART_bars.Children.Clear();
            PART_xAxis.Children.Clear();
            PART_highlight.Children.Clear();

            if (FilteredData.Count < 1)
            {
                base.OnRender(drawingContext);
                return;
            }
            var total = FilteredData.MaxValue();

            var context           = new ProviderContext(FilteredData.Count);
            var barAvailableWidth = PART_bars.RenderSize.Width / FilteredData.Count;
            var barActiveWidth    = barAvailableWidth * SegmentWidthPercentage;
            var barLeftSpacing    = (barAvailableWidth - barActiveWidth) / 2;
            var barLabelSize      = RenderingExtensions.EstimateLabelRenderSize(BarTotalFontFamily, BarTotalFontSize);

            MaterialProvider.Reset(context);
            var xtrace = 0;

            foreach (var d in FilteredData)
            {
                var materialSet = MaterialProvider.ProvideNext(context);
                var axisLabel   = new Label
                {
                    Content                    = d.CategoryName,
                    IsHitTestVisible           = false,
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment        = HorizontalAlignment.Left,
                    VerticalAlignment          = VerticalAlignment.Bottom,
                    Width       = barAvailableWidth,
                    Margin      = new Thickness(barAvailableWidth * xtrace, 0, 0, 0),
                    Foreground  = BarTotalForeground.GetMaterial(materialSet),
                    DataContext = this
                };
                axisLabel.BindTextualPrimitive <XAxisPrimitive>(this);

                PART_xAxis.Children.Add(axisLabel);
                xtrace++;
            }
            var horizontalTrace = 0d;
            var xAxisHeight     = PART_xAxis.ActualHeight;
            var backHeight      = PART_bars.RenderSize.Height - xAxisHeight;

            MaterialProvider.Reset(context);
            foreach (var d in FilteredData)
            {
                var materialSet   = MaterialProvider.ProvideNext(context);
                var backRectangle = new Rectangle
                {
                    Width               = barActiveWidth,
                    Height              = backHeight,
                    VerticalAlignment   = VerticalAlignment.Bottom,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Margin              = new Thickness(horizontalTrace + barLeftSpacing, 0, 0, xAxisHeight),
                    Fill = SegmentSpaceBackground.GetMaterial(materialSet)
                };
                //backRectangle.MouseEnter += (s, e) => barMouseEnter(d);
                //BindingOperations.SetBinding(backRectangle, Shape.FillProperty, new Binding("SegmentSpaceBackground") { Source = this });

                PART_bars.Children.Add(backRectangle);


                var verticalTrace = 0d;
                var pathBuffer    = new List <Shape>();


                var height    = d.Value.Map(0, total, 0, PART_bars.RenderSize.Height - xAxisHeight - barLabelSize.Height);
                var rectangle = new Rectangle
                {
                    Width               = barActiveWidth,
                    Height              = height + verticalTrace,
                    Fill                = SegmentForeground.GetMaterial(materialSet),
                    VerticalAlignment   = VerticalAlignment.Bottom,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Margin              = new Thickness(horizontalTrace + barLeftSpacing, 0, 0, xAxisHeight)
                };
                //rectangle.MouseEnter += (s, e) => barMouseEnter(d);
                //rectangle.MouseLeave += (s, e) => barMouseLeave(s, e, d, sd);
                rectangle.RenderTransform       = new ScaleTransform(1, (IsLoaded ? 1 : 0), .5, 1);           //TODO get rid of all isloaded conditional sets
                rectangle.RenderTransformOrigin = new Point(.5, 1);

                d.RenderedVisual = rectangle;
                pathBuffer.Add(rectangle);
                verticalTrace += height;

                for (var x = pathBuffer.Count - 1; x >= 0; x--)
                {
                    var path = pathBuffer[x];
                    PART_bars.Children.Add(path);
                }
                var barLabel = new Label
                {
                    Content                    = d.Value,
                    IsHitTestVisible           = false,
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment        = HorizontalAlignment.Left,
                    VerticalAlignment          = VerticalAlignment.Bottom,
                    Width      = barAvailableWidth,
                    Foreground = BarTotalForeground.GetMaterial(materialSet),
                    Margin     = new Thickness(horizontalTrace, 0, 0, xAxisHeight + verticalTrace),
                };
                barLabel.BindTextualPrimitive <BarTotalPrimitive>(this);
                d.RenderedVisual = pathBuffer;
                PART_bars.Children.Add(barLabel);
                horizontalTrace += barAvailableWidth;
            }
            base.OnRender(drawingContext);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Renders the series on the specified render context.
        /// </summary>
        /// <param name="rc">The rendering context.</param>
        /// <param name="model">The model.</param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            var points = this.Points;

            if (points.Count == 0)
            {
                return;
            }

            this.VerifyAxes();

            var clippingRect = GetClippingRect();

            int n = points.Count;

            // Transform all points to screen coordinates
            var segments = new List <ScreenPoint>(n * 6);

            for (int i = 0; i < n; i++)
            {
                var    sp     = XAxis.Transform(points[i].X, points[i].Y, YAxis);
                var    ei     = points[i] as ErrorItem;
                double errorx = ei != null ? ei.XError * XAxis.Scale : 0;
                double errory = ei != null?ei.YError *Math.Abs(YAxis.Scale) : 0;

                double d = 4;

                if (errorx > 0)
                {
                    var p0 = new ScreenPoint(sp.X - (errorx * 0.5), sp.Y);
                    var p1 = new ScreenPoint(sp.X + (errorx * 0.5), sp.Y);
                    segments.Add(p0);
                    segments.Add(p1);
                    segments.Add(new ScreenPoint(p0.X, p0.Y - d));
                    segments.Add(new ScreenPoint(p0.X, p0.Y + d));
                    segments.Add(new ScreenPoint(p1.X, p1.Y - d));
                    segments.Add(new ScreenPoint(p1.X, p1.Y + d));
                }

                if (errory > 0)
                {
                    var p0 = new ScreenPoint(sp.X, sp.Y - (errory * 0.5));
                    var p1 = new ScreenPoint(sp.X, sp.Y + (errory * 0.5));
                    segments.Add(p0);
                    segments.Add(p1);
                    segments.Add(new ScreenPoint(p0.X - d, p0.Y));
                    segments.Add(new ScreenPoint(p0.X + d, p0.Y));
                    segments.Add(new ScreenPoint(p1.X - d, p1.Y));
                    segments.Add(new ScreenPoint(p1.X + d, p1.Y));
                }
            }

            // clip the line segments with the clipping rectangle
            for (int i = 0; i + 1 < segments.Count; i += 2)
            {
                //TEST  rc.DrawClippedLine(
                RenderingExtensions.DrawClippedLine(rc,
                                                    new[] { segments[i], segments[i + 1] },
                                                    clippingRect,
                                                    2,
                                                    this.GetSelectableColor(this.Color),
                                                    this.StrokeThickness,
                                                    LineStyle.Solid,
                                                    OxyPenLineJoin.Bevel,
                                                    true);
            }
        }
Ejemplo n.º 16
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            //TODO potential rendering loop.
            if (FilteredData.Count < 1)
            {
                FilteredData = DataFilter.Filter(DataSorter.Sort(Data));
                base.OnRender(drawingContext);
                return;
            }
            visualContext = new ParetoChartVisualContext();

            PART_bars.Children.Clear();
            PART_barlabels.Children.Clear();
            PART_line.Children.Clear();
            PART_xaxis.Children.Clear();
            //_highlightGrid.Children.Clear();

            var max = FilteredData.MaxValue();

            var context           = new ProviderContext(FilteredData.Count);
            var barAvailableWidth = (PART_bars.RenderSize.Width) / FilteredData.Count;
            var barActiveWidth    = barAvailableWidth * SegmentWidthPercentage;
            var barLeftSpacing    = (barAvailableWidth - barActiveWidth) / 2;
            var barLabelSize      = RenderingExtensions.EstimateLabelRenderSize(BarTotalFontFamily, BarTotalFontSize);

            MaterialProvider.Reset(context);

            #region X-Axis Label Generation

            var xtrace = 0;
            foreach (var d in FilteredData)
            {
                var material = MaterialProvider.ProvideNext(context);
                var categoryVisualContext = new ParetoChartCategoryVisualContext();
                var axisLabel             = new Label
                {
                    Content                    = d.CategoryName,
                    IsHitTestVisible           = false,
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment        = HorizontalAlignment.Left,
                    VerticalAlignment          = VerticalAlignment.Bottom,
                    Width       = barAvailableWidth,
                    Margin      = new Thickness(barAvailableWidth * xtrace, 0, 0, 0),
                    DataContext = this,
                    Foreground  = XAxisForeground.GetMaterial(material)
                };
                axisLabel.BindTextualPrimitive <XAxisPrimitive>(this);
                categoryVisualContext.AxisLabel = axisLabel;
                PART_xaxis.Children.Add(axisLabel);
                visualContext.CategoryVisuals.Add(categoryVisualContext);
                xtrace++;
            }

            #endregion

            MaterialProvider.Reset(context);
            var horizontalTrace = 0d;
            var xAxisHeight     = barLabelSize.Height;         //_xAxisGrid.ActualHeight;
            var backHeight      = PART_bars.RenderSize.Height - xAxisHeight;
            var trace           = 0;
            foreach (var d in FilteredData)
            {
                var currentCategoryVisualContext = visualContext.CategoryVisuals[trace];
                currentCategoryVisualContext.CategoryDataPoint = d;
                //if (barActiveWidth <= 0 || backHeight <= 0) return; //TODO fix
                var material = MaterialProvider.ProvideNext(context);
                currentCategoryVisualContext.CategoryMaterialSet = material;

                var backRectangle = new Rectangle
                {
                    Width               = barActiveWidth,
                    Height              = Math.Abs(backHeight),
                    VerticalAlignment   = VerticalAlignment.Bottom,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Fill   = SegmentSpaceBackground.GetMaterial(material),
                    Margin = new Thickness(horizontalTrace + barLeftSpacing, 0, 0, xAxisHeight)
                };


                currentCategoryVisualContext.InactiveBarVisual = backRectangle;
                PART_bars.Children.Add(backRectangle);

                var height    = d.Value.Map(0, max, 0, PART_bars.RenderSize.Height - xAxisHeight - barLabelSize.Height);
                var rectangle = new Rectangle
                {
                    Width                 = barActiveWidth,
                    Height                = Math.Abs(height),
                    Fill                  = SegmentForeground.GetMaterial(material),
                    VerticalAlignment     = VerticalAlignment.Bottom,
                    HorizontalAlignment   = HorizontalAlignment.Left,
                    Margin                = new Thickness(horizontalTrace + barLeftSpacing, 0, 0, xAxisHeight),
                    RenderTransform       = new ScaleTransform(1, 0, .5, 1),
                    RenderTransformOrigin = new Point(.5, 1)
                };


                currentCategoryVisualContext.ActiveBarRenderTransformScaleYAnimationAspect =
                    new AnimationAspect <double, Transform, DoubleAnimation>(rectangle.RenderTransform,
                                                                             ScaleTransform.ScaleYProperty, 0, 1, animationState)
                {
                    AccelerationRatio = AnimationParameters.AccelerationRatio,
                    DecelerationRatio = AnimationParameters.DecelerationRatio,
                    Duration          = TimeSpan.FromMilliseconds(800)
                };

                //TODO replace .RenderedVisual pairing method completely
                d.RenderedVisual = rectangle;
                PART_bars.Children.Add(rectangle);

                #region Bar Value Label Generation

                var beginBarLabelMargin  = new Thickness(horizontalTrace, 0, 0, xAxisHeight);
                var actualBarLabelMargin = new Thickness(horizontalTrace, 0, 0, xAxisHeight + height);

                var barLabel = new Label
                {
                    Content                    = d.Value,
                    IsHitTestVisible           = false,
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment        = HorizontalAlignment.Left,
                    VerticalAlignment          = VerticalAlignment.Bottom,
                    Width      = barAvailableWidth,
                    Foreground = BarTotalForeground.GetMaterial(material)
                };
                barLabel.BindTextualPrimitive <BarTotalPrimitive>(this);

                currentCategoryVisualContext.BarLabelMarginAnimationAspect = new AnimationAspect
                                                                             <Thickness, Label, ThicknessAnimation>(
                    barLabel, MarginProperty, beginBarLabelMargin, actualBarLabelMargin, animationState)
                {
                    AccelerationRatio = AnimationParameters.AccelerationRatio,
                    DecelerationRatio = AnimationParameters.DecelerationRatio,
                    Duration          = TimeSpan.FromMilliseconds(800)
                };

                #endregion

                PART_barlabels.Children.Add(barLabel);
                horizontalTrace += barAvailableWidth;
                trace++;
            }
            var total = FilteredData.SumValue();
            var availableLineGraphSize = new Size(PART_bars.ActualWidth - (DotRadius * 2),
                                                  PART_bars.ActualHeight - (DotRadius * 2) - xAxisHeight);
            var startX = (barAvailableWidth / 2) - DotRadius;

            var verticalpttrace = 0d;
            var pttrace         = 0;

            var pathSegments = new PathSegmentCollection();
            var pathFigure   = new PathFigure
            {
                Segments = pathSegments
            };
            MaterialProvider.Reset(context);

            var isFirstPoint = true;
            foreach (var d in FilteredData)
            {
                var material = MaterialProvider.ProvideNext(context);
                var currentCategoryVisualContext = visualContext.CategoryVisuals[pttrace];
                var nextPoint          = new Point(startX + (barAvailableWidth * pttrace), verticalpttrace + xAxisHeight);
                var baseAnimationPoint = new Point(nextPoint.X, 0).LocalizeInCartesianSpace(PART_line);
                var actualNextPoint    = nextPoint.LocalizeInCartesianSpace(PART_line);

                // TODO get rid of this
                var plottedPoint = IsLoaded ? actualNextPoint : baseAnimationPoint;

                if (isFirstPoint)
                {
                    visualContext.PolyLineStartPointAnimationAspect = new AnimationAspect <Point, PathFigure, PointAnimation>(
                        pathFigure, PathFigure.StartPointProperty, baseAnimationPoint, actualNextPoint, animationState)
                    {
                        AccelerationRatio = AnimationParameters.AccelerationRatio,
                        DecelerationRatio = AnimationParameters.DecelerationRatio,
                        Duration          = TimeSpan.FromMilliseconds(800),
                    };
                    isFirstPoint = false;
                }
                else
                {
                    var lineSegment = new LineSegment(plottedPoint, true)
                    {
                        IsSmoothJoin = true
                    };
                    pathSegments.Add(lineSegment);

                    visualContext.LineSegmentVisuals.Add(new ParetoChartLineSegmentVisualContext
                    {
                        PointAnimationAspect =
                            new AnimationAspect <Point, LineSegment, PointAnimation>(lineSegment, LineSegment.PointProperty,
                                                                                     baseAnimationPoint, actualNextPoint, animationState)
                        {
                            AccelerationRatio = AnimationParameters.AccelerationRatio,
                            DecelerationRatio = AnimationParameters.DecelerationRatio,
                            Duration          = TimeSpan.FromMilliseconds(800)
                        }
                    });
                }

                var beginDotMargin  = new Thickness(nextPoint.X, 0, 0, xAxisHeight);
                var actualDotMargin = new Thickness(nextPoint.X, 0, 0, nextPoint.Y);

                var dot = new Ellipse
                {
                    Width               = (DotRadius * 2),
                    Height              = (DotRadius * 2),
                    VerticalAlignment   = VerticalAlignment.Bottom,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Fill   = DotFill.GetMaterial(material),
                    Stroke = DotStroke.GetMaterial(material),
                };
                BindingOperations.SetBinding(dot, Shape.StrokeThicknessProperty, new Binding("DotStrokeThickness")
                {
                    Source = this
                });

                currentCategoryVisualContext.DotMarginAnimationAspect =
                    new AnimationAspect <Thickness, Ellipse, ThicknessAnimation>(dot, MarginProperty,
                                                                                 beginDotMargin, actualDotMargin, animationState)
                {
                    AccelerationRatio = AnimationParameters.AccelerationRatio,
                    DecelerationRatio = AnimationParameters.DecelerationRatio,
                    Duration          = TimeSpan.FromMilliseconds(800)
                };

                PART_line.Children.Add(dot);
                Panel.SetZIndex(dot, 50);
                verticalpttrace += d.Value.Map(0, total, 0, availableLineGraphSize.Height);
                pttrace++;
            }

            var path = new Path
            {
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Left,
                Data = new PathGeometry
                {
                    Figures = new PathFigureCollection
                    {
                        pathFigure
                    }
                },
                Margin = new Thickness(DotRadius, 0, 0, xAxisHeight + DotRadius),
                Stroke = LineStroke.GetMaterial(FallbackMaterialSet),
            };
            BindingOperations.SetBinding(path, Shape.StrokeThicknessProperty, new Binding("LineStrokeThickness")
            {
                Source = this
            });

            PART_line.Children.Add(path);
            base.OnRender(drawingContext);
        }
Ejemplo n.º 17
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            visualContext = new HorizontalBarChartVisualContext();

            PART_bars.Rows  = FilteredData.Count;
            PART_yaxis.Rows = FilteredData.Count;

            PART_bars.Children.Clear();
            PART_yaxis.Children.Clear();

            if (FilteredData.Count < 1)
            {
                base.OnRender(drawingContext);
                return;
            }
            var effeectiveTargetRenderingMax = CommonFixedRangeMax > 0 ? CommonFixedRangeMax : FilteredData.MaxValue();

            var context = new ProviderContext(FilteredData.Count);

            MaterialProvider.Reset(context);
            double YAxisRenderingWidth;

            if (CommonYAxisWidth <= 0)
            {
                var maxYAxisTextLength = FilteredData.Select(d => RenderingExtensions.EstimateLabelRenderSize(
                                                                 YAxisFontFamily, YAxisFontSize, d.CategoryName))
                                         .Select(renderSize => renderSize.Width).Concat(new[] { 0.0 }).Max();
                YAxisRenderingWidth = maxYAxisTextLength;
            }
            else
            {
                YAxisRenderingWidth = CommonYAxisWidth;
            }
            PART_yaxis.Width = YAxisRenderingWidth;

            var maxValueTextLength = FilteredData.Select(d => RenderingExtensions.EstimateLabelRenderSize(
                                                             BarTotalFontFamily, BarTotalFontSize, new Thickness(10, 5, 10, 5), d.Value.ToString(CultureInfo.InvariantCulture)))
                                     .Select(renderSize => renderSize.Width).Concat(new[] { 0.0 }).Max();
            var totalAvailableVerticalSpace = 0.0;

            if (CommonFixedRowHeight > 0)
            {
                totalAvailableVerticalSpace = CommonFixedRowHeight;
            }
            else
            {
                totalAvailableVerticalSpace = PART_bars.ActualHeight / FilteredData.Count;
            }
            var totalAvailableHorizontalExpanse = PART_bars.ActualWidth;
            var totalAvailableHorizontalSpace   = totalAvailableHorizontalExpanse - maxValueTextLength;
            var actualBarHeight = totalAvailableVerticalSpace * SegmentWidthPercentage;

            foreach (var d in FilteredData)
            {
                var barContext  = new HorizontalBarChartSegmentVisualContext();
                var barWidth    = d.Value.Map(0, effeectiveTargetRenderingMax, 0, totalAvailableHorizontalSpace);
                var materialSet = MaterialProvider.ProvideNext(context);

                var barGrid = new Grid();

                var bar = new Rectangle
                {
                    Fill   = SegmentForeground.GetMaterial(materialSet),
                    Height = actualBarHeight,
                    Width  = barWidth,
                    HorizontalAlignment = HorizontalAlignment.Left
                };
                barGrid.Children.Add(bar);
                barContext.ActiveBar = bar;

                var barSpaceBackground = new Rectangle
                {
                    Fill   = SegmentSpaceBackground.GetMaterial(materialSet),
                    Height = actualBarHeight,
                    Width  = totalAvailableHorizontalExpanse,
                    HorizontalAlignment = HorizontalAlignment.Left
                };
                barGrid.Children.Add(barSpaceBackground);
                barContext.InactiveBar = barSpaceBackground;

                var barLabel = new Label
                {
                    Content                    = d.Value,
                    IsHitTestVisible           = false,
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment        = HorizontalAlignment.Left,
                    //VerticalAlignment = VerticalAlignment.Center ,
                    Width      = maxValueTextLength,
                    Padding    = new Thickness(10, 5, 10, 5),
                    Foreground = BarTotalForeground.GetMaterial(materialSet),
                    Margin     = new Thickness(barWidth, 0, 0, 0),
                };
                barLabel.BindTextualPrimitive <BarTotalPrimitive>(this);
                barGrid.Children.Add(barLabel);
                barContext.BarLabel = barLabel;

                PART_bars.Children.Add(barGrid);

                var yaxisLabel = new Label
                {
                    Content                    = TextRenderingStrategy.ProvideText(d.CategoryName, YAxisRenderingWidth, YAxisFontFamily, YAxisFontSize, YAxisPadding),
                    IsHitTestVisible           = false,
                    HorizontalContentAlignment = HorizontalAlignment.Left,
                    VerticalContentAlignment   = VerticalAlignment.Center,
                    ToolTip                    = d.CategoryName,
                    //HorizontalAlignment = HorizontalAlignment.Left,
                    //VerticalAlignment = VerticalAlignment.Center,
                    Width      = YAxisRenderingWidth,
                    Foreground = YAxisForeground.GetMaterial(materialSet),
                    Margin     = new Thickness(0, 0, 0, 0),
                    Padding    = YAxisPadding
                };
                yaxisLabel.BindTextualPrimitive <YAxisPrimitive>(this);
                PART_yaxis.Children.Add(yaxisLabel);

                visualContext.BarVisuals.Add(barContext);
            }
            base.OnRender(drawingContext);
        }
Ejemplo n.º 18
0
 public void GetParentRenderingIdsForRendering_WhenPlaceholderKeyIsInvalid_ThrowsException(string key)
 {
     Assert.Throws <ArgumentNullException>(() => RenderingExtensions.GetParentRenderingIdsForRendering(key));
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Renders the series on the specified render context.
        /// </summary>
        /// <param name="rc">The rendering context.</param>
        /// <param name="model">The model.</param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            if (this.Matrix == null)
            {
                return;
            }

            int m  = this.Matrix.GetLength(0);
            int n  = this.Matrix.GetLength(1);
            var p0 = this.Transform(0, 0);
            var p1 = this.Transform(n, m);

            if (this.image == null)
            {
                var pixels = new OxyColor[m, n];
                for (int i = 0; i < m; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        pixels[i, j] = Math.Abs(this.Matrix[m - 1 - i, j]) <= this.ZeroTolerance ? OxyColors.Transparent : this.NotZeroColor;
                    }
                }

                this.image = OxyImage.PngFromArgb(pixels);
            }

            var clip = this.GetClippingRect();
            var x0   = Math.Min(p0.X, p1.X);
            var y0   = Math.Min(p0.Y, p1.Y);
            var w    = Math.Abs(p0.X - p1.X);
            var h    = Math.Abs(p0.Y - p1.Y);

            //TEST  rc.DrawClippedImage(clip, this.image, x0, y0, w, h, 1, false);
            RenderingExtensions.DrawClippedImage(rc, clip, this.image, x0, y0, w, h, 1, false);


            var points = new List <ScreenPoint>();

            if (this.GridInterval > 0)
            {
                var p2 = this.Transform(this.GridInterval, this.GridInterval);
                if (Math.Abs(p2.Y - p0.Y) > this.MinimumGridLineDistance)
                {
                    for (int i = 1; i < n; i += this.GridInterval)
                    {
                        points.Add(this.Transform(0, i));
                        points.Add(this.Transform(n, i));
                    }
                }

                if (Math.Abs(p2.X - p0.X) > this.MinimumGridLineDistance)
                {
                    for (int j = 1; j < m; j += this.GridInterval)
                    {
                        points.Add(this.Transform(j, 0));
                        points.Add(this.Transform(j, m));
                    }
                }
            }

            if (this.ShowDiagonal)
            {
                points.Add(this.Transform(0, 0));
                points.Add(this.Transform(n, m));
            }

            //TEST  rc.DrawClippedLineSegments(points, clip, this.GridColor, 1, LineStyle.Solid, OxyPenLineJoin.Miter, true);
            RenderingExtensions.DrawClippedLineSegments(rc, points, clip, this.GridColor, 1, LineStyle.Solid, OxyPenLineJoin.Miter, true);

            if (this.BorderColor != null)
            {
                var borderPoints = new List <ScreenPoint>
                {
                    this.Transform(0, 0),
                    this.Transform(m, 0),
                    this.Transform(0, n),
                    this.Transform(m, n),
                    this.Transform(0, 0),
                    this.Transform(0, n),
                    this.Transform(m, 0),
                    this.Transform(m, n)
                };

                //TEST  rc.DrawClippedLineSegments(
                RenderingExtensions.DrawClippedLineSegments(rc,
                                                            borderPoints, clip, this.BorderColor, 1, LineStyle.Solid, OxyPenLineJoin.Miter, true);
            }
        }