/// <summary>
        /// Returns the left, top coordinate of the tooltip based on the found points, the position and the tooltip size.
        /// </summary>
        /// <param name="foundPoints"></param>
        /// <param name="position"></param>
        /// <param name="tooltipSize"></param>
        /// <returns></returns>
        public static PointF?GetCartesianTooltipLocation(
            this IEnumerable <TooltipPoint> foundPoints, TooltipPosition position, SizeF tooltipSize)
        {
            var count = 0f;

            var placementContext = new TooltipPlacementContext();

            foreach (var point in foundPoints)
            {
                if (point.Point.Context.HoverArea == null)
                {
                    continue;
                }
                point.Point.Context.HoverArea.SuggestTooltipPlacement(placementContext);
                count++;
            }

            if (count == 0)
            {
                return(null);
            }

            var avrgX = (placementContext.MostRight + placementContext.MostLeft) / 2f - tooltipSize.Width * 0.5f;
            var avrgY = (placementContext.MostTop + placementContext.MostBottom) / 2f - tooltipSize.Height * 0.5f;

            return(position switch
            {
                TooltipPosition.Top => new PointF(avrgX, placementContext.MostTop - tooltipSize.Height),
                TooltipPosition.Bottom => new PointF(avrgX, placementContext.MostBottom),
                TooltipPosition.Left => new PointF(placementContext.MostLeft - tooltipSize.Width, avrgY),
                TooltipPosition.Right => new PointF(placementContext.MostRight, avrgY),
                TooltipPosition.Center => new PointF(avrgX, avrgY),
                TooltipPosition.Hidden => new PointF(),
                _ => new PointF(),
            });
Esempio n. 2
0
        public static PointF?GetPieTooltipLocation(
            this IEnumerable <TooltipPoint> foundPoints, TooltipPosition position, SizeF tooltipSize)
        {
            var placementContext = new TooltipPlacementContext();
            var found            = false;

            foreach (var foundPoint in foundPoints)
            {
                if (foundPoint.Point.Context.HoverArea == null)
                {
                    continue;
                }
                foundPoint.Point.Context.HoverArea.SuggestTooltipPlacement(placementContext);
                found = true;
                break; // we only care about the first one.
            }

            return(found ? new PointF(placementContext.PieX, placementContext.PieY) : null);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns the left, top coordinate of the tooltip based on the found points, the position and the tooltip size.
        /// </summary>
        /// <param name="foundPoints"></param>
        /// <param name="position"></param>
        /// <param name="tooltipSize"></param>
        /// <returns></returns>
        public static PointF?GetCartesianTooltipLocation(
            this IEnumerable <TooltipPoint> foundPoints, TooltipPosition position, SizeF tooltipSize)
        {
            float count = 0f;

            var placementContext = new TooltipPlacementContext();

            foreach (var point in foundPoints)
            {
                if (point.Point.Context.HoverArea == null)
                {
                    continue;
                }
                point.Point.Context.HoverArea.SuggestTooltipPlacement(placementContext);
                count++;
            }

            if (count == 0)
            {
                return(null);
            }

            var avrgX = ((placementContext.MostRight + placementContext.MostLeft) / 2f) - tooltipSize.Width * 0.5f;
            var avrgY = ((placementContext.MostTop + placementContext.MostBottom) / 2f) - tooltipSize.Height * 0.5f;

            switch (position)
            {
            case TooltipPosition.Top: return(new PointF(avrgX, placementContext.MostTop - tooltipSize.Height));

            case TooltipPosition.Bottom: return(new PointF(avrgX, placementContext.MostBottom));

            case TooltipPosition.Left: return(new PointF(placementContext.MostLeft - tooltipSize.Width, avrgY));

            case TooltipPosition.Right: return(new PointF(placementContext.MostRight, avrgY));

            case TooltipPosition.Center: return(new PointF(avrgX, avrgY));

            default: throw new NotImplementedException();
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Suggests the tooltip placement.
 /// </summary>
 /// <param name="context">The context.</param>
 public abstract void SuggestTooltipPlacement(TooltipPlacementContext context);