private void CreateUIRepresentation() { if (Plotter == null) { return; } if (DataSource == null) { return; } drawnPaths.Clear(); DataSourceEnvironment environment = CreateEnvironment(); var points = DataSource.GetPoints(environment); var indexedPoints = IndexWrapper.Generate(points); // do nothing if there is nothing to draw if (!points.Any()) { return; } transformWhileCreateUI = Plotter.Viewport.Transform; int globalMinIndex; int globalMaxIndex; CreateAndAddPath(indexedPoints, out globalMinIndex, out globalMaxIndex, transformWhileCreateUI); indexRange = new Range <int>(globalMinIndex, globalMaxIndex); ViewportPanel.SetViewportBounds(canvas, Plotter.Viewport.Visible); // switching off content bounds calculation for children of ViewportHostPanel. panel.BeginBatchAdd(); if (canvas.Parent == null) { panel.Children.Add(canvas); } if (panel.Plotter == null) { Plotter.Dispatcher.BeginInvoke(() => { if (panel.Plotter == null && Plotter != null) { Plotter.Children.Add(panel); } }); } DataRect bounds = DataRect.Empty; if (environment.ContentBounds != null) { bounds = environment.ContentBounds.Value; } else { // todo is this necessary? bounds = points.GetBounds(); } Viewport2D.SetContentBounds(this, bounds); }
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(); } } }
protected override IEnumerable GetDataCore() { return(Filters.Filter(IndexWrapper.Generate(collection), Environment)); }