Skip to content

Commit

Permalink
Added support for Time axis options.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mischa Spelt committed Sep 12, 2024
1 parent 386dda9 commit 82642e7
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace BlazorBootstrap;
using System;

namespace BlazorBootstrap;

public interface IChartOptions { }

Expand Down Expand Up @@ -274,6 +276,12 @@ public class ChartAxes
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Type { get; set; }

/// <summary>
/// Gets or sets the time axis configuration
/// </summary>
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
public ChartTimeAxisOptions? Time { get; set; }

#endregion
}

Expand Down Expand Up @@ -649,3 +657,80 @@ public class ChartFont

#endregion
}

public enum ChartTimeUnit
{
Millisecond,
Second,
Minute,
Hour,
Day,
Week,
Month,
Quarter,
Year
}

/// <summary>
/// <see href="https://www.chartjs.org/docs/latest/axes/cartesian/time.html" />
/// </summary>
public class ChartTimeAxisOptions
{
#region Properties, Indexers

/// <summary>
/// Sets how different time units are displayed.
/// <summary>
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
public object? DisplayFormats { get; set; }

/// <summary>
/// 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)
/// <summary>
[JsonIgnore]
public DayOfWeek? IsoWeekday { get; set; }

[JsonInclude]
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
private int? isoWeekDay => (int?)IsoWeekday;

/// <summary>
/// If defined, dates will be rounded to the start of this unit. See Units below for the allowed units.
/// <summary>
[JsonIgnore]
public ChartTimeUnit? Round { get; set; }


[JsonInclude]
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
private string round => Round?.ToString().ToLower();

/// <summary>
/// The format string to use for the tooltip.
/// <summary>
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
public string? TooltipFormat { get; set; }

/// <summary>
/// If defined, will force the unit to be a certain type. See Units section below for details.
/// <summary>
[JsonIgnore]
public ChartTimeUnit? Unit { get; set; }

[JsonInclude]
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
private string unit => Unit?.ToString().ToLower();

/// <summary>
/// The minimum display format to be used for a time unit.
/// <summary>
[JsonIgnore]
public ChartTimeUnit? MinUnit { get; set; }


[JsonInclude]
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
private string minUnit => MinUnit?.ToString().ToLower();

#endregion
}

0 comments on commit 82642e7

Please sign in to comment.