-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more feature, refactored the whole code base.
- Loading branch information
Showing
92 changed files
with
4,824 additions
and
2,863 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
CommonLib/Axis/AxisDrawingSettings/AxisDrawingSettingsBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using MvvmCharting.Common; | ||
|
||
namespace MvvmCharting.Axis | ||
{ | ||
public abstract class AxisDrawingSettingsBase : IAxisDrawingSettingsBase | ||
{ | ||
protected double PlottingLength { get; } | ||
protected double ActualTickInterval { get; set; } | ||
protected int ActualTickCount { get; set; } | ||
protected double PixelPerUnit { get; set; } | ||
|
||
protected AxisDrawingSettingsBase(double plottingLength) | ||
{ | ||
this.PlottingLength = plottingLength; | ||
} | ||
|
||
public abstract IEnumerable<object> GetPlottingValues(); | ||
|
||
|
||
public virtual bool CanUpdateAxisItems() | ||
{ | ||
return !this.PlottingLength.IsNaNOrZero() && !this.ActualTickInterval.IsNaNOrZero(); | ||
} | ||
|
||
public virtual bool CanUpdateAxisItemsCoordinate() | ||
{ | ||
return true; | ||
} | ||
|
||
public abstract double CalculateCoordinate(double value, AxisType axisType); | ||
|
||
|
||
public override bool Equals(object obj) | ||
{ | ||
return Equals(obj as AxisDrawingSettingsBase); | ||
} | ||
|
||
public virtual bool Equals(AxisDrawingSettingsBase other) | ||
{ | ||
|
||
if (other == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return this.PlottingLength.NearlyEqual(other.PlottingLength, 0.0001) && | ||
this.ActualTickCount == other.ActualTickCount && | ||
this.ActualTickInterval == other.ActualTickInterval && | ||
this.PixelPerUnit == other.PixelPerUnit; | ||
} | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
CommonLib/Axis/AxisDrawingSettings/CategoryAxisDrawingSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using MvvmCharting.Common; | ||
|
||
namespace MvvmCharting.Axis | ||
{ | ||
public class CategoryAxisDrawingSettings : AxisDrawingSettingsBase | ||
{ | ||
|
||
|
||
private IList<object> PlottingItemValues { get; } | ||
|
||
private Range ValuePadding { get; } | ||
|
||
public CategoryAxisDrawingSettings(int tickInterval, CategoryPlottingRange plottingRange, double plottingLength) | ||
: base(plottingLength) | ||
{ | ||
if (plottingRange == null) | ||
{ | ||
throw new ArgumentException(); | ||
} | ||
|
||
var list = plottingRange.PlottingItemValues; | ||
if (list == null || list.Count == 0) | ||
{ | ||
throw new ArgumentException(); | ||
} | ||
|
||
this.PlottingItemValues = plottingRange.PlottingItemValues; | ||
this.ValuePadding = plottingRange.ValuePadding; | ||
|
||
|
||
|
||
this.PixelPerUnit = this.PlottingLength / (this.PlottingItemValues.Count + this.ValuePadding.Min + this.ValuePadding.Max); | ||
|
||
|
||
//calculated state: | ||
this.ActualTickInterval = tickInterval; | ||
|
||
this.ActualTickCount = (int)Math.Floor(this.PlottingItemValues.Count / this.ActualTickInterval) + 1; | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
public override bool Equals(AxisDrawingSettingsBase obj) | ||
{ | ||
if (!base.Equals(obj)) | ||
{ | ||
return false; | ||
} | ||
|
||
var other = obj as CategoryAxisDrawingSettings; | ||
if (other == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return this.PlottingItemValues?.Count == other.PlottingItemValues?.Count && | ||
this.PlottingItemValues != null && | ||
this.PlottingItemValues.SequenceEqual(other.PlottingItemValues); | ||
} | ||
|
||
public override IEnumerable<object> GetPlottingValues() | ||
{ | ||
return this.PlottingItemValues; | ||
} | ||
|
||
public override bool CanUpdateAxisItemsCoordinate() | ||
{ | ||
return !this.PlottingLength.IsNaNOrZero() && this.PlottingItemValues?.Count > 0; | ||
} | ||
|
||
public override double CalculateCoordinate(double i, AxisType axisType) | ||
{ | ||
|
||
var coordinate = (i + this.ValuePadding.Min) * this.PixelPerUnit; | ||
|
||
if (axisType == AxisType.Y) | ||
{ | ||
coordinate = this.PlottingLength - coordinate; | ||
} | ||
|
||
return coordinate; | ||
} | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
CommonLib/Axis/AxisDrawingSettings/IAxisDrawingSettingsBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace MvvmCharting.Axis | ||
{ | ||
public interface IAxisDrawingSettingsBase | ||
{ | ||
|
||
IEnumerable<object> GetPlottingValues(); | ||
|
||
bool CanUpdateAxisItems(); | ||
|
||
bool CanUpdateAxisItemsCoordinate(); | ||
|
||
double CalculateCoordinate(double value, AxisType axisType); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
CommonLib/Axis/AxisDrawingSettings/NumericAxisDrawingSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using MvvmCharting.Common; | ||
|
||
namespace MvvmCharting.Axis | ||
{ | ||
|
||
|
||
|
||
|
||
public class NumericAxisDrawingSettings : AxisDrawingSettingsBase | ||
{ | ||
|
||
|
||
private Range FullPlottingRange { get; } | ||
|
||
private Range ActualPlottingRange { get; } | ||
|
||
public NumericAxisDrawingSettings(int tickCount, double tickInterval, | ||
NumericPlottingRange plottingRange, double plottingLength) | ||
: base(plottingLength) | ||
{ | ||
var range = plottingRange.ActualRange; | ||
if (range.IsInvalid || plottingLength.IsNaNOrZero()) | ||
{ | ||
throw new ArgumentException(); | ||
} | ||
|
||
if (tickCount < 0 || tickCount > ushort.MaxValue) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
|
||
this.ActualPlottingRange = plottingRange.ActualRange; | ||
this.FullPlottingRange = plottingRange.FullRange; | ||
|
||
this.PixelPerUnit = plottingLength / plottingRange.FullRange.Span; | ||
|
||
//calculated state: | ||
this.ActualTickInterval = !tickInterval.IsNaN() ? tickInterval : this.ActualPlottingRange.Span / tickCount; | ||
this.ActualTickCount = (int)Math.Floor(this.ActualPlottingRange.Span / this.ActualTickInterval) + 1; | ||
} | ||
|
||
|
||
public override bool Equals(AxisDrawingSettingsBase obj) | ||
{ | ||
if (!base.Equals(obj)) | ||
{ | ||
return false; | ||
} | ||
var other = obj as NumericAxisDrawingSettings; | ||
if (other == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return this.FullPlottingRange == other.FullPlottingRange && | ||
this.ActualPlottingRange == other.ActualPlottingRange; | ||
} | ||
|
||
|
||
|
||
public override bool CanUpdateAxisItemsCoordinate() | ||
{ | ||
return !this.PlottingLength.IsNaNOrZero() && !this.FullPlottingRange.Span.IsNaNOrZero(); | ||
} | ||
public override IEnumerable<object> GetPlottingValues() | ||
{ | ||
var startValue = this.ActualPlottingRange.Min; | ||
|
||
|
||
for (int i = 0; i < this.ActualTickCount; i++) | ||
{ | ||
|
||
yield return startValue + i * this.ActualTickInterval; | ||
} | ||
} | ||
|
||
public override double CalculateCoordinate(double value, AxisType axisType) | ||
{ | ||
var offset = (value - this.FullPlottingRange.Min) * this.PixelPerUnit; | ||
|
||
if (axisType == AxisType.Y) | ||
{ | ||
offset = this.PlottingLength - offset; | ||
} | ||
|
||
return offset; | ||
} | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.