예제 #1
0
        private void UserControl_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            Graph.ClearSeries();

            var item = DataContext as ChartSong;
            if (item == null) return;

            var color = Colors.White;

            switch (item.ChangeDirection)
            {
                case ChartSong.Direction.Up:
                    color = Colors.Green;
                    break;
                case ChartSong.Direction.Down:
                    color = Colors.Red;
                    break;
            }

            ChangePercentBlock.Foreground = new SolidColorBrush(color);

            var data = item.Signals.Select((p, i) => new Point(i, p)).ToList();

            var serie = new Serie("Signals") {ShiftSize = 100};
            serie.SetData(data);

            Graph.AutoRedraw = true;
            Graph.AddSerie(serie);
        }
예제 #2
0
        public ChartSongViewer()
        {
            InitializeComponent();

            if (!ViewModelBase.IsInDesignModeStatic) return;
            var data =
                new[] { 0, 1, 5, -3, -1, 0, 2.5, 2.4, 2.3 }.Select((p, i) => new Point(i, p)).ToList();

            var serie = new Serie("Signals") { ShiftSize = 100};
            serie.SetData(data);

            Graph.AutoRedraw = true;
            Graph.AddSerie(serie);
        }
예제 #3
0
        public void AddSerie(Serie s)
        {
            if (s != null)
            {
                s.Color = _colors.Dequeue();
                _series.Add(s);
                s.DataUpdated += SerieDataUpdated;

                if (_loaded)
                {
                    Draw();
                }
            }
        }
예제 #4
0
 private void RemoveLine(Serie s)
 {
     Children.Remove(s.UiElement);
 }
예제 #5
0
 public void RemoveSerie(Serie s)
 {
     RemoveLine(s);
     _series.Remove(s);
 }
예제 #6
0
        private void DrawLine(Serie serie)
        {
            //this.InvalidateMeasure(); not sure why anymore...

            RemoveLine(serie);

            var height = ActualHeight - (2*DrawAreaVerticalOffset);
            var width = ActualWidth - (2*DrawAreaHorizontalOffset);

            _drawAreaBottom = 0 + height + DrawAreaVerticalOffset;
                // bottom left of drawing area, add 1 so the offset gets added below
            _drawAreaLeft = 0 + DrawAreaHorizontalOffset; // left of drawing area, add 1 so the offset gets added left

            _divisionX = (width/(_seriesMaxX - _seriesMinX));
            Debug.WriteLine("{0} : {1} / ({2} - {3}) = {4}", Name, width, _seriesMaxX, _seriesMinX, _divisionX);
            _divisionY = (height/(_seriesMaxY - _seriesMinY));

            var myPath = new Path();
            var myPathFigure = new PathFigure();
            var myPathSegmentCollection = new PathSegmentCollection();
            var myPathFigureCollection = new PathFigureCollection();
            var myPathGeometry = new PathGeometry();

            Point p;
            // prepare for drawing by modifying y value
            for (var i = 0; i < serie.Data.Count; i++) // for every datapoint in the serie
            {
                p = serie.Data[i];
                p.X = _drawAreaLeft + (_divisionX*i);
                p.Y = _drawAreaBottom - ((p.Y - _seriesMinY)*_divisionY);
                // data[i] = p; NO - Keep serie data unchanged

                Debug.WriteLine("{0} : ({1}) * {2} = {3}", Name, serie.Data[i], i, p.X);

                if (i == 0)
                {
                    myPathFigure.StartPoint = p;
                }
                else
                {
                    var segment = new LineSegment {Point = p};

                    myPathSegmentCollection.Add(segment);
                }
            }

            if (Fill) // not fully tested
            {
                p.Y = _drawAreaBottom - 0;
                var endsegment = new LineSegment {Point = p};
                myPathSegmentCollection.Add(endsegment);
            }

            myPathFigure.Segments = myPathSegmentCollection;
            myPathFigureCollection.Add(myPathFigure);
            myPathGeometry.Figures = myPathFigureCollection;

            myPath.Stroke = serie.Color;
            myPath.StrokeThickness = 2;
            if (Fill)
            {
                myPath.Fill = serie.Color;
            }

            myPath.Data = myPathGeometry;
            SetZIndex(myPath, 10);

            Children.Add(myPath);
            serie.UiElement = myPath;
        }