public void GradualChartSizeChanges()
        {
            Chart chart = new Chart {
                Template = (ControlTemplate)XamlReader.Load(BareChartTemplate)
            };
            DataPointSeries series = DefaultDataPointSeriesToTest;

            series.IndependentValueBinding = new Binding();
            series.ItemsSource             = new int[] { 1, 2, 3 };
            chart.Series.Add(series);
            EnqueueCallback(() => TestPanel.Children.Add(chart));
            for (int i = 400; 0 <= i; i--)
            {
                var capture = i;
                EnqueueCallback(() => chart.Width  = capture);
                EnqueueCallback(() => chart.Height = capture / 2);
            }
            for (int i = 1; i < 200; i++)
            {
                var capture = i;
                EnqueueCallback(() => chart.Width  = capture);
                EnqueueCallback(() => chart.Height = capture / 2);
            }
            EnqueueTestComplete();
        }
Ejemplo n.º 2
0
        private void UpdateSeriesSettings()
        {
            var numberOfSeries = (int)NumberOfSeries.Value;

            for (int i = 0; i < _seriesSettingsCollection.Count; i++)
            {
                bool seriesInUse = (i < numberOfSeries);
                _seriesSettingsCollection[i].Enabled = seriesInUse;
                if (null != Chart)
                {
                    DataPointSeries series = _seriesSettingsCollection[i].Series;
                    if (seriesInUse)
                    {
                        if (!Chart.Series.Contains(series))
                        {
                            Chart.Series.Insert(i, series);
                        }
                    }
                    else
                    {
                        if (Chart.Series.Contains(series))
                        {
                            Chart.Series.Remove(series);
                        }
                    }
                }
            }
        }
        public void SettingLegendItemStyleAfterTitleWorks()
        {
            Chart           chart  = new Chart();
            DataPointSeries series = DefaultDataPointSeriesToTest;

            series.IndependentValueBinding = new Binding();
            series.ItemsSource             = new int[] { 1, 2, 3 };
            series.Title = "Title";
            chart.Series.Add(series);
            TestAsync(
                chart,
                () =>
            {
                Style style = new Style(typeof(LegendItem));
                style.Setters.Add(new Setter(Control.FontSizeProperty, 50.0));
                series.LegendItemStyle = style;
            },
                () =>
            {
                foreach (LegendItem item in chart.GetVisualDescendents().OfType <LegendItem>())
                {
                    Assert.AreEqual(50, item.FontSize);
                }
            });
        }
        public void DateTimeAxisWorksAsIndependentAxis()
        {
            Chart           chart  = new Chart();
            DataPointSeries series = DefaultSeriesToTest;

            series.DependentValueBinding   = new Binding("Value");
            series.IndependentValueBinding = new Binding("Key");
            series.ItemsSource             = new KeyValuePair <DateTime, int>[]
            {
                new KeyValuePair <DateTime, int>(new DateTime(2009, 1, 1), 1),
                new KeyValuePair <DateTime, int>(new DateTime(2009, 1, 2), 3),
                new KeyValuePair <DateTime, int>(new DateTime(2009, 1, 3), 4),
            };
            var axis = new DateTimeAxis();

            axis.Interval     = 1;
            axis.IntervalType = DateTimeIntervalType.Days;
            if (series is BarSeries)
            {
                axis.Orientation = AxisOrientation.Y;
                ((BarSeries)series).IndependentAxis = axis;
            }
            else
            {
                axis.Orientation = AxisOrientation.X;
                ((ColumnSeries)series).IndependentAxis = axis;
            }
            chart.Series.Add(series);
            TestAsync(
                chart,
                () => Assert.AreEqual(3, ChartTestUtilities.GetDataPointsForSeries(series).Count));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Occurs when an input device begins a manipulation on the plot.
 /// </summary>
 /// <param name="e">
 /// The <see cref="OxyPlot.OxyMouseEventArgs" /> instance containing the event data.
 /// </param>
 public override void Started(OxyMouseEventArgs e)
 {
     base.Started(e);
     currentSeries = PlotView?.ActualModel?.Series
                     .FirstOrDefault(s => s.IsVisible) as DataPointSeries;
     Delta(e);
 }
        /// <summary>
        /// Generates various Series samples.
        /// </summary>
        /// <param name="panel">Panel to add the generated Charts to.</param>
        /// <param name="seriesConstructor">Function that returns a Series instance for each sample.</param>
        /// <param name="scenarios">Collection of scenarios to generate.</param>
        /// <param name="chartModifier">Function that applies any necessary modifications to the Chart.</param>
        private static void GenerateSeriesSamples(Panel panel, Func <Series> seriesConstructor, IEnumerable <Scenario> scenarios, Action <Chart> chartModifier)
        {
            Style wrapperStyle = Application.Current.Resources["WrapperStyle"] as Style;

            // For each scenario...
            foreach (Scenario scenario in scenarios)
            {
                // Create the sample Chart
                Chart chart = new Chart {
                    Title = scenario.Title, MaxWidth = 500, MaxHeight = 270
                };
                foreach (IEnumerable itemsSource in scenario.ItemsSources)
                {
                    DataPointSeries series = seriesConstructor() as DataPointSeries;
                    series.ItemsSource             = itemsSource;
                    series.DependentValueBinding   = scenario.DependentValueBinding;
                    series.IndependentValueBinding = scenario.IndependentValueBinding;
                    chart.Series.Add(series);
                }
                if (null != chartModifier)
                {
                    chartModifier(chart);
                }

                // Wrap the Chart in a suitably formatted Grid
                Grid grid = new Grid {
                    Style = wrapperStyle
                };
                grid.Children.Add(chart);
                panel.Children.Add(grid);
            }
        }
        private void chart_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ChartDataBase chartData = null;

            DataPointSeries seriesSender = (DataPointSeries)sender;

            foreach (var item in this.charts)
            {
                if (item.Series == sender)
                {
                    chartData = item;
                    continue;
                }

                item.Series.SelectionChanged -= this.chart_SelectionChanged;
                item.Series.SelectedItem      = null;
                item.Series.SelectionChanged += this.chart_SelectionChanged;
            }

            if (!chartData.HasFilter)
            {
                this.mainCollectionView.ClearSearch();
            }
            else
            {
                var filter = chartData.GetFilter(seriesSender.SelectedItem);
                this.mainCollectionView.SpecialSearch(filter.Item1, filter.Item2);
            }
        }
        public void DependentValueBindingConsistentWithDependentValuePath()
        {
            DataPointSeries series = DefaultSeriesToTest as DataPointSeries;

            string path = "Path1";

            series.DependentValueBinding = new Binding(path);
            Assert.IsNotNull(series.DependentValueBinding);
            Assert.AreEqual(path, series.DependentValueBinding.Path.Path);
            Assert.AreEqual(path, series.DependentValuePath);

            series.DependentValueBinding = null;
            Assert.IsNull(series.DependentValueBinding);
            Assert.IsNull(series.DependentValuePath);

            path = "Path2";
            series.DependentValuePath = path;
            Assert.AreEqual(path, series.DependentValuePath);
            Assert.IsNotNull(series.DependentValueBinding);
            Assert.AreEqual(path, series.DependentValueBinding.Path.Path);

            series.DependentValuePath = null;
            Assert.IsNull(series.DependentValuePath);
            Assert.IsNull(series.DependentValueBinding);

            path = "";
            series.DependentValuePath = path;
            Assert.AreEqual(path, series.DependentValuePath);
            Assert.IsNotNull(series.DependentValueBinding);
            Assert.AreEqual(path, series.DependentValueBinding.Path.Path);
        }
Ejemplo n.º 9
0
        public void PieSeriesWithTwoDoubles()
        {
            KeyValuePair <string, double>[] objects = new KeyValuePair <string, double>[]
            {
                new KeyValuePair <string, double>("A", 90000.0),
                new KeyValuePair <string, double>("B", 80000.0),
            };
            Chart           chart     = new Chart();
            DataPointSeries pieSeries = DefaultSeriesToTest;

            chart.Series.Add(pieSeries);
            pieSeries.IndependentValueBinding = new Binding("Key");
            pieSeries.DependentValueBinding   = new Binding("Value");
            TestAsync(
                chart,
                () => pieSeries.ItemsSource = objects,
                () => Assert.AreEqual(2, chart.LegendItems.Cast <object>().Count()),
                () =>
            {
                IList <PieDataPoint> pieDataPoints = ChartTestUtilities.GetDataPointsForSeries(pieSeries).Cast <PieDataPoint>().ToList();
                Assert.AreEqual(2, pieDataPoints.Count);
                foreach (PieDataPoint pieDataPoint in pieDataPoints)
                {
                    Assert.IsNotNull(pieDataPoint.Geometry);
                    Assert.AreSame(typeof(PathGeometry), pieDataPoint.Geometry.GetType());
                    Assert.IsNotNull(pieDataPoint.GeometryHighlight);
                    Assert.AreSame(typeof(PathGeometry), pieDataPoint.GeometryHighlight.GetType());
                    Assert.IsNotNull(pieDataPoint.GeometrySelection);
                    Assert.AreSame(typeof(PathGeometry), pieDataPoint.GeometrySelection.GetType());
                }
            });
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Occurs when a manipulation is complete.
        /// </summary>
        /// <param name="e">
        /// The <see cref="OxyPlot.OxyMouseEventArgs" /> instance containing the event data.
        /// </param>
        public override void Completed(OxyMouseEventArgs e)
        {
            base.Completed(e);
            e.Handled = true;

            currentSeries = null;
            PlotView.HideTracker();
        }
Ejemplo n.º 11
0
        public void TitleChangeString()
        {
            DataPointSeries series = DefaultSeriesToTest;
            string          title  = "String Title";

            series.Title = title;
            Assert.AreSame(title, series.Title);
        }
Ejemplo n.º 12
0
        public void TransitionDurationChange()
        {
            DataPointSeries series   = DefaultSeriesToTest;
            TimeSpan        duration = TimeSpan.FromSeconds(2);

            series.TransitionDuration = duration;
            Assert.AreEqual(duration, series.TransitionDuration);
        }
Ejemplo n.º 13
0
        public FuncPlotC(Func <double, double> f, double x0, double x1)
        {
            this.F  = f;
            this.X0 = x0;
            this.X1 = x1;

            S = new FunctionSeries();
        }
Ejemplo n.º 14
0
        public void TitleChangeObject()
        {
            DataPointSeries series = DefaultSeriesToTest;
            object          title  = new object();

            series.Title = title;
            Assert.AreSame(title, series.Title);
        }
Ejemplo n.º 15
0
 void FillDataPoints(DataPointSeries series)
 {
     series.Points.Clear();
     for (int i = 0; i < this._maxPoints; i++)
     {
         series.Points.Add(new DataPoint(i, 0));
     }
 }
Ejemplo n.º 16
0
        public void ItemsSourceChangeEmpty()
        {
            DataPointSeries  series           = DefaultSeriesToTest;
            ObjectCollection objectCollection = new ObjectCollection();

            series.ItemsSource = objectCollection;
            Assert.AreSame(objectCollection, series.ItemsSource);
        }
Ejemplo n.º 17
0
        public static void SetDependentAxis(this DataPointSeries series, DisplayAxis axis)
        {
            SeriesPropertyInformation seriesPropertyInformation = _seriesPropertyInformations[series.GetType()];

            if (null != seriesPropertyInformation.DependentAxisProperty)
            {
                series.SetValue(seriesPropertyInformation.DependentAxisProperty, axis);
            }
        }
        public void ClearAnUnusedSeries()
        {
            Chart           chart  = new Chart();
            DataPointSeries series = DefaultDataPointSeriesToTest;

            chart.Series.Add(series);
            TestAsync(
                chart,
                () => chart.Series.Clear());
        }
Ejemplo n.º 19
0
        public void TitleChangeButton()
        {
            DataPointSeries series = DefaultSeriesToTest;
            Button          title  = new Button {
                Content = "Button Title"
            };

            series.Title = title;
            Assert.AreSame(title, series.Title);
        }
Ejemplo n.º 20
0
        public static DisplayAxis GetDependentAxis(this DataPointSeries series)
        {
            SeriesPropertyInformation seriesPropertyInformation = _seriesPropertyInformations[series.GetType()];

            if (null != seriesPropertyInformation.DependentAxisProperty)
            {
                return(series.GetValue(seriesPropertyInformation.DependentAxisProperty) as DisplayAxis);
            }
            return(null);
        }
Ejemplo n.º 21
0
        private void PlotSmoothing(float time, float value, DataPointSeries line, bool doSmoothing)
        {
            line.Points.Add(new DataPoint(time, value));
            _dataSmoother.AddValue(value);

            if (doSmoothing)
            {
                DoSmoothing(line);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// When template is applied, the valuse of IndependentValuePath and DependentValuePath are propagated to the
        /// corresponding properties in PieSeries.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.UpdateValuePaths();

            series = this.GetTemplateChild("PieSeries_PART") as DataPointSeries;
            if (series != null)
            {
                series.SelectionChanged += new SelectionChangedEventHandler(series_SelectionChanged);
            }
        }
Ejemplo n.º 23
0
        public void ItemsSourceSwap()
        {
            DataPointSeries series = DefaultSeriesToTest;
            ObservableCollection <object> observableCollection = new ObservableCollection <object>();

            series.ItemsSource = observableCollection;
            Assert.AreSame(observableCollection, series.ItemsSource);
            observableCollection = new ObservableCollection <object>();
            series.ItemsSource   = observableCollection;
            Assert.AreSame(observableCollection, series.ItemsSource);
        }
 public void SetChartData <T, U>(List <KeyValuePair <T, U> > data, DiagramType type)
 {
     this._data                      = ChartTypeConverter(type);
     this._data.ItemsSource          = data;
     this._data.DependentValuePath   = "Value";
     this._data.IndependentValuePath = "Key";
     // Reload the Diagram
     this.Diagram          = new Chart();
     this._data.SeriesHost = null;
     this.Diagram.Series.Add(_data);
 }
        public virtual void UseDateTimeValueAsDependentValue()
        {
            Chart           chart  = new Chart();
            DataPointSeries series = DefaultSeriesToTest;

            DateTime[] dateTimes = new[] { DateTime.Now };
            TestAsync(
                chart,
                () => chart.Series.Add(series),
                () => series.ItemsSource = dateTimes);
        }
        public void SimpleChartOneIntegerValueZero()
        {
            DataPointSeries series = DefaultSeriesToTest;

            series.ItemsSource = new int[] { 0 };
            Chart chart = new Chart();

            chart.Series.Add(series);
            TestAsync(
                chart,
                () => Assert.AreEqual(1, ChartTestUtilities.GetDataPointsForSeries(series).Count));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Creates an example model and fills the specified series with points.
        /// </summary>
        /// <param name="series">The series.</param>
        /// <returns>A plot model.</returns>
        private static PlotModel CreateExampleModel(DataPointSeries series)
        {
            var model = new PlotModel { Title = "StemSeries", LegendSymbolLength = 24 };
            series.Title = "sin(x)";
            for (double x = 0; x < Math.PI * 2; x += 0.1)
            {
                series.Points.Add(new DataPoint(x, Math.Sin(x)));
            }

            model.Series.Add(series);
            return model;
        }
        public void AutomaticSeriesTitleRemoved()
        {
            DataPointSeries series = DefaultSeriesToTest;
            Chart           chart  = new Chart();

            TestAsync(
                chart,
                () => chart.Series.Add(series),
                () => Assert.AreEqual("Series 1", series.Title),
                () => chart.Series.Remove(series),
                () => Assert.IsNull(series.Title));
        }
        public void SimpleChartTwoIntegers()
        {
            DataPointSeries series = DefaultSeriesToTest;

            series.ItemsSource = new List <int>(new int[] { 1, -1 });
            Chart chart = new Chart();

            chart.Series.Add(series);
            TestAsync(
                chart,
                () => Assert.AreEqual(2, ChartTestUtilities.GetDataPointsForSeries(series).Count));
        }
        public void AutomaticSeriesTitleOverriddenByInPlaceBinding()
        {
            DataPointSeries series = DefaultSeriesToTest;
            Chart           chart  = new Chart();

            chart.DataContext = "Custom Title";
            series.SetBinding(Series.TitleProperty, new Binding());
            TestAsync(
                chart,
                () => chart.Series.Add(series),
                () => Assert.AreEqual("Custom Title", series.Title));
        }
Ejemplo n.º 31
0
        public void ItemsSourceContentChange()
        {
            DataPointSeries            series = DefaultSeriesToTest;
            ObservableCollection <int> observableCollection = new ObservableCollection <int>();

            observableCollection.Add(3);
            series.ItemsSource = observableCollection;
            Assert.AreSame(observableCollection, series.ItemsSource);
            observableCollection.Add(5);
            Assert.AreSame(observableCollection, series.ItemsSource);
            observableCollection.RemoveAt(0);
            Assert.AreSame(observableCollection, series.ItemsSource);
        }
        public static AnimationFrame GetFinalAnimationFrame(DataPointSeries series)
        {
            var animationFrame = new AnimationFrame
            {
                Duration = TimeSpan.Zero
            };

            var points = series.GetAnimatablePoints();
            foreach (var point in points)
            {
                animationFrame.AnimationPoints.Add(new AnimationPoint
                {
                    X = point.FinalX,
                    Y = point.FinalY
                });
            }

            return animationFrame;
        }
        public static async Task AnimateSeriesAsync(
            this PlotModel plotModel,
            DataPointSeries series,
            List<AnimationFrame> animationFrames)
        {
            if (animationFrames.Count == 0)
            {
                return;
            }

            var finalAnimationFrame = GetFinalAnimationFrame(series);
            animationFrames.Add(finalAnimationFrame);

            var xAxis = plotModel.DefaultXAxis;
            var oldXAxisMinimum = xAxis.Minimum;
            var oldXAxisMaximum = xAxis.Maximum;

            xAxis.Minimum = xAxis.ActualMinimum;
            xAxis.Maximum = xAxis.ActualMaximum;

            var yAxis = plotModel.DefaultYAxis;
            var oldYAxisMinimum = yAxis.Minimum;
            var oldYAxisMaximum = yAxis.Maximum;

            yAxis.Minimum = yAxis.ActualMinimum;
            yAxis.Maximum = yAxis.ActualMaximum;

            var previousDataFieldX = series.DataFieldX;
            var previousDataFieldY = series.DataFieldY;

            // Always fix up the data fields (we are using IAnimatablePoint from now on)
            series.DataFieldX = "X";
            series.DataFieldY = "Y";

            var points = series.GetAnimatablePoints();

            foreach (var animationFrame in animationFrames)
            {
                // TODO: consider implementing the IsVisible feature

                var animationPoints = animationFrame.AnimationPoints;
                if (animationPoints.Count > 0)
                {
                    for (var j = 0; j < points.Count; j++)
                    {
                        var animatablePoint = points[j];
                        if (animatablePoint != null)
                        {
                            if (j < animationPoints.Count)
                            {
                                var animationPoint = animationPoints[j];

                                animatablePoint.X = animationPoint.X;
                                animatablePoint.Y = animationPoint.Y;
                            }
                        }
                    }
                }

                plotModel.InvalidatePlot(true);

                await Task.Delay(animationFrame.Duration);
            }

            xAxis.Minimum = oldXAxisMinimum;
            xAxis.Maximum = oldXAxisMaximum;

            yAxis.Minimum = oldYAxisMinimum;
            yAxis.Maximum = oldYAxisMaximum;

            series.DataFieldX = previousDataFieldX;
            series.DataFieldY = previousDataFieldY;

            plotModel.InvalidatePlot(true);
        }