Skip to content

Commit 51737af

Browse files
author
Mischa Spelt
committed
Added Time Chart Axis Options
1 parent 00f54a9 commit 51737af

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace BlazorBootstrap;
1+
using System;
2+
3+
namespace BlazorBootstrap;
24

35
public interface IChartOptions { }
46

@@ -284,6 +286,12 @@ public class ChartAxes
284286
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
285287
public string? Type { get; set; }
286288

289+
/// <summary>
290+
/// Gets or sets the time axis configuration
291+
/// </summary>
292+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
293+
public ChartTimeAxisOptions? Time { get; set; }
294+
287295
#endregion
288296
}
289297

@@ -659,3 +667,80 @@ public class ChartFont
659667

660668
#endregion
661669
}
670+
671+
public enum ChartTimeUnit
672+
{
673+
Millisecond,
674+
Second,
675+
Minute,
676+
Hour,
677+
Day,
678+
Week,
679+
Month,
680+
Quarter,
681+
Year
682+
}
683+
684+
/// <summary>
685+
/// <see href="https://www.chartjs.org/docs/latest/axes/cartesian/time.html" />
686+
/// </summary>
687+
public class ChartTimeAxisOptions
688+
{
689+
#region Properties, Indexers
690+
691+
/// <summary>
692+
/// Sets how different time units are displayed.
693+
/// <summary>
694+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
695+
public object? DisplayFormats { get; set; }
696+
697+
/// <summary>
698+
/// 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)
699+
/// <summary>
700+
[JsonIgnore]
701+
public DayOfWeek? IsoWeekday { get; set; }
702+
703+
[JsonInclude]
704+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
705+
private int? isoWeekDay => (int?)IsoWeekday;
706+
707+
/// <summary>
708+
/// If defined, dates will be rounded to the start of this unit. See Units below for the allowed units.
709+
/// <summary>
710+
[JsonIgnore]
711+
public ChartTimeUnit? Round { get; set; }
712+
713+
714+
[JsonInclude]
715+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
716+
private string round => Round?.ToString().ToLower();
717+
718+
/// <summary>
719+
/// The format string to use for the tooltip.
720+
/// <summary>
721+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
722+
public string? TooltipFormat { get; set; }
723+
724+
/// <summary>
725+
/// If defined, will force the unit to be a certain type. See Units section below for details.
726+
/// <summary>
727+
[JsonIgnore]
728+
public ChartTimeUnit? Unit { get; set; }
729+
730+
[JsonInclude]
731+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
732+
private string unit => Unit?.ToString().ToLower();
733+
734+
/// <summary>
735+
/// The minimum display format to be used for a time unit.
736+
/// <summary>
737+
[JsonIgnore]
738+
public ChartTimeUnit? MinUnit { get; set; }
739+
740+
741+
[JsonInclude]
742+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
743+
private string minUnit => MinUnit?.ToString().ToLower();
744+
745+
#endregion
746+
}

0 commit comments

Comments
 (0)