void UpdateGraph(GraphDataProvider provider)
        {
            var shape = this.shapeTable[provider];

            RebuildGraphGeometry(provider, shape.PathGeometry);
            shape.InvalidateVisual();
        }
        void RebuildGraphGeometry(GraphDataProvider provider, PathGeometry geometry)
        {
            ulong startTime = this.TimeAxis.VisibleTimeStart;
            ulong endTime   = this.TimeAxis.VisibleTimeEnd;
            ulong granularity;

            // "granularity" is the time period at which nodes start to disappear.  The graph data provider
            // will return at most 3 nodes in one granularity unit of time (min, max, last).
            granularity = (ulong)((endTime - startTime) / (this.graphGrid.ActualWidth / 12));

            var pathFigure = new PathFigure {
                IsClosed = true
            };
            var    nodes = provider.GetNodesInTimespan(startTime, endTime, granularity);
            double height = this.graphGrid.ActualHeight;
            double x = 0, lastY = 0;
            bool   first = true;

            foreach (var node in nodes)
            {
                x = this.TimeAxis.TimeToScreen(node.StartTime);
                double y = height - this.SideBar.YToPixels(node.Y);

                if (first)
                {
                    pathFigure.StartPoint = new Point(x, height);
                    pathFigure.Segments.Add(new LineSegment(new Point(x, y), false));
                    first = false;
                }
                else
                {
                    if (this.SquarePeaks)
                    {
                        pathFigure.Segments.Add(new LineSegment(new Point(x, lastY), true));
                    }

                    pathFigure.Segments.Add(new LineSegment(new Point(x, y), true));
                }

                lastY = y;
            }

            geometry.Figures.Clear();

            if (first)
            {
                // No data in this time window
                return;
            }

            pathFigure.Segments.Add(new LineSegment(new Point(x, height), false));
            geometry.Figures.Add(pathFigure);
        }
        static void OnIsSelectedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            GraphDataProvider provider = obj as GraphDataProvider;

            if (provider != null)
            {
                if (provider.IsSelected)
                {
                    provider.ZIndex = ++nextZIndex;
                }

                provider.SetRenderValues();
            }
        }
        public bool AddDataSource(IGraphDataSource graphDataSource)
        {
            if (graphDataProviders.Count == MaxDataSources)
            {
                // Maximum number of data sources has already been reached
                return(false);
            }

            var provider = new GraphDataProvider {
                DataSource = graphDataSource, IsGraphed = true
            };

            provider.PenData = graphDataPens.FirstOrDefault(p => !usedPens.Contains(p));
            if (!(graphDataSource is IHiddenGraphDataSource))
            {
                this.usedPens.Add(provider.PenData);
            }
            this.graphDataProviders.Add(provider);
            provider.DataChanged += OnProviderDataChanged;

            var shape = new GraphShape {
                Stroke = provider.PenData.Brush, StrokeDashCap = PenLineCap.Round, StrokeLineJoin = PenLineJoin.Round
            };

            shape.SetBinding(Shape.StrokeThicknessProperty, new Binding {
                Source = provider, Path = new PropertyPath(GraphDataProvider.StrokeThicknessProperty)
            });
            shape.SetBinding(Shape.StrokeDashArrayProperty, new Binding {
                Source = provider, Path = new PropertyPath(GraphDataProvider.StrokeDashArrayProperty)
            });
            shape.SetBinding(Shape.FillProperty, new Binding {
                Source = provider, Path = new PropertyPath(GraphDataProvider.FillProperty)
            });
            shape.SetBinding(Panel.ZIndexProperty, new Binding {
                Source = provider, Path = new PropertyPath(GraphDataProvider.ZIndexProperty)
            });

            this.shapeTable.Add(provider, shape);

            if (this.canvas != null)
            {
                this.canvas.Children.Add(shape);
            }

            OnProviderDataChanged(provider, EventArgs.Empty);

            return(true);
        }
 public GraphDataBar()
 {
     this.SideBar = new GraphDataSideBar(this);
     this.SideBar.VerticalAlignment      = VerticalAlignment.Top;
     this.SideBar.YAxisChanged          += OnYAxisChanged;
     this.SideBar.YAxisDefaultRequested += OnYAxisDefaultRequested;
     this.readOnlyProviders              = new ReadOnlyObservableCollection <GraphDataProvider>(graphDataProviders);
     CollectionViewSource.GetDefaultView(readOnlyProviders).Filter = (item =>
     {
         GraphDataProvider gdp = item as GraphDataProvider;
         return(!(gdp.DataSource is IHiddenGraphDataSource));
     });
     this.timeStart     = 0;
     this.DataRangeStop = 0;
     this.timeEnd       = this.MinimumGraphTime;
     InitPausePointShape();
 }
        static void OnDataSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            GraphDataProvider provider = obj as GraphDataProvider;

            if (provider != null)
            {
                var oldSource = e.OldValue as IGraphDataSource;

                if (oldSource != null)
                {
                    oldSource.DataChanged -= provider.OnDataChanged;
                }

                var newSource = e.NewValue as IGraphDataSource;

                if (newSource != null)
                {
                    newSource.DataChanged += provider.OnDataChanged;
                }
            }
        }
        void RebuildGraphGeometry(GraphDataProvider provider, PathGeometry geometry)
        {
            ulong startTime = this.TimeAxis.VisibleTimeStart;
            ulong endTime = this.TimeAxis.VisibleTimeEnd;
            ulong granularity;

            // "granularity" is the time period at which nodes start to disappear.  The graph data provider
            // will return at most 3 nodes in one granularity unit of time (min, max, last).
            granularity = (ulong)((endTime - startTime) / (this.graphGrid.ActualWidth / 12));

            var pathFigure = new PathFigure { IsClosed = true };
            var nodes = provider.GetNodesInTimespan(startTime, endTime, granularity);
            double height = this.graphGrid.ActualHeight;
            double x = 0, lastY = 0;
            bool first = true;

            foreach (var node in nodes)
            {
                x = this.TimeAxis.TimeToScreen(node.StartTime);
                double y = height - this.SideBar.YToPixels(node.Y);

                if (first)
                {
                    pathFigure.StartPoint = new Point(x, height);
                    pathFigure.Segments.Add(new LineSegment(new Point(x, y), false));
                    first = false;
                }
                else
                {
                    if (this.SquarePeaks)
                    {
                        pathFigure.Segments.Add(new LineSegment(new Point(x, lastY), true));
                    }

                    pathFigure.Segments.Add(new LineSegment(new Point(x, y), true));
                }

                lastY = y;
            }

            geometry.Figures.Clear();

            if (first)
            {
                // No data in this time window
                return;
            }

            pathFigure.Segments.Add(new LineSegment(new Point(x, height), false));
            geometry.Figures.Add(pathFigure);
        }
 void UpdateGraph(GraphDataProvider provider)
 {
     var shape = this.shapeTable[provider];
     RebuildGraphGeometry(provider, shape.PathGeometry);
     shape.InvalidateVisual();
 }
        public bool AddDataSource(IGraphDataSource graphDataSource)
        {
            if (graphDataProviders.Count == MaxDataSources)
            {
                // Maximum number of data sources has already been reached
                return false;
            }

            var provider = new GraphDataProvider { DataSource = graphDataSource, IsGraphed = true };
            provider.PenData = graphDataPens.FirstOrDefault(p => !usedPens.Contains(p));
            if (!(graphDataSource is IHiddenGraphDataSource))
            {
                this.usedPens.Add(provider.PenData);
            }
            this.graphDataProviders.Add(provider);
            provider.DataChanged += OnProviderDataChanged;

            var shape = new GraphShape { Stroke = provider.PenData.Brush, StrokeDashCap = PenLineCap.Round, StrokeLineJoin = PenLineJoin.Round };

            shape.SetBinding(Shape.StrokeThicknessProperty, new Binding { Source = provider, Path = new PropertyPath(GraphDataProvider.StrokeThicknessProperty) });
            shape.SetBinding(Shape.StrokeDashArrayProperty, new Binding { Source = provider, Path = new PropertyPath(GraphDataProvider.StrokeDashArrayProperty) });
            shape.SetBinding(Shape.FillProperty, new Binding { Source = provider, Path = new PropertyPath(GraphDataProvider.FillProperty) });
            shape.SetBinding(Panel.ZIndexProperty, new Binding { Source = provider, Path = new PropertyPath(GraphDataProvider.ZIndexProperty) });

            this.shapeTable.Add(provider, shape);

            if (this.canvas != null)
            {
                this.canvas.Children.Add(shape);
            }

            OnProviderDataChanged(provider, EventArgs.Empty);

            return true;
        }