Skip to content

Commit

Permalink
Charts - Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gvreddy04 committed Jul 20, 2023
1 parent bfdeb23 commit 21857fd
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 45 deletions.
4 changes: 2 additions & 2 deletions blazorbootstrap/Models/Charts/ChartData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class ChartData
{
public List<string> Labels { get; set; }
public List<IChartDataset> Datasets { get; set; }
public List<string>? Labels { get; set; }
public List<IChartDataset>? Datasets { get; set; }
}
6 changes: 3 additions & 3 deletions blazorbootstrap/Models/Charts/ChartDataset/BarChartDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BarChartDataset : ChartDataset
/// The label for the dataset which appears in the legend and tooltips.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Label { get; set; }
public string? Label { get; set; }

//MaxBarThickness
//https://www.chartjs.org/docs/latest/api/interfaces/BarControllerDatasetOptions.html#maxbarthickness
Expand All @@ -40,11 +40,11 @@ public class BarChartDataset : ChartDataset
/// The ID of the x axis to plot this dataset on.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string XAxisID { get; set; }
public string? XAxisID { get; set; }

/// <summary>
/// The ID of the y axis to plot this dataset on.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string YAxisID { get; set; }
public string? YAxisID { get; set; }
}
12 changes: 6 additions & 6 deletions blazorbootstrap/Models/Charts/ChartDataset/BubbleChartDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
public class BubbleChartDataset : ChartDataset
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string BackgroundColor { get; set; }
public new string? BackgroundColor { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string BorderColor { get; set; }
public new string? BorderColor { get; set; }

public new double BorderWidth { get; set; }

public new List<BubbleData> Data { get; set; }
public new List<BubbleData>? Data { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string HoverBackgroundColor { get; set; }
public new string? HoverBackgroundColor { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string HoverBorderColor { get; set; }
public new string? HoverBorderColor { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string HoverBorderWidth { get; set; }
public new string? HoverBorderWidth { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Label { get; set; }
Expand Down
18 changes: 9 additions & 9 deletions blazorbootstrap/Models/Charts/ChartDataset/ChartDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ public class ChartDataset : IChartDataset
/// Get or sets the BackgroundColor.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string> BackgroundColor { get; set; }
public List<string>? BackgroundColor { get; set; }

/// <summary>
/// Get or sets the BorderColor.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string> BorderColor { get; set; }
public List<string>? BorderColor { get; set; }

/// <summary>
/// Get or sets the BorderWidth.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<double> BorderWidth { get; set; }
public List<double>? BorderWidth { get; set; }

/// <summary>
/// How to clip relative to chartArea. Positive value allows overflow, negative value clips that many pixels inside chartArea. 0 = clip at chartArea.
/// Clipping can also be configured per side: clip: {left: 5, top: false, right: -2, bottom: 0}
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Clip { get; set; }
public string? Clip { get; set; }

/// <summary>
/// Get or sets the Data.
/// </summary>
public List<double> Data { get; set; }
public List<double>? Data { get; set; }

/// <summary>
/// Configures the visibility state of the dataset. Set it to true, to hide the dataset from the chart.
Expand All @@ -43,23 +43,23 @@ public class ChartDataset : IChartDataset
/// Get or sets the HoverBackgroundColor.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string> HoverBackgroundColor { get; set; }
public List<string>? HoverBackgroundColor { get; set; }

/// <summary>
/// Get or sets the HoverBorderColor.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string> HoverBorderColor { get; set; }
public List<string>? HoverBorderColor { get; set; }

/// <summary>
/// Get or sets the HoverBorderWidth.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<double> HoverBorderWidth { get; set; }
public List<double>? HoverBorderWidth { get; set; }

/// <summary>
/// Gets or sets the chart type.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Type { get; protected set; }
public string? Type { get; protected set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LineChartDataset : ChartDataset
/// <summary>
/// Configures the visibility state of the dataset. Set it to true, to hide the dataset from the chart.
/// </summary>
public bool Hidden { get; set; }
public new bool Hidden { get; set; }

/// <summary>
/// Hover line dash.
Expand Down Expand Up @@ -143,6 +143,6 @@ public class LineChartDataset : ChartDataset

public LineChartDataset()
{
this.Type = "line";
Type = "line";
}
}
12 changes: 6 additions & 6 deletions blazorbootstrap/Models/Charts/ChartDataset/RadarChartDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
public class RadarChartDataset : ChartDataset
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string BackgroundColor { get; set; }
public new string? BackgroundColor { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string BorderColor { get; set; }
public new string? BorderColor { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new double BorderWidth { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string HoverBackgroundColor { get; set; }
public new string? HoverBackgroundColor { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string HoverBorderColor { get; set; }
public new string? HoverBorderColor { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public new string HoverBorderWidth { get; set; }
public new string? HoverBorderWidth { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Label { get; set; }
public string? Label { get; set; }
}
31 changes: 14 additions & 17 deletions blazorbootstrap/Models/Charts/ChartOptions/ChartOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Interaction
[JsonIgnore]
public InteractionMode Mode
{
get { return mode; }
get => mode;
set
{
mode = value;
Expand All @@ -61,19 +61,16 @@ public Interaction()
Mode = InteractionMode.Nearest;
}

private void SetMode(InteractionMode interactionMode)
private void SetMode(InteractionMode interactionMode) => ChartInteractionMode = interactionMode switch
{
ChartInteractionMode = interactionMode switch
{
InteractionMode.Dataset => "dataset",
InteractionMode.Index => "index",
InteractionMode.Nearest => "nearest",
InteractionMode.Point => "point",
InteractionMode.X => "x",
InteractionMode.Y => "y",
_ => ""
};
}
InteractionMode.Dataset => "dataset",
InteractionMode.Index => "index",
InteractionMode.Nearest => "nearest",
InteractionMode.Point => "point",
InteractionMode.X => "x",
InteractionMode.Y => "y",
_ => ""
};
}

public enum InteractionMode
Expand All @@ -92,7 +89,7 @@ public class Plugins
public Title? Title { get; set; } = new Title();

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ChartTooltip Tooltip { get; set; }
public ChartTooltip? Tooltip { get; set; }
}

public class Scales
Expand Down Expand Up @@ -228,7 +225,7 @@ public class ChartTooltip
public string BodyColor { get; set; } = "#fff";

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ChartFont BodyFont { get; set; }
public ChartFont? BodyFont { get; set; }

/// <summary>
/// Horizontal alignment of the body text lines. left/right/center.
Expand Down Expand Up @@ -280,10 +277,10 @@ public class ChartTooltip
/// <summary>
/// Position of the tooltip caret in the X direction. left/center/right.
/// </summary>
public string XAlign { get; set; }
public string? XAlign { get; set; }

/// <summary>
/// Position of the tooltip caret in the Y direction. top/center/bottom.
/// </summary>
public string YAlign { get; set; }
public string? YAlign { get; set; }
}

0 comments on commit 21857fd

Please sign in to comment.