//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 financial points
///
/// type to configure
public class FinancialMapper : IPointEvaluator
{
private Func _x = (v, i) => i;
private Func _y = (v, i) => 0;
private Func _open;
private Func _high;
private Func _low;
private Func _close;
///
/// 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);
point.Open = _open(value, key);
point.High = _high(value, key);
point.Close = _close(value, key);
point.Low = _low(value, key);
}
///
/// Maps X value
///
/// function that pulls X coordinate
/// current mapper instance
public FinancialMapper X(Func predicate)
{
return X((t, i) => predicate(t));
}
///
/// Maps X value
///
/// function that pulls X coordinate, with value and index as parameters
/// current mapper instance
public FinancialMapper X(Func predicate)
{
_x = predicate;
return this;
}
///
/// Maps Y value
///
/// function that pulls Y coordinate
/// current mapper instance
public FinancialMapper Y(Func predicate)
{
return Y((t, i) => predicate(t));
}
///
/// Maps Y value
///
/// function that pulls Y coordinate, with value and index as parameters
/// current mapper instance
public FinancialMapper Y(Func predicate)
{
_y = predicate;
return this;
}
///
/// Maps Open value
///
/// function that pulls open value
/// current mapper instance
public FinancialMapper Open(Func predicate)
{
return Open((t, i) => predicate(t));
}
///
/// Maps Open value
///
/// function that pulls open value, value and index as parameters
/// current mapper instance
public FinancialMapper Open(Func predicate)
{
_open = predicate;
return this;
}
///
/// Maps High value
///
/// function that pulls High value
/// current mapper instance
public FinancialMapper High(Func predicate)
{
return High((t, i) => predicate(t));
}
///
/// Maps High value
///
/// function that pulls High value
/// current mapper instance
public FinancialMapper High(Func predicate)
{
_high = predicate;
return this;
}
///
/// Maps Close value
///
/// function that pulls close value
/// current mapper instance
public FinancialMapper Close(Func predicate)
{
return Close((t, i) => predicate(t));
}
///
/// Maps Close value
///
/// function that pulls close value, value and index as parameters
/// current mapper instance
public FinancialMapper Close(Func predicate)
{
_close = predicate;
return this;
}
///
/// Maps Low value
///
/// function that pulls low value
/// current mapper instance
public FinancialMapper Low(Func predicate)
{
return Low((t, i) => predicate(t));
}
///
/// Maps Low value
///
/// function that pulls low value, index and value as parameters
/// current mapper instance
public FinancialMapper Low(Func predicate)
{
_low = predicate;
return this;
}
}
}