Skip to content

Commit 386dda9

Browse files
mhspeltMischa Speltgvreddy04
authored
ChartDataset.Data generics (#833)
* Charts: Made ChartDataset.Data generic so derived classes don't have to shadow it --------- Co-authored-by: Mischa Spelt <[email protected]> Co-authored-by: Vikram Reddy <[email protected]>
1 parent 73191ff commit 386dda9

File tree

8 files changed

+120
-190
lines changed

8 files changed

+120
-190
lines changed

blazorbootstrap/Models/Charts/ChartDataset/BarChart/BarChartDataset.cs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
namespace BlazorBootstrap;
22

33
/// <summary>
4-
/// The bar chart allows a number of properties to be specified for each dataset.
4+
/// The bar chart allows a number of properties to be specified for each dataset.
55
/// These are used to set display properties for a specific dataset.
66
/// <see href="https://www.chartjs.org/docs/latest/charts/bar.html#dataset-properties" />
77
/// <seealso href="https://www.chartjs.org/docs/latest/charts/bar.html#general" />
88
/// </summary>
9-
public class BarChartDataset : ChartDataset
9+
public class BarChartDataset : ChartDataset<double?>
1010
{
1111
#region Properties, Indexers
1212

@@ -29,11 +29,11 @@ public class BarChartDataset : ChartDataset
2929
public double BarPercentage { get; set; } = 0.9;
3030

3131
/// <summary>
32-
/// It is applied to the width of each bar, in pixels.
32+
/// It is applied to the width of each bar, in pixels.
3333
/// When this is enforced, barPercentage and categoryPercentage are ignored.
3434
/// </summary>
3535
/// <remarks>
36-
/// Default value is <see langword="null"/>.
36+
/// Default value is <see langword="null" />.
3737
/// </remarks>
3838
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
3939
public double? BarThickness { get; set; }
@@ -75,33 +75,25 @@ public class BarChartDataset : ChartDataset
7575
/// </remarks>
7676
public double CategoryPercentage { get; set; } = 0.8;
7777

78-
/// <summary>
79-
/// Get or sets the Data.
80-
/// </summary>
81-
/// <remarks>
82-
/// Default value is <see langword="null"/>.
83-
/// </remarks>
84-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
85-
public new List<double?>? Data { get; set; }
86-
87-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
78+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
8879
public BarChartDatasetDataLabels Datalabels { get; set; } = new(); // TODO: add the reference link
8980

9081
/// <summary>
91-
/// Should the bars be grouped on index axis.
92-
/// When <see langword="true"/>, all the datasets at same index value will be placed next to each other centering on that index value.
93-
/// When <see langword="false"/>, each bar is placed on its actual index-axis value.
82+
/// Should the bars be grouped on index axis.
83+
/// When <see langword="true" />, all the datasets at same index value will be placed next to each other centering on that
84+
/// index value.
85+
/// When <see langword="false" />, each bar is placed on its actual index-axis value.
9486
/// </summary>
9587
/// <remarks>
96-
/// Default value is <see langword="true"/>.
88+
/// Default value is <see langword="true" />.
9789
/// </remarks>
9890
public bool Grouped { get; set; } = true;
9991

10092
/// <summary>
10193
/// The bar background color when hovered.
10294
/// </summary>
10395
/// <remarks>
104-
/// Default value is <see langword="null"/>.
96+
/// Default value is <see langword="null" />.
10597
/// </remarks>
10698
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
10799
public List<string>? HoverBackgroundColor { get; set; }
@@ -110,7 +102,7 @@ public class BarChartDataset : ChartDataset
110102
/// The bar border color when hovered.
111103
/// </summary>
112104
/// <remarks>
113-
/// Default value is <see langword="null"/>.
105+
/// Default value is <see langword="null" />.
114106
/// </remarks>
115107
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
116108
public List<string>? HoverBorderColor { get; set; }
@@ -138,7 +130,7 @@ public class BarChartDataset : ChartDataset
138130
/// Supported values are 'x' and 'y'.
139131
/// </summary>
140132
/// <remarks>
141-
/// Default value is <see langword="null"/>.
133+
/// Default value is <see langword="null" />.
142134
/// </remarks>
143135
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
144136
public string? IndexAxis { get; set; }
@@ -150,7 +142,7 @@ public class BarChartDataset : ChartDataset
150142
/// Set this to ensure that bars are not sized thicker than this.
151143
/// </summary>
152144
/// <remarks>
153-
/// Default value is <see langword="null"/>.
145+
/// Default value is <see langword="null" />.
154146
/// </remarks>
155147
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
156148
public double? MaxBarThickness { get; set; }
@@ -159,7 +151,7 @@ public class BarChartDataset : ChartDataset
159151
/// Set this to ensure that bars have a minimum length in pixels.
160152
/// </summary>
161153
/// <remarks>
162-
/// Default value is <see langword="null"/>.
154+
/// Default value is <see langword="null" />.
163155
/// </remarks>
164156
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
165157
public double? MinBarLength { get; set; }
@@ -168,10 +160,11 @@ public class BarChartDataset : ChartDataset
168160
//https://www.chartjs.org/docs/latest/configuration/elements.html#point-styles
169161

170162
/// <summary>
171-
/// If <see langword="true"/>, null or undefined values will not be used for spacing calculations when determining bar size.
163+
/// If <see langword="true" />, null or undefined values will not be used for spacing calculations when determining bar
164+
/// size.
172165
/// </summary>
173166
/// <remarks>
174-
/// Default value is <see langword="false"/>.
167+
/// Default value is <see langword="false" />.
175168
/// </remarks>
176169
public bool SkipNull { get; set; }
177170

@@ -199,6 +192,4 @@ public class BarChartDataset : ChartDataset
199192
#endregion
200193
}
201194

202-
public class BarChartDatasetDataLabels : ChartDatasetDataLabels
203-
{
204-
}
195+
public class BarChartDatasetDataLabels : ChartDatasetDataLabels { }

blazorbootstrap/Models/Charts/ChartDataset/ChartDataset.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public interface IChartDataset { }
55
/// <summary>
66
/// <See href="https://www.chartjs.org/docs/latest/general/data-structures.html#dataset-configuration" />
77
/// </summary>
8-
public class ChartDataset : IChartDataset
8+
public class ChartDataset<TData> : IChartDataset
99
{
1010
#region Constructors
1111

@@ -24,7 +24,7 @@ public ChartDataset()
2424
/// Clipping can also be configured per side: clip: {left: 5, top: false, right: -2, bottom: 0}
2525
/// </summary>
2626
/// <remarks>
27-
/// Default value is <see langword="null"/>.
27+
/// Default value is <see langword="null" />.
2828
/// </remarks>
2929
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
3030
public string? Clip { get; set; }
@@ -33,16 +33,16 @@ public ChartDataset()
3333
/// Get or sets the Data.
3434
/// </summary>
3535
/// <remarks>
36-
/// Default value is <see langword="null"/>.
36+
/// Default value is <see langword="null" />.
3737
/// </remarks>
3838
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
39-
public object Data { get; set; }
39+
public List<TData>? Data { get; set; }
4040

4141
/// <summary>
42-
/// Configures the visibility state of the dataset. Set it to <see langword="true"/>, to hide the dataset from the chart.
42+
/// Configures the visibility state of the dataset. Set it to <see langword="true" />, to hide the dataset from the chart.
4343
/// </summary>
4444
/// <remarks>
45-
/// Default value is <see langword="false"/>.
45+
/// Default value is <see langword="false" />.
4646
/// </remarks>
4747
public bool Hidden { get; set; }
4848

@@ -75,7 +75,7 @@ public ChartDataset()
7575
/// Gets or sets the chart type.
7676
/// </summary>
7777
/// <remarks>
78-
/// Default value is <see langword="null"/>.
78+
/// Default value is <see langword="null" />.
7979
/// </remarks>
8080
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
8181
public string? Type { get; protected set; }

blazorbootstrap/Models/Charts/ChartDataset/DoughnutChart/DoughnutChartDataset.cs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
namespace BlazorBootstrap;
22

33
/// <summary>
4-
/// The doughnut/pie chart allows a number of properties to be specified for each dataset.
4+
/// The doughnut/pie chart allows a number of properties to be specified for each dataset.
55
/// These are used to set display properties for a specific dataset.
66
/// <see href="https://www.chartjs.org/docs/latest/charts/doughnut.html#dataset-properties" />.
77
/// </summary>
8-
public class DoughnutChartDataset : ChartDataset
8+
public class DoughnutChartDataset : ChartDataset<double?>
99
{
1010
#region Properties, Indexers
1111

@@ -20,7 +20,7 @@ public class DoughnutChartDataset : ChartDataset
2020

2121
/// <summary>
2222
/// Supported values are 'center' and 'inner'.
23-
/// When 'center' is set, the borders of arcs next to each other will overlap.
23+
/// When 'center' is set, the borders of arcs next to each other will overlap.
2424
/// When 'inner' is set, it is guaranteed that all borders will not overlap.
2525
/// </summary>
2626
/// <remarks>
@@ -42,7 +42,7 @@ public class DoughnutChartDataset : ChartDataset
4242
/// Arc border length and spacing of dashes.
4343
/// </summary>
4444
/// <remarks>
45-
/// Default value is <see langword="null"/>.
45+
/// Default value is <see langword="null" />.
4646
/// </remarks>
4747
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
4848
public List<double>? BorderDash { get; set; }
@@ -60,7 +60,7 @@ public class DoughnutChartDataset : ChartDataset
6060
/// Supported values are 'round', 'bevel', 'miter'.
6161
/// </summary>
6262
/// <remarks>
63-
/// Default value is <see langword="null"/>.
63+
/// Default value is <see langword="null" />.
6464
/// </remarks>
6565
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
6666
public List<string>? BorderJoinStyle { get; set; } // TODO: change this to enum
@@ -87,28 +87,19 @@ public class DoughnutChartDataset : ChartDataset
8787
/// Per-dataset override for the sweep that the arcs cover.
8888
/// </summary>
8989
/// <remarks>
90-
/// Default value is <see langword="null"/>.
90+
/// Default value is <see langword="null" />.
9191
/// </remarks>
9292
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
9393
public double? Circumference { get; set; }
9494

95-
/// <summary>
96-
/// Get or sets the Data.
97-
/// </summary>
98-
/// <remarks>
99-
/// Default value is <see langword="null"/>.
100-
/// </remarks>
101-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
102-
public new List<double?>? Data { get; set; }
103-
10495
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
10596
public DoughnutChartDatasetDataLabels Datalabels { get; set; } = new(); // TODO: add the reference link
10697

10798
/// <summary>
10899
/// Arc background color when hovered.
109100
/// </summary>
110101
/// <remarks>
111-
/// Default value is <see langword="null"/>.
102+
/// Default value is <see langword="null" />.
112103
/// </remarks>
113104
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
114105
public List<string>? HoverBackgroundColor { get; set; }
@@ -117,16 +108,16 @@ public class DoughnutChartDataset : ChartDataset
117108
/// Arc border color when hovered.
118109
/// </summary>
119110
/// <remarks>
120-
/// Default value is <see langword="null"/>.
111+
/// Default value is <see langword="null" />.
121112
/// </remarks>
122113
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
123114
public List<string>? HoverBorderColor { get; set; }
124115

125116
/// <summary>
126-
/// Arc border length and spacing of dashes when hovered.
117+
/// Arc border length and spacing of dashes when hovered.
127118
/// </summary>
128119
/// <remarks>
129-
/// Default value is <see langword="null"/>.
120+
/// Default value is <see langword="null" />.
130121
/// </remarks>
131122
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
132123
public List<double>? HoverBorderDash { get; set; }
@@ -135,7 +126,7 @@ public class DoughnutChartDataset : ChartDataset
135126
/// Arc border offset for line dashes when hovered.
136127
/// </summary>
137128
/// <remarks>
138-
/// Default value is <see langword="null"/>.
129+
/// Default value is <see langword="null" />.
139130
/// </remarks>
140131
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
141132
public double? HoverBorderDashOffset { get; set; }
@@ -145,7 +136,7 @@ public class DoughnutChartDataset : ChartDataset
145136
/// Supported values are 'round', 'bevel', 'miter'.
146137
/// </summary>
147138
/// <remarks>
148-
/// Default value is <see langword="null"/>.
139+
/// Default value is <see langword="null" />.
149140
/// </remarks>
150141
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
151142
public List<string>? HoverBorderJoinStyle { get; set; } // TODO: change this to enum
@@ -154,7 +145,7 @@ public class DoughnutChartDataset : ChartDataset
154145
/// Arc border width when hovered (in pixels).
155146
/// </summary>
156147
/// <remarks>
157-
/// Default value is <see langword="null"/>.
148+
/// Default value is <see langword="null" />.
158149
/// </remarks>
159150
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
160151
public List<double>? HoverBorderWidth { get; set; }
@@ -181,7 +172,7 @@ public class DoughnutChartDataset : ChartDataset
181172
/// Per-dataset override for the starting angle to draw arcs from.
182173
/// </summary>
183174
/// <remarks>
184-
/// Default value is <see langword="null"/>.
175+
/// Default value is <see langword="null" />.
185176
/// </remarks>
186177
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
187178
public double? Rotation { get; set; }
@@ -195,8 +186,8 @@ public class DoughnutChartDataset : ChartDataset
195186
public double Spacing { get; set; }
196187

197188
/// <summary>
198-
/// The relative thickness of the dataset.
199-
/// Providing a value for weight will cause the pie or doughnut dataset to be drawn
189+
/// The relative thickness of the dataset.
190+
/// Providing a value for weight will cause the pie or doughnut dataset to be drawn
200191
/// with a thickness relative to the sum of all the dataset weight values.
201192
/// </summary>
202193
/// <remarks>
@@ -207,6 +198,4 @@ public class DoughnutChartDataset : ChartDataset
207198
#endregion
208199
}
209200

210-
public class DoughnutChartDatasetDataLabels : ChartDatasetDataLabels
211-
{
212-
}
201+
public class DoughnutChartDatasetDataLabels : ChartDatasetDataLabels { }

blazorbootstrap/Models/Charts/ChartDataset/LineChart/LineChartDataset.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// These are used to set display properties for a specific dataset.
66
/// <see href="https://www.chartjs.org/docs/latest/charts/line.html#dataset-properties" />.
77
/// </summary>
8-
public class LineChartDataset : ChartDataset
8+
public class LineChartDataset : ChartDataset<double?>
99
{
1010
#region Methods
1111

@@ -188,17 +188,9 @@ public LineChartDataset FillToValue(double value)
188188
/// Default value is 'default'.
189189
/// </remarks>
190190
public string CubicInterpolationMode { get; set; } = "default";
191-
192-
/// <summary>
193-
/// Get or sets the Data.
194-
/// </summary>
195-
/// <remarks>
196-
/// Default value is <see langword="null" />.
197-
/// </remarks>
198-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
199-
public new List<double?>? Data { get; set; }
200-
201-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public LineChartDatasetDataLabels Datalabels { get; set; } = new(); // TODO: add the reference link
191+
192+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
193+
public LineChartDatasetDataLabels Datalabels { get; set; } = new(); // TODO: add the reference link
202194

203195
/// <summary>
204196
/// Draw the active points of a dataset over the other points of the dataset.

0 commit comments

Comments
 (0)