SetCenterCoordinate() private method

private SetCenterCoordinate ( UIElement element, double value ) : void
element UIElement
value double
return void
Beispiel #1
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>
        /// 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();
            }
        }