Example #1
0
        protected override Highlight GetClosestHighlight(int index, float x, float y)
        {
            var highlights = GetHighlightsAtIndex(index);

            float distanceToCenter = Chart.DistanceToCenter(x, y) / Chart.Factor;

            Highlight closest  = null;
            float     distance = float.MaxValue;

            for (int i = 0; i < highlights.Count; i++)
            {
                Highlight high = highlights[i];

                float cdistance = Math.Abs(high.Y - distanceToCenter);
                if (cdistance < distance)
                {
                    closest  = high;
                    distance = cdistance;
                }
            }

            return(closest);
        }
        /// <summary>
        /// Returns the Highlight of the DataSet that contains the closest value on the
        /// y-axis.
        /// </summary>
        /// <param name="closestValues">contains two Highlight objects per DataSet closest to the selected x-position(determined by
        ///                             rounding up an down)</param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="axis"> the closest axis</param>
        /// <param name="minSelectionDistance"></param>
        /// <returns></returns>
        public Highlight GetClosestHighlightByPixel(IList <Highlight> closestValues, float x, float y,
                                                    YAxisDependency axis, float minSelectionDistance)
        {
            Highlight closest  = null;
            float     distance = minSelectionDistance;

            for (int i = 0; i < closestValues.Count; i++)
            {
                Highlight high = closestValues[i];

                if (high.Axis == axis)
                {
                    float cDistance = GetDistance(x, y, high.XPx, high.YPx);

                    if (cDistance < distance)
                    {
                        closest  = high;
                        distance = cDistance;
                    }
                }
            }

            return(closest);
        }
 protected float GetHighlightPos(Highlight h)
 {
     return(h.YPx);
 }