A panel that plots elements on a one dimensional plane. In order to minimize collisions it moves elements further and further from the edge of the plane based on their priority. Elements that have the same priority level are always the same distance from the edge.
Inheritance: Windows.UI.Xaml.Controls.Panel
        /// <summary>
        /// OrientationProperty property changed handler.
        /// </summary>
        /// <param name="d">OrientedPanel that changed its Orientation.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnOrientationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            OrientedPanel source   = (OrientedPanel)d;
            Orientation   newValue = (Orientation)e.NewValue;

            source.OnOrientationPropertyChanged(newValue);
        }
Beispiel #2
0
        /// <summary>
        /// Renders the axis as an oriented axis.
        /// </summary>
        /// <param name="availableSize">The available size.</param>
        private void RenderOriented(Size availableSize)
        {
            _minorTickMarkPool.Reset();
            _majorTickMarkPool.Reset();
            _labelPool.Reset();

            double length = GetLength(availableSize);

            try
            {
                OrientedPanel.Children.Clear();
                if (ActualRange.HasData && !Object.Equals(ActualRange.Minimum, ActualRange.Maximum))
                {
                    foreach (IComparable axisValue in GetMajorTickMarkValues(availableSize))
                    {
                        UnitValue coordinate = GetPlotAreaCoordinate(axisValue, length);
                        if (ValueHelper.CanGraph(coordinate.Value))
                        {
                            Line line = _majorTickMarkPool.Next();
                            OrientedPanel.SetCenterCoordinate(line, coordinate.Value);
                            OrientedPanel.SetPriority(line, 0);
                            OrientedPanel.Children.Add(line);
                        }
                    }

                    foreach (IComparable axisValue in GetMinorTickMarkValues(availableSize))
                    {
                        UnitValue coordinate = GetPlotAreaCoordinate(axisValue, length);
                        if (ValueHelper.CanGraph(coordinate.Value))
                        {
                            Line line = _minorTickMarkPool.Next();
                            OrientedPanel.SetCenterCoordinate(line, coordinate.Value);
                            OrientedPanel.SetPriority(line, 0);
                            OrientedPanel.Children.Add(line);
                        }
                    }

                    int count = 0;
                    foreach (IComparable axisValue in GetLabelValues(availableSize))
                    {
                        UnitValue coordinate = GetPlotAreaCoordinate(axisValue, length);
                        if (ValueHelper.CanGraph(coordinate.Value))
                        {
                            Control axisLabel = _labelPool.Next();
                            PrepareAxisLabel(axisLabel, axisValue);
                            OrientedPanel.SetCenterCoordinate(axisLabel, coordinate.Value);
                            OrientedPanel.SetPriority(axisLabel, count + 1);
                            OrientedPanel.Children.Add(axisLabel);
                            count = (count + 1) % 2;
                        }
                    }
                }
            }
            finally
            {
                _minorTickMarkPool.Done();
                _majorTickMarkPool.Done();
                _labelPool.Done();
            }
        }
        /// <summary>
        /// MinimumDistanceBetweenChildrenProperty property changed handler.
        /// </summary>
        /// <param name="d">OrientedPanel that changed its MinimumDistanceBetweenChildren.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnMinimumDistanceBetweenChildrenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            OrientedPanel source   = (OrientedPanel)d;
            double        oldValue = (double)e.OldValue;
            double        newValue = (double)e.NewValue;

            source.OnMinimumDistanceBetweenChildrenPropertyChanged(oldValue, newValue);
        }
        /// <summary>
        /// IsReversedProperty property changed handler.
        /// </summary>
        /// <param name="d">OrientedPanel that changed its IsReversed.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnIsReversedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            OrientedPanel source   = (OrientedPanel)d;
            bool          oldValue = (bool)e.OldValue;
            bool          newValue = (bool)e.NewValue;

            source.OnIsReversedPropertyChanged(oldValue, newValue);
        }
        /// <summary>
        /// OffsetPaddingProperty property changed handler.
        /// </summary>
        /// <param name="d">OrientedPanel that changed its OffsetPadding.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnOffsetPaddingPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            OrientedPanel source   = (OrientedPanel)d;
            double        oldValue = (double)e.OldValue;
            double        newValue = (double)e.NewValue;

            source.OnOffsetPaddingPropertyChanged(oldValue, newValue);
        }
        /// <summary>
        /// PriorityProperty property changed handler.
        /// </summary>
        /// <param name="dependencyObject">UIElement that changed its Priority.</param>
        /// <param name="eventArgs">Event arguments.</param>
        public static void OnPriorityPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            UIElement source = dependencyObject as UIElement;

            if (source == null)
            {
                throw new ArgumentNullException(nameof(dependencyObject));
            }
            OrientedPanel parent = VisualTreeHelper.GetParent(source) as OrientedPanel;

            if (parent != null)
            {
                parent.InvalidateMeasure();
            }
        }
        /// <summary>
        /// Renders as an oriented axis.
        /// </summary>
        /// <param name="availableSize">The available size.</param>
        private void RenderOriented(Size availableSize)
        {
            _labelPool.Reset();
            _majorTickMarkPool.Reset();

            try
            {
                OrientedPanel.Children.Clear();
                this.GridLineCoordinatesToDisplay.Clear();

                if (this.Categories.Count > 0)
                {
                    double maximumLength = Math.Max(GetLength(availableSize) - 1, 0);

                    Action <double> placeTickMarkAt =
                        (pos) =>
                    {
                        Line tickMark = _majorTickMarkPool.Next();
                        OrientedPanel.SetCenterCoordinate(tickMark, pos);
                        OrientedPanel.SetPriority(tickMark, 0);
                        this.GridLineCoordinatesToDisplay.Add(new UnitValue(pos, Unit.Pixels));
                        OrientedPanel.Children.Add(tickMark);
                    };

                    int index    = 0;
                    int priority = 0;

                    foreach (object category in Categories)
                    {
                        Control axisLabel = CreateAndPrepareAxisLabel(category);
                        double  lower     = ((index * maximumLength) / Categories.Count) + 0.5;
                        double  upper     = (((index + 1) * maximumLength) / Categories.Count) + 0.5;
                        placeTickMarkAt(lower);
                        OrientedPanel.SetCenterCoordinate(axisLabel, (lower + upper) / 2);
                        OrientedPanel.SetPriority(axisLabel, priority + 1);
                        OrientedPanel.Children.Add(axisLabel);
                        index++;
                        priority = (priority + 1) % 2;
                    }
                    placeTickMarkAt(maximumLength + 0.5);
                }
            }
            finally
            {
                _labelPool.Done();
                _majorTickMarkPool.Done();
            }
        }