Esempio n. 1
0
    /// <inheritdoc cref="HoverArea.SuggestTooltipPlacement(TooltipPlacementContext)"/>
    public override void SuggestTooltipPlacement(TooltipPlacementContext context)
    {
        var angle = (StartAngle + EndAngle) / 2d;

        context.PieX = CenterX + (float)Math.Cos(angle * (Math.PI / 180)) * Radius;
        context.PieY = CenterY + (float)Math.Sin(angle * (Math.PI / 180)) * Radius;
    }
Esempio n. 2
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>
    /// <param name="chartSize"></param>
    /// <returns></returns>
    public static LvcPoint?GetCartesianTooltipLocation(
        this IEnumerable <ChartPoint> foundPoints, TooltipPosition position, LvcSize tooltipSize, LvcSize chartSize)
    {
        var count = 0f;

        var placementContext = new TooltipPlacementContext();

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

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

        if (placementContext.MostBottom > chartSize.Height - tooltipSize.Height)
        {
            placementContext.MostBottom = chartSize.Height - tooltipSize.Height;
        }
        if (placementContext.MostTop < 0)
        {
            placementContext.MostTop = 0;
        }

        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 LvcPoint(avrgX, placementContext.MostTop - tooltipSize.Height),
            TooltipPosition.Bottom => new LvcPoint(avrgX, placementContext.MostBottom),
            TooltipPosition.Left => new LvcPoint(placementContext.MostLeft - tooltipSize.Width, avrgY),
            TooltipPosition.Right => new LvcPoint(placementContext.MostRight, avrgY),
            TooltipPosition.Center => new LvcPoint(avrgX, avrgY),
            TooltipPosition.Hidden => new LvcPoint(),
            _ => new LvcPoint(),
        });
Esempio n. 3
0
 /// <summary>
 /// Suggests the tooltip placement.
 /// </summary>
 /// <param name="context">The context.</param>
 public abstract void SuggestTooltipPlacement(TooltipPlacementContext context);