Example #1
0
        public static PlotRangeTracker Install(PlotModel model)
        {
            var result = new PlotRangeTracker();

            var series = model.Series.OfType <XYAxisSeries>().FirstOrDefault();

            if (series == null)
            {
                throw new Exception("a XYAxisSeries derived series needed tobe set on the plot");
            }

            result.PlotSeries = series;
            result.Model      = model;
            model.MouseMove  += result.Plot_MouseMove;
            model.MouseDown  += result.Plot_MouseDown;
            model.MouseUp    += result.Plot_MouseUp;

            return(result);
        }
        public FrameTimeViewModel(IEventAggregator events)
        {
            Events = events;

            DisplayName = "Frame Timeline";

            Model = new PlotModel();
            Model.LegendBackground = OxyColor.FromArgb(200, 255, 255, 255);
            Model.LegendBorder     = OxyColors.Black;
            Model.LegendPlacement  = LegendPlacement.Inside;
            Model.LegendPosition   = LegendPosition.RightTop;
            Model.Title            = "Frame Timeline";

            DownSampler = new PlotDownsampler();

            /*
             *    var timeLineAxis = new TimeSpanAxis() {
             *      MajorGridlineStyle = LineStyle.Solid,
             *      MinorGridlineStyle = LineStyle.Dot,
             *      IntervalLength = 30,
             *      MajorStep = 1,
             *      Position = AxisPosition.Bottom,
             *      AbsoluteMinimum = 0,
             *    };
             */
            BottomAxis = new LinearAxis()
            {
                AbsoluteMinimum = 0,
                Position        = AxisPosition.Bottom,
                MinorStep       = 1000,
                MajorStep       = 1000 * 60,
            };

            BottomAxis.AxisChanged   += TimeLineAxis_AxisChanged;
            BottomAxis.LabelFormatter = t => $"{t/60000}";

            Model.Axes.Add(BottomAxis);

            /*
             * var dateTimeAxis = new DateTimeAxis {
             * Position = AxisPosition.Bottom,
             * IntervalType = DateTimeIntervalType.Seconds,
             * MinorIntervalType = DateTimeIntervalType.Milliseconds,
             * //IntervalLength = 50
             * };
             *
             * plotModel.Axes.Add(dateTimeAxis);
             */

            LeftAxis = new LinearAxis()
            {
                AbsoluteMinimum = 0,
                Position        = AxisPosition.Left,
                MinorStep       = 1,
                MajorStep       = 10,
                Title           = "Time Ms",
            };
            Model.Axes.Add(LeftAxis);
            LeftAxis.Zoom(0, 40);

            FrameTimeSeries = new LineSeries {
                Title           = "Frame",
                StrokeThickness = 1,
                // DataFieldX = nameof(FrameEntry.Time),
                //DataFieldY = nameof(FrameEntry.TimeTaken),
            };

            Model.Series.Add(FrameTimeSeries);
            DownSampler.AddSeries(FrameTimeSeries, this.OnPropertyChanges(n => FrametimePoints));

            SelectedTimeSeries = new LineSeries {
                Title           = "Selected",
                StrokeThickness = 1,
                Color           = OxyColors.Red,
            };

            Model.Series.Add(SelectedTimeSeries);
            DownSampler.AddSeries(SelectedTimeSeries, this.OnPropertyChanges(n => SelectedNode).
                                  Where(n => n != null || PLog.NodeStats.Count == 0).
                                  Select(n => GetNodeDataPoints(n)));

            UpdateWorldJobTimeSeries = new LineSeries {
                Title           = "UpdateWorldJob",
                StrokeThickness = 1,
                Color           = OxyColors.Black,
            };

            Model.Series.Add(UpdateWorldJobTimeSeries);
            DownSampler.AddSeries(UpdateWorldJobTimeSeries, this.OnPropertyChanges(n => FrametimePoints).
                                  Where(n => this.PLog.GetNameId("UpdateWorldJob::Run") != -1).
                                  Select(n => GetNodeDataPoints(this.PLog.GetNodeStats("UpdateWorldJob::Run"), f => f.InclusiveTime)));

            Ranges = PlotRangeTracker.Install(Model);

            Ranges.RangeCreated += Ranges_RangeCreated;
            Ranges.RangeMoved   += Ranges_RangeCreated;
            Ranges.RangeRemoved += (r, min, max) => { NodeList = PLog.NodeStats; };

            PLog = new ProfileLog();
        }