//The MIT License(MIT)
//Copyright(c) 2016 Alberto Rodriguez & LiveCharts Contributors
//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.
using System;
namespace LiveCharts.Configurations
{
///
/// Mapper to configure X and Y points
///
/// Type to configure
public class CartesianMapper : IPointEvaluator
{
private Func _x = (v, i) => i;
private Func _y = (v, i) => i;
private Func _stroke;
private Func _fill;
///
/// Sets values for a specific point
///
/// Point to set
///
///
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);
}
///
/// Sets the X mapper
///
/// function that pulls X coordinate
/// current mapper instance
public CartesianMapper X(Func predicate)
{
return X((t, i) => predicate(t));
}
///
/// Sets the X mapper
///
/// function that pulls X coordinate, with value and index as parameters
/// current mapper instance
public CartesianMapper X(Func predicate)
{
_x = predicate;
return this;
}
///
/// Sets the Y mapper
///
/// function that pulls Y coordinate
/// current mapper instance
public CartesianMapper Y(Func predicate)
{
return Y((t, i) => predicate(t));
}
///
/// Sets the Y mapper
///
/// function that pulls Y coordinate, with value and index as parameters
/// current mapper instance
public CartesianMapper Y(Func predicate)
{
_y = predicate;
return this;
}
///
/// Sets the Stroke of the point
///
///
///
public CartesianMapper Stroke(Func predicate)
{
return Stroke((t, i) => predicate(t));
}
///
/// Sets the Stroke of the point
///
///
///
public CartesianMapper Stroke(Func predicate)
{
_stroke = predicate;
return this;
}
///
/// Sets the Fill of the point
///
///
///
public CartesianMapper Fill(Func predicate)
{
return Fill((t, i) => predicate(t));
}
///
/// Sets the Fill of the point
///
///
///
public CartesianMapper Fill(Func predicate)
{
_fill = predicate;
return this;
}
}
}