Beispiel #1
0
        public void AddRow_ValidDataWithColor_AddRowToCollection()
        {
            // Setup
            const string name   = "Row 1";
            var          values = new[]
            {
                1.2
            };
            Color color = Color.Yellow;

            var data = new StackChartData();

            data.AddColumn("Column 1");

            // Call
            data.AddRow(name, values, color);

            // Assert
            Assert.AreEqual(1, data.Rows.Count());
            RowChartData row = data.Rows.First();

            Assert.AreEqual(name, row.Name);
            CollectionAssert.AreEqual(values, row.Values);
            Assert.AreEqual(color, row.Color);
        }
        /// <summary>
        /// Converts all general properties of <see cref="RowChartData"/>
        /// from <paramref name="data"/> to <paramref name="series"/>.
        /// </summary>
        /// <param name="data">The row chart data to convert the general properties from.</param>
        /// <param name="series">The series to convert the general properties to.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="data"/>
        /// or <paramref name="series"/> is <c>null</c>.</exception>
        public static void ConvertSeriesProperties(RowChartData data, ColumnSeries series)
        {
            ValidateParameters(data, series);

            series.Title = data.Name;

            if (data.Color.HasValue)
            {
                series.FillColor = ChartDataHelper.Convert(data.Color.Value);
            }
        }
        private static void ValidateParameters(RowChartData data, ColumnSeries series)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data), @"Null data cannot be converted into series data.");
            }

            if (series == null)
            {
                throw new ArgumentNullException(nameof(series), @"Null data cannot be used as conversion target.");
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new instance of <see cref="RowChartDataSeries"/>.
        /// </summary>
        /// <param name="rowChartData">The <see cref="RowChartData"/> which the series is based upon.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="rowChartData"/> is <c>null</c>.</exception>
        public RowChartDataSeries(RowChartData rowChartData)
        {
            if (rowChartData == null)
            {
                throw new ArgumentNullException(nameof(rowChartData));
            }

            IsStacked       = true;
            StrokeThickness = 1;

            RowChartDataConverter.ConvertSeriesData(rowChartData, this);
            RowChartDataConverter.ConvertSeriesProperties(rowChartData, this);
        }
Beispiel #5
0
        public void ConvertSeriesData_SeriesNull_ThrowsArgumentNullException()
        {
            // Setup
            var rowData = new RowChartData("data", new double[0], null);

            // Call
            TestDelegate test = () => RowChartDataConverter.ConvertSeriesData(rowData, null);

            // Assert
            const string expectedMessage = "Null data cannot be used as conversion target.";
            var          exception       = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentNullException>(test, expectedMessage);

            Assert.AreEqual("series", exception.ParamName);
        }
Beispiel #6
0
        public void ConvertSeriesData_DataWithValues_ColumnItemsAddedToSeries()
        {
            // Setup
            var values = new[]
            {
                0.2,
                0.7,
                0.1
            };

            var rowData = new RowChartData("data", values, null);
            var series  = new ColumnSeries();

            // Call
            RowChartDataConverter.ConvertSeriesData(rowData, series);

            // Assert
            CollectionAssert.AreEqual(values, series.Items.Select(i => i.Value));
        }
Beispiel #7
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            const string name   = "Row 1";
            Color        color  = Color.Blue;
            var          values = new[]
            {
                1.2,
                2.3
            };

            // Call
            var row = new RowChartData(name, values, color);

            // Assert
            Assert.AreEqual(name, row.Name);
            Assert.AreEqual(color, row.Color);
            CollectionAssert.AreEqual(values, row.Values);
        }
Beispiel #8
0
        public void ConvertSeriesProperties_WithData_SetPropertiesOfSeries(bool withColor)
        {
            // Setup
            const string name  = "data";
            Color?       color = withColor
                               ? (Color?)Color.Red
                               : null;

            var rowData = new RowChartData(name, new double[0], color);
            var series  = new ColumnSeries();

            // Call
            RowChartDataConverter.ConvertSeriesProperties(rowData, series);

            // Assert
            Assert.AreEqual(name, series.Title);

            OxyColor actualColor = withColor
                                       ? OxyColor.FromArgb(color.Value.A, color.Value.R, color.Value.G, color.Value.B)
                                       : OxyColors.Automatic;

            Assert.AreEqual(actualColor, series.FillColor);
        }
        /// <summary>
        /// Sets data to <paramref name="series"/> based on <paramref name="data"/>.
        /// </summary>
        /// <param name="data">The row chart data to create the series from.</param>
        /// <param name="series">The series to set the converted data to.</param>
        public static void ConvertSeriesData(RowChartData data, ColumnSeries series)
        {
            ValidateParameters(data, series);

            series.Items.AddRange(data.Values.Select(i => new ColumnItem(i)));
        }