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",
_ => ""
};
///
/// Sets which elements appear in the interaction.
///
[JsonPropertyName("mode")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? ChartInteractionMode { get; private set; }
///
/// if , the interaction mode only applies when the mouse position intersects an item on the chart.
///
///
/// Default value is .
///
public bool Intersect { get; set; } = true;
///
/// Sets which elements appear in the tooltip. See Interaction Modes for details.
///
[JsonIgnore]
public InteractionMode Mode
{
get => mode;
set
{
mode = value;
SetMode(value);
}
}
///
/// Gets or sets which directions are used in calculating distances.
/// Defaults to for ==
/// and for == or .
///
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public AxisDirection? Axis { get; set; }
///
/// if true, the invisible points that are outside of the chart area will also be included when evaluating interactions.
///
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool? IncludeInvisible { get; set; }
}