/// <summary>
 /// Returns the category at a given coordinate.
 /// </summary>
 /// <param name="position">The plot area position.</param>
 /// <returns>The category at the given plot area position.</returns>
 public object GetCategoryAtPosition(UnitValue position)
 {
     if (this.ActualLength == 0.0 || this.Categories.Count == 0)
     {
         return null;
     }
     if (position.Unit == Unit.Pixels)
     {
         double coordinate = position.Value;
         int index = (int)Math.Floor(coordinate / (this.ActualLength / this.Categories.Count));
         if (index >= 0 && index < this.Categories.Count)
         {
             if (Orientation == AxisOrientation.X)
             {
                 return this.Categories[index];
             }
             else
             {
                 return this.Categories[(this.Categories.Count - 1) - index];
             }
         }
     }
     else
     {
         throw new NotImplementedException();
     }
     return null;
 }
        /// <summary>
        /// Returns the value range given a plot area coordinate.
        /// </summary>
        /// <param name="value">The position.</param>
        /// <returns>A range of values at that plot area coordinate.</returns>
        protected override IComparable GetValueAtPosition(UnitValue value)
        {
            if (ActualRange.HasData && ActualLength != 0.0)
            {
                long coordinate = (long)value.Value;
                if (value.Unit == Unit.Pixels)
                {
                    long minimumAsDouble = ActualDateTimeRange.Minimum.Ticks;
                    long rangelength = ActualDateTimeRange.Maximum.Ticks - minimumAsDouble;
                    long longoutput = (long)(coordinate * (rangelength / ActualLength) + minimumAsDouble);
                    DateTime output = new DateTime(longoutput);

                    return output;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return null;
        }
        /// <summary>
        /// Returns the value range given a plot area coordinate.
        /// </summary>
        /// <param name="value">The plot area position.</param>
        /// <returns>The value at that plot area coordinate.</returns>
        protected override IComparable GetValueAtPosition(UnitValue value)
        {
            if (ActualRange.HasData && ActualLength != 0.0)
            {
                if (value.Unit == Unit.Pixels)
                {
                    double coordinate = value.Value;

                    double rangelength = ActualDoubleRange.Maximum - ActualDoubleRange.Minimum;
                    double output = ((coordinate * (rangelength / ActualLength)) + ActualDoubleRange.Minimum);

                    return output;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return null;
        }
        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;
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Returns the value range given a plot area coordinate.
 /// </summary>
 /// <param name="value">The plot area coordinate.</param>
 /// <returns>A range of values at that plot area coordinate.</returns>
 IComparable IRangeAxis.GetValueAtPosition(UnitValue value)
 {
     return GetValueAtPosition(value);
 }
 /// <summary>
 /// Returns the value range given a plot area coordinate.
 /// </summary>
 /// <param name="value">The plot area coordinate.</param>
 /// <returns>A range of values at that plot area coordinate.</returns>
 protected abstract IComparable GetValueAtPosition(UnitValue value);
 /// <summary>
 /// Returns the value range given a plot area coordinate.
 /// </summary>
 /// <param name="value">The plot area coordinate.</param>
 /// <returns>A range of values at that plot area coordinate.</returns>
 IComparable IRangeAxis.GetValueAtPosition(UnitValue value)
 {
     return(GetValueAtPosition(value));
 }
 /// <summary>
 /// Returns the value range given a plot area coordinate.
 /// </summary>
 /// <param name="value">The plot area coordinate.</param>
 /// <returns>A range of values at that plot area coordinate.</returns>
 protected abstract IComparable GetValueAtPosition(UnitValue value);