CanGraph() public static méthode

Returns a value indicating whether this value can be graphed on a linear axis.
public static CanGraph ( double value ) : bool
value double The value to evaluate.
Résultat bool
        /// <summary>
        /// Updates the data point's visual representation.
        /// </summary>
        /// <param name="dataPoint">The data point.</param>
        protected override void UpdateDataPoint(DataPoint dataPoint)
        {
            double maximumDiameter = Math.Min(PlotAreaSize.Width, PlotAreaSize.Height) * MaximumBubbleSizeAsRatioOfSmallestDimension;

            BubbleDataPoint bubbleDataPoint = (BubbleDataPoint)dataPoint;

            double ratioOfLargestBubble =
                (_rangeOfActualSizeValues.HasData && _rangeOfActualSizeValues.Maximum != 0.0 && bubbleDataPoint.ActualSize >= 0.0) ? Math.Abs(bubbleDataPoint.ActualSize) / _rangeOfActualSizeValues.Maximum : 0.0;

            bubbleDataPoint.Width  = ratioOfLargestBubble * maximumDiameter;
            bubbleDataPoint.Height = ratioOfLargestBubble * maximumDiameter;

            double left =
                (ActualIndependentAxis.GetPlotAreaCoordinate(bubbleDataPoint.ActualIndependentValue)).Value
                - (bubbleDataPoint.Width / 2.0);

            double top =
                (PlotAreaSize.Height
                 - (bubbleDataPoint.Height / 2.0))
                - ActualDependentRangeAxis.GetPlotAreaCoordinate(bubbleDataPoint.ActualDependentValue).Value;

            if (ValueHelper.CanGraph(left) && ValueHelper.CanGraph(top))
            {
                dataPoint.Visibility = Visibility.Visible;

                Canvas.SetLeft(bubbleDataPoint, left);
                Canvas.SetTop(bubbleDataPoint, top);
            }
            else
            {
                dataPoint.Visibility = Visibility.Collapsed;
            }
        }
        /// <summary>
        /// Updates the Series shape object.
        /// </summary>
        protected virtual void UpdateShape()
        {
            double maximum = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value;

            Func <DataPoint, Point> createPoint =
                dataPoint =>
                new Point(
                    ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value,
                    maximum - ActualDependentRangeAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value);

            IEnumerable <Point> points = Enumerable.Empty <Point>();

            if (ValueHelper.CanGraph(maximum))
            {
                if (ActualIndependentAxis is IRangeAxis)
                {
                    points = DataPointsByIndependentValue.Select(createPoint);
                }
                else
                {
                    points =
                        ActiveDataPoints
                        .Select(createPoint)
                        .OrderBy(point => point.X);
                }
            }
            UpdateShapeFromPoints(points);
        }
Exemple #3
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>
        /// Updates the visual representation of the data point.
        /// </summary>
        /// <param name="dataPoint">The data point to update.</param>
        protected override void UpdateDataPoint(DataPoint dataPoint)
        {
            double maximum = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value;

            if (ValueHelper.CanGraph(maximum))
            {
                double x = ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value;
                double y = ActualDependentRangeAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value;

                if (ValueHelper.CanGraph(x) && ValueHelper.CanGraph(y))
                {
                    dataPoint.Visibility = Visibility.Visible;

                    double coordinateY = Math.Round(maximum - (y + (dataPoint.ActualHeight / 2)));
                    Canvas.SetTop(dataPoint, coordinateY);
                    double coordinateX = Math.Round(x - (dataPoint.ActualWidth / 2));
                    Canvas.SetLeft(dataPoint, coordinateX);
                }
                else
                {
                    dataPoint.Visibility = Visibility.Collapsed;
                }
            }

            if (!UpdatingDataPoints)
            {
                UpdateShape();
            }
        }
        /// <summary>
        /// Gets the margin to use for an independent axis that does not implement ICategoryAxis.
        /// </summary>
        /// <param name="axis">Axis to get the margin for.</param>
        /// <returns>Margin for axis.</returns>
        private double GetMarginForNonCategoryAxis(IAxis axis)
        {
            Debug.Assert(!(axis is ICategoryAxis), "This method is unnecessary for ICategoryAxis.");

            // Find the smallest distance between two independent value plot area coordinates
            double smallestDistance = double.MaxValue;
            double lastCoordinate   = double.NaN;

            foreach (double coordinate in
                     IndependentValueGroupsOrderedByIndependentValue
                     .Select(g => axis.GetPlotAreaCoordinate(g.IndependentValue).Value)
                     .Where(v => ValueHelper.CanGraph(v)))
            {
                if (!double.IsNaN(lastCoordinate))
                {
                    double distance = coordinate - lastCoordinate;
                    if (distance < smallestDistance)
                    {
                        smallestDistance = distance;
                    }
                }
                lastCoordinate = coordinate;
            }
            // Return the margin
            if (double.MaxValue == smallestDistance)
            {
                // No smallest distance because <= 1 independent values to plot
                FrameworkElement element = axis as FrameworkElement;
                if (null != element)
                {
                    // Use width of provided axis so single column scenario looks good
                    return(element.GetMargin(axis));
                }
                else
                {
                    // No information to work with; no idea what margin to return
                    throw new NotSupportedException();
                }
            }
            else
            {
                // Found the smallest distance; margin is half of that
                return(smallestDistance / 2);
            }
        }
        /// <summary>
        /// Updates the Series shape object from a collection of Points.
        /// </summary>
        /// <param name="points">Collection of Points.</param>
        protected override void UpdateShapeFromPoints(IEnumerable <Point> points)
        {
            UnitValue originCoordinate  = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Origin);
            UnitValue maximumCoordinate = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum);

            if (points.Any() && ValueHelper.CanGraph(originCoordinate.Value) && ValueHelper.CanGraph(maximumCoordinate.Value))
            {
                double     originY = Math.Floor(originCoordinate.Value);
                PathFigure figure  = new PathFigure();
                figure.IsClosed = true;
                figure.IsFilled = true;

                double maximum = maximumCoordinate.Value;
                Point  startPoint;
                IEnumerator <Point> pointEnumerator = points.GetEnumerator();
                pointEnumerator.MoveNext();
                startPoint        = new Point(pointEnumerator.Current.X, maximum - originY);
                figure.StartPoint = startPoint;

                Point lastPoint;
                do
                {
                    lastPoint = pointEnumerator.Current;
                    figure.Segments.Add(new LineSegment {
                        Point = pointEnumerator.Current
                    });
                }while (pointEnumerator.MoveNext());
                figure.Segments.Add(new LineSegment {
                    Point = new Point(lastPoint.X, maximum - originY)
                });

                if (figure.Segments.Count > 1)
                {
                    PathGeometry geometry = new PathGeometry();
                    geometry.Figures.Add(figure);
                    Geometry = geometry;
                    return;
                }
            }
            else
            {
                Geometry = null;
            }
        }
Exemple #7
0
 /// <summary>
 /// Called when the value of the OffsetRatioProperty property changes.
 /// </summary>
 /// <param name="oldValue">The value to be replaced.</param>
 /// <param name="newValue">The new value.</param>
 private void OnOffsetRatioPropertyChanged(double oldValue, double newValue)
 {
     if (ValueHelper.CanGraph(newValue))
     {
         RoutedPropertyChangedEventHandler <double> handler = this.OffsetRatioChanged;
         if (handler != null)
         {
             handler(this, new RoutedPropertyChangedEventArgs <double>(oldValue, newValue));
         }
         if (this.State == (int)DataPointState.Created)
         {
             ActualOffsetRatio = newValue;
         }
     }
     else
     {
         this.OffsetRatio = 0.0;
     }
 }
Exemple #8
0
        /// <summary>
        /// Calculates the length of the data points.
        /// </summary>
        protected void CalculateDataPointLength()
        {
            if (!(ActualIndependentAxis is ICategoryAxis))
            {
                IEnumerable <UnitValue> values =
                    ActiveDataPoints
                    .Select(dataPoint => ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue))
                    .Where(value => ValueHelper.CanGraph(value.Value))
                    .OrderBy(value => value.Value)
                    .ToList();

                _dataPointlength =
                    EnumerableFunctions.Zip(
                        values,
                        values.Skip(1),
                        (left, right) => new Range <double>(left.Value, right.Value))
                    .Select(range => range.Maximum - range.Minimum)
                    .MinOrNullable();
            }
        }
Exemple #9
0
        /// <summary>
        /// Called when the value of the ActualRatioProperty property changes.
        /// </summary>
        /// <param name="oldValue">The value to be replaced.</param>
        /// <param name="newValue">The new value.</param>
        private void OnActualRatioPropertyChanged(double oldValue, double newValue)
        {
            if (ValueHelper.CanGraph(newValue))
            {
                RoutedPropertyChangedEventHandler <double> handler = this.ActualRatioChanged;
                if (handler != null)
                {
                    handler(this, new RoutedPropertyChangedEventArgs <double>(oldValue, newValue));
                }
            }
            else
            {
                this.ActualRatio = 0.0;
            }

            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                PieSeries.UpdatePieDataPointGeometry(this, ActualWidth, ActualHeight);
            }
        }
Exemple #10
0
        /// <summary>
        /// Called when the value of the RatioProperty property changes.
        /// </summary>
        /// <param name="oldValue">The value to be replaced.</param>
        /// <param name="newValue">The new value.</param>
        private void OnRatioPropertyChanged(double oldValue, double newValue)
        {
            if (ValueHelper.CanGraph(newValue))
            {
                SetFormattedProperty(FormattedRatioProperty, RatioStringFormat, newValue);
                RoutedPropertyChangedEventHandler <double> handler = this.RatioChanged;
                if (handler != null)
                {
                    handler(this, new RoutedPropertyChangedEventArgs <double>(oldValue, newValue));
                }

                if (this.State == (int)DataPointState.Created)
                {
                    ActualRatio = newValue;
                }
            }
            else
            {
                this.Ratio = 0.0;
            }
        }
Exemple #11
0
        /// <summary>
        /// Updates the ratios of each data point.
        /// </summary>
        private void UpdateRatios()
        {
            double sum = ActivePieDataPoints.Select(pieDataPoint => Math.Abs(ValueHelper.ToDouble(pieDataPoint.DependentValue))).Sum();

            // Priming the loop by calculating initial value of
            // offset ratio and its corresponding points.
            double offsetRatio = 0;

            foreach (PieDataPoint dataPoint in ActivePieDataPoints)
            {
                double dependentValue = Math.Abs(ValueHelper.ToDouble(dataPoint.DependentValue));
                double ratio          = dependentValue / sum;
                if (!ValueHelper.CanGraph(ratio))
                {
                    ratio = 0.0;
                }
                dataPoint.Ratio       = ratio;
                dataPoint.OffsetRatio = offsetRatio;
                offsetRatio          += ratio;
            }
        }
Exemple #12
0
        /// <summary>
        /// Gets a range in which to render a data point.
        /// </summary>
        /// <param name="category">The category to retrieve the range for.
        /// </param>
        /// <returns>The range in which to render a data point.</returns>
        protected Range <UnitValue> GetCategoryRange(object category)
        {
            ICategoryAxis categoryAxis = ActualIndependentAxis as CategoryAxis;

            if (categoryAxis != null)
            {
                return(categoryAxis.GetPlotAreaCoordinateRange(category));
            }
            else
            {
                UnitValue unitValue = ActualIndependentAxis.GetPlotAreaCoordinate(category);
                if (ValueHelper.CanGraph(unitValue.Value) && _dataPointlength.HasValue)
                {
                    double halfLength = _dataPointlength.Value / 2.0;

                    return(new Range <UnitValue>(
                               new UnitValue(unitValue.Value - halfLength, unitValue.Unit),
                               new UnitValue(unitValue.Value + halfLength, unitValue.Unit)));
                }

                return(new Range <UnitValue>());
            }
        }
Exemple #13
0
        /// <summary>
        /// This method updates a single data point.
        /// </summary>
        /// <param name="dataPoint">The data point to update.</param>
        protected override void UpdateDataPoint(DataPoint dataPoint)
        {
            double PlotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value;
            double dataPointX     = ActualIndependentAxis.GetPlotAreaCoordinate(dataPoint.ActualIndependentValue).Value;
            double dataPointY     = ActualDependentRangeAxis.GetPlotAreaCoordinate(dataPoint.ActualDependentValue).Value;

            if (ValueHelper.CanGraph(dataPointX) && ValueHelper.CanGraph(dataPointY))
            {
                dataPoint.Visibility = Visibility.Visible;

                // Set the Position
                Canvas.SetLeft(
                    dataPoint,
                    Math.Round(dataPointX - (dataPoint.ActualWidth / 2)));
                Canvas.SetTop(
                    dataPoint,
                    Math.Round(PlotAreaHeight - (dataPointY + (dataPoint.ActualHeight / 2))));
            }
            else
            {
                dataPoint.Visibility = Visibility.Collapsed;
            }
        }
        /// <summary>
        /// Updates each point.
        /// </summary>
        /// <param name="dataPoint">The data point to update.</param>
        protected override void UpdateDataPoint(DataPoint dataPoint)
        {
            if (SeriesHost == null || PlotArea == null)
            {
                return;
            }

            object            category        = dataPoint.ActualIndependentValue ?? (this.ActiveDataPoints.IndexOf(dataPoint) + 1);
            Range <UnitValue> coordinateRange = GetCategoryRange(category);

            if (!coordinateRange.HasData)
            {
                return;
            }

            if (coordinateRange.Maximum.Unit != Unit.Pixels || coordinateRange.Minimum.Unit != Unit.Pixels)
            {
                throw new InvalidOperationException(Properties.Resources.DataPointSeriesWithAxes_ThisSeriesDoesNotSupportRadialAxes);
            }

            double minimum = (double)coordinateRange.Minimum.Value;
            double maximum = (double)coordinateRange.Maximum.Value;

            double plotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value;
            IEnumerable <ColumnSeries> columnSeries = SeriesHost.Series.OfType <ColumnSeries>().Where(series => series.ActualIndependentAxis == ActualIndependentAxis);
            int    numberOfSeries       = columnSeries.Count();
            double coordinateRangeWidth = (maximum - minimum);
            double segmentWidth         = coordinateRangeWidth * 0.8;
            double columnWidth          = segmentWidth / numberOfSeries;
            int    seriesIndex          = columnSeries.IndexOf(this);

            double dataPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(dataPoint.ActualDependentValue)).Value;
            double zeroPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Origin).Value;

            double offset     = seriesIndex * Math.Round(columnWidth) + coordinateRangeWidth * 0.1;
            double dataPointX = minimum + offset;

            if (GetIsDataPointGrouped(category))
            {
                // Multiple DataPoints share this category; offset and overlap them appropriately
                IGrouping <object, DataPoint> categoryGrouping = GetDataPointGroup(category);
                int index = categoryGrouping.IndexOf(dataPoint);
                dataPointX  += (index * (columnWidth * 0.2)) / (categoryGrouping.Count() - 1);
                columnWidth *= 0.8;
                Canvas.SetZIndex(dataPoint, -index);
            }

            if (ValueHelper.CanGraph(dataPointY) && ValueHelper.CanGraph(dataPointX) && ValueHelper.CanGraph(zeroPointY))
            {
                dataPoint.Visibility = Visibility.Visible;

                double left  = Math.Round(dataPointX);
                double width = Math.Round(columnWidth);

                double top    = Math.Round(plotAreaHeight - Math.Max(dataPointY, zeroPointY) + 0.5);
                double bottom = Math.Round(plotAreaHeight - Math.Min(dataPointY, zeroPointY) + 0.5);
                double height = bottom - top + 1;

                Canvas.SetLeft(dataPoint, left);
                Canvas.SetTop(dataPoint, top);
                dataPoint.Width  = width;
                dataPoint.Height = height;
            }
            else
            {
                dataPoint.Visibility = Visibility.Collapsed;
            }
        }
Exemple #15
0
        /// <summary>
        /// Updates the placement of the DataItems (data points) of the series.
        /// </summary>
        /// <param name="dataItems">DataItems in need of an update.</param>
        protected override void UpdateDataItemPlacement(IEnumerable <DefinitionSeries.DataItem> dataItems)
        {
            if ((null != ActualDependentAxis) && (null != ActualIndependentAxis))
            {
                double         plotAreaMaximumDependentCoordinate = ActualDependentAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value;
                double         lineTopBuffer = 1;
                List <Point>[] points        = new List <Point> [SeriesDefinitions.Count];
                for (int i = 0; i < points.Length; i++)
                {
                    points[i] = new List <Point>();
                }
                foreach (IndependentValueGroup group in IndependentValueGroupsOrderedByIndependentValue)
                {
                    double sum = IsStacked100 ?
                                 group.DataItems.Sum(di => Math.Abs(ValueHelper.ToDouble(di.DataPoint.ActualDependentValue))) :
                                 1;
                    if (0 == sum)
                    {
                        sum = 1;
                    }
                    double x = ActualIndependentAxis.GetPlotAreaCoordinate(group.IndependentValue).Value;
                    if (ValueHelper.CanGraph(x))
                    {
                        double           lastValue      = 0;
                        Point            lastPoint      = new Point(x, Math.Max(plotAreaMaximumDependentCoordinate - ActualDependentRangeAxis.GetPlotAreaCoordinate(lastValue).Value, lineTopBuffer));
                        int              i              = -1;
                        SeriesDefinition lastDefinition = null;
                        foreach (DataItem dataItem in group.DataItems)
                        {
                            if (lastDefinition != dataItem.SeriesDefinition)
                            {
                                i++;
                            }

                            while (dataItem.SeriesDefinition != SeriesDefinitions[i])
                            {
                                points[i].Add(lastPoint);
                                i++;
                            }

                            DataPoint dataPoint = dataItem.DataPoint;
                            double    value     = IsStacked100 ?
                                                  (ValueHelper.ToDouble(dataItem.DataPoint.ActualDependentValue) * (100 / sum)) :
                                                  ValueHelper.ToDouble(dataItem.DataPoint.ActualDependentValue);
                            if (ValueHelper.CanGraph(value))
                            {
                                value += lastValue;
                                dataItem.ActualStackedDependentValue = value;
                                double y = ActualDependentRangeAxis.GetPlotAreaCoordinate(value).Value;
                                lastValue   = value;
                                lastPoint.Y = Math.Max(plotAreaMaximumDependentCoordinate - y, lineTopBuffer);
                                points[i].Add(lastPoint);

                                dataItem.CenterPoint = new Point(x, plotAreaMaximumDependentCoordinate - y);
                                double left = dataItem.CenterPoint.X - (dataPoint.ActualWidth / 2);
                                double top  = dataItem.CenterPoint.Y - (dataPoint.ActualHeight / 2);

                                Canvas.SetLeft(dataItem.Container, Math.Round(left));
                                Canvas.SetTop(dataItem.Container, Math.Round(top));
                                dataPoint.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                points[i].Add(lastPoint);
                                dataPoint.Visibility = Visibility.Collapsed;
                            }

                            lastDefinition = dataItem.SeriesDefinition;
                        }
                    }
                    else
                    {
                        foreach (DataPoint dataPoint in group.DataItems.Select(di => di.DataPoint))
                        {
                            dataPoint.Visibility = Visibility.Collapsed;
                        }
                    }
                }
                UpdateShape(points);
            }
        }
        protected override void UpdateDataItemPlacement(IEnumerable <DefinitionSeries.DataItem> dataItems)
        {
            IAxis actualIndependentAxis = ActualIndependentAxis;

            if ((null != ActualDependentAxis) && (null != actualIndependentAxis))
            {
                double        plotAreaMaximumDependentCoordinate = ActualDependentAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value;
                double        zeroCoordinate = ActualDependentAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Origin ?? 0.0).Value;
                ICategoryAxis actualIndependentCategoryAxis = actualIndependentAxis as ICategoryAxis;
                double        nonCategoryAxisRangeMargin    = (null != actualIndependentCategoryAxis) ? 0 : GetMarginForNonCategoryAxis(actualIndependentAxis);
                foreach (IndependentValueGroup group in IndependentValueGroups)
                {
                    Range <UnitValue> categoryRange = new Range <UnitValue>();
                    if (null != actualIndependentCategoryAxis)
                    {
                        categoryRange = actualIndependentCategoryAxis.GetPlotAreaCoordinateRange(group.IndependentValue);
                    }
                    else
                    {
                        UnitValue independentValueCoordinate = actualIndependentAxis.GetPlotAreaCoordinate(group.IndependentValue);
                        if (ValueHelper.CanGraph(independentValueCoordinate.Value))
                        {
                            categoryRange = new Range <UnitValue>(new UnitValue(independentValueCoordinate.Value - nonCategoryAxisRangeMargin, independentValueCoordinate.Unit), new UnitValue(independentValueCoordinate.Value + nonCategoryAxisRangeMargin, independentValueCoordinate.Unit));
                        }
                    }
                    if (categoryRange.HasData)
                    {
                        double categoryMinimumCoordinate = categoryRange.Minimum.Value;
                        double categoryMaximumCoordinate = categoryRange.Maximum.Value;
                        double padding = 0.1 * (categoryMaximumCoordinate - categoryMinimumCoordinate);
                        categoryMinimumCoordinate += padding;
                        categoryMaximumCoordinate -= padding;

                        double sum = IsStacked100 ?
                                     group.DataItems.Sum(di => Math.Abs(ValueHelper.ToDouble(di.DataPoint.ActualDependentValue))) :
                                     1;
                        if (0 == sum)
                        {
                            sum = 1;
                        }
                        double ceiling = 0;
                        double floor   = 0;
                        foreach (DataItem dataItem in group.DataItems)
                        {
                            DataPoint dataPoint = dataItem.DataPoint;
                            double    value     = IsStacked100 ? (ValueHelper.ToDouble(dataPoint.ActualDependentValue) * (100 / sum)) : ValueHelper.ToDouble(dataPoint.ActualDependentValue);
                            if (ValueHelper.CanGraph(value))
                            {
                                double valueCoordinate  = ActualDependentAxis.GetPlotAreaCoordinate(value).Value;
                                double fillerCoordinate = (0 <= value) ? ceiling : floor;

                                double topCoordinate = 0, leftCoordinate = 0, height = 0, width = 0, deltaCoordinate = 0;
                                if (AxisOrientation.Y == ActualDependentAxis.Orientation)
                                {
                                    topCoordinate = plotAreaMaximumDependentCoordinate - Math.Max(valueCoordinate + fillerCoordinate, zeroCoordinate + fillerCoordinate);
                                    double bottomCoordinate = plotAreaMaximumDependentCoordinate - Math.Min(valueCoordinate + fillerCoordinate, zeroCoordinate + fillerCoordinate);
                                    deltaCoordinate = bottomCoordinate - topCoordinate;
                                    height          = (0 < deltaCoordinate) ? deltaCoordinate + 1 : 0;
                                    leftCoordinate  = categoryMinimumCoordinate;
                                    width           = categoryMaximumCoordinate - categoryMinimumCoordinate + 1;
                                }
                                else
                                {
                                    leftCoordinate = Math.Min(valueCoordinate + fillerCoordinate, zeroCoordinate + fillerCoordinate);
                                    double rightCoordinate = Math.Max(valueCoordinate + fillerCoordinate, zeroCoordinate + fillerCoordinate);
                                    deltaCoordinate = rightCoordinate - leftCoordinate;
                                    width           = (0 < deltaCoordinate) ? deltaCoordinate + 1 : 0;
                                    topCoordinate   = categoryMinimumCoordinate;
                                    height          = categoryMaximumCoordinate - categoryMinimumCoordinate + 1;
                                }

                                double roundedTopCoordinate = Math.Round(topCoordinate);
                                Canvas.SetTop(dataItem.Container, roundedTopCoordinate);
                                dataPoint.Height = Math.Round(topCoordinate + height - roundedTopCoordinate);
                                double roundedLeftCoordinate = Math.Round(leftCoordinate);
                                Canvas.SetLeft(dataItem.Container, roundedLeftCoordinate);
                                dataPoint.Width      = Math.Round(leftCoordinate + width - roundedLeftCoordinate);
                                dataPoint.Visibility = Visibility.Visible;

                                if (0 <= value)
                                {
                                    ceiling += deltaCoordinate;
                                }
                                else
                                {
                                    floor -= deltaCoordinate;
                                }
                            }
                            else
                            {
                                dataPoint.Visibility = Visibility.Collapsed;
                            }
                        }
                    }
                    else
                    {
                        foreach (DataPoint dataPoint in group.DataItems.Select(di => di.DataPoint))
                        {
                            dataPoint.Visibility = Visibility.Collapsed;
                        }
                    }
                }
            }
        }
Exemple #17
0
 /// <summary>
 /// Returns a sequence of the major grid line coordinates.
 /// </summary>
 /// <param name="availableSize">The available size.</param>
 /// <returns>A sequence of the major grid line coordinates.</returns>
 protected override IEnumerable <UnitValue> GetMajorGridLineCoordinates(Size availableSize)
 {
     return(GetMajorTickMarkValues(availableSize).Select(value => GetPlotAreaCoordinate(value)).Where(value => ValueHelper.CanGraph(value.Value)));
 }
Exemple #18
0
        /// <summary>
        /// Returns the range for the data points of the series.
        /// </summary>
        /// <param name="rangeConsumer">Consumer of the range.</param>
        /// <returns>Range of values.</returns>
        protected override Range <IComparable> IRangeProviderGetRange(IRangeConsumer rangeConsumer)
        {
            if (rangeConsumer == ActualDependentAxis)
            {
                IEnumerable <Range <double> > dependentValueRangesByIndependentValue = IndependentValueDependentValues
                                                                                       .Select(g => g.Where(d => ValueHelper.CanGraph(d)))
                                                                                       .Select(g => g.Scan(0.0, (s, t) => s + t).Skip(1).GetRange())
                                                                                       .DefaultIfEmpty(new Range <double>(0, 0))
                                                                                       .ToArray();
                double minimum = dependentValueRangesByIndependentValue.Min(r => r.Minimum);
                double maximum = dependentValueRangesByIndependentValue.Max(r => r.Maximum);

                if (IsStacked100)
                {
                    minimum = Math.Min(minimum, 0);
                    maximum = Math.Max(maximum, 0);
                }

                return(new Range <IComparable>(minimum, maximum));
            }
            else
            {
                return(base.IRangeProviderGetRange(rangeConsumer));
            }
        }