예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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);
        }