Index: Core/Components/src/Core.Components.OxyPlot.Forms/BaseChart.cs =================================================================== diff -u -r2c97a81a5403ee33f12550aaa89fd1f1b3be52ea -rd0f1bca0f6a4833a790ae7eba9fde30674a52ddb --- Core/Components/src/Core.Components.OxyPlot.Forms/BaseChart.cs (.../BaseChart.cs) (revision 2c97a81a5403ee33f12550aaa89fd1f1b3be52ea) +++ Core/Components/src/Core.Components.OxyPlot.Forms/BaseChart.cs (.../BaseChart.cs) (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -7,6 +7,7 @@ using Core.Common.Base; using Core.Components.Charting; using Core.Components.Charting.Data; +using Core.Components.OxyPlot.Converter; using Core.Components.OxyPlot.Properties; using OxyPlot; using OxyPlot.Axes; Index: Core/Components/src/Core.Components.OxyPlot/Converter/AreaDataConverter.cs =================================================================== diff -u --- Core/Components/src/Core.Components.OxyPlot/Converter/AreaDataConverter.cs (revision 0) +++ Core/Components/src/Core.Components.OxyPlot/Converter/AreaDataConverter.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,34 @@ +using System; +using Core.Components.Charting.Data; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Converter +{ + /// + /// This class converts into . + /// + public class AreaDataConverter : ChartDataConverter + { + protected override Type SupportedType + { + get + { + return typeof(AreaData); + } + } + + internal override Series Convert(ChartData data) + { + var series = new AreaSeries(); + foreach (var p in data.Points) + { + series.Points.Add(TupleToDataPoint(p)); + } + if (series.Points.Count > 0) + { + series.Points2.Add(series.Points[0]); + } + return series; + } + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.OxyPlot/Converter/ChartDataConverter.cs =================================================================== diff -u --- Core/Components/src/Core.Components.OxyPlot/Converter/ChartDataConverter.cs (revision 0) +++ Core/Components/src/Core.Components.OxyPlot/Converter/ChartDataConverter.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,52 @@ +using System; +using Core.Components.Charting.Data; +using OxyPlot; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Converter +{ + /// + /// Provides an abstract base class for transforming in specific + /// instances. + /// + public abstract class ChartDataConverter + { + /// + /// Returns the type that the can convert + /// into a new instance. + /// + protected abstract Type SupportedType { get; } + + /// + /// Transforms a given object into a . Can be used as a + /// . + /// + /// The object to convert into a . + /// A new based on . + /// Thrown when is not + /// of type of . + protected static DataPoint TupleToDataPoint(object obj) + { + var point = (Tuple) obj; + return new DataPoint(point.Item1, point.Item2); + } + + /// + /// Checks whether the can convert the . + /// + /// The to check for. + /// true if the can be converted by the + /// , false otherwise. + internal bool CanConvertSeries(ChartData data) + { + return data.GetType() == SupportedType; + } + + /// + /// Creates a based on the that was given. + /// + /// The data to transform into a . + /// A new instance. + internal abstract Series Convert(ChartData data); + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.OxyPlot/Converter/LineDataConverter.cs =================================================================== diff -u --- Core/Components/src/Core.Components.OxyPlot/Converter/LineDataConverter.cs (revision 0) +++ Core/Components/src/Core.Components.OxyPlot/Converter/LineDataConverter.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,31 @@ +using System; +using System.Linq; +using Core.Components.Charting.Data; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Converter +{ + /// + /// This class converts into . + /// + public class LineDataConverter : ChartDataConverter + { + protected override Type SupportedType + { + get + { + return typeof(LineData); + } + } + + internal override Series Convert(ChartData data) + { + var series = new LineSeries + { + ItemsSource = data.Points.ToArray(), + Mapping = TupleToDataPoint + }; + return series; + } + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.OxyPlot/Converter/PointDataConverter.cs =================================================================== diff -u --- Core/Components/src/Core.Components.OxyPlot/Converter/PointDataConverter.cs (revision 0) +++ Core/Components/src/Core.Components.OxyPlot/Converter/PointDataConverter.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,31 @@ +using System; +using System.Linq; +using Core.Components.Charting.Data; +using OxyPlot; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Converter +{ + public class PointDataConverter : ChartDataConverter + { + protected override Type SupportedType + { + get + { + return typeof(PointData); + } + } + + internal override Series Convert(ChartData data) + { + var series = new LineSeries + { + ItemsSource = data.Points.ToArray(), + Mapping = TupleToDataPoint, + LineStyle = LineStyle.None, + MarkerType = MarkerType.Circle + }; + return series; + } + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.OxyPlot/Converter/SeriesFactory.cs =================================================================== diff -u --- Core/Components/src/Core.Components.OxyPlot/Converter/SeriesFactory.cs (revision 0) +++ Core/Components/src/Core.Components.OxyPlot/Converter/SeriesFactory.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Core.Components.Charting.Data; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Converter +{ + /// + /// This class creates new objects from . + /// + public class SeriesFactory + { + /// + /// Collection of converters that the can use to transform . + /// + private readonly IEnumerable converters = new Collection + { + new AreaDataConverter(), + new LineDataConverter(), + new PointDataConverter() + }; + + /// + /// Creates a new from the given . + /// + /// The to base the creation of a upon. + /// A new . + public Series Create(ChartData data) + { + foreach (var converter in converters) + { + if (converter.CanConvertSeries(data)) + { + return converter.Convert(data); + } + } + throw new NotSupportedException(string.Format("IChartData of type {0} is not supported.", data.GetType().Name)); + } + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.OxyPlot/Core.Components.OxyPlot.csproj =================================================================== diff -u -rba3f5abc18676f64d95d75270494424f169b3c4e -rd0f1bca0f6a4833a790ae7eba9fde30674a52ddb --- Core/Components/src/Core.Components.OxyPlot/Core.Components.OxyPlot.csproj (.../Core.Components.OxyPlot.csproj) (revision ba3f5abc18676f64d95d75270494424f169b3c4e) +++ Core/Components/src/Core.Components.OxyPlot/Core.Components.OxyPlot.csproj (.../Core.Components.OxyPlot.csproj) (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -48,13 +48,17 @@ Properties\GlobalAssembly.cs - + + + True True Resources.resx + + Index: Core/Components/src/Core.Components.OxyPlot/Properties/AssemblyInfo.cs =================================================================== diff -u -r3c816a265bc4ea959ced0376d8b4b0d244e146b3 -rd0f1bca0f6a4833a790ae7eba9fde30674a52ddb --- Core/Components/src/Core.Components.OxyPlot/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 3c816a265bc4ea959ced0376d8b4b0d244e146b3) +++ Core/Components/src/Core.Components.OxyPlot/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -5,4 +5,4 @@ [assembly: AssemblyTitle("Core.Components.OxyPlot")] [assembly: AssemblyProduct("Core.Components.OxyPlot")] [assembly: Guid("05a1a16f-6f4f-4ebb-9540-b09a94bfded0")] -[assembly: InternalsVisibleTo("Core.Components.OxyPlot.Forms")] \ No newline at end of file +[assembly: InternalsVisibleTo("Core.Components.OxyPlot.Test")] \ No newline at end of file Fisheye: Tag d0f1bca0f6a4833a790ae7eba9fde30674a52ddb refers to a dead (removed) revision in file `Core/Components/src/Core.Components.OxyPlot/SeriesFactory.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Components/test/Core.Components.OxyPlot.Test/Converter/AreaDataConverterTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.OxyPlot.Test/Converter/AreaDataConverterTest.cs (revision 0) +++ Core/Components/test/Core.Components.OxyPlot.Test/Converter/AreaDataConverterTest.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using Core.Components.Charting.Data; +using Core.Components.Charting.TestUtil; +using Core.Components.OxyPlot.Converter; +using NUnit.Framework; +using OxyPlot; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Test.Converter +{ + [TestFixture] + public class AreaDataConverterTest + { + + [Test] + public void DefaultConstructor_IsChartDataConverter() + { + // Call + var converter = new AreaDataConverter(); + + // Assert + Assert.IsInstanceOf(converter); + } + + [Test] + public void CanConvertSeries_PointData_ReturnTrue() + { + // Setup + var converter = new AreaDataConverter(); + var areaData = new AreaData(new Collection>()); + + // Call & Assert + Assert.IsTrue(converter.CanConvertSeries(areaData)); + } + + [Test] + public void CanConvertSeries_ChartData_ReturnsFalse() + { + // Setup + var converter = new AreaDataConverter(); + var chartData = new TestChartData(); + + // Call & Assert + Assert.IsFalse(converter.CanConvertSeries(chartData)); + } + + [Test] + public void Convert_RandomPointData_ReturnsNewSeries() + { + // Setup + var converter = new AreaDataConverter(); + var random = new Random(21); + var randomCount = random.Next(5, 10); + var points = new Collection>(); + + for (int i = 0; i < randomCount; i++) + { + points.Add(new Tuple(random.NextDouble(), random.NextDouble())); + } + + var areaData = new AreaData(points); + + // Call + var series = converter.Convert(areaData); + + // Assert + Assert.IsInstanceOf(series); + var areaSeries = ((AreaSeries)series); + var expectedData = points.Select(t => new DataPoint(t.Item1, t.Item2)).ToArray(); + CollectionAssert.AreEqual(expectedData, areaSeries.Points); + CollectionAssert.AreEqual(new Collection { expectedData.First() }, areaSeries.Points2); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.OxyPlot.Test/Converter/ChartDataConverterTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.OxyPlot.Test/Converter/ChartDataConverterTest.cs (revision 0) +++ Core/Components/test/Core.Components.OxyPlot.Test/Converter/ChartDataConverterTest.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Core.Components.Charting.Data; +using Core.Components.Charting.TestUtil; +using Core.Components.OxyPlot.Converter; +using NUnit.Framework; +using OxyPlot; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Test.Converter +{ + [TestFixture] + public class ChartDataConverterTest + { + [Test] + public void TupleToDataPoint_RandomTupleDoubleDouble_ReturnsDataPoint() + { + // Setup + var random = new Random(21); + var a = random.NextDouble(); + var b = random.NextDouble(); + var tuple = new Tuple(a,b); + var testConverter = new TestChartDataConverter(typeof(object)); + + // Call + var point = testConverter.PublicTupleToDataPoint(tuple); + + // Assert + Assert.AreEqual(a, point.X); + Assert.AreEqual(b, point.Y); + } + + [Test] + public void CanConvertSeries_DifferentInherritingTypes_OnlySupportsExactType() + { + // Setup + var testConverter = new TestChartDataConverter(typeof(Class)); + + // Call + var chartDataResult = testConverter.CanConvertSeries(new TestChartData()); + var classResult = testConverter.CanConvertSeries(new Class()); + var childResult = testConverter.CanConvertSeries(new Child()); + + // Assert + Assert.IsFalse(chartDataResult); + Assert.IsTrue(classResult); + Assert.IsFalse(childResult); + } + + private class Class : ChartData { + public Class() : base(new Collection>()) { } + } + + private class Child : Class {} + + private class TestChartDataConverter : ChartDataConverter + { + private readonly Type supportedType; + + public TestChartDataConverter(Type type) + { + supportedType = type; + } + + protected override Type SupportedType + { + get + { + return supportedType; + } + } + + internal override Series Convert(ChartData data) + { + throw new NotImplementedException(); + } + + public DataPoint PublicTupleToDataPoint(object obj) + { + return TupleToDataPoint(obj); + } + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.OxyPlot.Test/Converter/LineDataConverterTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.OxyPlot.Test/Converter/LineDataConverterTest.cs (revision 0) +++ Core/Components/test/Core.Components.OxyPlot.Test/Converter/LineDataConverterTest.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,72 @@ +using System; +using System.Collections.ObjectModel; +using Core.Components.Charting.Data; +using Core.Components.Charting.TestUtil; +using Core.Components.OxyPlot.Converter; +using NUnit.Framework; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Test.Converter +{ + [TestFixture] + public class LineDataConverterTest + { + [Test] + public void DefaultConstructor_IsChartDataConverter() + { + // Call + var converter = new LineDataConverter(); + + // Assert + Assert.IsInstanceOf(converter); + } + + [Test] + public void CanConvertSeries_PointData_ReturnTrue() + { + // Setup + var converter = new LineDataConverter(); + var lineData = new LineData(new Collection>()); + + // Call & Assert + Assert.IsTrue(converter.CanConvertSeries(lineData)); + } + + [Test] + public void CanConvertSeries_ChartData_ReturnsFalse() + { + // Setup + var converter = new LineDataConverter(); + var chartData = new TestChartData(); + + // Call & Assert + Assert.IsFalse(converter.CanConvertSeries(chartData)); + } + + [Test] + public void Convert_RandomPointData_ReturnsNewSeries() + { + // Setup + var converter = new LineDataConverter(); + var random = new Random(21); + var randomCount = random.Next(5, 10); + var points = new Collection>(); + + for (int i = 0; i < randomCount; i++) + { + points.Add(new Tuple(random.NextDouble(), random.NextDouble())); + } + + var lineData = new LineData(points); + + // Call + var series = converter.Convert(lineData); + + // Assert + Assert.IsInstanceOf(series); + var lineSeries = ((LineSeries)series); + CollectionAssert.AreEqual(points, lineSeries.ItemsSource); + Assert.AreNotSame(points, lineSeries.ItemsSource); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.OxyPlot.Test/Converter/PointDataConverterTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.OxyPlot.Test/Converter/PointDataConverterTest.cs (revision 0) +++ Core/Components/test/Core.Components.OxyPlot.Test/Converter/PointDataConverterTest.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,75 @@ +using System; +using System.Collections.ObjectModel; +using Core.Components.Charting.Data; +using Core.Components.Charting.TestUtil; +using Core.Components.OxyPlot.Converter; +using NUnit.Framework; +using OxyPlot; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Test.Converter +{ + [TestFixture] + public class PointDataConverterTest + { + [Test] + public void DefaultConstructor_IsChartDataConverter() + { + // Call + var converter = new PointDataConverter(); + + // Assert + Assert.IsInstanceOf(converter); + } + + [Test] + public void CanConvertSeries_PointData_ReturnTrue() + { + // Setup + var converter = new PointDataConverter(); + var pointData = new PointData(new Collection>()); + + // Call & Assert + Assert.IsTrue(converter.CanConvertSeries(pointData)); + } + + [Test] + public void CanConvertSeries_ChartData_ReturnsFalse() + { + // Setup + var converter = new PointDataConverter(); + var chartData = new TestChartData(); + + // Call & Assert + Assert.IsFalse(converter.CanConvertSeries(chartData)); + } + + [Test] + public void Convert_RandomPointData_ReturnsNewSeries() + { + // Setup + var converter = new PointDataConverter(); + var random = new Random(21); + var randomCount = random.Next(5, 10); + var points = new Collection>(); + + for (int i = 0; i < randomCount; i++) + { + points.Add(new Tuple(random.NextDouble(), random.NextDouble())); + } + + var pointData = new PointData(points); + + // Call + var series = converter.Convert(pointData); + + // Assert + Assert.IsInstanceOf(series); + var lineSeries = ((LineSeries)series); + CollectionAssert.AreEqual(points, lineSeries.ItemsSource); + Assert.AreNotSame(points, lineSeries.ItemsSource); + Assert.AreEqual(LineStyle.None, lineSeries.LineStyle); + Assert.AreEqual(MarkerType.Circle, lineSeries.MarkerType); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.OxyPlot.Test/Converter/SeriesFactoryTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.OxyPlot.Test/Converter/SeriesFactoryTest.cs (revision 0) +++ Core/Components/test/Core.Components.OxyPlot.Test/Converter/SeriesFactoryTest.cs (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using Core.Components.Charting.Data; +using Core.Components.Charting.TestUtil; +using Core.Components.OxyPlot.Converter; +using NUnit.Framework; +using OxyPlot; +using OxyPlot.Series; + +namespace Core.Components.OxyPlot.Test.Converter +{ + [TestFixture] + public class SeriesFactoryTest + { + [Test] + public void Create_AreaData_ReturnsAreaSeries() + { + // Setup + var factory = new SeriesFactory(); + var testData = CreateTestData(); + var expectedData = CreateExpectedData(testData); + + // Call + Series series = factory.Create(new AreaData(testData)); + + // Assert + Assert.IsInstanceOf(series); + var areaSeries = ((AreaSeries)series); + CollectionAssert.AreEqual(expectedData, areaSeries.Points); + CollectionAssert.AreEqual(new Collection{expectedData.First()}, areaSeries.Points2); + Assert.AreNotSame(expectedData, areaSeries.ItemsSource); + } + + [Test] + public void Create_LineData_ReturnsLineSeries() + { + // Setup + var factory = new SeriesFactory(); + var testData = CreateTestData(); + + // Call + Series series = factory.Create(new LineData(testData)); + + // Assert + Assert.IsInstanceOf(series); + var lineSeries = ((LineSeries)series); + CollectionAssert.AreEqual(testData, lineSeries.ItemsSource); + Assert.AreNotSame(testData, lineSeries.ItemsSource); + } + + [Test] + public void Create_PointData_ReturnsLinesSeriesWithPointStyle() + { + // Setup + var factory = new SeriesFactory(); + var testData = CreateTestData(); + + // Call + Series series = factory.Create(new PointData(testData)); + + // Assert + Assert.IsInstanceOf(series); + var lineSeries = ((LineSeries)series); + CollectionAssert.AreEqual(testData, lineSeries.ItemsSource); + Assert.AreNotSame(testData, lineSeries.ItemsSource); + Assert.AreEqual(LineStyle.None, lineSeries.LineStyle); + Assert.AreEqual(MarkerType.Circle, lineSeries.MarkerType); + } + + [Test] + public void Create_OtherData_ThrowsNotSupportedException() + { + // Setup + var factory = new SeriesFactory(); + var testData = new TestChartData(); + + // Call + TestDelegate test = () => factory.Create(testData); + + // Assert + Assert.Throws(test); + } + + private static ICollection CreateExpectedData(IEnumerable> testData) + { + return testData.Select(p => new DataPoint(p.Item1, p.Item2)).ToArray(); + } + + private static Collection> CreateTestData() + { + return new Collection> + { + new Tuple(1.2, 3.4), + new Tuple(3.2, 3.4), + new Tuple(0.2, 2.4) + }; + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.OxyPlot.Test/Core.Components.OxyPlot.Test.csproj =================================================================== diff -u -rdaaa148db691a71c042fcdd3ca039cf13c59217c -rd0f1bca0f6a4833a790ae7eba9fde30674a52ddb --- Core/Components/test/Core.Components.OxyPlot.Test/Core.Components.OxyPlot.Test.csproj (.../Core.Components.OxyPlot.Test.csproj) (revision daaa148db691a71c042fcdd3ca039cf13c59217c) +++ Core/Components/test/Core.Components.OxyPlot.Test/Core.Components.OxyPlot.Test.csproj (.../Core.Components.OxyPlot.Test.csproj) (revision d0f1bca0f6a4833a790ae7eba9fde30674a52ddb) @@ -50,8 +50,12 @@ + + + + - + Fisheye: Tag d0f1bca0f6a4833a790ae7eba9fde30674a52ddb refers to a dead (removed) revision in file `Core/Components/test/Core.Components.OxyPlot.Test/SeriesFactoryTest.cs'. Fisheye: No comparison available. Pass `N' to diff?