Skip to content

Commit

Permalink
Merge pull request Live-Charts#455 from beto-rodriguez/develop
Browse files Browse the repository at this point in the history
Some love to PieChart
  • Loading branch information
beto-rodriguez authored Feb 5, 2017
2 parents 9e76c02 + 2ed514d commit 3679e95
Show file tree
Hide file tree
Showing 53 changed files with 818 additions and 337 deletions.
94 changes: 94 additions & 0 deletions Core/Configurations/PieMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;

namespace LiveCharts.Configurations
{
/// <summary>
/// Mapper to configure X and Y points
/// </summary>
/// <typeparam name="T">Type to configure</typeparam>
public class PieMapper<T> : IPointEvaluator<T>
{
private readonly Func<T, int, double> _x = (v, i) => i;
private Func<T, int, double> _y = (v, i) => i;
private Func<T, int, object> _stroke;
private Func<T, int, object> _fill;

/// <summary>
/// Sets values for a specific point
/// </summary>
/// <param name="point">Point to set</param>
/// <param name="value"></param>
/// <param name="key"></param>
public void Evaluate(int key, T value, ChartPoint point)
{
point.X = _x(value, key);
point.Y = _y(value, key);
if (_stroke != null) point.Stroke = _stroke(value, key);
if (_fill != null) point.Fill = _fill(value, key);
}


/// <summary>
/// Sets the Y mapper
/// </summary>
/// <param name="predicate">function that pulls Y coordinate</param>
/// <returns>current mapper instance</returns>
public PieMapper<T> Value(Func<T, double> predicate)
{
return Value((t, i) => predicate(t));
}

/// <summary>
/// Sets the Y mapper
/// </summary>
/// <param name="predicate">function that pulls Y coordinate, with value and index as parameters</param>
/// <returns>current mapper instance</returns>
public PieMapper<T> Value(Func<T, int, double> predicate)
{
_y = predicate;
return this;
}

/// <summary>
/// Sets the Stroke of the point
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public PieMapper<T> Stroke(Func<T, object> predicate)
{
return Stroke((t, i) => predicate(t));
}

/// <summary>
/// Sets the Stroke of the point
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public PieMapper<T> Stroke(Func<T, int, object> predicate)
{
_stroke = predicate;
return this;
}

/// <summary>
/// Sets the Fill of the point
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public PieMapper<T> Fill(Func<T, object> predicate)
{
return Fill((t, i) => predicate(t));
}

/// <summary>
/// Sets the Fill of the point
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public PieMapper<T> Fill(Func<T, int, object> predicate)
{
_fill = predicate;
return this;
}
}
}
3 changes: 3 additions & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@
<Compile Include="Configurations\GanttMapper.cs" />
<Compile Include="Configurations\IPointEvaluator.cs" />
<Compile Include="Configurations\Mappers.cs" />
<Compile Include="Configurations\PieMapper.cs" />
<Compile Include="Configurations\PolarMapper.cs" />
<Compile Include="Configurations\WeightedMapper.cs" />
<Compile Include="DataLabelViewModel.cs" />
<Compile Include="Defaults\AxisLimits.cs" />
<Compile Include="Defaults\DateTimePoint.cs" />
<Compile Include="Defaults\GanttPoint.cs" />
Expand Down Expand Up @@ -134,6 +136,7 @@
<Compile Include="LogarithmicAxisCore.cs" />
<Compile Include="Maps\MapData.cs" />
<Compile Include="PanningOptions.cs" />
<Compile Include="PieLabelPosition.cs" />
<Compile Include="PointTracker.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScrollMode.cs" />
Expand Down
46 changes: 46 additions & 0 deletions Core/DataLabelViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//The MIT License(MIT)

//Copyright(c) 2016 Alberto Rodriguez

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

namespace LiveCharts
{
/// <summary>
/// Describes a data label view model
/// </summary>
public class DataLabelViewModel
{
/// <summary>
/// Gets or sets the formatted text of the current point
/// </summary>
/// <value>
/// The formatted text.
/// </value>
public string FormattedText { get; set; }
/// <summary>
/// Gets the instance of the current point.
/// </summary>
/// <value>
/// The instance.
/// </value>
public object Instance { get; internal set; }

}
}
39 changes: 39 additions & 0 deletions Core/PieLabelPosition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//The MIT License(MIT)

//copyright(c) 2016 Alberto Rodriguez

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

namespace LiveCharts
{
/// <summary>
/// Describes where a label should be placed
/// </summary>
public enum PieLabelPosition
{
/// <summary>
/// Places the label inside the pie slice
/// </summary>
InsideSlice,
/// <summary>
/// Places the label outside the pie slice
/// </summary>
OutsideSlice
}
}
4 changes: 1 addition & 3 deletions Core/SeriesAlgorithms/PieAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public override void Update()
{
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels
? (chartPoint.Participation > 0.05
? View.GetLabelPointFormatter()(chartPoint)
: string.Empty)
? View.GetLabelPointFormatter()(chartPoint)
: null);

var pieSlice = (IPieSlicePointView) chartPoint.View;
Expand Down
10 changes: 10 additions & 0 deletions Core40/Configurations/Mappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,15 @@ public static PolarMapper<T> Polar<T>()
{
return new PolarMapper<T>();
}

/// <summary>
/// PGets a mapper to configure a pie chart
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static PieMapper<T> Pie<T>()
{
return new PieMapper<T>();
}
}
}
94 changes: 94 additions & 0 deletions Core40/Configurations/PieMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;

namespace LiveCharts.Configurations
{
/// <summary>
/// Mapper to configure X and Y points
/// </summary>
/// <typeparam name="T">Type to configure</typeparam>
public class PieMapper<T> : IPointEvaluator<T>
{
private readonly Func<T, int, double> _x = (v, i) => i;
private Func<T, int, double> _y = (v, i) => i;
private Func<T, int, object> _stroke;
private Func<T, int, object> _fill;

/// <summary>
/// Sets values for a specific point
/// </summary>
/// <param name="point">Point to set</param>
/// <param name="value"></param>
/// <param name="key"></param>
public void Evaluate(int key, T value, ChartPoint point)
{
point.X = _x(value, key);
point.Y = _y(value, key);
if (_stroke != null) point.Stroke = _stroke(value, key);
if (_fill != null) point.Fill = _fill(value, key);
}


/// <summary>
/// Sets the Y mapper
/// </summary>
/// <param name="predicate">function that pulls Y coordinate</param>
/// <returns>current mapper instance</returns>
public PieMapper<T> Value(Func<T, double> predicate)
{
return Value((t, i) => predicate(t));
}

/// <summary>
/// Sets the Y mapper
/// </summary>
/// <param name="predicate">function that pulls Y coordinate, with value and index as parameters</param>
/// <returns>current mapper instance</returns>
public PieMapper<T> Value(Func<T, int, double> predicate)
{
_y = predicate;
return this;
}

/// <summary>
/// Sets the Stroke of the point
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public PieMapper<T> Stroke(Func<T, object> predicate)
{
return Stroke((t, i) => predicate(t));
}

/// <summary>
/// Sets the Stroke of the point
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public PieMapper<T> Stroke(Func<T, int, object> predicate)
{
_stroke = predicate;
return this;
}

/// <summary>
/// Sets the Fill of the point
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public PieMapper<T> Fill(Func<T, object> predicate)
{
return Fill((t, i) => predicate(t));
}

/// <summary>
/// Sets the Fill of the point
/// </summary>
/// <param name="predicate"></param>
/// <returns></returns>
public PieMapper<T> Fill(Func<T, int, object> predicate)
{
_fill = predicate;
return this;
}
}
}
3 changes: 3 additions & 0 deletions Core40/Core40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@
<Compile Include="Configurations\GanttMapper.cs" />
<Compile Include="Configurations\IPointEvaluator.cs" />
<Compile Include="Configurations\Mappers.cs" />
<Compile Include="Configurations\PieMapper.cs" />
<Compile Include="Configurations\PolarMapper.cs" />
<Compile Include="Configurations\WeightedMapper.cs" />
<Compile Include="DataLabelViewModel.cs" />
<Compile Include="Defaults\AxisLimits.cs" />
<Compile Include="Defaults\DateTimePoint.cs" />
<Compile Include="Defaults\GanttPoint.cs" />
Expand Down Expand Up @@ -137,6 +139,7 @@
<Compile Include="LogarithmicAxisCore.cs" />
<Compile Include="Maps\MapData.cs" />
<Compile Include="PanningOptions.cs" />
<Compile Include="PieLabelPosition.cs" />
<Compile Include="PointTracker.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScrollMode.cs" />
Expand Down
46 changes: 46 additions & 0 deletions Core40/DataLabelViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//The MIT License(MIT)

//Copyright(c) 2016 Alberto Rodriguez

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

namespace LiveCharts
{
/// <summary>
/// Describes a data label view model
/// </summary>
public class DataLabelViewModel
{
/// <summary>
/// Gets or sets the formatted text of the current point
/// </summary>
/// <value>
/// The formatted text.
/// </value>
public string FormattedText { get; set; }
/// <summary>
/// Gets the instance of the current point.
/// </summary>
/// <value>
/// The instance.
/// </value>
public object Instance { get; internal set; }

}
}
Loading

0 comments on commit 3679e95

Please sign in to comment.