Duplicate graph in a function
I have two (related) questions.
1. I would like to duplicate a graph using code, i.e. the equivalent of the menu item Edit/Duplicate Graph. The forum archive has a post (https://www.wavemetrics.com/code-snippet/clone-window) from 2010 with two functions by RGerkin that I cannot get to work because they include GetWinCoords, which I assume is a custom function. Before I write my own function to get window coordinates, is there a more direct command or function to duplicate a graph programmatically now?
(I thought of creating the graph's macro using the doWindow /R command, but the manual says "However, /R does nothing if a macro or function is running.")
2. The general task I am programming is to plot a long time series as 5 very wide graphs arranged in a vertical column on a layout. Each graph would show 1/5 of the full time series. If the time series' entire range is from x0 to x1:
- the top graph's range should be (x0, (x1-x0)/5)
- the second graph's range should be ((x1-x0)/5), 2*(x1-x0)/5)
...and so on. The approach I am taking is to start from a plot that has the entire range; duplicate it; set the range to the sub-range appropriate for that graph.
If anyone wants to suggest a better way, feel free.
Pietro
WinRecreation(winStr, options) will put the recreation macro into a string.
edit note: not WinReaction
May 13, 2022 at 03:22 pm - Permalink
and then you can execute that recreation macro using Execute from your code.
Note that if the graph is a subwindow, you will have to go through some gyrations if want just the gaph.
May 13, 2022 at 04:06 pm - Permalink
In reply to WinReaction(winStr, options)… by jjweimer
Thank you jjweimer! I think your text autocorrect software may not have liked "WinRecreation", but I found it just the same. Exactly what I needed.
May 15, 2022 at 11:21 am - Permalink
In reply to and then you can execute… by johnweeks
Yes, the Execute command has saved me before, thanks. And no, fortunately I am not using subwindows for this task.
May 15, 2022 at 11:27 am - Permalink
Sadly, DoIgorMenu "Edit", "Duplicate Graph" doesn't seem to be allowed :(
May 19, 2022 at 01:23 am - Permalink
In reply to Sadly, DoIgorMenu "Edit", … by tony
This works for me in my code:
May 19, 2022 at 04:03 am - Permalink
In reply to This works for me in my code… by ilavsky
Aha!
Then we have
win = SelectString(strlen(win)==0, win, WinName(0, 1))
if (strlen(win) == 0)
return ""
endif
DoWindow /F $win
if (V_flag == 0)
return ""
endif
DoIgorMenu "Edit", "Duplicate"
return WinName(0, 1)
end
May 19, 2022 at 05:14 am - Permalink
In reply to Aha! Then we have … by tony
You mean there is a DoIgorMenu command?! Oh boy, this is fantastic. Thanks for the complete function!
Pietro
May 19, 2022 at 08:59 am - Permalink
DoIgorMenu solves some nasty problems, but can create others...
And I'm pretty sure this is equivalent, explicitly using code that Edit->Duplicate uses internally:
gname = SelectString(strlen(gname)==0, gname, WinName(0, 1))
if (strlen(gname) == 0)
return nan
endif
String recstr = WinRecreation(gname, 0)
Execute recstr
end
The new graph window winds up on top because the Display command in recstr just does that.
May 19, 2022 at 09:37 am - Permalink
In reply to DoIgorMenu solves some nasty… by johnweeks
Thanks, John!
May 19, 2022 at 09:59 am - Permalink