From 82642e7a67960ec1ec6420bc87c02865777b1cbd Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Thu, 15 Aug 2024 11:41:00 +0200 Subject: [PATCH] Added support for Time axis options. --- .../Charts/ChartOptions/ChartOptions.cs | 87 ++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs b/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs index 686eebea3..17e45cb76 100644 --- a/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs +++ b/blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs @@ -1,4 +1,6 @@ -namespace BlazorBootstrap; +using System; + +namespace BlazorBootstrap; public interface IChartOptions { } @@ -274,6 +276,12 @@ public class ChartAxes [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Type { get; set; } + /// + /// Gets or sets the time axis configuration + /// + [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] + public ChartTimeAxisOptions? Time { get; set; } + #endregion } @@ -649,3 +657,80 @@ public class ChartFont #endregion } + +public enum ChartTimeUnit +{ + Millisecond, + Second, + Minute, + Hour, + Day, + Week, + Month, + Quarter, + Year +} + +/// +/// +/// +public class ChartTimeAxisOptions +{ + #region Properties, Indexers + + /// + /// Sets how different time units are displayed. + /// + [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] + public object? DisplayFormats { get; set; } + + /// + /// If boolean and true and the unit is set to 'week', then the first day of the week will be Monday. Otherwise, it will be Sunday. If number, the index of the first day of the week (0 - Sunday, 6 - Saturday) + /// + [JsonIgnore] + public DayOfWeek? IsoWeekday { get; set; } + + [JsonInclude] + [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] + private int? isoWeekDay => (int?)IsoWeekday; + + /// + /// If defined, dates will be rounded to the start of this unit. See Units below for the allowed units. + /// + [JsonIgnore] + public ChartTimeUnit? Round { get; set; } + + + [JsonInclude] + [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] + private string round => Round?.ToString().ToLower(); + + /// + /// The format string to use for the tooltip. + /// + [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] + public string? TooltipFormat { get; set; } + + /// + /// If defined, will force the unit to be a certain type. See Units section below for details. + /// + [JsonIgnore] + public ChartTimeUnit? Unit { get; set; } + + [JsonInclude] + [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] + private string unit => Unit?.ToString().ToLower(); + + /// + /// The minimum display format to be used for a time unit. + /// + [JsonIgnore] + public ChartTimeUnit? MinUnit { get; set; } + + + [JsonInclude] + [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )] + private string minUnit => MinUnit?.ToString().ToLower(); + + #endregion +} \ No newline at end of file