Ejemplo n.º 1
0
        private static IEnumerable <FrameworkElement> DefaultLegendItemsBuilder(IPlotterElement element)
        {
            LineChartBase lineChart = (LineChart)element;

            Line line = new Line
            {
                X1          = 0,
                Y1          = 10,
                X2          = 20,
                Y2          = 0,
                Stretch     = Stretch.Fill,
                DataContext = lineChart
            };

            line.SetBinding(Line.StrokeProperty, "Stroke");
            line.SetBinding(Line.StrokeThicknessProperty, "StrokeThickness");
            line.SetBinding(Line.StrokeDashArrayProperty, "StrokeDashArray");
            Legend.SetVisualContent(lineChart, line);

            var legendItem = LegendItemsHelper.BuildDefaultLegendItem(lineChart);

            yield return(legendItem);
        }
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 OnYMissingValueReplaced(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     LineChartBase owner = (LineChartBase)d;
     // todo some notification logic here
 }