Skip to content

Commit

Permalink
Merge pull request Live-Charts#441 from beto-rodriguez/develop
Browse files Browse the repository at this point in the history
0.9 release
  • Loading branch information
beto-rodriguez authored Jan 17, 2017
2 parents f28412d + 3d66109 commit 9b1320d
Show file tree
Hide file tree
Showing 68 changed files with 1,798 additions and 308 deletions.
10 changes: 7 additions & 3 deletions Core/AxisCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,15 @@ public IEnumerable<SeparatorElementCore> CurrentSeparators
internal double BotSeriesLimit { get; set; }
internal double MaxPointRadius { get; set; }
internal double Magnitude { get; set; }
internal int CleanFactor { get; set; }
internal double CleanFactor { get; set; }
internal Dictionary<double, SeparatorElementCore> Cache { get; set; }
internal double? LastAxisMax { get; set; }
internal double? LastAxisMin { get; set; }
internal CoreRectangle LastPlotArea { get; set; }
internal int GarbageCollectorIndex { get; set; }
internal double PreviousTop { get; set; }
internal double PreviousBot { get; set; }

#endregion

#region Internal Methods
Expand Down Expand Up @@ -239,7 +240,7 @@ internal void CalculateSeparator(ChartCore chart, AxisOrientation source)
if (Labels != null) S = S < 1 ? 1 : S;
}

internal CoreMargin PrepareChart(AxisOrientation source, ChartCore chart)
internal virtual CoreMargin PrepareChart(AxisOrientation source, ChartCore chart)
{
if (!(Math.Abs(TopLimit - BotLimit) > S*.01) || !ShowLabels) return new CoreMargin();

Expand Down Expand Up @@ -472,7 +473,10 @@ public void ClearSeparators()

#region Privates

private void InitializeGarbageCollector()
/// <summary>
/// Initializes the garbage collector.
/// </summary>
protected void InitializeGarbageCollector()
{
if (GarbageCollectorIndex == int.MaxValue)
{
Expand Down
30 changes: 18 additions & 12 deletions Core/Charts/CartesianChartCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void PrepareAxes()
xi.CalculateSeparator(this, AxisOrientation.X);

// ReSharper disable once AccessToModifiedClosure
SetAxisLimits(xi, cartesianSeries.Where(x => x.View.ScalesXAt == index), AxisOrientation.X);
SetAxisLimits(xi, cartesianSeries.Where(x => x.View.ScalesXAt == index).ToArray(), AxisOrientation.X);

if (Math.Abs(xi.BotLimit - xi.TopLimit) < xi.S * .01)
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public override void PrepareAxes()
yi.CalculateSeparator(this, AxisOrientation.Y);

// ReSharper disable once AccessToModifiedClosure
SetAxisLimits(yi, cartesianSeries.Where(x => x.View.ScalesYAt == index), AxisOrientation.Y);
SetAxisLimits(yi, cartesianSeries.Where(x => x.View.ScalesYAt == index).ToArray(), AxisOrientation.Y);

if (Math.Abs(yi.BotLimit - yi.TopLimit) < yi.S * .01)
{
Expand Down Expand Up @@ -188,20 +188,26 @@ public void DrawOrUpdateSections()

#region Privates

private static void SetAxisLimits(AxisCore ax, IEnumerable<ICartesianSeries> series, AxisOrientation orientation)
private static void SetAxisLimits(AxisCore ax, IList<ICartesianSeries> series, AxisOrientation orientation)
{
// [ max, min, pointRadius ]
var boundries = new[] { double.MinValue, double.MaxValue, 0d };
var first = new CoreLimit();
var firstR = 0d;

//yi.BotLimit = double.IsNaN(yi.MinValue) ? cartesianSeries.Where(x => x.View.ScalesYAt == index)
// .Select(x => x.GetMinY(yi))
// .DefaultIfEmpty(0).Min() : yi.MinValue;
//yi.TopLimit = double.IsNaN(yi.MaxValue) ? cartesianSeries.Where(x => x.View.ScalesYAt == index)
// .Select(x => x.GetMaxY(yi))
// .DefaultIfEmpty(0).Max() : yi.MaxValue;
if (series.Count > 0)
{
first = orientation == AxisOrientation.X
? new CoreLimit(series[0].GetMinX(ax), series[0].GetMaxX(ax))
: new CoreLimit(series[0].GetMinY(ax), series[0].GetMaxY(ax));
var view = series[0].View as IAreaPoint;
firstR = view != null ? view.GetPointDiameter() : 0;
}

// [ max, min, pointRadius ]
var boundries = new[] { first.Max, first.Min, firstR };

foreach (var cartesianSeries in series)
for (var index = 1; index < series.Count; index++)
{
var cartesianSeries = series[index];
var limit = orientation == AxisOrientation.X
? new CoreLimit(cartesianSeries.GetMinX(ax), cartesianSeries.GetMaxX(ax))
: new CoreLimit(cartesianSeries.GetMinY(ax), cartesianSeries.GetMaxY(ax));
Expand Down
23 changes: 18 additions & 5 deletions Core/Charts/ChartCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public virtual void PrepareAxes()
AxisX[index],
View.ActualSeries
// ReSharper disable once AccessToModifiedClosure
.Where(series => series.Values != null && series.ScalesXAt == index),
.Where(series => series.Values != null && series.ScalesXAt == index).ToArray(),
AxisOrientation.X);
}

Expand All @@ -212,7 +212,7 @@ public virtual void PrepareAxes()
AxisY[index],
View.ActualSeries
// ReSharper disable once AccessToModifiedClosure
.Where(series => series.Values != null && series.ScalesYAt == index),
.Where(series => series.Values != null && series.ScalesYAt == index).ToArray(),
AxisOrientation.Y);
}
}
Expand Down Expand Up @@ -677,13 +677,26 @@ protected void StackPoints(IEnumerable<ISeriesView> stackables, AxisOrientation
#endregion

#region Privates
private static void SetAxisLimits(AxisCore ax, IEnumerable<ISeriesView> series, AxisOrientation orientation)
private static void SetAxisLimits(AxisCore ax, IList<ISeriesView> series, AxisOrientation orientation)
{
var first = new CoreLimit();
var firstR = 0d;

if (series.Count > 0)
{
first = orientation == AxisOrientation.X
? series[0].Values.GetTracker(series[0]).XLimit
: series[0].Values.GetTracker(series[0]).YLimit;
var view = series[0] as IAreaPoint;
firstR = view != null ? view.GetPointDiameter() : 0;
}

// [ max, min, pointRadius ]
var boundries = new [] {double.MinValue, double.MaxValue, 0d};
var boundries = new[] {first.Max, first.Min, firstR};

foreach (var seriesView in series)
for (var index = 1; index < series.Count; index++)
{
var seriesView = series[index];
var tracker = seriesView.Values.GetTracker(seriesView);
var limit = orientation == AxisOrientation.X ? tracker.XLimit : tracker.YLimit;
var view = seriesView as IAreaPoint;
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="Definitions\Charts\ICartesianChart.cs" />
<Compile Include="Definitions\Charts\ICartesianVisualElement.cs" />
<Compile Include="Definitions\Charts\IChartView.cs" />
<Compile Include="Definitions\Charts\ILogarithmicAxisView.cs" />
<Compile Include="Definitions\Charts\IPieChart.cs" />
<Compile Include="Definitions\Charts\ISeparatorElementView.cs" />
<Compile Include="Definitions\Charts\ISeparatorView.cs" />
Expand Down Expand Up @@ -126,6 +127,7 @@
<Compile Include="IChartValues.cs" />
<Compile Include="IObservableChartPoint.cs" />
<Compile Include="LegendLocation.cs" />
<Compile Include="LogarithmicAxisCore.cs" />
<Compile Include="Maps\MapData.cs" />
<Compile Include="PointTracker.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
39 changes: 39 additions & 0 deletions Core/Definitions/Charts/ILogarithmicAxisView.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.Definitions.Charts
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.Definitions.Charts.IAxisView" />
public interface ILogarithmicAxisView : IAxisView
{
/// <summary>
/// Gets or sets the base.
/// </summary>
/// <value>
/// The base.
/// </value>
double Base { get; set; }
}
}
3 changes: 2 additions & 1 deletion Core/Events/Delegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace LiveCharts.Events
/// <summary>
///
/// </summary>
public delegate void UpdaterTickHandler();
/// <param name="sender">The sender.</param>
public delegate void UpdaterTickHandler(object sender);

/// <summary>
///
Expand Down
157 changes: 157 additions & 0 deletions Core/LogarithmicAxisCore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
//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.

using System;
using LiveCharts.Charts;
using LiveCharts.Definitions.Charts;
using LiveCharts.Dtos;

namespace LiveCharts
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.AxisCore" />
public class LogarithmicAxisCore : AxisCore
{
/// <summary>
/// Initializes a new instance of the <see cref="LogarithmicAxisCore"/> class.
/// </summary>
/// <param name="view">The view.</param>
public LogarithmicAxisCore(IAxisView view) : base(view)
{
CleanFactor = 1.5;
}

internal override CoreMargin PrepareChart(AxisOrientation source, ChartCore chart)
{
if (!(Math.Abs(TopLimit - BotLimit) > S * .01) || !ShowLabels) return new CoreMargin();

CalculateSeparator(chart, source);

var f = GetFormatter();

var currentMargin = new CoreMargin();
if (S < 1) S = 1;
var tolerance = S / 10;

InitializeGarbageCollector();

var bl = Math.Ceiling(BotLimit / Magnitude) * Magnitude;
var @base = ((ILogarithmicAxisView) View).Base;

for (var i = bl; i <= TopLimit - (EvaluatesUnitWidth ? 1 : 0); i += S)
{
var minTolerance = tolerance/10;
if (Math.Abs(i - bl) > tolerance)
{
var step = Math.Pow(@base, i - 1);
for (var j = Math.Pow(@base, i - 1) + step;
j < Math.Pow(@base, i);
j += step)
{
SeparatorElementCore minorAsc;
var scaledJ = Math.Log(j, @base);

var minorKey = Math.Round(scaledJ / minTolerance) * minTolerance;
if (!Cache.TryGetValue(minorKey, out minorAsc))
{
minorAsc = new SeparatorElementCore { IsNew = true };
Cache[minorKey] = minorAsc;
}
else
{
minorAsc.IsNew = false;
}

View.RenderSeparator(minorAsc, Chart);

minorAsc.Key = minorKey;
minorAsc.Value = scaledJ;
minorAsc.GarbageCollectorIndex = GarbageCollectorIndex;

minorAsc.View.UpdateLabel(string.Empty, this, source);

if (LastAxisMax == null)
{
minorAsc.State = SeparationState.InitialAdd;
continue;
}

minorAsc.State = SeparationState.Keep;
}
}

SeparatorElementCore asc;

var key = Math.Round(i / tolerance) * tolerance;
if (!Cache.TryGetValue(key, out asc))
{
asc = new SeparatorElementCore { IsNew = true };
Cache[key] = asc;
}
else
{
asc.IsNew = false;
}

View.RenderSeparator(asc, Chart);

asc.Key = key;
asc.Value = i;
asc.GarbageCollectorIndex = GarbageCollectorIndex;

var labelsMargin = asc.View.UpdateLabel(f(i), this, source);

currentMargin.Width = labelsMargin.TakenWidth > currentMargin.Width
? labelsMargin.TakenWidth
: currentMargin.Width;
currentMargin.Height = labelsMargin.TakenHeight > currentMargin.Height
? labelsMargin.TakenHeight
: currentMargin.Height;

currentMargin.Left = labelsMargin.Left > currentMargin.Left
? labelsMargin.Left
: currentMargin.Left;
currentMargin.Right = labelsMargin.Right > currentMargin.Right
? labelsMargin.Right
: currentMargin.Right;

currentMargin.Top = labelsMargin.Top > currentMargin.Top
? labelsMargin.Top
: currentMargin.Top;
currentMargin.Bottom = labelsMargin.Bottom > currentMargin.Bottom
? labelsMargin.Bottom
: currentMargin.Bottom;

if (LastAxisMax == null)
{
asc.State = SeparationState.InitialAdd;
continue;
}

asc.State = SeparationState.Keep;
}
return currentMargin;
}
}
}
4 changes: 2 additions & 2 deletions Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.8.1.1")]
[assembly: AssemblyFileVersion("0.8.1.1")]
[assembly: AssemblyVersion("0.9")]
[assembly: AssemblyFileVersion("0.9")]

[assembly: InternalsVisibleTo("LiveCharts.Wpf")]
[assembly: InternalsVisibleTo("LiveCharts.Uwp")]
Expand Down
Loading

0 comments on commit 9b1320d

Please sign in to comment.