Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Waveform Graph Grid Lines Become Offset

I have a really interesting problem. I have two waveform graphs, each with two plots. Each graph has the major division grid lines visible. The user has the ability to make both plots visible or one at a time. The user is able to scroll the x-axis, within a certain range. They are not able to go lower than 0. Even though I have the minimum for the X-axis range programatically set at 0, I was still able to scroll past 0 so I put in the follow code to prevent that from happening:

 

if (Ch1Graph.XAxes[0].Range.Minimum < 0)
{
Ch1Graph.XAxes[0].Range = new Range(0, WindowInterval);
Ch2Graph.XAxes[0].Range = new Range(0, WindowInterval);
}

 

When I have both plots visible, this works just fine. (first picture) However, when I only have one of the plots in each graph enabled, if I try to scroll lower than 0, my scale doesn't go lower than 0 and my data won't move, but the grid lines will continue to scroll, causing them to become offset from the actual division ticks. (second and third picture) The only thing I'm changing is the visible property of the plots. Any ideas why this is happening or ways to prevent it?

 

Grid Lines Offset

Download All
0 Kudos
Message 1 of 20
(6,933 Views)

Hi VHalbur,

 

When you say scroll left and right on the plots are you referring to the implementation of the Pan Left and Pan Right buttons that you have? What is the action of those buttons to enable scrolling to the left and right?


Milan
0 Kudos
Message 2 of 20
(6,921 Views)

No. I have the InteractionDefaultMode set to PanX, so the user is able to "grab" onto the graph and move it with the mouse as well as utalize the buttons I have. The gridlines only get offset when the user "grabs" and moves the graph. However, if the gridlines are offset and the user then uses the pan left or right button, the gridlines stay offset while panning.

0 Kudos
Message 3 of 20
(6,918 Views)

Hi VHalbur,

 

Is it possible to provide a piece of example code that shows this behavior?


Milan
0 Kudos
Message 4 of 20
(6,912 Views)

Pan buttons:

 

private void btnPanLeft_MouseDown(object sender, MouseEventArgs e)
        {
            bPanButton = true;
            if (Ch1Graph.XAxes[0].Range.Minimum > 0)
            {
                Ch1Graph.PanXY(-1 / 24F, 0);
                xMin = Ch1Graph.XAxes[0].Range.Minimum;
                xMax = Ch1Graph.XAxes[0].Range.Maximum;
                PanLeftTimer.Enabled = true;
            }
        }

        private void btnPanLeft_MouseUp(object sender, MouseEventArgs e)
        {
            bPanButton = false;
            PanLeftTimer.Enabled = false;
        }

        private void PanLeftTimer_Tick(object sender, EventArgs e)
        {
            Ch1Graph.PanXY(-1 / 24F, 0);
        }

        private void btnPanRight_MouseDown(object sender, MouseEventArgs e)
        {
            bPanButton = true;
            Ch1Graph.PanXY(1 / 24F, 0);
            xMin = Ch1Graph.XAxes[0].Range.Minimum;
            xMax = Ch1Graph.XAxes[0].Range.Maximum;
            PanRightTimer.Enabled = true;
        }

        private void btnPanRight_MouseUp(object sender, MouseEventArgs e)
        {
            bPanButton = false;
            PanRightTimer.Enabled = false;
        }

        private void PanRightTimer_Tick(object sender, EventArgs e)
        {
            Ch1Graph.PanXY(1 / 24F, 0);
        }

 

Code for if the user "grabs" the plot and drags it to pan:

 

private void Ch1Graph_BeforeDrawPlot(object sender, BeforeDrawXYPlotEventArgs e)
        {
            if (bPanButton == false)
            {
                xMin = Ch1Graph.XAxes[0].Range.Minimum;
                xMax = Ch1Graph.XAxes[0].Range.Maximum;
            }
            if (Ch1Graph.XAxes[0].Range.Minimum < 0)
            {
                Ch1Graph.XAxes[0].Range = new Range(0, WindowInterval);
                Ch2Graph.XAxes[0].Range = new Range(0, WindowInterval);
            }

            else if (Ch1Graph.XAxes[0].Range.Maximum > totalMax)
            {
                Ch1Graph.XAxes[0].Range = new Range(totalMax - WindowInterval, totalMax);
                Ch2Graph.XAxes[0].Range = new Range(totalMax - WindowInterval, totalMax);
            }

            Ch2Graph.XAxes[0].Range = new Range(xMin, xMax);
        }

        private void Ch2Graph_BeforeDrawPlot(object sender, BeforeDrawXYPlotEventArgs e)
        {
            if (bPanButton == false)
            {
                xMin = Ch2Graph.XAxes[0].Range.Minimum;
                xMax = Ch2Graph.XAxes[0].Range.Maximum;
            }
            if (Ch2Graph.XAxes[0].Range.Minimum < 0)
            {
                Ch1Graph.XAxes[0].Range = new Range(0, WindowInterval);
                Ch2Graph.XAxes[0].Range = new Range(0, WindowInterval);
            }

            else if (Ch2Graph.XAxes[0].Range.Maximum > totalMax)
            {
                Ch1Graph.XAxes[0].Range = new Range(totalMax - WindowInterval, totalMax);
                Ch2Graph.XAxes[0].Range = new Range(totalMax - WindowInterval, totalMax);
            }

            Ch1Graph.XAxes[0].Range = new Range(xMin, xMax);
        }

 

 

The DefaultInteractionMode is always PanX.

0 Kudos
Message 5 of 20
(6,907 Views)

Hi VHalbur,

 

Thank you for posting the contents of callbacks. I was wondering if you were able to isolate the problem into a small example that shows the behavior. It would be much easier to find the source of the problem if we have functional example code that can reproduce the issue.


Milan
0 Kudos
Message 6 of 20
(6,899 Views)

Honestly, I haven't had time to even try and isolate the problem in a small example. I have much more important things to finish coding first. They need this program as soon as possible for research and this is more a minor nuisance than a necessity to fix.

0 Kudos
Message 7 of 20
(6,897 Views)

Hi VHalbur,

 

It's good to know that the behavior is not hampering progression of your application. If you are able to post a sample program that reproduces the issue in the future we can definitely look into it closer.


Milan
0 Kudos
Message 8 of 20
(6,888 Views)

I've been able to isolate where the problem is coming in, but have no idea what it means or how to fix it. Each graph has 2 plots that the user is able to "turn on and off": make them visible or invisible via checkboxes. The code for the checkboxes are as follows:

 

private void ckbRawData_CheckedChanged(object sender, EventArgs e)
        {
            if (ckbRawData.Checked == true)
            {
                Channel1.Visible = true;
                Channel2.Visible = true;
            }
            else
            {
                Channel1.Visible = false;
                Channel2.Visible = false;
            }
        }

        private void ckbSmoothedData_CheckedChanged(object sender, EventArgs e)
        {
            if (ckbSmoothedData.Checked == true)
            {
                Channel1Smoothed.Visible = true;
                Channel2Smoothed.Visible = true;
                for (int x = 0; x < Ch1Graph.Annotations.Count; x++)
                {
                    Ch1Graph.Annotations[x].Visible = true;
                }
                for (int x = 0; x < Ch2Graph.Annotations.Count; x++)
                {
                    Ch2Graph.Annotations[x].Visible = true;
                }
                for (int x = 2; x < Ch1Graph.Plots.Count; x++)
                {
                    Ch1Graph.Plots[x].Visible = true;
                }
                for (int x = 2; x < Ch2Graph.Plots.Count; x++)
                {
                    Ch1Graph.Plots[x].Visible = true;
                }
            }
            else
            {
                Channel1Smoothed.Visible = false;
                Channel2Smoothed.Visible = false;
                for (int x = 0; x < Ch1Graph.Annotations.Count; x++)
                {
                    Ch1Graph.Annotations[x].Visible = false;
                }
                for (int x = 0; x < Ch2Graph.Annotations.Count; x++)
                {
                    Ch2Graph.Annotations[x].Visible = false;
                }
                for (int x = 2; x < Ch1Graph.Plots.Count; x++)
                {
                    Ch1Graph.Plots[x].Visible = false;
                }
                for (int x = 2; x < Ch2Graph.Plots.Count; x++)
                {
                    Ch1Graph.Plots[x].Visible = false;
                }
            }
        }

 

 

If I change the code to only make one plot visible/invisible, I no longer have this problem with the gridlines.

 

private void ckbRawData_CheckedChanged(object sender, EventArgs e)
        {
            if (ckbRawData.Checked == true)
            {
                Channel1.Visible = true;
                
            }
            else
            {
                Channel1.Visible = false;
                
            }
        }

        private void ckbSmoothedData_CheckedChanged(object sender, EventArgs e)
        {
            if (ckbSmoothedData.Checked == true)
            {
                Channel1Smoothed.Visible = true;
                
                for (int x = 0; x < Ch1Graph.Annotations.Count; x++)
                {
                    Ch1Graph.Annotations[x].Visible = true;
                }
                for (int x = 0; x < Ch2Graph.Annotations.Count; x++)
                {
                    Ch2Graph.Annotations[x].Visible = true;
                }
                for (int x = 2; x < Ch1Graph.Plots.Count; x++)
                {
                    Ch1Graph.Plots[x].Visible = true;
                }
                for (int x = 2; x < Ch2Graph.Plots.Count; x++)
                {
                    Ch1Graph.Plots[x].Visible = true;
                }
            }
            else
            {
                Channel1Smoothed.Visible = false;
                
                for (int x = 0; x < Ch1Graph.Annotations.Count; x++)
                {
                    Ch1Graph.Annotations[x].Visible = false;
                }
                for (int x = 0; x < Ch2Graph.Annotations.Count; x++)
                {
                    Ch2Graph.Annotations[x].Visible = false;
                }
                for (int x = 2; x < Ch1Graph.Plots.Count; x++)
                {
                    Ch1Graph.Plots[x].Visible = false;
                }
                for (int x = 2; x < Ch2Graph.Plots.Count; x++)
                {
                    Ch1Graph.Plots[x].Visible = false;
                }
            }
        }

 

0 Kudos
Message 9 of 20
(6,885 Views)

Hi VHalbur,

 

Thank you again for taking the time to post more example code. Unfortunately, as you mentioned it is difficult to narrow down exactly what is causing the behavior from just the callbacks provided. Is it possible to post a full piece of stand-alone sample code that can be compiled and executed with instructions on how to reproduce the behavior during execution? Ideally the program should be stripped down as much as possible so the primary behavior can be identified.


Milan
0 Kudos
Message 10 of 20
(6,883 Views)