public void TestSimpleCase() { IEnumerable <object> x = new object[] { 0d, 1d, 2d }; IEnumerable <object> y = new object[] { 1d, 2d, 4d }; IEnumerable <object> xerr = new object[] { 0.25, 0.5, 0.75 }; IEnumerable <object> yerr = new object[] { 0.5, 0.25, 0.125 }; Line line = new Line(LineType.Solid, LineThickness.Thin); LineThickness bar = LineThickness.Thin; LineThickness stopper = LineThickness.Normal; Marker marker = new Marker(MarkerType.Cross, MarkerSize.Normal, 1); ErrorSeries input = new ErrorSeries("asdf", Color.Blue, true, x, y, line, marker, bar, stopper, xerr, yerr, "", ""); var output = exporter.Export(input, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is ScatterErrorSeries); ScatterErrorSeries errorSeries = (ScatterErrorSeries)output; Assert.AreEqual("asdf", errorSeries.Title); Assert.AreEqual(3, errorSeries.ItemsSource.Count()); // Marker style Assert.AreEqual(OxyPlot.MarkerType.Cross, errorSeries.MarkerType); Assert.AreEqual(7, errorSeries.MarkerSize); // Line style TBI // Bar style Assert.AreEqual(0.25, errorSeries.ErrorBarStrokeThickness); // TBI: stopper thickness // Colours Assert.AreEqual(OxyColors.Blue, errorSeries.ErrorBarColor); }
public void TestOneDateSeries() { int n = 10; IEnumerable <DateTime> x = Enumerable.Range(2, n).Select(i => new DateTime(1900, i, 1)); double[] y = Enumerable.Range(100, n).Select(i => Convert.ToDouble(i)).ToArray(); Line line = new Line(LineType.None, LineThickness.Thin); Marker marker = new Marker(MarkerType.FilledCircle, MarkerSize.Normal, 1); LineSeries inputSeries = new LineSeries("", Color.Black, false, x.Cast <object>(), y.Cast <object>(), line, marker, "", ""); // Convert the series to an oxyplot series. Series output = exporter.Export(inputSeries, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is OxyLineSeries); OxyLineSeries series = (OxyLineSeries)output; Assert.AreEqual(n, series.ItemsSource.Count()); double[] expectedX = new double[] { 33, 61, 92, 122, 153, 183, 214, 245, 275, 306 }; int i = 0; foreach (DataPoint point in series.ItemsSource) { Assert.AreEqual(expectedX[i], point.X); Assert.AreEqual(y[i], point.Y); i++; } }
public void TestSimpleCase() { IEnumerable <object> x = new object[] { 0d, 1d, 2d, 4d }; IEnumerable <object> y = new object[] { 1d, 2d, 4d, 8d }; Line line = new Line(LineType.Solid, LineThickness.Thin); Marker marker = new Marker(MarkerType.Square, MarkerSize.Normal, 1); string title = "asdf"; LineSeries input = new LineSeries(title, Color.Blue, true, x, y, line, marker, "", ""); Series output = exporter.Export(input, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is OxyLineSeries); OxyLineSeries series = (OxyLineSeries)output; Assert.AreEqual(title, series.Title); Assert.AreEqual(4, series.ItemsSource.Count()); // Marker style Assert.AreEqual(OxyPlot.MarkerType.Square, series.MarkerType); Assert.AreEqual(7, series.MarkerSize); // Line style Assert.AreEqual(OxyPlot.LineStyle.Solid, series.LineStyle); Assert.AreEqual(0.25, series.StrokeThickness); // Colours Assert.AreEqual(OxyColors.Blue, series.Color); }
public void TestTwoDateSeries() { int n = 10; IEnumerable <DateTime> x = Enumerable.Range(1, n).Select(i => new DateTime(2000, 1, i)); IEnumerable <DateTime> y = Enumerable.Range(2000, n).Select(i => new DateTime(i, 1, 1)); Line line = new Line(LineType.None, LineThickness.Thin); Marker marker = new Marker(MarkerType.FilledCircle, MarkerSize.Normal, 1); LineSeries inputSeries = new LineSeries("", Color.Black, false, x.Cast <object>(), y.Cast <object>(), line, marker, "", ""); // Convert the series to an oxyplot series. Series output = exporter.Export(inputSeries, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is OxyLineSeries); OxyLineSeries series = (OxyLineSeries)output; Assert.AreEqual(n, series.ItemsSource.Count()); double[] expectedX = new double[] { 36526, 36527, 36528, 36529, 36530, 36531, 36532, 36533, 36534, 36535 }; double[] expectedY = new double[] { 36526, 36892, 37257, 37622, 37987, 38353, 38718, 39083, 39448, 39814 }; int i = 0; foreach (DataPoint point in series.ItemsSource) { Assert.AreEqual(expectedX[i], point.X); Assert.AreEqual(expectedY[i], point.Y); i++; } }
public void TestMarkerFill() { MarkerType[] filledMarkers = new MarkerType[4] { MarkerType.FilledCircle, MarkerType.FilledDiamond, MarkerType.FilledSquare, MarkerType.FilledTriangle }; MarkerType[] nonFilledMarkers = new MarkerType[] { MarkerType.Circle, MarkerType.Cross, MarkerType.Diamond, MarkerType.None, MarkerType.Plus, MarkerType.Square, MarkerType.Star, MarkerType.Triangle }; object[] x = new object[5] { 0d, 1d, 2d, 3d, 4d }; object[] y = new object[5] { 0d, 0d, 1d, 2d, 2d }; Line line = new Line(LineType.Solid, LineThickness.Normal); foreach (MarkerType markerType in filledMarkers) { Marker marker = new Marker(markerType, MarkerSize.Normal, 1); BoxWhiskerSeries series = new BoxWhiskerSeries("Title", Color.Green, true, x, y, line, marker, "", ""); BoxPlotSeries oxySeries = (BoxPlotSeries)exporter.Export(series, AxisLabelCollection.Empty()).Result; // Because marker type is "filled", series should be filled with colour. Assert.AreEqual(OxyColors.Green, oxySeries.Fill); } foreach (MarkerType markerType in nonFilledMarkers) { Marker marker = new Marker(markerType, MarkerSize.Normal, 1); BoxWhiskerSeries series = new BoxWhiskerSeries("Title", Color.Green, true, x, y, line, marker, "", ""); BoxPlotSeries oxySeries = (BoxPlotSeries)exporter.Export(series, AxisLabelCollection.Empty()).Result; // Because marker type is "filled", series should be filled with colour. // todo // Assert.AreEqual(OxyColors.Transparent, oxySeries.Fill); } }
public void TestNoData() { IEnumerable <object> x = Enumerable.Empty <object>(); IEnumerable <object> y = Enumerable.Empty <object>(); Line line = new Line(LineType.Solid, LineThickness.Thin); Marker marker = new Marker(MarkerType.Square, MarkerSize.Normal, 1); LineSeries input = new LineSeries("", Color.Blue, true, x, y, line, marker, "", ""); Series output = exporter.Export(input, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is OxyLineSeries); OxyLineSeries series = (OxyLineSeries)output; Assert.AreEqual(0, series.ItemsSource.Count()); }
public void TestSimpleCase() { object[] x = new object[7] { 0d, 1d, 2d, 3d, 4d, 5d, 6d }; object[] y = new object[7] { 0d, 1d, 1d, 2d, 3d, 3d, 4d }; Line line = new Line(LineType.Solid, LineThickness.Normal); Marker marker = new Marker(MarkerType.FilledSquare, MarkerSize.Normal, 1); BoxWhiskerSeries series = new BoxWhiskerSeries("Title", Color.Red, true, x, y, line, marker, "", ""); var oxySeries = exporter.Export(series, AxisLabelCollection.Empty()).Result; Assert.NotNull(oxySeries); Assert.True(oxySeries is BoxPlotSeries); BoxPlotSeries boxPlot = (BoxPlotSeries)oxySeries; // Line style Assert.AreEqual(OxyPlot.LineStyle.Solid, boxPlot.LineStyle); Assert.AreEqual(0.5, boxPlot.StrokeThickness); // Marker style Assert.AreEqual(OxyPlot.MarkerType.Square, boxPlot.OutlierType); Assert.AreEqual(7, boxPlot.OutlierSize); // Colours Assert.AreEqual(OxyColors.Transparent, boxPlot.Stroke); Assert.AreEqual(OxyColors.Red, boxPlot.Fill); // Title Assert.AreEqual("Title", boxPlot.Title); // Contents of series. Assert.AreEqual(1, boxPlot.Items.Count); BoxPlotItem item = boxPlot.Items[0]; Assert.NotNull(item); // Test box plot whisker values. Assert.AreEqual(0, item.X); Assert.AreEqual(0, item.LowerWhisker); Assert.AreEqual(1, item.BoxBottom); Assert.AreEqual(2, item.Median); Assert.AreEqual(3, item.BoxTop); Assert.AreEqual(4, item.UpperWhisker); }
/// <summary> /// Create a series with the given marker size, conver it to an oxyplot /// series, and return the generated series' marker size. /// </summary> /// <param name="markerSize">Desired marker size.</param> private double GetExportedMarkerSize(MarkerSize markerSize) { IEnumerable <object> x = Enumerable.Empty <object>(); IEnumerable <object> y = Enumerable.Empty <object>(); Line line = new Line(LineType.Solid, LineThickness.Normal); Marker marker = new Marker(MarkerType.FilledCircle, markerSize, 1); LineSeries inputSeries = new LineSeries("", Color.Black, true, x, y, line, marker, "", ""); // Convert the series to an oxyplot series. Series output = exporter.Export(inputSeries, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is OxyLineSeries); OxyLineSeries series = (OxyLineSeries)output; return(series.MarkerSize); }
/// <summary> /// Create a series with the given title and 'show on legend' value. /// Then convert to an oxyplot series and ensure that the generated /// series' title matches the specified expected value. /// </summary> /// <param name="title">Input title.</param> /// <param name="showOnLegend">Input value for 'show on legend'.</param> /// <param name="expectedTitle">Expected title of the oxyplot series.</param> private void TestShowOnLegend(string title, bool showOnLegend, string expectedTitle) { // Create an apsim series with the given inputs. IEnumerable <object> x = Enumerable.Empty <object>(); IEnumerable <object> y = Enumerable.Empty <object>(); Line line = new Line(LineType.None, LineThickness.Thin); Marker marker = new Marker(MarkerType.FilledCircle, MarkerSize.Normal, 1); LineSeries inputSeries = new LineSeries(title, Color.Black, false, x, y, line, marker, "", ""); // Convert the series to an oxyplot series. Series output = exporter.Export(inputSeries, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is OxyLineSeries); OxyLineSeries series = (OxyLineSeries)output; Assert.Null(series.Title); }
/// <summary> /// Create a series with the given System.Drawing.Color and marker type, /// then convert to an oxyplot series and ensure that the generated series' /// marker colour matches the given colour. /// </summary> /// <param name="inputColour">Colour to use when creating the series.</param> /// <param name="markerType">Marker type for the created series.</param> /// <param name="expectedOutput">Expected colour of the output series.</param> private void TestMarkerColour(Color inputColour, MarkerType markerType, OxyColor expectedOutput) { // Create an apsim series with the given inputs. IEnumerable <object> x = Enumerable.Empty <object>(); IEnumerable <object> y = Enumerable.Empty <object>(); Line line = new Line(LineType.None, LineThickness.Thin); Marker marker = new Marker(markerType, MarkerSize.Normal, 1); LineSeries inputSeries = new LineSeries("", inputColour, true, x, y, line, marker, "", ""); // Convert the series to an oxyplot series. Series output = exporter.Export(inputSeries, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is OxyLineSeries); OxyLineSeries series = (OxyLineSeries)output; Assert.AreEqual(expectedOutput, series.MarkerFill); }
public void TestSeriesWithThisData(IEnumerable <double> x, IEnumerable <double> y, IEnumerable <double> xerr, IEnumerable <double> yerr) { Line line = new Line(LineType.Solid, LineThickness.Thin); LineThickness bar = LineThickness.Thin; LineThickness stopper = LineThickness.Normal; Marker marker = new Marker(MarkerType.Cross, MarkerSize.Normal, 1); ErrorSeries input = new ErrorSeries("asdf", Color.Blue, true, x, y, line, marker, bar, stopper, xerr, yerr, "", ""); var output = exporter.Export(input, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is ScatterErrorSeries); ScatterErrorSeries series = (ScatterErrorSeries)output; int n = x.Count(); Assert.AreEqual(n, series.ItemsSource.Count()); IEnumerable <ScatterErrorPoint> points = series.ItemsSource.Cast <ScatterErrorPoint>(); bool havexError = xerr != null && xerr.Any(); bool haveyError = yerr != null && yerr.Any(); IEnumerator <double> enumeratorX = x.GetEnumerator(); IEnumerator <double> enumeratorY = y.GetEnumerator(); IEnumerator <ScatterErrorPoint> seriesEnumerator = points.GetEnumerator(); IEnumerator <double> enumeratorXErr = xerr?.GetEnumerator(); IEnumerator <double> enumeratorYErr = yerr?.GetEnumerator(); while (enumeratorX.MoveNext() && enumeratorY.MoveNext() && seriesEnumerator.MoveNext() && (!havexError || enumeratorXErr.MoveNext()) && (!haveyError || enumeratorYErr.MoveNext())) { ScatterErrorPoint point = seriesEnumerator.Current; Assert.AreEqual(enumeratorX.Current, point.X); Assert.AreEqual(enumeratorY.Current, point.Y); double expectedXerr = havexError ? enumeratorXErr.Current : 0; double expectedYerr = haveyError ? enumeratorYErr.Current : 0; Assert.AreEqual(expectedXerr, point.ErrorX); Assert.AreEqual(expectedYerr, point.ErrorY); } Assert.False(enumeratorX.MoveNext(), "X input has more data"); Assert.False(enumeratorY.MoveNext(), "Y input has more data"); Assert.False(seriesEnumerator.MoveNext(), "Series has more data"); }
/// <summary> /// Create an apsim series with the given input line type, then /// convert the apsim series to an oxyplot series and ensure that /// the output series' line type matches the expected output. /// </summary> /// <param name="input"></param> /// <param name="expectedOutput"></param> private void TestLineType(LineType input, LineStyle expectedOutput) { // Create an apsim series with the given line type. IEnumerable <object> x = Enumerable.Empty <object>(); IEnumerable <object> y = Enumerable.Empty <object>(); Line line = new Line(input, LineThickness.Thin); Marker marker = new Marker(MarkerType.None, MarkerSize.Normal, 1); LineSeries inputSeries = new LineSeries("", Color.Black, true, x, y, line, marker, "", ""); // Convert the series to an oxyplot series. Series output = exporter.Export(inputSeries, AxisLabelCollection.Empty()).Result; Assert.NotNull(output); Assert.True(output is OxyLineSeries); OxyLineSeries series = (OxyLineSeries)output; // Ensure that the line type matches the expected line type. Assert.AreEqual(expectedOutput, series.LineStyle); }
public void TestTitle() { // Create an apsim series with the given inputs. IEnumerable <object> x = Enumerable.Empty <object>(); IEnumerable <object> y = Enumerable.Empty <object>(); Line line = new Line(LineType.None, LineThickness.Thin); Marker marker = new Marker(MarkerType.FilledCircle, MarkerSize.Normal, 1); string[] titles = new[] { null, "", "A somewhat long title containing spaces" }; foreach (string title in titles) { LineSeries inputSeries = new LineSeries(title, Color.Black, true, x, y, line, marker, "", ""); Assert.AreEqual(title, exporter.Export(inputSeries, AxisLabelCollection.Empty()).Result.Title); } }
/// <summary> /// Ensure that the given data type is valid or invalid for series data. /// Ensure that the appropriate exception type is thrown for invalid /// data types, or that no exception is thrown for valid data types. /// </summary> /// <param name="valid">Is this data type valid.</param> /// <typeparam name="T">Data type.</typeparam> private void TestDataTypeValidity <T>(bool valid) { Line line = new Line(LineType.None, LineThickness.Thin); Marker marker = new Marker(MarkerType.FilledCircle, MarkerSize.Normal, 1); IEnumerable <T> emptyInvalid = Enumerable.Empty <T>(); IEnumerable <T> populatedInvalid = new List <T>() { default(T) }; IEnumerable <double> emptyValid = Enumerable.Empty <double>(); IEnumerable <double> populatedValid = new double[1]; // If the data type is an invalid nullable type, we should except an ArgumentNullException. // If the datatype is any other invalid type, we expect a NotImplementedException. Type exceptionType = default(T) == null ? typeof(ArgumentNullException) : typeof(NotImplementedException); IEnumerable <object> x = null; IEnumerable <object> y = null; TestDelegate createDefaultSeries = () => exporter.Export(new LineSeries("", Color.Black, false, x, y, line, marker, "", ""), AxisLabelCollection.Empty()); string errorHelper = $"DataType = {typeof(T)}"; // 1. Empty invalid x, valid y - no error should be thrown, because no data. x = emptyInvalid.Cast <object>(); y = emptyValid.Cast <object>(); Assert.DoesNotThrow(createDefaultSeries, errorHelper); // 2. Populated invalid x, valid y. x = populatedInvalid.Cast <object>(); y = populatedValid.Cast <object>(); if (valid) { Assert.DoesNotThrow(createDefaultSeries, errorHelper); } else { Assert.Throws(exceptionType, createDefaultSeries, errorHelper); } // 3. Empty invalid x, invalid y - no error should be thrown, because no data. x = emptyInvalid.Cast <object>(); y = emptyInvalid.Cast <object>(); Assert.DoesNotThrow(createDefaultSeries, errorHelper); // 4. Populated invalid x, invalid y. x = populatedInvalid.Cast <object>(); y = populatedInvalid.Cast <object>(); if (valid) { Assert.DoesNotThrow(createDefaultSeries, errorHelper); } else { Assert.Throws(exceptionType, createDefaultSeries, errorHelper); } // 5. Valid x, Empty invalid y - no error should be thrown, because no data. x = emptyValid.Cast <object>(); y = emptyInvalid.Cast <object>(); Assert.DoesNotThrow(createDefaultSeries, errorHelper); // 6. Valid x, Populated invalid y. x = populatedValid.Cast <object>(); y = populatedInvalid.Cast <object>(); if (valid) { Assert.DoesNotThrow(createDefaultSeries, errorHelper); } else { Assert.Throws(exceptionType, createDefaultSeries, errorHelper); } }