Calibration bar within subwindow
chrisNell
I need to plot calibration bars in my electrophys graphs instead of regular axis with multiple subwindows. I have seen that there is a macro that can do it but this macro can't reach the subwindows.
When I use "Calibrator()" the macro window is opened but I am not able to interact with it.
When I try to trigger the function of interest from macro and gives it the name of my subwindows "WMNewCalibratorInGraph("subwin")", there is no effect.
So it will be wonderful if somebody know how to do it )))))
Function EasyGraph()
String CDF, win, subwin
CDF=GetDataFolder(1)
Display/K=1/W=(0,0,600, 500) as "test"
Win=S_name
//Set the subwindows
Variable i, j, Rows = 1, Columns = 2
for (i=0; i<Rows; i+=1)
for (j=0; j<Columns; j+=1)
Display/HOST=$Win/W=(j/Columns,i/Rows, (j+1)/Columns, (i+1)/Rows)
MoveSubwindow fnum=(j/Columns,((i/Rows)*0.97)+0.03, (j+1)/Columns, (((i+1)/Rows)*0.97)+0.03) //CN move all the subwindow to allow the title in the beginning of the page
endfor
endfor
SetActiveSubwindow $StringFromList(0, Win, "#")
// Subwindow are set
Subwin=Win+"#G"+num2str(0)
appendToGraph/W=$subwin root:DA119_RPip_ch2_1000 //Name of a specific wave
ModifyGraph/W=$Subwin nticks=0,noLabel=2,axThick=0
//WMNewCalibratorInGraph("subwin") //Test, idea is to put the basic calibration bar
Subwin=Win+"#G"+num2str(1)
appendToGraph/W=$subwin root:DA119_RPip_ch3_1000
ModifyGraph/W=$Subwin nticks=0,noLabel=2,axThick=0
Calibrator() // Idea is to open the calibrator menu and then put it by hand. The calibrator menu is open but I am not able to interact with it
End
<pre><code class="language-igor">
String CDF, win, subwin
CDF=GetDataFolder(1)
Display/K=1/W=(0,0,600, 500) as "test"
Win=S_name
//Set the subwindows
Variable i, j, Rows = 1, Columns = 2
for (i=0; i<Rows; i+=1)
for (j=0; j<Columns; j+=1)
Display/HOST=$Win/W=(j/Columns,i/Rows, (j+1)/Columns, (i+1)/Rows)
MoveSubwindow fnum=(j/Columns,((i/Rows)*0.97)+0.03, (j+1)/Columns, (((i+1)/Rows)*0.97)+0.03) //CN move all the subwindow to allow the title in the beginning of the page
endfor
endfor
SetActiveSubwindow $StringFromList(0, Win, "#")
// Subwindow are set
Subwin=Win+"#G"+num2str(0)
appendToGraph/W=$subwin root:DA119_RPip_ch2_1000 //Name of a specific wave
ModifyGraph/W=$Subwin nticks=0,noLabel=2,axThick=0
//WMNewCalibratorInGraph("subwin") //Test, idea is to put the basic calibration bar
Subwin=Win+"#G"+num2str(1)
appendToGraph/W=$subwin root:DA119_RPip_ch3_1000
ModifyGraph/W=$Subwin nticks=0,noLabel=2,axThick=0
Calibrator() // Idea is to open the calibrator menu and then put it by hand. The calibrator menu is open but I am not able to interact with it
End
<pre><code class="language-igor">
but I still have problem with GetAxis and AxisInfo when I use subwindow... thanks if you have any advice regarding these command with subwindow
September 2, 2015 at 05:55 am - Permalink
#include<InsertSubwindowInGraph>
I created a graph and added a calibrator to it. Then I used the second utility above to embed this in another graph. The subgraph was successfully embedded, but the Calibrator drawing DID NOT appear in the embedded subgraph.
An awkward solution is to use the Calbrator in the parent graph, and drag it over your subgraph. The disadvantage to this is having to get the correct Calibrator scale factors (which follow the parent graph). One way to do this is to create new free axes so that the embedded subgraph's axes match smaller regions of the parent graph free axes. Apply the free axes scaling when using the calibrator GUI window. You can then hide the free axes using zero thickness and turning off labels.
September 2, 2015 at 09:40 am - Permalink
September 2, 2015 at 11:02 am - Permalink
I have used the include, so the problem is really to have access to the graph within the subwindow. As it was impossible to use function such as getAxis and AxeInfo, I have use the traces and done it manually with:
variable leftAxis = (V_Max - V_Min)/8
variable NiceleftAxis = CN_WMCalibratorNiceNumber(leftAxis)
string Duration=StringByKey("DURATION0", note($"root:"+Trace),"#","\r") //Attention, this parameter is not correcly set for some traces such as DA119_TestAmpl_ch*_10*
variable DurationBar=Str2Num(Duration)/8
variable NiceDurationBar = CN_WMCalibratorNiceNumber(DurationBar)
string TimeUnits = num2str(NiceDurationBar)+ " s", CurrentOrVoltage
If(NiceDurationBar < 0.5)
TimeUnits = num2str(NiceDurationBar*10^3) +" ms"
endif
variable ValueToPrint
if(mod(Str2Num(Channel),2)==0) //Attention, for a few traces such as RPip, the units are inverted with the channels
CurrentOrVoltage = num2str(NiceleftAxis)+" V"
if(leftAxis < 0.1*10^-9)
ValueToPrint = NiceleftAxis*10^12
CurrentOrVoltage =num2str(ValueToPrint)+ " pV"
DoAlert, 0, "Attention, check units for trace: "+ Trace +", they may be inverted according to the channel"
elseif(leftAxis < 0.1*10^-6)
ValueToPrint =NiceleftAxis*10^9
CurrentOrVoltage = num2str(ValueToPrint) + " nV"
elseif(leftAxis < 0.1)
ValueToPrint =NiceleftAxis*10^3
CurrentOrVoltage = num2str(ValueToPrint) + " mV"
endif
else
CurrentOrVoltage = num2str(NiceleftAxis)+ " A"
if(leftAxis < 0.1*10^-9)
ValueToPrint =NiceleftAxis*10^12
CurrentOrVoltage = num2str(ValueToPrint) + " pA"
elseif(leftAxis < 0.1*10^-6)
ValueToPrint =NiceleftAxis*10^9
CurrentOrVoltage = num2str(ValueToPrint) + "nA"
elseif(leftAxis < 0.1)
ValueToPrint =NiceleftAxis*10^3
CurrentOrVoltage = num2str(ValueToPrint) + "mA"
DoAlert, 0, "Attention, check units for trace: "+ Trace +", they may be inverted according to the channel"
else
DoAlert, 0, "Attention, check units for trace: "+ Trace +", they may be inverted according to the channel"
endif
endif
ShowTools/A
SetDrawLayer UserFront
//For the time
SetDrawEnv/W=$subwin xcoord= bottom,ycoord= left
DrawLine/W=$subwin -DurationBar/8, V_min-leftAxis/12, NiceDurationBar-DurationBar/8, V_min-leftAxis/12
SetDrawEnv/W=$subwin xcoord= bottom,ycoord= left, fsize = 8
DrawText/W=$subwin -DurationBar/8,V_min-leftAxis/3, TimeUnits //1.07 with ycoord=prel
//For the volt/current
SetDrawEnv/W=$subwin xcoord= bottom,ycoord= left
DrawLine/W=$subwin -DurationBar/8, V_Min-leftAxis/12, -DurationBar/8, V_min + NiceleftAxis-leftAxis/12
SetDrawEnv/W=$subwin xcoord= bottom,ycoord= left, fsize = 8
if(ValueToPrint > 99)
DrawText/W=$subwin -DurationBar/1.8, V_Min +NiceleftAxis/5, CurrentOrVoltage //-0.05 with xcoord=prel
else
DrawText/W=$subwin -DurationBar/2, V_Min +NiceleftAxis/5, CurrentOrVoltage //-0.045 with xcoord=prel
endif
ModifyGraph/W=$Subwin nticks=0,noLabel=2,axThick=0
September 3, 2015 at 05:38 am - Permalink
String info = AxisInfo("Graph0#G0", "Left")
will deposit the info string into the string variable "info".
Most functions and operations that get information or manipulate graphs have a way to specify a subwindow.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 3, 2015 at 10:35 am - Permalink
For your enjoyment, I've attached the procedure files and a screen shot showing the revised panel at work.
The panel now adds the calibrator to the active sub window or active top-level graph.
Replace your existing Axis Utilities.ipf and Append Calibrator.ipf files in the WaveMetrics Procedure folder with the attached files.
Let me know if you find them useful or if they have problems.
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
September 3, 2015 at 11:32 am - Permalink
It works perfectly, thanks a lot Jim!!!
I used Execute in the loop that goes through all the subwindow to put my scale bar within them:
sprintf cmd, "SetActiveSubwindow %s", SubWin
Execute/P/Q cmd
Execute/P/Q "WMCalibratorPresetButtonProc(\"xNice\")"
Execute/P/Q "WMCalibratorPresetButtonProc(\"yNice\")"
Execute/P/Q "WMCalibratorCreateButtonProc(\"create\")"
ModifyGraph/W=$Subwin nticks=0,noLabel=2,axThick=0 //Finally we can remove the basic axis
September 8, 2015 at 02:15 am - Permalink
But this function is great, only the position of the scale bar is a bit tricky because for multiple graph, if I move it manually, even by double clicking on it, I can't set up the exact position.
Best
Chris
September 8, 2015 at 08:55 am - Permalink
The attached revision of Append Calibrator.ipf has controls to position the calibrator, and WMNewCalibrator has optional parameters, too:
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
September 8, 2015 at 12:12 pm - Permalink
The last thing that can still be improved is the possibility to rotate the all the text for the y-axis by 90° like in the units regular graph axis. I can do it by selecting the text box -> ungroup ->selecting text, ->text orientation -> 90°
But as I wanted to automatize everything, if you have an idea to do it faster let me know.
September 9, 2015 at 06:41 am - Permalink
The attached revision will do that.
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
September 10, 2015 at 11:01 am - Permalink
September 15, 2015 at 08:41 am - Permalink
I have a small question because I have an error that comes all the time when I try to target specific function form Calibrator:
While executing SetVariable, the following error occurred: No child data folder of that name exists.
I use it with this code:
string SubWin, Win
string cmd
sprintf cmd, "SetActiveSubwindow %s", SubWin
Execute/P/Q cmd
Execute/P/Q "Calibrator()"
Execute/P/Q "WMCalibratorPresetButtonProc(\"xNice\")"
Execute/P/Q "WMCalibratorPresetButtonProc(\"yNice\")"
Execute/P/Q "WMCalibratorPopMenuProc(\"corner\", 3, \"lower left\")"
Execute/P/Q "WMCalibratorNumPopMenuProc(\"numbers\", 4, \"print with units, K, m, etc\")"
Execute/P/Q "WMCalibratorStr2NumPopMenuProc(\"digits\", 1, \"0\")"
Execute/P/Q "WMCalibratorStr2NumPopMenuProc(\"lineSize\", 3, \"1\")"
sprintf cmd, "root:Packages:WMCalibrator:%s:G%s:horizInset = -5", Win, subwin[strlen(subwin)-1]
Execute/P/Q cmd
sprintf cmd, "root:Packages:WMCalibrator:%s:G%s:vertInset = -5", Win, subwin[strlen(subwin)-1]
Execute/P/Q cmd
Execute/P/Q "WMCalibratorCreateButtonProc(\"create\")"
ModifyGraph/W=$Subwin nticks=0,noLabel=1,axThick=0 //Finally we can remove the basic axis
Label/W=$Subwin left, " " //Erase the units label on the left. If we delete the label with modifyGraph, it will delete the name for ever.
End
Thank you
September 22, 2015 at 09:13 am - Permalink
They won't execute until after the function returns.
Also, why not call the underlying routine explicitly instead of calling the panel code?
SetDrawLayer/W=$graphName $layer
WMNewCalibrator(graphName, xAxis, yAxis,xBar ? xLength : 0,yBar ? yLength : 0,orientation,numbers,digits, lineSize, lineRed, lineGreen, lineBlue,location=corner,horizInset=horizInset,vertInset=vertInset,vertTextRot=vtr)
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
September 22, 2015 at 09:23 am - Permalink
Cheers
Chris
September 23, 2015 at 12:19 am - Permalink
To be sure it's not an experiment-specific problem I made a blank new experiment and just created two waves, displaying both in separate graphs. When I subwindow one into the other, I can still append a calibrator in the main graph, but as soon as I click into the subwindow area and click on "add calibrator to layer" or even just the calibrator panel, I get the following error message in the history:
** DoWindow gave error: names must start with a letter and contain letters, digits or '_'
Using the debugger I trailed this problem to the line " list=HVAxisList(graphName,1) // horizontal axes, if any" in the following part:
String graphName // can be "Panel0#G0", for example
if( strlen(graphName) == 0 )
graphName= WMCalibratorTopGraph() // can be compound name like "Panel0#Graph0"
endif
Variable noGraph= strlen(graphName) == 0
SetVariable subwindow,win=CalibratorPanel,value= _STR:graphName // VERY IMPORTANT: See
String oldDF= WMCalibratorSetDF(graphName)
String df= GetDataFolder(1) // has trailing ":"
// set up defaults or load current values
// NOTE: the control name must match the name of the global var or str in the data folder.
String str, path, list
Variable var
Variable disable=0 // disable everything if no axes.
// Axes
// xAxis
list=HVAxisList(graphName,1) // horizontal axes, if any
if( strlen(list) == 0 )
if( noGraph )
list= "no graph"
else
list= "missing X axis"
endif
disable=2 // shown, but disabled.
endif
When I clicked in the subwindow area and then try to open the calibrator panel from the menu bar, I get the error message:
"While executing SetVariable, the following error occured: No child data folder of that name exists"
SetVariable vertInset,format="%g %%"
SetVariable vertInset,limits={0,100,1},value= root:Packages:WMCalibrator:Graph1:P0:G0:P0:G0:insetPercent
SetVariable horizInset,pos={23,195},size={89,15},bodyWidth=55,title="H Inset"
SetVariable horizInset,format="%g %%"
SetVariable horizInset,limits={0,100,1},value= root:Packages:WMCalibrator:Graph1:P0:G0:P0:G0:insetPercent
This error message appears when debug-switching from 3rd to 4th line, and yeah, indeed, there is just a sub-folder series WMCalibrator:Graph0:Graph1, nothing that corresponds to the part called in the ipf.
Is there a way for you to fix these problems?
Yours, Dominik
November 3, 2017 at 09:30 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
November 3, 2017 at 09:43 am - Permalink
Twice in the beginning, calling the CalibratorPanel
DoWindow/K CalibratorPanel
NewPanel/K=1 /W=(465,48,705,607) as "Append Calibrator"
DoWindow/C CalibratorPanel
ModifyPanel/W=CalibratorPanel fixedSize=1,noEdit=1
DefaultGUIFont/W=CalibratorPanel/Mac all={"_IgorSmall",0,0}, tabcontrol={"_IgorMedium",0,0}, button={"_IgorLarge",0,0}
and once later:
Variable hideDigits
DoWindow CalibratorPanel
if( V_Flag )
PopupMenu digits,win=CalibratorPanel, disable=hideDigits
endif
End
So I see actually no reason fot he problem to occur at the positions shown by the debugger...
But, there is the "axis utilities.ipf" which seems to be the actual problem, at least for the DoWindow error message (remember, it was evoked when reaching the HVaxislist part):
String graphName // "" for top graph (same as WinName(0,1)
Variable wantHorizAxes // 0 for vertical (left, right, etc), 1 for horizontal (bottom, top, etc).
String hvlist=""
if( strlen(graphName) == 0 )
graphName= WinName(0,1)
endif
if( strlen(graphName) )
DoWindow $graphName
if( V_Flag )
String axlist=AxisList(graphName)
Variable index=0
do
String axis= StringFromList(index,axlist)
if (strlen(axis) == 0)
break // ran out of items
endif
String info=AxisInfo(graphName,axis)
if( AxisOrientation(info,wantHorizAxes) )
hvlist += axis + ";"
endif
index += 1
while (1) // loop until break above
endif
endif
return hvlist
End
November 3, 2017 at 09:52 am - Permalink
You also need the attached Axis Utilities: it doesn't use DoWindow the way you show above, and doesn't suffer from this limitation.
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
November 3, 2017 at 10:27 am - Permalink
November 5, 2017 at 04:11 am - Permalink