public PlotElement(int columnIndex, int rowIndex, Plot plt)
 {
     this.columnIndex = columnIndex;
     this.rowIndex    = rowIndex;
     wpfPlot          = new WpfPlot();
     wpfPlot.Reset(plt);
 }
Beispiel #2
0
    public GraphicsPage()
    {
        Title = "Graphics";
        var physics = new Physics();

        var points   = new List <Vector2>();
        var position = new Vector2(0, 0);

        for (int i = 0; i < 20; i++)
        {
            position = physics.Trajectory(position, i, 45f, 100f);
            points.Add(position);
        }

        var xValues = points.Select(x => x.X.ToDouble()).ToArray();
        var yValues = points.Select(x => x.Y.ToDouble()).ToArray();

        var signalPlot = new ScatterPlot(xValues, yValues)
        {
        };


        var wpfPlot = new WpfPlot();
        var plot    = new Plot();

        plot.Add(signalPlot);

        wpfPlot.Plot.Add(signalPlot);

        var view = new Grid();

        view.Children.Add(wpfPlot);

        Content = view;
    }
Beispiel #3
0
    internal static Pixel Pixel(this MouseEventArgs e, WpfPlot plot)
    {
        DpiScale dpiScale = VisualTreeHelper.GetDpi(plot);
        double   x        = e.GetPosition(plot).X *dpiScale.DpiScaleX;
        double   y        = e.GetPosition(plot).Y *dpiScale.DpiScaleY;

        return(new Pixel((float)x, (float)y));
    }
 //For some reason, ScottPlot doesn't like their graphs being cloned so we have to make the graph all over again...
 public GraphWindow(DataGrabber dgrabber, WpfPlot plt, ConfigGrabber confgg, double xOffsetIN, double yOffsetIN)
 {
     InitializeComponent();
     xOffset     = xOffsetIN;
     yOffset     = yOffsetIN;
     DataContext = this;
     dgrab       = dgrabber;
     confg       = confgg;
     createScatterPlot();
 }
Beispiel #5
0
        public void Initialize(WpfPlot wpfPlot)
        {
            _wpfPlot = wpfPlot;

            _timer = new Timer(100)
            {
                Enabled = true
            };
            _timer.Elapsed += OnTimerTick;

            StartListeningToMicrophone();
        }
Beispiel #6
0
        public Sparkline()
        {
            Unloaded += OnUnloaded;

            _plotUserControl = new WpfPlot();
            _plotUserControl.Configure(recalculateLayoutOnMouseUp: false, enablePanning: false, enableRightClickMenu: false, enableRightClickZoom: false, enableScrollWheelZoom: false);
            _plotUserControl.plt.Grid(false);
            _plotUserControl.plt.Frame(false);
            _plotUserControl.plt.Ticks(false, false);
            _plotUserControl.plt.Style(figBg: Color.Empty, dataBg: Color.Empty);

            Content = _plotUserControl;
        }
Beispiel #7
0
        private void AxesChanged(object sender, EventArgs e)
        {
            WpfPlot changedPlot   = (WpfPlot)sender;
            var     newAxisLimits = changedPlot.Plot.GetAxisLimits();

            foreach (WpfPlot wp in WpfPlots)
            {
                if (wp == changedPlot)
                {
                    continue;
                }

                // disable events briefly to prevent an infinite loop
                wp.Configuration.AxesChangedEventEnabled = false;
                wp.Plot.SetAxisLimits(newAxisLimits);
                wp.Render();
                wp.Configuration.AxesChangedEventEnabled = true;
            }
        }
Beispiel #8
0
        public OHLCModel(WpfPlot wpfPlot, IObservable <OHLC> dataObservable, IObservable <Unit> renderObservable = null, IScheduler uiScheduler = null)
        {
            uiScheduler ??= Scheduler.CurrentThread;

            this.wpfPlot = wpfPlot;

            dataObservable.Subscribe(d =>
            {
                data.Add(d);
            });

            (renderObservable ?? dataObservable.Select(a => Unit.Default))
            .SubscribeOn(uiScheduler)
            .Subscribe(a =>
            {
                Render();
                //mainThread.Send(a => Render(), null);
            });
        }
        public DoubleModel(WpfPlot wpfPlot, IObservable <double> dataObservable, IObservable <Unit> renderObservable = null)
        {
            context      = SynchronizationContext.Current;
            this.wpfPlot = wpfPlot;
            var signal = wpfPlot.plt.PlotSignal(data);

            signal.maxRenderIndex = 1;

            dataObservable.Subscribe(d =>
            {
                signal.maxRenderIndex = index;
                data[index++]         = d;
            });

            (renderObservable ?? dataObservable.Select(a => Unit.Default))
            .Subscribe(a =>
            {
                context.Send(a => Render(), null);
            });
        }
        private WpfPlot DisplayNormalDistribution(DataColumn column, int columnIndex, int columnsCount)
        {
            var wpfPlot = new WpfPlot
            {
                Margin = new System.Windows.Thickness(columnIndex * (1800 / columnsCount), 0, 1800 - (columnIndex + 1) * (1800 / columnsCount), 500)
            };

            (var minimum, var maximum) = DistributionProcessor.GetColumnBoundaries(column);

            var    normalDistributionEmpirical = new ScottPlot.Statistics.Histogram(column.Data.ToArray(), binCount: 10, min: minimum, max: maximum);
            double barWidth = normalDistributionEmpirical.binSize * 1.2;

            wpfPlot.plt.PlotBar(normalDistributionEmpirical.bins, normalDistributionEmpirical.countsFrac.Select(v => v / normalDistributionEmpirical.binSize).ToArray(), barWidth: barWidth, outlineWidth: 0, fillColor: Color.Gray);
            wpfPlot.plt.PlotScatter(column.NormalDistribution.Select(nd => nd.x).ToArray(), column.NormalDistribution.Select(nd => nd.y).ToArray(), markerSize: 0, lineWidth: 2);
            wpfPlot.plt.AxisAutoY(margin: 0);
            wpfPlot.plt.Axis(x1: minimum);
            wpfPlot.plt.Ticks(numericFormatStringY: "0.00");
            wpfPlot.plt.Title(column.Name);

            return(wpfPlot);
        }
        public void RenderGraph(GraphData item)
        {
            PlotPanel.Children.Clear();
            WpfPlot plot = new WpfPlot();

            PlotPanel.Children.Add(plot);
            foreach (var signal in item.Data)
            {
                if (signal.Value.y.Length == 0)
                {
                    continue;
                }
                if (item.StartDate != null)
                {
                    plot.plt.PlotScatter(Array.ConvertAll(signal.Value.x, x => x + item.StartDate.GetValueOrDefault().ToOADate()), Array.ConvertAll(signal.Value.y, x => (double)x), label: signal.Key, markerSize: 0);
                }
                else
                {
                    plot.plt.PlotScatter(Array.ConvertAll(signal.Value.x, x => (double)x), Array.ConvertAll(signal.Value.y, x => (double)x), label: signal.Key, markerSize: 0);
                }
            }
            if (item.StartDate != null)
            {
                plot.plt.Ticks(dateTimeX: true);
            }
            plot.plt.Legend(true, location: legendLocation.upperLeft);
            plot.plt.XLabel(item.XAxisLabel, enable: true);
            plot.plt.YLabel(item.YAxisLabel, enable: true);
            plot.plt.Style(
                Helper.ConvertColor(brush: (SolidColorBrush)FindResource("BackgroundDark")),
                Helper.ConvertColor((SolidColorBrush)FindResource("Background")),
                ColorTranslator.FromHtml("#888"),
                Helper.ConvertColor((SolidColorBrush)FindResource("TextColor")),
                Helper.ConvertColor((SolidColorBrush)FindResource("TextColor")),
                Helper.ConvertColor((SolidColorBrush)FindResource("TextColor"))
                );
            plot.Render();
        }
Beispiel #12
0
 private void Render(object sender, EventArgs e)
 {
     WpfPlot.Plot.AxisAuto(0);
     WpfPlot.Render();
 }
        public MainWindowViewModel()
        {
            MoistureContent = "0";
            Data            = new ObservableCollection <Tuple <double, double> >()
            {
            };

            Series = new WpfPlot();
            Series.plt.Title("Liquid limit test", fontSize: 20);
            Series.plt.XLabel("Number of blows (N)", bold: true);
            Series.plt.YLabel("Moisture content (%)", bold: true);
            Series.plt.Ticks(logScaleY: true);
            Series.Configure(lockHorizontalAxis: true, lockVerticalAxis: true);

            Series.plt.AxisAuto(horizontalMargin: 0, verticalMargin: 0.9);

            //_dataPlot = Series.plt.PlotScatter(_data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), _data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray());

            ClearDataCommand = new DelegateCommand(() =>
            {
                NumberOfBlows   = 0;
                MoistureContent = "";
                Data.Clear();
                Series.plt.Clear();

                if (_dataPlot == null)
                {
                    _dataPlot = Series.plt.PlotScatter(Data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), Data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray());
                }
            });

            AddDataCommand = new DelegateCommand(() =>
            {
                Data.Add(new Tuple <double, double>(NumberOfBlows, Double.Parse(MoistureContent)));
                if (Data.Count() >= 2)
                {
                    Series.plt.Clear();
                    _dataPlot = Series.plt.PlotScatter(Data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), Data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray(), color: System.Drawing.Color.Gray, lineStyle: LineStyle.Dash);

                    DrawRegressionLine();
                }

                NumberOfBlows   = 0;
                MoistureContent = "0";
            });

            ExportCommand = new DelegateCommand(() =>
            {
                var dialog    = new SaveFileDialog();
                dialog.Filter = "Excel file (*.xls)|*.xls";
                dialog.ShowDialog();
                ;

                var fileName = dialog.FileName;

                if (String.IsNullOrEmpty(fileName))
                {
                    return;
                }

                Series.plt.SaveFig($"{fileName}.png");

                var book = new BinBook();

                var id = book.addPicture(fileName + ".png");

                var sheet = book.addSheet("Chart");
                sheet.setPicture(10, 3, id);

                book.save(fileName);
            });
        }
        public MainWindowViewModel()
        {
            Data = new ObservableCollection <Tuple <double, double> >();

            Series = new WpfPlot();
            Series.plt.Title("Potential Expansivess", bold: true, fontSize: 22);
            Series.plt.XLabel("Clay fraction of whole sample", bold: true);
            Series.plt.YLabel("PI of whole sample", bold: true);


            Series.plt.AxisBounds(0, _xMax, 0, _yMax);
            Series.Configure(lockHorizontalAxis: true, lockVerticalAxis: true);
            Series.plt.Grid(xSpacing: 10, ySpacing: 10, lineWidth: 2);
            // Series.plt.AxisZoom(0, 0, -20, -20);
            //Series.Width = 800;

            AddDataCommand = new DelegateCommand(() =>
            {
                Data.Add(new Tuple <double, double>(ClayFractionOfWholeSample, PiOfWholeSample));

                Series.plt.PlotPoint(ClayFractionOfWholeSample, PiOfWholeSample, GetColor(), 15);
                Series.plt.PlotText(_pointLabel, ClayFractionOfWholeSample - 0.5, PiOfWholeSample + 1, System.Drawing.Color.Black);

                Series.Render();
            });

            ClearDataCommand = new DelegateCommand(() =>
            {
                ClayFractionOfWholeSample = 0;
                PiOfWholeSample           = 0;

                Data.Clear();
                Series.plt.Clear();
                DrawAbaque();
                Series.plt.AxisBounds(0, _xMax, 0, _yMax);
                Series.Render();
            });

            ExportCommand = new DelegateCommand(() =>
            {
                var dialog    = new SaveFileDialog();
                dialog.Filter = "Excel file (*.xls)|*.xls";
                dialog.ShowDialog();
                ;

                var fileName = dialog.FileName;

                if (String.IsNullOrEmpty(fileName))
                {
                    return;
                }

                Series.plt.SaveFig($"{fileName}.png");

                var book = new BinBook();

                var id = book.addPicture(fileName + ".png");

                var sheet = book.addSheet("Chart");
                sheet.setPicture(10, 3, id);

                book.save(fileName);
            });

            DrawAbaque();
        }
Beispiel #15
0
 public Sparkline()
 {
     Loaded   += OnLoaded;
     Unloaded += OnUnloaded;
     Content   = _plot = Initialize();
 }
        public static void ParseStreamIntoChart(MainWindow InMainWindow, NetworkStream InStream, WpfPlot NetworkChart, FilterValues InFilterValues)
        {
            var StartTime = DateTime.UtcNow;

            InMainWindow.ShowProgress(true);
            NetworkChart.Plot.Clear();

            for (int i = 0; i < InMainWindow.DefaultSeriesTypes.Count; i++)
            {
                float Percent = (float)i / (float)InMainWindow.DefaultSeriesTypes.Count;
                InMainWindow.UpdateProgress((int)(Percent * 100));
                InMainWindow.DefaultSeriesTypes[i].Reset();
            }

            int FrameCounter = 0;

            foreach (PartialNetworkStream RawFrame in InStream.Frames)
            {
                if (FrameCounter % 1000 == 0)
                {
                    float Percent = (float)FrameCounter / (float)InStream.Frames.Count;
                    InMainWindow.UpdateProgress((int)(Percent * 100));
                }

                PartialNetworkStream Frame = RawFrame.Filter(InFilterValues);
                if (Frame.EndTime == Frame.StartTime)
                {
                    throw new InvalidOperationException("End time and Start time cannot be same.");
                }

                float OneOverDeltaTime  = 1 / (Frame.EndTime - Frame.StartTime);
                int   OutgoingBandwidth = Frame.UnrealSocketSize + Frame.OtherSocketSize + NetworkStream.PacketOverhead * (Frame.UnrealSocketCount + Frame.OtherSocketCount);

                InMainWindow.AddChartPoint(SeriesType.OutgoingBandwidthSize, FrameCounter, OutgoingBandwidth);
                InMainWindow.AddChartPoint(SeriesType.OutgoingBandwidthSizeSec, FrameCounter, OutgoingBandwidth * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.ActorCount, FrameCounter, Frame.ActorCount);
                InMainWindow.AddChartPoint(SeriesType.PropertySize, FrameCounter, Frame.ReplicatedSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.PropertySizeSec, FrameCounter, Frame.ReplicatedSizeBits / 8 * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.RPCSize, FrameCounter, Frame.RPCSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.RPCSizeSec, FrameCounter, Frame.RPCSizeBits / 8 * OneOverDeltaTime);

#if true
                InMainWindow.AddChartPoint(SeriesType.ActorCountSec, FrameCounter, Frame.ActorCount * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.PropertyCount, FrameCounter, Frame.PropertyCount);
                InMainWindow.AddChartPoint(SeriesType.PropertyCountSec, FrameCounter, Frame.PropertyCount * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.RPCCount, FrameCounter, Frame.RPCCount);
                InMainWindow.AddChartPoint(SeriesType.RPCCountSec, FrameCounter, Frame.RPCCount * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.ExportBunchCount, FrameCounter, Frame.ExportBunchCount);
                InMainWindow.AddChartPoint(SeriesType.ExportBunchSize, FrameCounter, Frame.ExportBunchSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.MustBeMappedGuidsCount, FrameCounter, Frame.MustBeMappedGuidCount / 8);
                InMainWindow.AddChartPoint(SeriesType.MustBeMappedGuidsSize, FrameCounter, Frame.MustBeMappedGuidSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.SendAckCount, FrameCounter, Frame.SendAckCount);
                InMainWindow.AddChartPoint(SeriesType.SendAckCountSec, FrameCounter, Frame.SendAckCount * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.SendAckSize, FrameCounter, Frame.SendAckSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.SendAckSizeSec, FrameCounter, Frame.SendAckSizeBits / 8 * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.ContentBlockHeaderSize, FrameCounter, Frame.ContentBlockHeaderSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.ContentBlockFooterSize, FrameCounter, Frame.ContentBlockFooterSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.PropertyHandleSize, FrameCounter, Frame.PropertyHandleSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.SendBunchCount, FrameCounter, Frame.SendBunchCount);
                InMainWindow.AddChartPoint(SeriesType.SendBunchCountSec, FrameCounter, Frame.SendBunchCount * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.SendBunchSize, FrameCounter, Frame.SendBunchSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.SendBunchSizeSec, FrameCounter, Frame.SendBunchSizeBits / 8 * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.SendBunchHeaderSize, FrameCounter, Frame.SendBunchHeaderSizeBits / 8);
                InMainWindow.AddChartPoint(SeriesType.GameSocketSendSize, FrameCounter, Frame.UnrealSocketSize);
                InMainWindow.AddChartPoint(SeriesType.GameSocketSendSizeSec, FrameCounter, Frame.UnrealSocketSize * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.GameSocketSendCount, FrameCounter, Frame.UnrealSocketCount);
                InMainWindow.AddChartPoint(SeriesType.GameSocketSendCountSec, FrameCounter, Frame.UnrealSocketCount * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.ActorReplicateTimeInMS, FrameCounter, Frame.ActorReplicateTimeInMS);
#endif

#if false
                InMainWindow.AddChartPoint(SeriesType.MiscSocketSendSize, FrameCounter, Frame.OtherSocketSize);
                InMainWindow.AddChartPoint(SeriesType.MiscSocketSendSizeSec, FrameCounter, Frame.OtherSocketSize * OneOverDeltaTime);
                InMainWindow.AddChartPoint(SeriesType.MiscSocketSendCount, FrameCounter, Frame.OtherSocketCount);
                InMainWindow.AddChartPoint(SeriesType.MiscSocketSendCountSec, FrameCounter, Frame.OtherSocketCount * OneOverDeltaTime);
#endif

                if (Frame.NumEvents > 0)
                {
                    InMainWindow.AddChartPoint(SeriesType.Events, FrameCounter, 0);
                }

                FrameCounter++;
            }

            InMainWindow.ShowProgress(false);
            Console.WriteLine("Adding data to chart took {0} seconds", (DateTime.UtcNow - StartTime).TotalSeconds);
            InMainWindow.Dispatcher.Invoke(new Action(() => InMainWindow.UpdateNetworkChart()));
        }