Skip to content

Commit

Permalink
Make some datasets generic
Browse files Browse the repository at this point in the history
The default, non-generic type is tied to double which is most natural for JavaScript interop but you can now use other types like int if you don't want to use double (e.g. to avoid casting or for semantic reasons).

Closes mariusmuntean#116
  • Loading branch information
Joelius300 committed Sep 6, 2020
1 parent f0c6eaf commit 57638d6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
25 changes: 19 additions & 6 deletions src/ChartJs.Blazor/ChartJS/PieChart/PieDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,27 @@

namespace ChartJs.Blazor.ChartJS.PieChart
{
/// <inheritdoc/>
public class PieDataset : PieDataset<double>
{
/// <inheritdoc/>
public PieDataset(bool useDoughnutDefaults = false) : base(useDoughnutDefaults) { }

/// <inheritdoc/>
public PieDataset(IEnumerable<double> data, bool useDoughnutDefaults = false) : base(data, useDoughnutDefaults) { }

/// <inheritdoc/>
protected PieDataset(ChartType type) : base(type) { }
}

/// <summary>
/// Represents a dataset for a pie or doughnut chart.
/// As per documentation <a href="https://www.chartjs.org/docs/latest/charts/doughnut.html#dataset-properties">here (Chart.js)</a>.
/// </summary>
public class PieDataset : Dataset<double>
public class PieDataset<T> : Dataset<T>
{
/// <summary>
/// Creates a new instance of <see cref="PieDataset"/>.
/// Creates a new instance of <see cref="PieDataset{T}"/>.
/// </summary>
/// <param name="useDoughnutDefaults">
/// If <see langword="true"/>, the dataset-type will be set to <see cref="ChartType.Doughnut"/>
Expand All @@ -25,16 +38,16 @@ public class PieDataset : Dataset<double>
public PieDataset(bool useDoughnutDefaults = false) : base(useDoughnutDefaults ? ChartType.Doughnut : ChartType.Pie) { }

/// <summary>
/// Creates a new instance of <see cref="PieDataset"/> with initial data.
/// Creates a new instance of <see cref="PieDataset{T}"/> with initial data.
/// </summary>
/// <inheritdoc cref="PieDataset(bool)"/>
public PieDataset(IEnumerable<double> data, bool useDoughnutDefaults = false) : this(useDoughnutDefaults)
public PieDataset(IEnumerable<T> data, bool useDoughnutDefaults = false) : this(useDoughnutDefaults)
{
AddRange(data);
}

/// <summary>
/// Creates a new instance of <see cref="PieDataset"/> with
/// Creates a new instance of <see cref="PieDataset{T}"/> with
/// a custom <see cref="ChartType"/>. Use this constructor when
/// you implement a pie-like chart.
/// </summary>
Expand Down Expand Up @@ -90,4 +103,4 @@ protected PieDataset(ChartType type) : base(type) { }
/// </summary>
public int? Weight { get; set; }
}
}
}
25 changes: 19 additions & 6 deletions src/ChartJs.Blazor/ChartJS/PolarAreaChart/PolarAreaDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,41 @@

namespace ChartJs.Blazor.ChartJS.PolarAreaChart
{
/// <inheritdoc/>
public class PolarAreaDataset : PolarAreaDataset<double>
{
/// <inheritdoc/>
public PolarAreaDataset() { }

/// <inheritdoc/>
public PolarAreaDataset(IEnumerable<double> data) : base(data) { }

/// <inheritdoc/>
protected PolarAreaDataset(ChartType type) : base(type) { }
}

/// <summary>
/// Represents a dataset for a pie or doughnut chart.
/// Represents a dataset for a polar area chart.
/// As per documentation <a href="https://www.chartjs.org/docs/latest/charts/polar.html#dataset-properties">here (Chart.js)</a>.
/// </summary>
// Very similar to PieDataset, so the summaries are inherited.
public class PolarAreaDataset : Dataset<double>
public class PolarAreaDataset<T> : Dataset<T>
{
/// <summary>
/// Creates a new instance of <see cref="PolarAreaDataset"/>.
/// Creates a new instance of <see cref="PolarAreaDataset{T}"/>.
/// </summary>
public PolarAreaDataset() : base(ChartType.PolarArea) { }

/// <summary>
/// Creates a new instance of <see cref="PolarAreaDataset"/> with initial data.
/// Creates a new instance of <see cref="PolarAreaDataset{T}"/> with initial data.
/// </summary>
public PolarAreaDataset(IEnumerable<double> data) : this()
public PolarAreaDataset(IEnumerable<T> data) : this()
{
AddRange(data);
}

/// <summary>
/// Creates a new instance of <see cref="PolarAreaDataset"/> with
/// Creates a new instance of <see cref="PolarAreaDataset{T}"/> with
/// a custom <see cref="ChartType"/>. Use this constructor when
/// you implement a polar-area-like chart.
/// </summary>
Expand Down
23 changes: 18 additions & 5 deletions src/ChartJs.Blazor/ChartJS/RadarChart/RadarDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,41 @@

namespace ChartJs.Blazor.ChartJS.RadarChart
{
/// <inheritdoc/>
public class RadarDataset : RadarDataset<double>
{
/// <inheritdoc/>
public RadarDataset() { }

/// <inheritdoc/>
public RadarDataset(IEnumerable<double> data) : base(data) { }

/// <inheritdoc/>
protected RadarDataset(ChartType type) : base(type) { }
}

/// <summary>
/// Represents a dataset for a radar chart.
/// As per documentation <a href="https://www.chartjs.org/docs/latest/charts/radar.html#dataset-properties">here (Chart.js)</a>.
/// </summary>
// Very similar to LineDataset, so the summaries are inherited.
public class RadarDataset : Dataset<double>
public class RadarDataset<T> : Dataset<T>
{
/// <summary>
/// Creates a new instance of <see cref="RadarDataset"/>.
/// Creates a new instance of <see cref="RadarDataset{T}"/>.
/// </summary>
public RadarDataset() : base(ChartType.Radar) { }

/// <summary>
/// Creates a new instance of <see cref="RadarDataset"/> with initial data.
/// Creates a new instance of <see cref="RadarDataset{T}"/> with initial data.
/// </summary>
public RadarDataset(IEnumerable<double> data) : this()
public RadarDataset(IEnumerable<T> data) : this()
{
AddRange(data);
}

/// <summary>
/// Creates a new instance of <see cref="RadarDataset"/> with
/// Creates a new instance of <see cref="RadarDataset{T}"/> with
/// a custom <see cref="ChartType"/>. Use this constructor when
/// you implement a radar-like chart.
/// </summary>
Expand Down

0 comments on commit 57638d6

Please sign in to comment.