예제 #1
0
        public void GivenChartControlWithoutData_WhenDataSetToChartDataCollection_ThenChartControlUpdated()
        {
            // Given
            using (var chartControl = new ChartControl())
            {
                LinearPlotView linearPlotView             = GetLinearPlotView(chartControl);
                var            chartPointData             = new ChartPointData("Points");
                var            chartLineData              = new ChartLineData("Lines");
                var            chartAreaData              = new ChartAreaData("Areas");
                var            chartDataCollection        = new ChartDataCollection("Root collection");
                var            nestedChartDataCollection1 = new ChartDataCollection("Nested collection 1");
                var            nestedChartDataCollection2 = new ChartDataCollection("Nested collection 2");

                chartDataCollection.Add(chartPointData);
                chartDataCollection.Add(nestedChartDataCollection1);
                nestedChartDataCollection1.Add(chartLineData);
                nestedChartDataCollection1.Add(nestedChartDataCollection2);
                nestedChartDataCollection2.Add(chartAreaData);

                // When
                chartControl.Data = chartDataCollection;

                // Then
                ElementCollection <Series> series = linearPlotView.Model.Series;
                Assert.AreEqual(3, series.Count);
                Assert.AreEqual("Points", series[0].Title);
                Assert.AreEqual("Lines", series[1].Title);
                Assert.AreEqual("Areas", series[2].Title);
            }
        }
예제 #2
0
        public void GivenChartControlWithData_WhenChartDataNotifiesChange_ThenAllSeriesReused()
        {
            // Given
            using (var chartControl = new ChartControl())
            {
                LinearPlotView linearPlotView             = GetLinearPlotView(chartControl);
                var            chartPointData             = new ChartPointData("Points");
                var            chartLineData              = new ChartLineData("Lines");
                var            chartAreaData              = new ChartAreaData("Areas");
                var            chartDataCollection        = new ChartDataCollection("Root collection");
                var            nestedChartDataCollection1 = new ChartDataCollection("Nested collection 1");
                var            nestedChartDataCollection2 = new ChartDataCollection("Nested collection 2");

                chartDataCollection.Add(chartPointData);
                chartDataCollection.Add(nestedChartDataCollection1);
                nestedChartDataCollection1.Add(chartLineData);
                nestedChartDataCollection1.Add(nestedChartDataCollection2);
                nestedChartDataCollection2.Add(chartAreaData);

                chartControl.Data = chartDataCollection;

                List <Series> seriesBeforeUpdate = linearPlotView.Model.Series.ToList();

                // When
                chartLineData.Points = new Point2D[0];
                chartLineData.NotifyObservers();

                // Then
                CollectionAssert.AreEqual(seriesBeforeUpdate, linearPlotView.Model.Series);
            }
        }
예제 #3
0
        public void SetExtent_DataRangeInYSmallerThanMinimumRange_AxesUpdatedWithCorrectionForY()
        {
            // Setup
            using (var form = new Form())
                using (var view = new LinearPlotView())
                {
                    form.Controls.Add(view);

                    form.Show();

                    const double range = 0.02;
                    const int    xMin  = 3;
                    const int    xMax  = 7;
                    const int    yMin  = 1;

                    // Call
                    view.SetExtent(new Extent(xMin, xMax, yMin, yMin + range));

                    // Assert
                    Assert.AreEqual(xMin, view.Model.Axes[0].ActualMinimum);
                    Assert.AreEqual(xMax, view.Model.Axes[0].ActualMaximum);
                    Assert.AreEqual(yMin - 0.04, view.Model.Axes[1].ActualMinimum);
                    Assert.AreEqual(yMin + 0.06, view.Model.Axes[1].ActualMaximum);
                }
        }
예제 #4
0
        public void GivenChartControlWithData_WhenDataSetToOtherChartDataCollection_ThenChartControlUpdated()
        {
            // Given
            using (var chartControl = new ChartControl())
            {
                LinearPlotView linearPlotView       = GetLinearPlotView(chartControl);
                var            chartPointData       = new ChartPointData("Points");
                var            chartLineData        = new ChartLineData("Lines");
                var            chartAreaData        = new ChartAreaData("Areas");
                var            chartDataCollection1 = new ChartDataCollection("Collection 1");
                var            chartDataCollection2 = new ChartDataCollection("Collection 2");

                chartDataCollection1.Add(chartPointData);
                chartDataCollection2.Add(chartLineData);
                chartDataCollection2.Add(chartAreaData);

                chartControl.Data = chartDataCollection1;

                // Precondition
                Assert.AreEqual(1, linearPlotView.Model.Series.Count);
                Assert.AreEqual("Points", linearPlotView.Model.Series[0].Title);

                // When
                chartControl.Data = chartDataCollection2;

                // Then
                Assert.AreEqual(2, linearPlotView.Model.Series.Count);
                Assert.AreEqual("Lines", linearPlotView.Model.Series[0].Title);
                Assert.AreEqual("Areas", linearPlotView.Model.Series[1].Title);
            }
        }
예제 #5
0
        public void SetExtent_RangeLargerThanMinimumRange_AxesUpdated()
        {
            // Setup
            using (var form = new Form())
                using (var view = new LinearPlotView())
                {
                    form.Controls.Add(view);

                    form.Show();

                    const int xMin = 3;
                    const int xMax = 5;
                    const int yMin = 1;
                    const int yMax = 2;

                    // Call
                    view.SetExtent(new Extent(xMin, xMax, yMin, yMax));

                    // Assert
                    Assert.AreEqual(xMin, view.Model.Axes[0].ActualMinimum);
                    Assert.AreEqual(xMax, view.Model.Axes[0].ActualMaximum);
                    Assert.AreEqual(yMin, view.Model.Axes[1].ActualMinimum);
                    Assert.AreEqual(yMax, view.Model.Axes[1].ActualMaximum);
                }
        }
예제 #6
0
        public void ZoomToVisibleSeries_ChartInFormWithEmptyDataSetAndZoomChildChartData_ViewNotInvalidated()
        {
            // Setup
            using (var form = new Form())
            {
                var            chartControl   = new ChartControl();
                LinearPlotView linearPlotView = GetLinearPlotView(chartControl);
                form.Controls.Add(chartControl);
                form.Show();

                var chartDataCollection = new ChartDataCollection("Collection");
                var chartData           = new ChartPointData("Test data");
                var invalidated         = 0;

                chartDataCollection.Add(chartData);

                chartControl.Data = chartDataCollection;
                chartControl.Update();

                var expectedExtent = new Extent(
                    linearPlotView.Model.Axes[0].ActualMinimum,
                    linearPlotView.Model.Axes[0].ActualMaximum,
                    linearPlotView.Model.Axes[1].ActualMinimum,
                    linearPlotView.Model.Axes[1].ActualMaximum);

                linearPlotView.Invalidated += (sender, args) => invalidated++;

                // Call
                chartControl.ZoomToVisibleSeries(chartData);

                // Assert
                Assert.AreEqual(0, invalidated);
                AssertExpectedExtent(linearPlotView.Model.Axes, expectedExtent);
            }
        }
예제 #7
0
        public void DefaultConstructor_HasTwoLinearAxes()
        {
            // Call
            var view = new LinearPlotView();

            // Assert
            Assert.IsInstanceOf <PlotView>(view);
            Assert.AreEqual(DockStyle.Fill, view.Dock);

            ElementCollection <Axis> axes = view.Model.Axes;

            Assert.AreEqual(2, axes.Count);
            CollectionAssert.AllItemsAreInstancesOfType(axes, typeof(LinearAxis));
            CollectionAssert.AreEqual(new[]
            {
                "L",
                "Hoogte"
            }, axes.Select(a => a.Title));
            CollectionAssert.AreEqual(new[]
            {
                AxisPosition.Bottom,
                AxisPosition.Left
            }, axes.Select(a => a.Position));
            CollectionAssert.AreEqual(new[]
            {
                TickStyle.None,
                TickStyle.None
            }, axes.Select(a => a.TickStyle));
            CollectionAssert.AreEqual(new[]
            {
                AxisLayer.AboveSeries,
                AxisLayer.AboveSeries
            }, axes.Select(a => a.Layer));
            CollectionAssert.AreEqual(new[]
            {
                LineStyle.Solid,
                LineStyle.Solid
            }, axes.Select(a => a.MajorGridlineStyle));
            CollectionAssert.AreEqual(new[]
            {
                LineStyle.Dot,
                LineStyle.Dot
            }, axes.Select(a => a.MinorGridlineStyle));
            CollectionAssert.AreEqual(new[]
            {
                0.1,
                0.1
            }, axes.Select(a => a.MinimumRange));
            CollectionAssert.AreEqual(new[]
            {
                1.0e12,
                1.0e12
            }, axes.Select(a => a.MaximumRange));
        }
예제 #8
0
        public void Constructor_PropertiesSet()
        {
            // Call
            using (var chartControl = new ChartControl())
            {
                // Assert
                Assert.IsInstanceOf <UserControl>(chartControl);
                Assert.IsInstanceOf <IChartControl>(chartControl);
                Assert.IsNull(chartControl.Data);

                LinearPlotView linearPlotView = GetLinearPlotView(chartControl);
                Assert.AreEqual(Color.White, linearPlotView.BackColor);
                Assert.IsFalse(linearPlotView.Model.IsLegendVisible);
            }
        }
예제 #9
0
        public void ZoomToAll_ViewInForm_InvalidatesView()
        {
            // Setup
            using (var form = new Form())
                using (var view = new LinearPlotView())
                {
                    form.Controls.Add(view);
                    var invalidated = 0;
                    view.Invalidated += (sender, args) => invalidated++;

                    form.Show();

                    // Call
                    view.ZoomToAll();

                    // Assert
                    Assert.AreEqual(1, invalidated);
                }
        }
예제 #10
0
        public void ZoomToVisibleSeries_ChartInFormForChildChartData_ViewInvalidatedSeriesSame()
        {
            // Setup
            using (var form = new Form())
            {
                var            chartControl   = new ChartControl();
                LinearPlotView linearPlotView = GetLinearPlotView(chartControl);
                form.Controls.Add(chartControl);
                form.Show();

                var chartDataCollection = new ChartDataCollection("Collection");
                var chartData           = new ChartLineData("test data")
                {
                    IsVisible = true,
                    Points    = new[]
                    {
                        new Point2D(0.0, 0.0),
                        new Point2D(1.0, 1.0)
                    }
                };
                chartDataCollection.Add(chartData);
                var invalidated = 0;

                chartControl.Data = chartDataCollection;
                chartControl.Update();

                linearPlotView.Invalidated += (sender, args) => invalidated++;

                // Call
                chartControl.ZoomToVisibleSeries(chartData);

                // Assert
                Assert.AreEqual(1, invalidated);

                var expectedExtent = new Extent(
                    -0.01,
                    1.01,
                    -0.01,
                    1.01);

                AssertExpectedExtent(linearPlotView.Model.Axes, expectedExtent);
            }
        }
예제 #11
0
        public void SetLeftAxisTitle_Always_SetsNewTitleToLeftAxisAndInvalidatesView(string newTitle)
        {
            // Setup
            using (var form = new Form())
                using (var view = new LinearPlotView())
                {
                    form.Controls.Add(view);
                    var invalidated = 0;
                    view.Invalidated += (sender, args) => invalidated++;

                    form.Show();

                    // Call
                    view.LeftAxisTitle = newTitle;

                    // Assert
                    Assert.AreEqual(view.LeftAxisTitle, newTitle);
                    Assert.AreEqual(1, invalidated);
                }
        }
예제 #12
0
        public void GivenMultipleAreaSeriesAddedToView_WhenViewOpenedAndUpdated_ThenXYAxisIncludesSeriesValues()
        {
            // Given
            const int maxY   = 100;
            const int minY   = -25;
            const int maxX   = 50;
            const int minX   = -10;
            var       series = new MultipleAreaSeries
            {
                Areas =
                {
                    new[]
                    {
                        new DataPoint(minX, maxY)
                    },
                    new[]
                    {
                        new DataPoint(maxX, minY)
                    }
                }
            };

            using (var form = new Form())
                using (var view = new LinearPlotView())
                {
                    form.Controls.Add(view);

                    view.Model.Series.Add(series);

                    // When
                    form.Show();
                    view.Update();
                }

            // Then
            Assert.AreEqual(maxX, series.XAxis.DataMaximum);
            Assert.AreEqual(minX, series.XAxis.DataMinimum);
            Assert.AreEqual(maxY, series.YAxis.DataMaximum);
            Assert.AreEqual(minY, series.YAxis.DataMinimum);
        }
예제 #13
0
        public void GivenChartControlWithData_WhenChartDataAdded_ThenCorrespondingSeriesAddedAndOtherSeriesReused()
        {
            // Given
            using (var chartControl = new ChartControl())
            {
                LinearPlotView linearPlotView             = GetLinearPlotView(chartControl);
                var            chartPointData             = new ChartPointData("Points");
                var            chartLineData              = new ChartLineData("Lines");
                var            chartAreaData              = new ChartAreaData("Areas");
                var            chartDataCollection        = new ChartDataCollection("Root collection");
                var            nestedChartDataCollection1 = new ChartDataCollection("Nested collection 1");
                var            nestedChartDataCollection2 = new ChartDataCollection("Nested collection 2");

                chartDataCollection.Add(chartPointData);
                chartDataCollection.Add(nestedChartDataCollection1);
                nestedChartDataCollection1.Add(chartLineData);
                nestedChartDataCollection1.Add(nestedChartDataCollection2);
                nestedChartDataCollection2.Add(chartAreaData);

                chartControl.Data = chartDataCollection;

                List <Series> seriesBeforeUpdate = linearPlotView.Model.Series.ToList();

                // Precondition
                Assert.AreEqual(3, seriesBeforeUpdate.Count);

                // When
                nestedChartDataCollection1.Insert(0, new ChartAreaData("Additional areas"));
                nestedChartDataCollection1.NotifyObservers();

                // Then
                ElementCollection <Series> series = linearPlotView.Model.Series;
                Assert.AreEqual(4, series.Count);
                Assert.AreEqual("Points", series[0].Title);
                Assert.AreEqual("Additional areas", series[1].Title);
                Assert.AreEqual("Lines", series[2].Title);
                Assert.AreEqual("Areas", series[3].Title);
                Assert.AreEqual(0, seriesBeforeUpdate.Except(series).Count());
            }
        }
예제 #14
0
        public void SetChartTitle_Always_SetsNewTitleToModelAndViewInvalidated(string newTitle)
        {
            // Setup
            using (var form = new Form())
            {
                var            chartControl   = new ChartControl();
                LinearPlotView linearPlotView = GetLinearPlotView(chartControl);
                form.Controls.Add(chartControl);

                form.Show();

                var invalidated = 0;
                linearPlotView.Invalidated += (sender, args) => invalidated++;

                // Call
                chartControl.ChartTitle = newTitle;

                // Assert
                Assert.AreEqual(chartControl.ChartTitle, newTitle);
                Assert.AreEqual(1, invalidated);
            }
        }
예제 #15
0
        public void GivenChartControlWithData_WhenChartDataMoved_ThenCorrespondingSeriesMovedAndAllSeriesReused()
        {
            // Given
            using (var chartControl = new ChartControl())
            {
                LinearPlotView linearPlotView      = GetLinearPlotView(chartControl);
                var            chartPointData      = new ChartPointData("Points");
                var            chartLineData       = new ChartLineData("Lines");
                var            chartAreaData       = new ChartAreaData("Areas");
                var            chartDataCollection = new ChartDataCollection("Root collection");

                chartDataCollection.Add(chartPointData);
                chartDataCollection.Add(chartLineData);
                chartDataCollection.Add(chartAreaData);

                chartControl.Data = chartDataCollection;

                List <Series> seriesBeforeUpdate = linearPlotView.Model.Series.ToList();

                // Precondition
                Assert.AreEqual(3, seriesBeforeUpdate.Count);
                Assert.AreEqual("Points", seriesBeforeUpdate[0].Title);
                Assert.AreEqual("Lines", seriesBeforeUpdate[1].Title);
                Assert.AreEqual("Areas", seriesBeforeUpdate[2].Title);

                // When
                chartDataCollection.Remove(chartPointData);
                chartDataCollection.Add(chartPointData);
                chartDataCollection.NotifyObservers();

                // Then
                ElementCollection <Series> series = linearPlotView.Model.Series;
                Assert.AreEqual(3, series.Count);
                Assert.AreEqual("Lines", series[0].Title);
                Assert.AreEqual("Areas", series[1].Title);
                Assert.AreEqual("Points", series[2].Title);
                Assert.AreEqual(0, seriesBeforeUpdate.Except(series).Count());
            }
        }
예제 #16
0
        public void ZoomToVisibleSeries_ForInvisibleChildChartData_DoNotChangeViewExtentsOfChartView()
        {
            // Setup
            using (var form = new Form())
            {
                var            chartControl   = new ChartControl();
                LinearPlotView linearPlotView = GetLinearPlotView(chartControl);
                form.Controls.Add(chartControl);
                form.Show();

                var chartDataCollection = new ChartDataCollection("Collection");
                var chartData           = new ChartLineData("test data")
                {
                    IsVisible = false,
                    Points    = new[]
                    {
                        new Point2D(3.2, 4.1),
                        new Point2D(11.2, 5.8)
                    }
                };

                chartDataCollection.Add(chartData);
                chartControl.Data = chartDataCollection;
                chartControl.Update();

                var expectedExtent = new Extent(
                    linearPlotView.Model.Axes[0].ActualMinimum,
                    linearPlotView.Model.Axes[0].ActualMaximum,
                    linearPlotView.Model.Axes[1].ActualMinimum,
                    linearPlotView.Model.Axes[1].ActualMaximum);

                // Call
                chartControl.ZoomToVisibleSeries(chartData);

                // Assert
                AssertExpectedExtent(linearPlotView.Model.Axes, expectedExtent);
            }
        }
예제 #17
0
        public void GivenEmptyMultipleAreaSeriesAddedToView_WhenViewOpenedAndUpdated_ThenXYAxisNotChanged()
        {
            // Given

            var series = new MultipleAreaSeries();

            using (var form = new Form())
                using (var view = new LinearPlotView())
                {
                    form.Controls.Add(view);
                    view.Model.Series.Add(series);

                    // When
                    form.Show();
                    view.Update();
                }

            // Then
            Assert.AreEqual(double.NaN, series.XAxis.DataMaximum);
            Assert.AreEqual(double.NaN, series.XAxis.DataMinimum);
            Assert.AreEqual(double.NaN, series.YAxis.DataMaximum);
            Assert.AreEqual(double.NaN, series.YAxis.DataMinimum);
        }