Ejemplo n.º 1
0
        private void HandleCollectionAdd(NotifyCollectionChangedEventArgs e)
        {
            Range <int> addedRange = e.GetAddedRange();

            var paths = (from path in drawnPaths
                         let pathRange = PointChartBase.GetIndexRange(path)
                                         where pathRange.IntersectsWith(addedRange)
                                         let bounds = PointChartBase.GetContentBounds(path)
                                                      select new { path, bounds }).ToList();

            DataRect unitedContentBounds = paths.Aggregate(
                DataRect.Empty, (rect, other) => DataRect.Union(rect, other.bounds));

            var added = e.NewItems;

            // todo finish
        }
Ejemplo n.º 2
0
        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            base.OnCollectionChanged(e);

            // todo temp
            HandleCollectionReset();
            return;

            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                HandleCollectionReset();
            }
            else if (e.Action == NotifyCollectionChangedAction.Add)
            {
                if (e.NewItems != null)
                {
                    Range <int> addedRange = e.GetAddedRange();

                    if (indexRange.IntersectsWith(addedRange))
                    {
                        HandleCollectionAdd(e);
                    }
                    else if (indexRange.Max == addedRange.Min - 1)                     // item was added into the end of collection
                    {
                        Path        lastPath     = drawnPaths.Last();
                        int         lastCount    = LineChartBase.GetPointsCount(lastPath);
                        Range <int> requestRange = new Range <int>(addedRange.Min - 1, addedRange.Max);

                        // have path with non-filled geometry
                        if (lastCount + addedRange.GetLength() <= pathLength)
                        {
                            canvas.Children.Remove(lastPath);
                            drawnPaths.Remove(lastPath);
                            pathsPool.Put(lastPath);
                            Range <int> lastPathRange = PointChartBase.GetIndexRange(lastPath);
                            int         min           = requestRange.Min;

                            if (min % pathLength == 0)
                            {
                                min -= 1;
                            }

                            requestRange = new Range <int>(min, addedRange.Max);
                        }

                        var points = DataSource.GetPointData(requestRange);

                        var indexedPoints = IndexWrapper.Generate(points, requestRange.Min);

                        // do nothing if there is nothing to draw
                        if (!points.Any())
                        {
                            return;
                        }

                        int minIndex;
                        int maxIndex;
                        CreateAndAddPath(indexedPoints, out minIndex, out maxIndex, transformWhileCreateUI);

                        this.indexRange = new Range <int>(indexRange.Min, maxIndex);
                    }
                    else
                    {
                        // todo
                        // do nothing?
                    }
                }
                else
                {
                    HandleCollectionReset();
                }
            }
        }
Ejemplo n.º 3
0
        private void CreateAndAddPath(IEnumerable <IndexWrapper <Point> > indexedPoints,
                                      out int globalMinIndex, out int globalMaxIndex, CoordinateTransform transform)
        {
            var screenPoints = indexedPoints.DataToScreen(transform);

            var parts = screenPoints.Split(pathLength);

            var splittedParts = from part in parts
                                select missingValueSplitter.SplitMissingValue(part);

            bool isSmoothJoin = UseSmoothJoin;

            Point?lastPoint = null;

            globalMinIndex = Int32.MaxValue;
            globalMaxIndex = Int32.MinValue;

            foreach (var shortSegment in splittedParts)
            {
                foreach (var part in shortSegment)
                {
                    if (part.MinIndex < globalMinIndex)
                    {
                        globalMinIndex = part.MinIndex;
                    }
                    if (part.MaxIndex > globalMaxIndex)
                    {
                        globalMaxIndex = part.MaxIndex;
                    }

                    List <Point> list = part.GetPoints().ToList();
                    if (list.Count == 0)
                    {
                        continue;
                    }

                    if (part.Splitted)
                    {
                        lastPoint = null;
                    }

                    StreamGeometry geometry = new StreamGeometry();
                    using (var context = geometry.Open())
                    {
                        var start = lastPoint ?? list[0];

                        context.BeginFigure(start, isFilled: false, isClosed: false);
                        context.PolyLineTo(list, isStroked: true, isSmoothJoin: isSmoothJoin);
                    }

                    lastPoint = list.Last();

                    Path path = pathsPool.GetOrCreate();
                    drawnPaths.Add(path);

                    PointChartBase.SetIndexRange(path, new Range <int>(part.MinIndex, part.MaxIndex));
                    LineChartBase.SetPointsCount(path, list.Count);

                    DataRect localBounds = list.GetBounds();
                    PointChartBase.SetContentBounds(path, localBounds);

                    //if (path.CacheMode == null)
                    //    path.CacheMode = new BitmapCache();

                    // todo for debug purpose
                    //path.Stroke = ColorHelper.RandomBrush;

                    path.SetBinding(Path.StrokeProperty, strokeBinding);
                    path.SetBinding(Path.StrokeThicknessProperty, strokeThicknessBinding);
                    path.SetBinding(Path.StrokeDashArrayProperty, strokeDashArrayBinding);
                    path.SetBinding(Panel.ZIndexProperty, zIndexBinding);
                    path.SetBinding(Path.IsHitTestVisibleProperty, isHitTestVisibleBinding);
                    path.SetBinding(Path.VisibilityProperty, visibilityBinding);
                    path.SetBinding(Path.ToolTipProperty, tooltipBinding);

                    path.Data = geometry;

                    canvas.Children.Add(path);
                }
            }
        }
Ejemplo n.º 4
0
        private static void OnDataSourceReplaced(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PointChartBase owner = (PointChartBase)d;

            owner.OnDataSourceReplaced((PointDataSourceBase)e.OldValue, (PointDataSourceBase)e.NewValue);
        }
Ejemplo n.º 5
0
        private static void OnItemsSourceReplaced(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PointChartBase owner = (PointChartBase)d;

            owner.OnItemsSourceReplacedCore(e.OldValue, e.NewValue);
        }