Пример #1
0
        public static void Mandelbrot(PlotControl plot)
        {
            // Here we add the Mandelbrot set to the plot.

            Function2DItem m = new Function2DItem(
                // The source represents the body of the following function:
                // double[] p, dfdp;
                // double f(double x, double y) {
                //   ...
                // }
                @"
					double xn = 0, yn = 0, x2 = 0, y2 = 0;
					for (int n = 0; n < 500; n++) {
						yn = 2*xn*yn + y;
						xn = x2 - y2 + x;
						x2 = xn*xn; y2 = yn*yn; 
						if (x2 + y2 > 4) return n;
					}
					return -1;
				"                );

            plot.Model.FixXtoY = true;             // We fix the x-plotrange to the y-plotrange, so the
            // proportions of the plot will be correct.
            plot.SetRange(plot.x0, plot.x1, plot.y0, plot.y1, 0, 20);
            // We set the view range of the plot, so the Mandelbrot set will be
            // fully visible. We set the z-plotrange from 0 to 20.
            plot.Model.Add(m);
        }
Пример #2
0
 public static string BPlotReset(string plotId)
 {
     if (!String.IsNullOrWhiteSpace(plotId))
     {
         Shell s = Shell.GetShell(plotId);
         if (s != null)
         {
             if (s.MainControl.Dispatcher.CheckAccess())
             {
                 PlotControl p = s.MainControl as PlotControl;
                 if (p != null)
                 {
                     p.ResetCache();
                     return(plotId);
                 }
                 return("Error: unable to open plot control.");
             }
             else
             {
                 return(s.MainControl.Dispatcher.Invoke(new Func <string>(() => { return BPlotReset(plotId); })));
             }
         }
         return("Error: unable to open plot shell.");
     }
     return("Error: plot Id.");
 }
Пример #3
0
 public static string BPlotTitles(string plotId, string title, string yAxis = "Y", string xAxis = "Time")
 {
     if (!String.IsNullOrWhiteSpace(plotId))
     {
         Shell s = Shell.GetShell(plotId);
         if (s != null)
         {
             if (s.MainControl.Dispatcher.CheckAccess())
             {
                 PlotControl p = s.MainControl as PlotControl;
                 if (p != null)
                 {
                     p.SetTitles(title, yAxis, xAxis);
                     return(plotId);
                 }
                 return("Error: unable to open plot control.");
             }
             else
             {
                 return(s.MainControl.Dispatcher.Invoke(new Func <string>(() => { return BPlotTitles(plotId, title, yAxis, xAxis); })));
             }
         }
         return("Error: unable to open plot shell.");
     }
     return("Error: plot Id.");
 }
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.plotSurface = new Florence.WinForms.PlotControl();
     this.components = new System.ComponentModel.Container();
     this.SuspendLayout();
     //
     // plotSurface
     //
     this.plotSurface.BackColor = System.Drawing.SystemColors.ControlLightLight;
     this.plotSurface.Dock = System.Windows.Forms.DockStyle.Fill;
     this.plotSurface.Location = new System.Drawing.Point(0, 0);
     this.plotSurface.Name = "plotSurface";
     this.plotSurface.Size = new System.Drawing.Size(292, 273);
     this.plotSurface.TabIndex = 0;
     this.plotSurface.Text = "Plot Surface";
     //
     // InteractivePlotForm
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize = new System.Drawing.Size(292, 273);
     this.Controls.Add(this.plotSurface);
     this.Name = "InteractivePlotForm";
     this.Text = "InteractivePlotForm";
     this.ResumeLayout(false);
 }
Пример #5
0
        public static void Cos(PlotControl plot)
        {
            // We create a new CosFunction, set its parameters and add it to the
            // PlotModel plot.
            CosFunction cos = new CosFunction();

            cos.Color     = Color.Red;
            cos.LineWidth = 2;
            cos.LineStyle = DashStyle.Dash;
            plot.Model.Add(cos);
        }
Пример #6
0
        public FitDemo(PlotControl plot)
        {
            this.plot = plot;

            plot.Model.Clear();

            // create a new DataItem
            data = new DataItem();

            data.Dimensions   = 2;              // This property is only used by the LoadText method, it is not required for the fit algorithm.
            data.ErrorColumns = true;           // This property is only used by the LoadText method, it is not required for the fit algorithm.

            // preset the x, dx and dy values to functions:
            data.x.Source  = "n/Length*12 - 8"; // place the data in the visible plot range (x0: -8; x1: 4 in this demo application)
            data.dx.Source = "0.5";             // set the x errors to 0.5 (the x errors are not used by the fit algorithm)
            data.dy.Source = "y[n]*0.2";        // set y errors to 20% of the x values
            data.Compile();

            data.LoadText("Gauss data.txt", "\n");             // Load the data from the "Gauss data.txt" text file.

            // Display data
            plot.Model.Add(data);

            // create a new function
            f = new Function1DItem(@"
				// M - gauss curves with derivative information in dfdp.
				const int M = 3;
				double arg, ex, fac, sum = 0;
				for (int n = 0; n < 3*M; n += 3) {
					arg = (x - p[n + 1])/p[n + 2];
					ex = Math.Exp(-arg*arg);
					fac = p[n]*ex*2*arg;

					// Compute derivative information in order to speed up the Marquardt fitting algorithm. Marquardt also works with no
					// derivative information provided by the funciton, so you can also omit this, it then computes numerical derivatives.
					// The NelderMead fitting algorithm uses no derivatives.
					dfdp[n] = ex;
					dfdp[n + 1] = fac/p[n + 2];
					dfdp[n + 2] = fac*arg/p[n + 2];

					// compute the sum over all gauss curves.
					sum += p[n]*ex;
				}
				return sum;
			"            );
            f.Compile();

            // Set initial fit guess.

            ResetGuess();

            // Display function
            plot.Model.Add(f);
        }
Пример #7
0
        public OptionsForm(PlotControl plot)
        {
            //
            // Required for Windows Form Designer support
            //
            this.plot = plot;

            InitializeComponent();

            xDigits.KeyPress     += intKeyPress;
            yDigits.KeyPress     += intKeyPress;
            xFormat.DropDownStyle = ComboBoxStyle.DropDownList;
            yFormat.DropDownStyle = ComboBoxStyle.DropDownList;
        }
Пример #8
0
        public RangeForm(PlotControl plot)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.plot           = plot;
            x0TextBox.KeyPress += numberKeyPress;
            y0TextBox.KeyPress += numberKeyPress;
            x1TextBox.KeyPress += numberKeyPress;
            y1TextBox.KeyPress += numberKeyPress;
            z0TextBox.KeyPress += numberKeyPress;
            z1TextBox.KeyPress += numberKeyPress;
        }
        private void CreateGraphObjects()
        {
            if (Data == null)
            {
                return;
            }
            int index = 0;

            foreach (string sample in Data.Keys)
            {
                TICData         sampleData  = Data[sample];
                Color           graphColor  = colorArray[index % colorArray.Length];
                GraphBaseObject graphObject = new TICGraphObject(sampleData, graphColor);
                PlotControl.AddItem(index, 0, graphObject);
                index++;
            }
        }
Пример #10
0
        public static void WAV(PlotControl plot)
        {
            DataItem data = new DataItem();

            data.Lines        = true;       // join data points with a line
            data.Marks        = false;      // draw no error marks
            data.Color        = Color.Green;
            data.Dimensions   = 2;          // use x and y columns of the DataItem
            data.ErrorColumns = false;      // WAV data contains no error info
            try {
                // Load WAV data
                data.LoadWAV("test.wav");
            } catch (Exception ex) {
                MessageBox.Show("Could not open the file test.wav\n" + ex.Message);
            }
            plot.SetRange(0, 1, -1, 1);
            plot.Model.Add(data);
        }
Пример #11
0
        public static void Text(PlotControl plot)
        {
            // Loads a DataItem from a text csv file

            DataItem data = new DataItem();

            data.Dimensions   = 2;           // Load the x and y column
            data.ErrorColumns = true;        // Load the dx and dy column
            try {
                // Load Text data
                data.LoadText("data.csv", " ,;\n\r\t");                 // Load text data where the
                // numbers are separated by
                // spaces, commas, semicolons, newlines, carriage-returns, and tabs.
            } catch (Exception ex) {
                MessageBox.Show("Could not open the file data.csv\n" + ex.Message);
            }
            plot.Model.Add(data);
        }
Пример #12
0
        public static void Gauss(PlotControl plot)
        {
            // Here we create a new Function1DItem, directly setting and compiling
            // its source throught the constructor.
            Function1DItem gauss = new Function1DItem(
                // Here the source accesses the array p, an array of function parameters.
                // When you compile the item, the size of p is automatically set to the
                // highest element referred to in the source.
                @"
					double arg = (x-p[0])/p[1];
					return p[2]*exp(-arg*arg);
				"                );

            gauss.p[0] = 1;             // The position of the curve's peak
            gauss.p[1] = 1;             // The width of the peak
            gauss.p[2] = 4;             // The height of the peak
            plot.Model.Add(gauss);
        }
Пример #13
0
    public class Demo {     // a class that implements demo routines
        public static void Sin(PlotControl plot)
        {
            // We create a new Function1DItem, set its parameters and add it to the
            // PlotModel plot.
            Function1DItem sin = new Function1DItem();

            // The source represents the body of the following function:
            //
            // double[] p, dfdp;
            // double f(double x) {
            //  ...
            // }
            sin.Source = "return sin(x);";
            sin.Compile();
            sin.Color     = Color.Blue;
            sin.LineWidth = 2;
            plot.Model.Add(sin);
        }
Пример #14
0
        public ImageForm(PlotControl plot)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.plot           = plot;
            this.picture        = new ImageControl();
            this.picture.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                         | System.Windows.Forms.AnchorStyles.Left)
                                                                        | System.Windows.Forms.AnchorStyles.Right)));
            this.picture.Location = new System.Drawing.Point(0, 35);
            this.picture.Name     = "picture";
            this.picture.Size     = new System.Drawing.Size(440, 210);
            this.picture.TabIndex = 3;
            this.picture.TabStop  = false;
            this.Controls.Add(this.picture);
        }
Пример #15
0
 public static string BPlot(string exchangeName, int messageId = ProtocolConstants.IDENT_USER, bool hasTimeData = true)
 {
     if (!String.IsNullOrWhiteSpace(exchangeName))
     {
         string id = PlotControl.OpenPlotShell();
         Shell  s  = Shell.GetShell(id);
         if (s != null)
         {
             PlotControl p = s.MainControl as PlotControl;
             if (p != null)
             {
                 BabelMessageDataCache d = new BabelMessageDataCache(exchangeName, messageId, true, hasTimeData);
                 p.SetCache(d);
                 return(id);
             }
             s.Close();
             return("Error: unable to open plot control.");
         }
         return("Error: unable to open plot shell.");
     }
     return("Error: bad exchange name.");
 }
        private void InitializeControls()
        {
            TaskControl LiferegTaskControl = InitializeDataControl();

            LiferegTaskControl.SetTree("TreeNodeData", RMString.GetString("STreeNodeData"));
            TaskControlList.Add(LiferegTaskControl);

            LiferegTaskControl = new ModelControl();
            LiferegTaskControl.SetTree("TreeNodeModel", RMString.GetString("STreeNodeModel"));
            TaskControlList.Add(LiferegTaskControl);

            LiferegTaskControl = new PlotControl();
            LiferegTaskControl.SetTree("TreeNodePlot", RMString.GetString("STreeNodePlot"));
            TaskControlList.Add(LiferegTaskControl);

            LiferegTaskControl = new OutputControl();
            LiferegTaskControl.SetTree("TreeNodeOutput", RMString.GetString("STreeNodeOutput"));
            TaskControlList.Add(LiferegTaskControl);

            LiferegTaskControl = new OptionsControl();
            LiferegTaskControl.SetTree("TreeNodeOptions", RMString.GetString("STreeNodeOptions"));
            TaskControlList.Add(LiferegTaskControl);
        }
Пример #17
0
        public static PlotControl Plot(string title, double[] x, double[] y, bool ShowPlot = true, bool useDockableWindow = true)
        {
            System.Windows.Forms.Form win = new System.Windows.Forms.Form();
            if (useDockableWindow)
            {
                win = new PlotterWindowDockable();
            }
            win.Text = title;
            ZedGraph.ZedGraphControl zed = new ZedGraph.ZedGraphControl();
            zed.Dock = System.Windows.Forms.DockStyle.Fill;
            win.Controls.Add(zed);
            GraphPane     cPane = zed.GraphPane;
            PointPairList lst   = new PointPairList(x, y);
            LineItem      curve = cPane.AddCurve(title, lst, Color.Blue);

            cPane.Title.Text  = title;
            curve.Symbol.Type = SymbolType.None;
            if (ShowPlot)
            {
                if (useDockableWindow)
                {
                    var w = (PlotterWindowDockable)win;
                    AppGlobals.ShowWin(w, WeifenLuo.WinFormsUI.Docking.DockState.Float);
                }
                else
                {
                    win.Show();
                }
            }
            PlotControl p = new PlotControl();

            p.Curve   = curve;
            p.Control = zed;
            p.Window  = win;
            p.Points  = lst;
            return(p);
        }
Пример #18
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
     this.plot           = new JohnsHope.FPlot.Library.PlotControl();
     this.button1        = new System.Windows.Forms.Button();
     this.options        = new System.Windows.Forms.Button();
     this.sin            = new System.Windows.Forms.Button();
     this.cos            = new System.Windows.Forms.Button();
     this.data           = new System.Windows.Forms.Button();
     this.button3        = new System.Windows.Forms.Button();
     this.button4        = new System.Windows.Forms.Button();
     this.progressBar1   = new System.Windows.Forms.ProgressBar();
     this.loadwav        = new System.Windows.Forms.Button();
     this.saveButton     = new System.Windows.Forms.Button();
     this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
     this.button2        = new System.Windows.Forms.Button();
     this.button5        = new System.Windows.Forms.Button();
     this.SuspendLayout();
     //
     // plot
     //
     this.plot.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                               | System.Windows.Forms.AnchorStyles.Left)
                                                              | System.Windows.Forms.AnchorStyles.Right)));
     this.plot.BackColor   = System.Drawing.Color.White;
     this.plot.Border      = true;
     this.plot.Cursor      = System.Windows.Forms.Cursors.Cross;
     this.plot.FixXtoY     = false;
     this.plot.Location    = new System.Drawing.Point(0, 0);
     this.plot.Name        = "plot";
     this.plot.ProgressBar = null;
     this.plot.Size        = new System.Drawing.Size(350, 387);
     this.plot.TabIndex    = 0;
     this.plot.Text        = "plot";
     this.plot.x0          = -8;
     this.plot.x1          = 4;
     this.plot.xGrid       = true;
     this.plot.y0          = -4.1973373870943052;
     this.plot.y1          = 4.2374452216013472;
     this.plot.yGrid       = true;
     this.plot.z0          = 0;
     this.plot.z1          = 20;
     //
     // button1
     //
     this.button1.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     this.button1.Location = new System.Drawing.Point(366, 323);
     this.button1.Name     = "button1";
     this.button1.Size     = new System.Drawing.Size(75, 23);
     this.button1.TabIndex = 1;
     this.button1.Text     = "Quit";
     this.button1.Click   += new System.EventHandler(this.quitClick);
     //
     // options
     //
     this.options.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.options.Location = new System.Drawing.Point(366, 56);
     this.options.Name     = "options";
     this.options.Size     = new System.Drawing.Size(104, 24);
     this.options.TabIndex = 2;
     this.options.Text     = "Options...";
     this.options.Click   += new System.EventHandler(this.optionsClick);
     //
     // sin
     //
     this.sin.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.sin.Location = new System.Drawing.Point(366, 86);
     this.sin.Name     = "sin";
     this.sin.Size     = new System.Drawing.Size(104, 23);
     this.sin.TabIndex = 3;
     this.sin.Text     = "Add sin(x)...";
     this.sin.Click   += new System.EventHandler(this.sinClick);
     //
     // cos
     //
     this.cos.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.cos.Location = new System.Drawing.Point(366, 115);
     this.cos.Name     = "cos";
     this.cos.Size     = new System.Drawing.Size(104, 24);
     this.cos.TabIndex = 4;
     this.cos.Text     = "Add cos(x)...";
     this.cos.Click   += new System.EventHandler(this.cosClick);
     //
     // data
     //
     this.data.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.data.Location = new System.Drawing.Point(366, 205);
     this.data.Name     = "data";
     this.data.Size     = new System.Drawing.Size(104, 23);
     this.data.TabIndex = 5;
     this.data.Text     = "Load text data...";
     this.data.Click   += new System.EventHandler(this.textClick);
     //
     // button3
     //
     this.button3.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.button3.Location = new System.Drawing.Point(366, 145);
     this.button3.Name     = "button3";
     this.button3.Size     = new System.Drawing.Size(104, 24);
     this.button3.TabIndex = 7;
     this.button3.Text     = "Add gaussian...";
     this.button3.Click   += new System.EventHandler(this.gaussClick);
     //
     // button4
     //
     this.button4.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.button4.Location = new System.Drawing.Point(366, 175);
     this.button4.Name     = "button4";
     this.button4.Size     = new System.Drawing.Size(104, 24);
     this.button4.TabIndex = 8;
     this.button4.Text     = "Add Mandelbrot...";
     this.button4.Click   += new System.EventHandler(this.mandelbrotClick);
     //
     // progressBar1
     //
     this.progressBar1.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     this.progressBar1.Location = new System.Drawing.Point(366, 363);
     this.progressBar1.Name     = "progressBar1";
     this.progressBar1.Size     = new System.Drawing.Size(104, 16);
     this.progressBar1.TabIndex = 9;
     //
     // loadwav
     //
     this.loadwav.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.loadwav.Location = new System.Drawing.Point(366, 234);
     this.loadwav.Name     = "loadwav";
     this.loadwav.Size     = new System.Drawing.Size(104, 23);
     this.loadwav.TabIndex = 10;
     this.loadwav.Text     = "Load WAV file...";
     this.loadwav.Click   += new System.EventHandler(this.wavClick);
     //
     // saveButton
     //
     this.saveButton.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.saveButton.Location = new System.Drawing.Point(366, 263);
     this.saveButton.Name     = "saveButton";
     this.saveButton.Size     = new System.Drawing.Size(104, 23);
     this.saveButton.TabIndex = 11;
     this.saveButton.Text     = "Save bitmap...";
     this.saveButton.Click   += new System.EventHandler(this.saveButtonClick);
     //
     // saveFileDialog
     //
     this.saveFileDialog.Filter = "Image Files (GIF JPEG TIFF BMP PNG EMF)|*.gif;*.jpg;*.jpeg;*.bmp;*.png;*.tif;*.ti" +
                                  "ff;*.emf";
     //
     // button2
     //
     this.button2.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.button2.Location = new System.Drawing.Point(366, 292);
     this.button2.Name     = "button2";
     this.button2.Size     = new System.Drawing.Size(104, 23);
     this.button2.TabIndex = 12;
     this.button2.Text     = "Fitting demo...";
     this.button2.Click   += new System.EventHandler(this.fitDemo);
     //
     // button5
     //
     this.button5.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.button5.Location = new System.Drawing.Point(366, 12);
     this.button5.Name     = "button5";
     this.button5.Size     = new System.Drawing.Size(104, 24);
     this.button5.TabIndex = 13;
     this.button5.Text     = "Clear";
     this.button5.Click   += new System.EventHandler(this.clearClick);
     //
     // MainForm
     //
     this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
     this.ClientSize        = new System.Drawing.Size(478, 384);
     this.Controls.Add(this.button5);
     this.Controls.Add(this.button2);
     this.Controls.Add(this.saveButton);
     this.Controls.Add(this.loadwav);
     this.Controls.Add(this.progressBar1);
     this.Controls.Add(this.button4);
     this.Controls.Add(this.button3);
     this.Controls.Add(this.data);
     this.Controls.Add(this.cos);
     this.Controls.Add(this.sin);
     this.Controls.Add(this.options);
     this.Controls.Add(this.button1);
     this.Controls.Add(this.plot);
     this.Name = "MainForm";
     this.Text = "FPlot Demo";
     this.ResumeLayout(false);
 }