public void updateGraph(Object sender, EventArgs e)
        {
            // TODO !!
            // Part of this code (the part that generates a preview interpolation of the waveform) can
            // be copied from existing WaveformGraph class.
            //
            // This interpolation probably gets stored internal to the object in some way,
            // and then updateGraph should call this.Refresh(), which will request that the operating system repaint the control.
            if (waveform != null)
            {
                this.waveFormNameLabel.Text = waveform.WaveformName;
                //this.channelLabel.Text = "placeholder";

                //This I should probably keep over the two crap lines above
                //his.waveFormNameLabel.Text = waveform.WaveformName;
                //this.channelLabel.Text = channelName;

                //WHY? do you do this? why not just use NumSamples?
                int      nSamples = NumSamples;
                double[] yValues;
                try
                {
                    //yValues are in Volts
                    yValues = waveform.getInterpolation(nSamples, Storage.sequenceData.Variables, Storage.sequenceData.CommonWaveforms);
                    double duration   = waveform.WaveformDuration.getBaseValue();   //Duration is in seconds
                    double stepSize   = duration / (double)nSamples;
                    double g_stepSize = (g_active_width - g_x_plot_mar) / (double)nSamples;

                    //These will hold the max/min values of yValues
                    double maxY = -10000;
                    double minY = 10000;
                    for (int i = 0; i < nSamples; i++)
                    {
                        //If statements to find min/max values of yValues
                        if (yValues[i] < minY)
                        {
                            minY = yValues[i];
                        }
                        if (yValues[i] > maxY)
                        {
                            maxY = yValues[i];
                        }
                    }



                    if ((maxY - minY) <= 1e-7)
                    {    //If we have essential a flat-line waveform, make the surrounding yScale +/-1V of the Waveform value
                        maxY = maxY + 1;
                        minY = minY - 1;
                    }
                    if (duration < 1e-10) //Less than 1ns durations are ridiculous
                    {
                        duration = 1e-9;  //clamp it to a nanosecond? WHY?
                    }

                    NiceScale yScale = new NiceScale(minY, maxY);
                    NiceScale xScale = new NiceScale(0, duration);


                    y_label_min = yScale.getNiceMin();
                    y_label_max = yScale.getNiceMax();

                    x_label_min = xScale.getNiceMin();
                    x_label_max = xScale.getNiceMax();


                    double yRange = y_label_max - y_label_min;
                    double xRange = x_label_max - x_label_min;


                    double yScaleFactor = (g_active_height - g_y_plot_mar) / yRange;
                    double xScaleFactor = (g_active_width - g_x_plot_mar) / xRange;
                    x_label_spacing  = xScale.getTickSpacing();
                    g_x_tick_spacing = x_label_spacing * xScaleFactor;

                    y_label_spacing  = yScale.getTickSpacing();
                    g_y_tick_spacing = y_label_spacing * yScaleFactor;
                    // if (yRange>1e-7)//Use 100nV as resolution cutoff beyong which the axes will just be static
                    // {
                    for (int i = 0; i < nSamples; i++)
                    {
                        g_waveform[i].X = g_mar_x_left + (int)(i * g_stepSize) + g_x_plot_mar;        //We add a single pixel offset to the X-coordinate so that the
                        //waveform doesn't overlap with the y-axis. This is purely for aesthetics.
                        g_waveform[i].Y = (int)((g_active_height - g_y_plot_mar) - (yValues[i] - y_label_min) * yScaleFactor + g_mar_y_top);
                    }
                    //  }
                    //  else

                    /*  {
                     *
                     *    for (int i = 0; i < nSamples; i++)
                     *    {
                     *        g_waveform[i].X = g_mar_x_left + (int)(i * g_stepSize);
                     *        g_waveform[i].Y = this.Size.Height-g_mar_y_bottom-(int)(g_active_width/2);
                     *    }
                     * }*/
                }
                catch (InterpolationException exception)
                {
                    // user changed something that caused an interpolation error. Let's try to undo it.
                    IParameterEditor ipe = sender as IParameterEditor;
                    if (ipe != null)
                    {
                        MessageBox.Show("Invalid data detected, attempting to undo.");
                        ipe.undoLastChange(this, null);
                        this.updateGraph(this, null);
                    }
                    else
                    {
                        MessageBox.Show("Invalid data, unable to undo. " + exception.Message);
                    }
                }
            }
            else
            {
                waveFormNameLabel.Text = "I was Null";
                channelLabel.Text      = "D:";
            }

            this.Refresh();
        }
        public void updateGraph(Object sender, EventArgs e)
        {
            // TODO !!
            // Part of this code (the part that generates a preview interpolation of the waveform) can
            // be copied from existing WaveformGraph class.
            //
            // This interpolation probably gets stored internal to the object in some way,
            // and then updateGraph should call this.Refresh(), which will request that the operating system repaint the control.
            if (waveform!=null)
                {
                    this.waveFormNameLabel.Text = waveform.WaveformName;
                    //this.channelLabel.Text = "placeholder";

                    //This I should probably keep over the two crap lines above
                    //his.waveFormNameLabel.Text = waveform.WaveformName;
                    //this.channelLabel.Text = channelName;

                    //WHY? do you do this? why not just use NumSamples?
                    int nSamples = NumSamples;
                    double[] yValues;
                    try
                    {
                        //yValues are in Volts
                        yValues = waveform.getInterpolation(nSamples, Storage.sequenceData.Variables, Storage.sequenceData.CommonWaveforms);
                        double duration = waveform.WaveformDuration.getBaseValue(); //Duration is in seconds
                        double stepSize = duration / (double)nSamples;
                        double g_stepSize = (g_active_width-g_x_plot_mar)/(double)nSamples;

                        //These will hold the max/min values of yValues
                        double maxY=-10000;
                        double minY=10000;
                        for (int i = 0; i < nSamples; i++)
                        {
                            //If statements to find min/max values of yValues
                            if (yValues[i]<minY)
                            {
                                minY=yValues[i];
                            }
                            if (yValues[i]>maxY)
                            {
                                maxY=yValues[i];
                            }
                        }

                        if ((maxY-minY) <= 1e-7)
                        {//If we have essential a flat-line waveform, make the surrounding yScale +/-1V of the Waveform value
                            maxY = maxY+1;
                            minY = minY-1;

                        }
                        if (duration<1e-10)//Less than 1ns durations are ridiculous
                        {
                            duration=1e-9;//clamp it to a nanosecond? WHY?
                        }

                        NiceScale yScale = new NiceScale(minY, maxY);
                        NiceScale xScale = new NiceScale(0, duration);

                        y_label_min=yScale.getNiceMin();
                        y_label_max=yScale.getNiceMax();

                        x_label_min=xScale.getNiceMin();
                        x_label_max=xScale.getNiceMax();

                        double yRange = y_label_max - y_label_min;
                        double xRange= x_label_max-x_label_min;

                        double yScaleFactor=(g_active_height-g_y_plot_mar)/yRange;
                        double xScaleFactor=(g_active_width-g_x_plot_mar)/xRange;
                        x_label_spacing=xScale.getTickSpacing();
                        g_x_tick_spacing=x_label_spacing*xScaleFactor;

                        y_label_spacing=yScale.getTickSpacing();
                        g_y_tick_spacing=y_label_spacing*yScaleFactor;
                       // if (yRange>1e-7)//Use 100nV as resolution cutoff beyong which the axes will just be static
                       // {
                            for (int i = 0; i < nSamples; i++)
                            {
                                g_waveform[i].X = g_mar_x_left + (int)(i * g_stepSize) + g_x_plot_mar;//We add a single pixel offset to the X-coordinate so that the
                                //waveform doesn't overlap with the y-axis. This is purely for aesthetics.
                                g_waveform[i].Y=(int)((g_active_height-g_y_plot_mar)-(yValues[i]-y_label_min)*yScaleFactor+g_mar_y_top);
                            }
                      //  }
                      //  else
                      /*  {

                            for (int i = 0; i < nSamples; i++)
                            {
                                g_waveform[i].X = g_mar_x_left + (int)(i * g_stepSize);
                                g_waveform[i].Y = this.Size.Height-g_mar_y_bottom-(int)(g_active_width/2);
                            }
                        }*/

                    }
                    catch (InterpolationException exception)
                    {
                        // user changed something that caused an interpolation error. Let's try to undo it.
                        IParameterEditor ipe = sender as IParameterEditor;
                        if (ipe != null)
                        {
                            MessageBox.Show("Invalid data detected, attempting to undo.");
                            ipe.undoLastChange(this, null);
                            this.updateGraph(this, null);
                        }
                        else
                        {
                            MessageBox.Show("Invalid data, unable to undo. " + exception.Message);
                        }
                    }
                }
                else
                {

                    waveFormNameLabel.Text = "I was Null";
                    channelLabel.Text = "D:";
                }

            this.Refresh();
        }