Scroll graph using commands in a function?
I would like to have a graph scroll horizontally from right to left, analogously to a scrolling ticker tape at the bottom of a TV news program, and similarly to what a chart recorder control does. Questions:
1) I can achieve this by pressing the Option key, click on a graph, drag to the left, and let go of the mouse while it's still moving. Can I replicate this behavior through commands in a function?
2) I have approximated this behavior through the function below: increment xAxisMin and xAxisMax by the same amount, and doUpdate. This works ok but the updates seem to occur at not-quite-regular intervals. Any alternative ways to code this capability so that the scrolling is less choppy?
Basically I am looking for a chart recorder control, but one that scrolls through an existing wave rather than plotting live data as it's being acquired.
variable leftEdge = 0
variable rightEdge = 10
variable seconds = 0
wave moveRestState
Display /w=(50, 50, 750, 150) moveRestState
ImproveInitGraph(1)
ModifyGraph mode=6
SetAxis bottom *,10
ModifyGraph grid(bottom)=1,manTick(bottom)={0,5,0,0},manMinor(bottom)={0,0}
ModifyGraph manTick(bottom)={0,5,0,0},manMinor(bottom)={4,0}
doUpdate
do
waitPM(100)
seconds += .1
leftEdge += .1
rightEdge += .1
SetAxis bottom leftEdge, rightEdge
ModifyGraph grid(bottom)=1,manTick(bottom)={0,5,0,0},manMinor(bottom)={0,0}
//doUpdate
while (seconds < 40)
End //ScrollGraph
I have posted code in a recent snippet.
https://www.wavemetrics.com/code-snippet/scroll-through-trace
Hope this gives you a useful starting point.
November 11, 2021 at 04:01 pm - Permalink
In reply to Here is a code that will… by jjweimer
This works beautifully. Thanks! I have not yet figured out what makes your code scroll so smoothly, as your basic technique (change the horizontal axes' min and max) is similar to mine. But your method for pausing (the sleep command, as opposed to the explicit loop I use in my waitPM function) may execute more uniformly.
November 12, 2021 at 02:23 pm - Permalink
The sleep command and DoUpdate will guarantee that the graph re-draws. Your loop doesn't have a chance for the graph to redraw reliably.
November 12, 2021 at 03:13 pm - Permalink
Here's just a note in case the goal is to keep this running for a longer time (e.g., to simulate a long acquisition): Running this in a function with a for- or do-while loop keeps the function working hard and may stall other things within Igor (and may actually eat quite a lot of cpu time in some cases). An alternative could be to implement a periodic scrolling (or extension of the data in the background) via a background task. You can read more here:
DisplayHelpTopic "Background Tasks"
November 12, 2021 at 04:41 pm - Permalink