RobotNet/RobotNet.WebApp/Charts/Models/Common/Interaction.cs
2025-10-15 15:15:53 +07:00

68 lines
2.2 KiB
C#

using RobotNet.WebApp.Charts.Enums;
using System.Text.Json.Serialization;
namespace RobotNet.WebApp.Charts.Models.Common;
public class Interaction
{
private InteractionMode mode;
public Interaction() => Mode = InteractionMode.Nearest;
private void SetMode(InteractionMode interactionMode) =>
ChartInteractionMode = interactionMode switch
{
InteractionMode.Dataset => "dataset",
InteractionMode.Index => "index",
InteractionMode.Nearest => "nearest",
InteractionMode.Point => "point",
InteractionMode.X => "x",
InteractionMode.Y => "y",
_ => ""
};
/// <summary>
/// Sets which elements appear in the interaction.
/// </summary>
[JsonPropertyName("mode")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? ChartInteractionMode { get; private set; }
/// <summary>
/// if <see langword="true" />, the interaction mode only applies when the mouse position intersects an item on the chart.
/// </summary>
/// <remarks>
/// Default value is <see langword="true" />.
/// </remarks>
public bool Intersect { get; set; } = true;
/// <summary>
/// Sets which elements appear in the tooltip. See Interaction Modes for details.
/// </summary>
[JsonIgnore]
public InteractionMode Mode
{
get => mode;
set
{
mode = value;
SetMode(value);
}
}
/// <summary>
/// Gets or sets which directions are used in calculating distances.
/// Defaults to <see cref="AxisDirection.X"/> for <see cref="Mode"/> == <see cref="InteractionMode.Index"/>
/// and <see cref="AxisDirection.XY"/> for <see cref="Mode"/> == <see cref="InteractionMode.Dataset"/> or <see cref="InteractionMode.Nearest"/>.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public AxisDirection? Axis { get; set; }
/// <summary>
/// if true, the invisible points that are outside of the chart area will also be included when evaluating interactions.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool? IncludeInvisible { get; set; }
}