/// <summary>
 /// Updates the Shape for the series.
 /// </summary>
 /// <param name="definitionPoints">Locations of the points of each SeriesDefinition in the series.</param>
 protected override void UpdateShape(IList <IEnumerable <Point> > definitionPoints)
 {
     for (int i = SeriesDefinitions.Count - 1; 0 < i; i--)
     {
         PointCollection     pointCollection = new PointCollection();
         IEnumerable <Point> topPoints       = (ActualIndependentAxis is ICategoryAxis) ? definitionPoints[i].OrderBy(p => p.X) : definitionPoints[i];
         foreach (Point p in topPoints)
         {
             pointCollection.Add(p);
         }
         IEnumerable <Point> bottomPoints = (ActualIndependentAxis is ICategoryAxis) ? definitionPoints[i - 1].OrderByDescending(p => p.X) : definitionPoints[i - 1].Reverse();
         foreach (Point p in bottomPoints)
         {
             pointCollection.Add(p);
         }
         SetPolygonPointsProperty((Polygon)SeriesDefinitionShapes[SeriesDefinitions[i]], pointCollection);
     }
     if (1 <= SeriesDefinitions.Count)
     {
         double      plotAreaMaximumDependentCoordinate = ActualDependentAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value;
         IComparable zeroValue = ActualDependentRangeAxis.Origin ?? 0.0;
         if (zeroValue.CompareTo(ActualDependentRangeAxis.Range.Minimum) < 0)
         {
             zeroValue = ActualDependentRangeAxis.Range.Minimum;
         }
         if (0 < zeroValue.CompareTo(ActualDependentRangeAxis.Range.Maximum))
         {
             zeroValue = ActualDependentRangeAxis.Range.Maximum;
         }
         double          zeroCoordinate  = ActualDependentAxis.GetPlotAreaCoordinate(zeroValue).Value;
         PointCollection pointCollection = new PointCollection();
         Point[]         topPoints       = ((ActualIndependentAxis is ICategoryAxis) ? definitionPoints[0].OrderBy(p => p.X) : definitionPoints[0]).ToArray();
         foreach (Point p in topPoints)
         {
             pointCollection.Add(p);
         }
         if (0 < topPoints.Length)
         {
             Point firstPoint = topPoints[0];
             Point lastPoint  = topPoints[topPoints.Length - 1];
             pointCollection.Add(new Point(lastPoint.X, plotAreaMaximumDependentCoordinate - zeroCoordinate));
             pointCollection.Add(new Point(firstPoint.X, plotAreaMaximumDependentCoordinate - zeroCoordinate));
         }
         SetPolygonPointsProperty((Polygon)SeriesDefinitionShapes[SeriesDefinitions[0]], pointCollection);
     }
 }
Esempio n. 2
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;
                        }
                    }
                }
            }
        }