예제 #1
0
            private void WpfPlot_ButtonClicked(WpfPlotViewControlHorizontal sender, int ndx)
            {
                // access
                var wpfPlot = sender?.WpfPlot;

                if (wpfPlot == null)
                {
                    return;
                }

                if (ndx == 1 || ndx == 2)
                {
                    // Horizontal scale Plus / Minus
                    var ax    = wpfPlot.plt.Axis();
                    var width = Math.Abs(ax[1] - ax[0]);

                    if (ndx == 1)
                    {
                        wpfPlot.plt.Axis(x1: ax[0] - width / 2, x2: ax[1] + width / 2);
                    }

                    if (ndx == 2)
                    {
                        wpfPlot.plt.Axis(x1: ax[0] + width / 4, x2: ax[1] - width / 4);
                    }

                    // no autoscale for X
                    _autoScaleX = false;

                    // call for the other
                    WpfPlot_AxisChanged(wpfPlot, null);
                }

                if (ndx == 3 || ndx == 4)
                {
                    // Vertical scale Plus / Minus
                    var ax     = wpfPlot.plt.Axis();
                    var height = Math.Abs(ax[3] - ax[2]);

                    if (ndx == 3)
                    {
                        wpfPlot.plt.Axis(y1: ax[2] - height / 2, y2: ax[3] + height / 2);
                    }

                    if (ndx == 4)
                    {
                        wpfPlot.plt.Axis(y1: ax[2] + height / 4, y2: ax[3] - height / 4);
                    }

                    // no autoscale for Y
                    _autoScaleY = false;

                    // call for the other
                    WpfPlot_AxisChanged(wpfPlot, null);
                }

                if (ndx == 5)
                {
                    // swithc auto scale ON and hope the best
                    _autoScaleX = true;
                    _autoScaleY = true;
                }

                if (ndx == 6)
                {
                    // plot larger
                    sender.Height += 100;
                }

                if (ndx == 7 && sender.Height >= 299)
                {
                    // plot smaller
                    sender.Height -= 100;
                }
            }
예제 #2
0
            public List <PlotItemGroup> RenderAllGroups(StackPanel panel, double plotHeight)
            {
                // first access
                var res = new List <PlotItemGroup>();

                if (panel == null)
                {
                    return(null);
                }
                panel.Children.Clear();

                // before applying arguments
                _autoScaleX = true;
                _autoScaleY = true;

                // go over all groups
                ScottPlot.WpfPlot lastPlot = null;
                foreach (var groupPI in GetItemsGrouped())
                {
                    // start new group
                    var pvc = new WpfPlotViewControlHorizontal();
                    pvc.Text = "Single value plot";
                    if (groupPI.Group >= 0 && groupPI.Group < 9999)
                    {
                        pvc.Text += $"; grp={groupPI.Group}";
                    }
                    var wpfPlot = pvc.WpfPlot;

                    // some basic attributes
                    lastPlot = wpfPlot;
                    wpfPlot.plt.AntiAlias(false, false, false);
                    wpfPlot.AxisChanged += (s, e) => WpfPlot_AxisChanged(wpfPlot, e);
                    groupPI.WpfPlot      = wpfPlot;
                    res.Add(groupPI);

                    // for all wpf / all signals
                    pvc.Height       = plotHeight;
                    pvc.ButtonClick += WpfPlot_ButtonClicked;

                    // for each signal
                    double?yMin = null, yMax = null;

                    foreach (var pi in groupPI)
                    {
                        // value
                        var val = pi.SME?.ValueAsDouble();

                        // integrate args
                        if (pi.Args != null)
                        {
                            if (pi.Args.ymin.HasValue)
                            {
                                yMin = Nullable.Compare(pi.Args.ymin, yMin) > 0 ? pi.Args.ymin : yMin;
                            }

                            if (pi.Args.ymax.HasValue)
                            {
                                yMax = Nullable.Compare(yMax, pi.Args.ymax) > 0 ? yMax : pi.Args.ymax;
                            }
                        }

                        // prepare data
                        var pb = new PlotBuffer();
                        pi.Buffer = pb;

                        // factory new Plottable
                        pb.Plottable = wpfPlot.plt.PlotSignal(pb.BufferData, label: "" + pi.DisplayPath);
                        pb.Push(val.HasValue ? val.Value : 0.0);
                    }

                    // apply some more args to the group
                    if (yMin.HasValue)
                    {
                        wpfPlot.plt.Axis(y1: yMin.Value);
                        _autoScaleY = false;
                    }

                    if (yMax.HasValue)
                    {
                        wpfPlot.plt.Axis(y2: yMax.Value);
                        _autoScaleY = false;
                    }

                    // render the plot into panel
                    wpfPlot.plt.Legend(fontSize: 9.0f);
                    panel.Children.Add(pvc);
                    wpfPlot.Render(skipIfCurrentlyRendering: true);
                }

                // for the last plot ..
                if (lastPlot != null)
                {
                    lastPlot.plt.XLabel("Samples");
                }

                // return groups for notice
                return(res);
            }