项目结构调整

This commit is contained in:
艾竹
2023-04-16 20:11:40 +08:00
parent cbfbf96033
commit 81f91f3f35
2124 changed files with 218 additions and 5516 deletions

View File

@@ -0,0 +1,117 @@
//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 LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class CandleAlgorithm : SeriesAlgorithm, ICartesianSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="CandleAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public CandleAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Horizontal;
PreferredSelectionMode = TooltipSelectionMode.SharedXValues;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var castedSeries = (IFinancialSeriesView) View;
const double padding = 1.2;
var totalSpace = ChartFunctions.GetUnitWidth(AxisOrientation.X, Chart, View.ScalesXAt) - padding;
double exceed = 0;
double candleWidth;
if (totalSpace > castedSeries.MaxColumnWidth)
{
exceed = totalSpace - castedSeries.MaxColumnWidth;
candleWidth = castedSeries.MaxColumnWidth;
}
else
{
candleWidth = totalSpace;
}
foreach (var chartPoint in View.ActualValues.GetPoints(View))
{
var x = ChartFunctions.ToDrawMargin(chartPoint.X, AxisOrientation.X, Chart, View.ScalesXAt);
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels ? View.GetLabelPointFormatter()(chartPoint) : null);
chartPoint.SeriesView = View;
var candeView = (IOhlcPointView) chartPoint.View;
candeView.Open = ChartFunctions.ToDrawMargin(chartPoint.Open, AxisOrientation.Y, Chart, View.ScalesYAt);
candeView.Close = ChartFunctions.ToDrawMargin(chartPoint.Close, AxisOrientation.Y, Chart, View.ScalesYAt);
candeView.High = ChartFunctions.ToDrawMargin(chartPoint.High, AxisOrientation.Y, Chart, View.ScalesYAt);
candeView.Low = ChartFunctions.ToDrawMargin(chartPoint.Low, AxisOrientation.Y, Chart, View.ScalesYAt);
candeView.Width = candleWidth - padding > 0 ? candleWidth - padding : 0;
candeView.Left = x + exceed/2 + padding;
candeView.StartReference = (candeView.High + candeView.Low)/2;
chartPoint.ChartLocation = new CorePoint(x + exceed/2, (candeView.High + candeView.Low)/2);
chartPoint.View.DrawOrMove(null, chartPoint, 0, Chart);
}
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return AxisLimits.UnitRight(axis);
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return AxisLimits.SeparatorMin(axis);
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return AxisLimits.SeparatorMaxRounded(axis);
}
}
}

View File

@@ -0,0 +1,146 @@
//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;
using System.Linq;
using LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class ColumnAlgorithm : SeriesAlgorithm, ICartesianSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="ColumnAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public ColumnAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Horizontal;
PreferredSelectionMode = TooltipSelectionMode.SharedXValues;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var columnSeries = (IColumnSeriesView) View;
var padding = columnSeries.ColumnPadding;
var totalSpace = ChartFunctions.GetUnitWidth(AxisOrientation.X, Chart, View.ScalesXAt) - padding;
var typeSeries = Chart.View.ActualSeries.Where(x =>
{
if (x == View) return true;
var icsv = x as IColumnSeriesView;
return icsv != null && icsv.SharesPosition;
}).ToList();
var singleColWidth = totalSpace / typeSeries.Count;
double exceed = 0;
var seriesPosition = typeSeries.IndexOf(columnSeries);
if (singleColWidth > columnSeries.MaxColumnWidth)
{
exceed = (singleColWidth - columnSeries.MaxColumnWidth)*typeSeries.Count/2;
singleColWidth = columnSeries.MaxColumnWidth;
}
var relativeLeft = padding + exceed + singleColWidth*(seriesPosition);
var startAt = CurrentYAxis.FirstSeparator >= 0 && CurrentYAxis.LastSeparator > 0 //both positive
? CurrentYAxis.FirstSeparator //then use axisYMin
: (CurrentYAxis.FirstSeparator < 0 && CurrentYAxis.LastSeparator <= 0 //both negative
? CurrentYAxis.LastSeparator //then use axisYMax
: 0); //if mixed then use 0
var zero = ChartFunctions.ToDrawMargin(startAt, AxisOrientation.Y, Chart, View.ScalesYAt);
foreach (var chartPoint in View.ActualValues.GetPoints(View))
{
var reference =
ChartFunctions.ToDrawMargin(chartPoint, View.ScalesXAt, View.ScalesYAt, Chart);
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels ? View.GetLabelPointFormatter()(chartPoint) : null);
chartPoint.SeriesView = View;
var rectangleView = (IRectanglePointView) chartPoint.View;
var h = Math.Abs(reference.Y - zero);
var t = reference.Y < zero
? reference.Y
: zero;
rectangleView.Data.Height = h;
rectangleView.Data.Top = t;
rectangleView.Data.Left = reference.X + relativeLeft;
rectangleView.Data.Width = singleColWidth - padding;
rectangleView.ZeroReference = zero;
chartPoint.ChartLocation = new CorePoint(rectangleView.Data.Left + singleColWidth/2 - padding/2,
t);
chartPoint.View.DrawOrMove(null, chartPoint, 0, Chart);
}
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return AxisLimits.UnitRight(axis);
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
var f = AxisLimits.SeparatorMin(axis);
return CurrentYAxis.BotLimit >= 0 && CurrentYAxis.TopLimit > 0
? (f >= 0 ? f : 0)
: f;
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
var f = AxisLimits.SeparatorMaxRounded(axis);
return CurrentYAxis.BotLimit < 0 && CurrentYAxis.TopLimit <= 0
? (f >= 0 ? f : 0)
: f;
}
}
}

View File

@@ -0,0 +1,195 @@
//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.5
using System.Collections.Generic;
using System.Linq;
using LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
using LiveCharts.Helpers;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class HeatAlgorithm : SeriesAlgorithm, ICartesianSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="HeatAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public HeatAlgorithm(ISeriesView view) : base(view)
{
PreferredSelectionMode = TooltipSelectionMode.OnlySender;
}
/// <summary>
/// Updates this instance.
/// </summary>
/// <exception cref="LiveCharts.Helpers.LiveChartsException">There is no a valid gradient to create a heat series.</exception>
public override void Update()
{
var heatSeries = (IHeatSeriesView)View;
var uw = new CorePoint(
0 * ChartFunctions.GetUnitWidth(AxisOrientation.X, Chart, View.ScalesXAt) / 2,
-ChartFunctions.GetUnitWidth(AxisOrientation.Y, Chart, View.ScalesYAt));
// ReSharper disable once CompareOfFloatsByEqualityOperator
var wd = CurrentXAxis.TopLimit - CurrentXAxis.BotLimit == 0
? double.MaxValue
: CurrentXAxis.TopLimit - CurrentXAxis.BotLimit;
// ReSharper disable once CompareOfFloatsByEqualityOperator
var hd = CurrentYAxis.TopLimit - CurrentYAxis.BotLimit == 0
? double.MaxValue
: CurrentYAxis.TopLimit - CurrentYAxis.BotLimit;
var w = Chart.DrawMargin.Width / wd;
var h = Chart.DrawMargin.Height / hd;
//lets force the gradients to always have an 'interpol-able' model
if (!heatSeries.Stops.Any())
throw new LiveChartsException("There is no a valid gradient to create a heat series.");
var correctedGradients = heatSeries.Stops.Select(x => new CoreGradientStop
{
Color = x.Color,
Offset = x.Offset < 0 ? 0 : (x.Offset > 1 ? 1 : x.Offset)
}).ToList();
var min = correctedGradients[0];
min.Offset = 0;
correctedGradients.Insert(0, min);
var max = correctedGradients[correctedGradients.Count - 1];
max.Offset = 1;
correctedGradients.Add(max);
foreach (var chartPoint in View.ActualValues.GetPoints(View))
{
chartPoint.ChartLocation = ChartFunctions.ToDrawMargin(
chartPoint, View.ScalesXAt, View.ScalesYAt, Chart) + uw;
chartPoint.SeriesView = View;
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels ? View.GetLabelPointFormatter()(chartPoint) : null);
var heatView = (IHeatPointView)chartPoint.View;
heatView.ColorComponents = ColorInterpolation(correctedGradients,
(chartPoint.Weight - Chart.WLimit.Min)/(Chart.WLimit.Max - Chart.WLimit.Min));
heatView.Width = w;
heatView.Height = h;
chartPoint.View.DrawOrMove(null, chartPoint, 0, Chart);
}
}
/// <summary>
/// Gets the minimum x.
/// </summary>
/// <param name="axis">The axis.</param>
/// <returns></returns>
public double GetMinX(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
/// <summary>
/// Gets the maximum x.
/// </summary>
/// <param name="axis">The axis.</param>
/// <returns></returns>
public double GetMaxX(AxisCore axis)
{
return AxisLimits.StretchMax(axis) + 1;
}
/// <summary>
/// Gets the minimum y.
/// </summary>
/// <param name="axis">The axis.</param>
/// <returns></returns>
public double GetMinY(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
/// <summary>
/// Gets the maximum y.
/// </summary>
/// <param name="axis">The axis.</param>
/// <returns></returns>
public double GetMaxY(AxisCore axis)
{
return AxisLimits.StretchMax(axis) + 1;
}
private static CoreColor ColorInterpolation(IList<CoreGradientStop> gradients, double weight)
{
CoreColor from = new CoreColor(0, 0, 0, 0), to = new CoreColor(0, 0, 0, 0);
double fromOffset = 0, toOffset = 0;
for (var i = 0; i < gradients.Count; i++)
{
// ReSharper disable once InvertIf
if (double.IsNaN(weight) || gradients[i].Offset <= weight && gradients[i + 1].Offset >= weight)
{
from = gradients[i].Color;
to = gradients[i + 1].Color;
fromOffset = gradients[i].Offset;
toOffset = gradients[i + 1].Offset;
break;
}
}
return new CoreColor(
InterpolateColorComponent(from.A, to.A, fromOffset, toOffset, weight),
InterpolateColorComponent(from.R, to.R, fromOffset, toOffset, weight),
InterpolateColorComponent(from.G, to.G, fromOffset, toOffset, weight),
InterpolateColorComponent(from.B, to.B, fromOffset, toOffset, weight));
}
private static byte InterpolateColorComponent(byte fromComponent, byte toComponent,
double fromOffset, double toOffset, double value)
{
if (fromComponent == toComponent)
{
return fromComponent;
}
else
{
var deltaX = toOffset - fromOffset;
// ReSharper disable once CompareOfFloatsByEqualityOperator
var m = (toComponent - fromComponent) / (deltaX == 0 ? double.MinValue : deltaX);
return (byte)(m * (value - fromOffset) + fromComponent);
}
}
}
}

View File

@@ -0,0 +1,212 @@
//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;
using System.Linq;
using LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
using LiveCharts.Helpers;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class LineAlgorithm : SeriesAlgorithm, ICartesianSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="LineAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public LineAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Horizontal;
PreferredSelectionMode = TooltipSelectionMode.SharedXValues;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var points = View.ActualValues.GetPoints(View).ToArray();
var segmentPosition = 0;
var lineView = (ILineSeriesView) View;
var smoothness = lineView.LineSmoothness;
smoothness = smoothness > 1 ? 1 : (smoothness < 0 ? 0 : smoothness);
foreach (var segment in points.SplitEachNaN())
{
var p0 = segment.Count > 0
? ChartFunctions.ToDrawMargin(segment[0], View.ScalesXAt, View.ScalesYAt, Chart)
: new CorePoint(0, 0);
var p1 = segment.Count > 0
? ChartFunctions.ToDrawMargin(segment[0], View.ScalesXAt, View.ScalesYAt, Chart)
: p0;
var p2 = segment.Count > 1
? ChartFunctions.ToDrawMargin(segment[1], View.ScalesXAt, View.ScalesYAt, Chart)
: p1;
var p3 = segment.Count > 2
? ChartFunctions.ToDrawMargin(segment[2], View.ScalesXAt, View.ScalesYAt, Chart)
: p2;
var uw = new CorePoint(
CurrentXAxis.EvaluatesUnitWidth
? ChartFunctions.GetUnitWidth(AxisOrientation.X, Chart, View.ScalesXAt)/2
: 0,
CurrentYAxis.EvaluatesUnitWidth
? ChartFunctions.GetUnitWidth(AxisOrientation.Y, Chart, View.ScalesYAt)/2
: 0);
if (SeriesOrientation == SeriesOrientation.Horizontal)
{
p0 += uw;
p1 += uw;
p2 += uw;
p3 += uw;
}
else
{
p0 = new CorePoint(p0.X + uw.X, p0.Y - uw.Y);
p1 = new CorePoint(p1.X + uw.X, p1.Y - uw.Y);
p2 = new CorePoint(p2.X + uw.X, p2.Y - uw.Y);
p3 = new CorePoint(p3.X + uw.X, p3.Y - uw.Y);
}
ChartPoint previousDrawn = null;
var isOpen = false;
for (var index = 0; index < segment.Count; index++)
{
if (!isOpen)
{
lineView.StartSegment(segmentPosition, p1);
segmentPosition += segmentPosition == 0 ? 1 : 2;
}
var chartPoint = segment[index];
chartPoint.ChartLocation = p1;
chartPoint.SeriesView = View;
var xc1 = (p0.X + p1.X)/2.0;
var yc1 = (p0.Y + p1.Y)/2.0;
var xc2 = (p1.X + p2.X)/2.0;
var yc2 = (p1.Y + p2.Y)/2.0;
var xc3 = (p2.X + p3.X)/2.0;
var yc3 = (p2.Y + p3.Y)/2.0;
var len1 = Math.Sqrt((p1.X - p0.X)*(p1.X - p0.X) + (p1.Y - p0.Y)*(p1.Y - p0.Y));
var len2 = Math.Sqrt((p2.X - p1.X)*(p2.X - p1.X) + (p2.Y - p1.Y)*(p2.Y - p1.Y));
var len3 = Math.Sqrt((p3.X - p2.X)*(p3.X - p2.X) + (p3.Y - p2.Y)*(p3.Y - p2.Y));
var k1 = len1/(len1 + len2);
var k2 = len2/(len2 + len3);
if (double.IsNaN(k1)) k1 = 0d;
if (double.IsNaN(k2)) k2 = 0d;
var xm1 = xc1 + (xc2 - xc1)*k1;
var ym1 = yc1 + (yc2 - yc1)*k1;
var xm2 = xc2 + (xc3 - xc2)*k2;
var ym2 = yc2 + (yc3 - yc2)*k2;
var c1X = xm1 + (xc2 - xm1)*smoothness + p1.X - xm1;
var c1Y = ym1 + (yc2 - ym1)*smoothness + p1.Y - ym1;
var c2X = xm2 + (xc2 - xm2)*smoothness + p2.X - xm2;
var c2Y = ym2 + (yc2 - ym2)*smoothness + p2.Y - ym2;
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels ? View.GetLabelPointFormatter()(chartPoint) : null);
var bezierView = chartPoint.View as IBezierPointView;
if (bezierView == null) continue;
bezierView.Data = index == segment.Count - 1
? new BezierData(new CorePoint(p1.X, p1.Y))
: new BezierData
{
Point1 = index == 0 ? new CorePoint(p1.X, p1.Y) : new CorePoint(c1X, c1Y),
Point2 = new CorePoint(c2X, c2Y),
Point3 = new CorePoint(p2.X, p2.Y)
};
chartPoint.View.DrawOrMove(previousDrawn, chartPoint, segmentPosition, Chart);
segmentPosition++;
previousDrawn = chartPoint.View.IsNew
? previousDrawn
: chartPoint;
p0 = new CorePoint(p1);
p1 = new CorePoint(p2);
p2 = new CorePoint(p3);
p3 = segment.Count > index + 3
? ChartFunctions.ToDrawMargin(segment[index + 3], View.ScalesXAt, View.ScalesYAt, Chart)
: p2;
if (SeriesOrientation == SeriesOrientation.Horizontal)
{
p3 += uw;
}
else
{
p3 = new CorePoint(p3.X + uw.X, p3.Y - uw.Y);
}
isOpen = true;
}
if (!isOpen) continue;
lineView.EndSegment(segmentPosition, p1);
segmentPosition++;
}
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return AxisLimits.StretchMax(axis);
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return AxisLimits.SeparatorMin(axis);
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return AxisLimits.SeparatorMaxRounded(axis);
}
}
}

View File

@@ -0,0 +1,117 @@
//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 LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class OhlcAlgorithm : SeriesAlgorithm, ICartesianSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="OhlcAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public OhlcAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Horizontal;
PreferredSelectionMode = TooltipSelectionMode.SharedXValues;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var castedSeries = (IFinancialSeriesView) View;
const double padding = 1.2;
var totalSpace = ChartFunctions.GetUnitWidth(AxisOrientation.X, Chart, View.ScalesXAt) - padding;
double exceed = 0;
double candleWidth = 0;
if (totalSpace > castedSeries.MaxColumnWidth)
{
exceed = totalSpace - castedSeries.MaxColumnWidth;
candleWidth = castedSeries.MaxColumnWidth;
}
else
{
candleWidth = totalSpace;
}
foreach (var chartPoint in View.ActualValues.GetPoints(View))
{
var x = ChartFunctions.ToDrawMargin(chartPoint.X, AxisOrientation.X, Chart, View.ScalesXAt);
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels ? View.GetLabelPointFormatter()(chartPoint) : null);
chartPoint.SeriesView = View;
var ohclView = (IOhlcPointView) chartPoint.View;
ohclView.Open = ChartFunctions.ToDrawMargin(chartPoint.Open, AxisOrientation.Y, Chart, View.ScalesYAt);
ohclView.Close = ChartFunctions.ToDrawMargin(chartPoint.Close, AxisOrientation.Y, Chart, View.ScalesYAt);
ohclView.High = ChartFunctions.ToDrawMargin(chartPoint.High, AxisOrientation.Y, Chart, View.ScalesYAt);
ohclView.Low = ChartFunctions.ToDrawMargin(chartPoint.Low, AxisOrientation.Y, Chart, View.ScalesYAt);
ohclView.Width = candleWidth - padding > 0 ? candleWidth - padding : 0;
ohclView.Left = x + exceed/2 + padding;
ohclView.StartReference = (ohclView.High + ohclView.Low)/2;
chartPoint.ChartLocation = new CorePoint(x + exceed/2, (ohclView.High + ohclView.Low)/2);
chartPoint.View.DrawOrMove(null, chartPoint, 0, Chart);
}
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return AxisLimits.UnitRight(axis);
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return AxisLimits.SeparatorMin(axis);
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return AxisLimits.SeparatorMaxRounded(axis);
}
}
}

View File

@@ -0,0 +1,97 @@
//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.Linq;
using LiveCharts.Definitions.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.IPieSeries" />
public class PieAlgorithm : SeriesAlgorithm, IPieSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="PieAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public PieAlgorithm(ISeriesView view) : base(view)
{
PreferredSelectionMode= TooltipSelectionMode.SharedXValues;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var pieChart = (IPieChart) View.Model.Chart.View;
var maxPushOut = View.Model.Chart.View.ActualSeries
.OfType<IPieSeriesView>()
.Select(x => x.PushOut)
.DefaultIfEmpty(0).Max();
var minDimension = Chart.DrawMargin.Width < Chart.DrawMargin.Height
? Chart.DrawMargin.Width
: Chart.DrawMargin.Height;
minDimension -= 10 + maxPushOut;
minDimension = minDimension < 10 ? 10 : minDimension;
var inner = pieChart.InnerRadius;
var startAt = pieChart.StartingRotationAngle > 360
? 360
: (pieChart.StartingRotationAngle < 0
? 0
: pieChart.StartingRotationAngle);
foreach (var chartPoint in View.ActualValues.GetPoints(View))
{
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels
? View.GetLabelPointFormatter()(chartPoint)
: null);
var pieSlice = (IPieSlicePointView) chartPoint.View;
var space = pieChart.InnerRadius +
((minDimension/2) - pieChart.InnerRadius)*((chartPoint.X + 1)/(View.Values.GetTracker(View).XLimit.Max + 1));
chartPoint.SeriesView = View;
pieSlice.Radius = space;
pieSlice.InnerRadius = inner;
pieSlice.Rotation = startAt + (chartPoint.StackedParticipation - chartPoint.Participation)*360;
pieSlice.Wedge = chartPoint.Participation*360 > 0 ? chartPoint.Participation*360 : 0;
chartPoint.View.DrawOrMove(null, chartPoint, 0, Chart);
inner = pieSlice.Radius;
}
}
}
}

View File

@@ -0,0 +1,150 @@
//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;
using System.Linq;
using LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class RowAlgorithm : SeriesAlgorithm, ICartesianSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="RowAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public RowAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Vertical;
PreferredSelectionMode = TooltipSelectionMode.SharedYInSeries;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var castedSeries = (IRowSeriesView) View;
var padding = castedSeries.RowPadding;
var totalSpace = ChartFunctions.GetUnitWidth(AxisOrientation.Y, Chart, View.ScalesYAt) - padding;
var typeSeries = Chart.View.ActualSeries.OfType<IRowSeriesView>().ToList();
var singleRowHeight = totalSpace/typeSeries.Count;
double exceed = 0;
var seriesPosition = typeSeries.IndexOf((IRowSeriesView) View);
if (singleRowHeight > castedSeries.MaxRowHeigth)
{
exceed = (singleRowHeight - castedSeries.MaxRowHeigth)*typeSeries.Count/2;
singleRowHeight = castedSeries.MaxRowHeigth;
}
var relativeTop = padding + exceed + singleRowHeight * (seriesPosition);
var startAt = CurrentXAxis.FirstSeparator >= 0 && CurrentXAxis.LastSeparator > 0 //both positive
? CurrentXAxis.FirstSeparator //then use Min
: (CurrentXAxis.FirstSeparator < 0 && CurrentXAxis.LastSeparator <= 0 //both negative
? CurrentXAxis.LastSeparator //then use Max
: 0); //if mixed then use 0
var zero = ChartFunctions.ToDrawMargin(startAt, AxisOrientation.X, Chart, View.ScalesXAt);
var correction = ChartFunctions.GetUnitWidth(AxisOrientation.Y, Chart, View.ScalesYAt);
foreach (var chartPoint in View.ActualValues.GetPoints(View))
{
var reference =
ChartFunctions.ToDrawMargin(chartPoint, View.ScalesXAt, View.ScalesYAt, Chart);
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels ? View.GetLabelPointFormatter()(chartPoint) : null);
chartPoint.SeriesView = View;
var rectangleView = (IRectanglePointView) chartPoint.View;
var w = Math.Abs(reference.X - zero);
var l = reference.X < zero
? reference.X
: zero;
if (chartPoint.EvaluatesGantt)
{
l = ChartFunctions.ToDrawMargin(chartPoint.XStart, AxisOrientation.X, Chart, View.ScalesXAt);
if (!(reference.X < zero && l < zero)) w -= l;
}
rectangleView.Data.Height = singleRowHeight - padding;
rectangleView.Data.Top = reference.Y + relativeTop - correction;
rectangleView.Data.Left = l;
rectangleView.Data.Width = w;
rectangleView.ZeroReference = zero;
chartPoint.ChartLocation = new CorePoint(rectangleView.Data.Left + rectangleView.Data.Width,
rectangleView.Data.Top);
chartPoint.View.DrawOrMove(null, chartPoint, 0, Chart);
}
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
var f = AxisLimits.SeparatorMin(axis);
return CurrentXAxis.BotLimit >= 0 && CurrentXAxis.TopLimit > 0
? (f >= 0 ? f : 0)
: f;
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
var f = AxisLimits.SeparatorMaxRounded(axis);
return CurrentXAxis.BotLimit < 0 && CurrentXAxis.TopLimit <= 0
? (f >= 0 ? f : 0)
: f;
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return AxisLimits.UnitRight(axis);
}
}
}

View File

@@ -0,0 +1,112 @@
//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 LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class ScatterAlgorithm : SeriesAlgorithm, ICartesianSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="ScatterAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public ScatterAlgorithm(ISeriesView view) : base(view)
{
PreferredSelectionMode = TooltipSelectionMode.OnlySender;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var bubbleSeries = (IScatterSeriesView) View;
var p1 = new CorePoint();
var p2 = new CorePoint();
p1.X = Chart.WLimit.Max;
p1.Y = bubbleSeries.MaxPointShapeDiameter;
p2.X = Chart.WLimit.Min;
p2.Y = bubbleSeries.MinPointShapeDiameter;
var deltaX = p2.X - p1.X;
// ReSharper disable once CompareOfFloatsByEqualityOperator
var m = (p2.Y - p1.Y) / (deltaX == 0 ? double.MinValue : deltaX);
var uw = new CorePoint(
CurrentXAxis.EvaluatesUnitWidth
? ChartFunctions.GetUnitWidth(AxisOrientation.X, Chart, View.ScalesXAt) / 2
: 0,
CurrentYAxis.EvaluatesUnitWidth
? ChartFunctions.GetUnitWidth(AxisOrientation.Y, Chart, View.ScalesYAt) / 2
: 0);
foreach (var chartPoint in View.ActualValues.GetPoints(View))
{
chartPoint.ChartLocation = ChartFunctions.ToDrawMargin(
chartPoint, View.ScalesXAt, View.ScalesYAt, Chart) + uw;
chartPoint.SeriesView = View;
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels ? View.GetLabelPointFormatter()(chartPoint) : null);
var bubbleView = (IScatterPointView) chartPoint.View;
bubbleView.Diameter = m*(chartPoint.Weight - p1.X) + p1.Y;
chartPoint.View.DrawOrMove(null, chartPoint, 0, Chart);
}
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return AxisLimits.StretchMax(axis);
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return AxisLimits.StretchMax(axis);
}
}
}

View File

@@ -0,0 +1,210 @@
//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;
using System.Linq;
using LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
using LiveCharts.Helpers;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class StackedAreaAlgorithm : SeriesAlgorithm, ICartesianSeries
{
private readonly IStackModelableSeriesView _stackModelable;
/// <summary>
/// Initializes a new instance of the <see cref="StackedAreaAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public StackedAreaAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Horizontal;
_stackModelable = (IStackModelableSeriesView)view;
PreferredSelectionMode = TooltipSelectionMode.SharedXValues;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var points = View.ActualValues.GetPoints(View).ToList();
var segmentPosition = 0;
var lineView = View as ILineSeriesView;
if (lineView == null) return;
var smoothness = lineView.LineSmoothness;
smoothness = smoothness > 1 ? 1 : (smoothness < 0 ? 0 : smoothness);
foreach (var segment in points.SplitEachNaN())
{
var p0 = segment.Count > 0
? GetStackedPoint(segment[0])
: new CorePoint(0, 0);
var p1 = segment.Count > 0
? GetStackedPoint(segment[0])
: p0;
var p2 = segment.Count > 1
? GetStackedPoint(segment[1])
: p1;
var p3 = segment.Count > 2
? GetStackedPoint(segment[2])
: p2;
var uw = new CorePoint(
CurrentXAxis.EvaluatesUnitWidth
? ChartFunctions.GetUnitWidth(AxisOrientation.X, Chart, View.ScalesXAt) / 2
: 0,
CurrentYAxis.EvaluatesUnitWidth
? ChartFunctions.GetUnitWidth(AxisOrientation.Y, Chart, View.ScalesYAt) / 2
: 0);
p0 += uw;
p1 += uw;
p2 += uw;
p3 += uw;
lineView.StartSegment(segmentPosition, p1);
segmentPosition += segmentPosition == 0 ? 1 : 2;
ChartPoint previousDrawn = null;
for (var index = 0; index < segment.Count; index++)
{
var chartPoint = segment[index];
chartPoint.ChartLocation = p1;
chartPoint.SeriesView = View;
var xc1 = (p0.X + p1.X) / 2.0;
var yc1 = (p0.Y + p1.Y) / 2.0;
var xc2 = (p1.X + p2.X) / 2.0;
var yc2 = (p1.Y + p2.Y) / 2.0;
var xc3 = (p2.X + p3.X) / 2.0;
var yc3 = (p2.Y + p3.Y) / 2.0;
var len1 = Math.Sqrt((p1.X - p0.X) * (p1.X - p0.X) + (p1.Y - p0.Y) * (p1.Y - p0.Y));
var len2 = Math.Sqrt((p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) * (p2.Y - p1.Y));
var len3 = Math.Sqrt((p3.X - p2.X) * (p3.X - p2.X) + (p3.Y - p2.Y) * (p3.Y - p2.Y));
var k1 = len1 / (len1 + len2);
var k2 = len2 / (len2 + len3);
if (double.IsNaN(k1)) k1 = 0d;
if (double.IsNaN(k2)) k2 = 0d;
var xm1 = xc1 + (xc2 - xc1) * k1;
var ym1 = yc1 + (yc2 - yc1) * k1;
var xm2 = xc2 + (xc3 - xc2) * k2;
var ym2 = yc2 + (yc3 - yc2) * k2;
var c1X = xm1 + (xc2 - xm1) * smoothness + p1.X - xm1;
var c1Y = ym1 + (yc2 - ym1) * smoothness + p1.Y - ym1;
var c2X = xm2 + (xc2 - xm2) * smoothness + p2.X - xm2;
var c2Y = ym2 + (yc2 - ym2) * smoothness + p2.Y - ym2;
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels
? (chartPoint.Participation > 0.05 ? View.GetLabelPointFormatter()(chartPoint) : string.Empty)
: null);
var bezierView = chartPoint.View as IBezierPointView;
if (bezierView == null) continue;
bezierView.Data = index == segment.Count - 1
? new BezierData(new CorePoint(p1.X, p1.Y))
: new BezierData
{
Point1 = index == 0 ? new CorePoint(p1.X, p1.Y) : new CorePoint(c1X, c1Y),
Point2 = new CorePoint(c2X, c2Y),
Point3 = new CorePoint(p2.X, p2.Y)
};
chartPoint.View.DrawOrMove(previousDrawn, chartPoint, segmentPosition, Chart);
segmentPosition++;
previousDrawn = chartPoint.View.IsNew
? previousDrawn
: chartPoint;
p0 = new CorePoint(p1);
p1 = new CorePoint(p2);
p2 = new CorePoint(p3);
p3 = segment.Count > index + 3
? GetStackedPoint(segment[index + 3])
: p2;
p3 += uw;
}
lineView.EndSegment(segmentPosition, p1);
segmentPosition++;
}
}
/// <summary>
/// Gets the stacked point.
/// </summary>
/// <param name="chartPoint">The chart point.</param>
/// <returns></returns>
protected virtual CorePoint GetStackedPoint(ChartPoint chartPoint)
{
if (_stackModelable.StackMode == StackMode.Values)
return new CorePoint(
ChartFunctions.ToDrawMargin(chartPoint.X, AxisOrientation.X, Chart, View.ScalesXAt),
ChartFunctions.ToDrawMargin(chartPoint.To, AxisOrientation.Y, Chart, View.ScalesYAt));
return new CorePoint(
ChartFunctions.ToDrawMargin(chartPoint.X, AxisOrientation.X, Chart, View.ScalesXAt),
ChartFunctions.ToDrawMargin(chartPoint.StackedParticipation, AxisOrientation.Y, Chart, View.ScalesYAt));
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return AxisLimits.StretchMax(axis);
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return AxisLimits.SeparatorMaxRounded(axis);
}
}
}

View File

@@ -0,0 +1,144 @@
//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;
using LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class StackedColumnAlgorithm : SeriesAlgorithm , ICartesianSeries
{
private readonly IStackModelableSeriesView _stackModelable;
/// <summary>
/// Initializes a new instance of the <see cref="StackedColumnAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public StackedColumnAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Horizontal;
_stackModelable = (IStackModelableSeriesView) view;
PreferredSelectionMode = TooltipSelectionMode.SharedXValues;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var castedSeries = (IStackedColumnSeriesView) View;
var padding = castedSeries.ColumnPadding;
var totalSpace = ChartFunctions.GetUnitWidth(AxisOrientation.X, Chart, View.ScalesXAt) - padding;
var singleColWidth = totalSpace;
double exceed = 0;
if (singleColWidth > castedSeries.MaxColumnWidth)
{
exceed = (singleColWidth - castedSeries.MaxColumnWidth)/2;
singleColWidth = castedSeries.MaxColumnWidth;
}
var relativeLeft = padding + exceed;
var startAt = CurrentYAxis.FirstSeparator >= 0 && CurrentYAxis.LastSeparator > 0
? CurrentYAxis.FirstSeparator
: (CurrentYAxis.FirstSeparator < 0 && CurrentYAxis.LastSeparator <= 0
? CurrentYAxis.LastSeparator
: 0);
var zero = ChartFunctions.ToDrawMargin(startAt, AxisOrientation.Y, Chart, View.ScalesYAt);
foreach (var chartPoint in View.ActualValues.GetPoints(View))
{
var x = ChartFunctions.ToDrawMargin(chartPoint.X, AxisOrientation.X, Chart, View.ScalesXAt);
var from = _stackModelable.StackMode == StackMode.Values
? ChartFunctions.ToDrawMargin(chartPoint.From, AxisOrientation.Y, Chart, View.ScalesYAt)
: ChartFunctions.ToDrawMargin(chartPoint.From/chartPoint.Sum, AxisOrientation.Y, Chart, View.ScalesYAt);
var to = _stackModelable.StackMode == StackMode.Values
? ChartFunctions.ToDrawMargin(chartPoint.To, AxisOrientation.Y, Chart, View.ScalesYAt)
: ChartFunctions.ToDrawMargin(chartPoint.To/chartPoint.Sum, AxisOrientation.Y, Chart, View.ScalesYAt);
if (double.IsNaN(from)) from = 0;
if (double.IsNaN(to)) to = 0;
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels
? (chartPoint.Participation > 0.05
? View.GetLabelPointFormatter()(chartPoint)
: string.Empty)
: null);
chartPoint.SeriesView = View;
var rectangleView = (IRectanglePointView) chartPoint.View;
var h = Math.Abs(to - zero) - Math.Abs(from - zero);
var t = to < zero
? to
: from;
rectangleView.Data.Height = h;
rectangleView.Data.Top = t;
rectangleView.Data.Left = x + relativeLeft;
rectangleView.Data.Width = singleColWidth - padding;
rectangleView.ZeroReference = zero;
chartPoint.ChartLocation = new CorePoint(rectangleView.Data.Left + singleColWidth/2 - padding/2,
t);
chartPoint.View.DrawOrMove(null, chartPoint, 0, Chart);
}
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return AxisLimits.UnitRight(axis);
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return double.MaxValue;
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return double.MinValue;
}
}
}

View File

@@ -0,0 +1,141 @@
//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;
using LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class StackedRowAlgorithm : SeriesAlgorithm, ICartesianSeries
{
private readonly IStackModelableSeriesView _stackModelable;
/// <summary>
/// Initializes a new instance of the <see cref="StackedRowAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public StackedRowAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Vertical;
_stackModelable = (IStackModelableSeriesView) view;
PreferredSelectionMode = TooltipSelectionMode.SharedYValues;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
var castedSeries = (IStackedRowSeriesView) View;
var padding = castedSeries.RowPadding;
var totalSpace = ChartFunctions.GetUnitWidth(AxisOrientation.Y, Chart, View.ScalesYAt) - padding;
var singleColHeigth = totalSpace;
double exceed = 0;
if (singleColHeigth > castedSeries.MaxRowHeight)
{
exceed = (singleColHeigth - castedSeries.MaxRowHeight)/2;
singleColHeigth = castedSeries.MaxRowHeight;
}
var relativeTop = padding + exceed;
var startAt = CurrentXAxis.FirstSeparator >= 0 && CurrentXAxis.LastSeparator > 0
? CurrentXAxis.FirstSeparator
: (CurrentXAxis.FirstSeparator < 0 && CurrentXAxis.LastSeparator <= 0
? CurrentXAxis.LastSeparator
: 0);
var zero = ChartFunctions.ToDrawMargin(startAt, AxisOrientation.X, Chart, View.ScalesXAt);
foreach (var chartPoint in View.ActualValues.GetPoints(View))
{
var y = ChartFunctions.ToDrawMargin(chartPoint.Y, AxisOrientation.Y, Chart, View.ScalesYAt) - ChartFunctions.GetUnitWidth(AxisOrientation.Y, Chart, View.ScalesYAt);
var from = _stackModelable.StackMode == StackMode.Values
? ChartFunctions.ToDrawMargin(chartPoint.From, AxisOrientation.X, Chart, View.ScalesXAt)
: ChartFunctions.ToDrawMargin(chartPoint.From/chartPoint.Sum, AxisOrientation.X, Chart, View.ScalesXAt);
var to = _stackModelable.StackMode == StackMode.Values
? ChartFunctions.ToDrawMargin(chartPoint.To, AxisOrientation.X, Chart, View.ScalesXAt)
: ChartFunctions.ToDrawMargin(chartPoint.To/chartPoint.Sum, AxisOrientation.X, Chart, View.ScalesXAt);
chartPoint.View = View.GetPointView(chartPoint,
View.DataLabels
? (chartPoint.Participation > 0.05
? View.GetLabelPointFormatter()(chartPoint)
: string.Empty)
: null);
chartPoint.SeriesView = View;
var rectangleView = (IRectanglePointView) chartPoint.View;
var w = Math.Abs(to - zero) - Math.Abs(from - zero);
var l = to < zero
? to
: from;
rectangleView.Data.Height = singleColHeigth - padding;
rectangleView.Data.Top = y + relativeTop;
rectangleView.Data.Left = l;
rectangleView.Data.Width = w;
rectangleView.ZeroReference = zero;
chartPoint.ChartLocation = new CorePoint(rectangleView.Data.Left + rectangleView.Data.Width,
rectangleView.Data.Top);
chartPoint.View.DrawOrMove(null, chartPoint, 0, Chart);
}
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return double.MaxValue;
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return double.MinValue;
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return AxisLimits.UnitRight(axis);
}
}
}

View File

@@ -0,0 +1,101 @@
//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 LiveCharts.Defaults;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class StepLineAlgorithm : SeriesAlgorithm, ICartesianSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="StepLineAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public StepLineAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Horizontal;
PreferredSelectionMode = TooltipSelectionMode.SharedXValues;
}
/// <summary>
/// Updates this instance.
/// </summary>
public override void Update()
{
ChartPoint previous = null;
var i = 0;
foreach (var current in View.ActualValues.GetPoints(View))
{
current.View = View.GetPointView(current,
View.DataLabels ? View.GetLabelPointFormatter()(current) : null);
current.SeriesView = View;
var stepView = (IStepPointView) current.View;
current.ChartLocation = new CorePoint(
ChartFunctions.ToDrawMargin(current.X, AxisOrientation.X, Chart, View.ScalesXAt),
ChartFunctions.ToDrawMargin(current.Y, AxisOrientation.Y, Chart, View.ScalesYAt));
if (previous != null)
{
stepView.DeltaX = current.ChartLocation.X - previous.ChartLocation.X;
stepView.DeltaY = current.ChartLocation.Y - previous.ChartLocation.Y;
}
current.View.DrawOrMove(previous, current, i, Chart);
i++;
previous = current;
}
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return AxisLimits.StretchMax(axis);
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return AxisLimits.SeparatorMin(axis);
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return AxisLimits.SeparatorMaxRounded(axis);
}
}
}

View File

@@ -0,0 +1,65 @@
//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 LiveCharts.Defaults;
using LiveCharts.Definitions.Series;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithms.LineAlgorithm" />
/// <seealso cref="LiveCharts.Definitions.Series.ICartesianSeries" />
public class VerticalLineAlgorithm : LineAlgorithm, ICartesianSeries
{
/// <summary>
/// Initializes a new instance of the <see cref="VerticalLineAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public VerticalLineAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Vertical;
PreferredSelectionMode = TooltipSelectionMode.SharedYValues;
}
double ICartesianSeries.GetMinX(AxisCore axis)
{
return AxisLimits.SeparatorMin(axis);
}
double ICartesianSeries.GetMaxX(AxisCore axis)
{
return AxisLimits.SeparatorMaxRounded(axis);
}
double ICartesianSeries.GetMinY(AxisCore axis)
{
return AxisLimits.StretchMin(axis);
}
double ICartesianSeries.GetMaxY(AxisCore axis)
{
return AxisLimits.StretchMax(axis);
}
}
}

View File

@@ -0,0 +1,64 @@
//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 LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
namespace LiveCharts.SeriesAlgorithms
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.SeriesAlgorithms.StackedAreaAlgorithm" />
public class VerticalStackedAreaAlgorithm : StackedAreaAlgorithm
{
private readonly IStackModelableSeriesView _stackModelable;
/// <summary>
/// Initializes a new instance of the <see cref="VerticalStackedAreaAlgorithm"/> class.
/// </summary>
/// <param name="view">The view.</param>
public VerticalStackedAreaAlgorithm(ISeriesView view) : base(view)
{
SeriesOrientation = SeriesOrientation.Vertical;
_stackModelable = (IStackModelableSeriesView) view;
PreferredSelectionMode = TooltipSelectionMode.SharedYValues;
}
/// <summary>
/// Gets the stacked point.
/// </summary>
/// <param name="chartPoint">The chart point.</param>
/// <returns></returns>
protected override CorePoint GetStackedPoint(ChartPoint chartPoint)
{
if (_stackModelable.StackMode == StackMode.Values)
return new CorePoint(
ChartFunctions.ToDrawMargin(chartPoint.To, AxisOrientation.X, Chart, View.ScalesXAt),
ChartFunctions.ToDrawMargin(chartPoint.Y, AxisOrientation.Y, Chart, View.ScalesYAt));
return new CorePoint(
ChartFunctions.ToDrawMargin(chartPoint.StackedParticipation, AxisOrientation.X, Chart, View.ScalesXAt),
ChartFunctions.ToDrawMargin(chartPoint.Y, AxisOrientation.Y, Chart, View.ScalesYAt));
}
}
}