Size a Graph


#pragma rtGlobals=1		// Use modern global access method.
// This routine places a command under the "Graph" menu which allows
// sizing of the outer portion of a graph in units of inches. Thus one can 
// arrange annotations while the graph is at it's proper size. The graph 
// can then be exported and should appear just as it does on screen.
// This was written using IgorPro 6.02 and tested on a Windows XP box.
//
// Version 11-01-07-01	   C. DeJoseph, Jr.
// Version 11-02-07-01	   Jim Prouty, ICS
// Version 11-05-07-01	   C. DeJoseph, Jr.
// Version 02-07-08-01	   C. DeJoseph, Jr.
//
Menu "Graph", dynamic
	SizeTheGraphMenu(), /Q, DoSizing()
end

function/S SizeTheGraphMenu()

	String text="Size the Graph"
	string GrName=WinName(0,1)
	if( strlen(GrName) )
		 GetWindow $GrName hook(SetGraphSize)
		 if( strlen(S_Value) )	// already hooked
			text="Exit Graph Sizing"
		 endif
	endif
	return text
End

function DoSizing()
	string GrName=WinName(0,1)
	GetWindow $GrName hook(SetGraphSize)
	if( strlen(S_Value) )	// already hooked
		ExitSizing("")
	else
		SetGraphSize()
	endif
End

function SetGraphSize()
	string GrName=WinName(0,1)
	variable/G gGraphWidth, gGraphHeight
	if(strlen(GrName)<1)
		DoAlert 0, "No Graph selected"
		return -1
	endif
	getGraphSize(Grname)
	ControlInfo/W=$Grname kwControlBar
	Variable/G oldControlBar= V_Height
	getwindow kwTopWin, wsize     // get cordinates for top-left to keep the graph area the same size
	Variable morePixels= 54
	ControlBar/W=$GrName morePixels+oldControlBar
	MoveWindow /W=$"" V_left, V_top, V_right, V_bottom+morePixels/ScreenResolution*72
	SetWindow $GrName hook(SetGraphSize)=UpdateSizeHook
	SetVariable setvarSetGSize0,pos={10,oldControlBar+3},size={140,23},disable=2,title="Width (inches):"
	SetVariable setvarSetGSize0,fSize=14,format="%4.2f",limits={-inf,inf,0}, value=gGraphWidth
	SetVariable setvarSetGSize1,pos={10,oldControlBar+29},size={140,23},disable=2,title="Height (inches):"
	SetVariable setvarSetGSize1,fSize=14,format="%4.2f",limits={-inf,inf,0}, value=gGraphHeight
	Button buttonSetGSize0,pos={154,oldControlBar+15.5},size={50,23},disable=0,proc=ExitSizing,title="Exit"
end
Function UpdateSizeHook(s)
	STRUCT WMWinHookStruct &s

	strswitch(s.eventName)
		case "resize":
			getGraphSize(s.winName)
			break
	endswitch
	return 0
End
function UpdateSize(infoStr)
	String infoStr
	String Grname= StringByKey("HCSPEC",infoStr)
	getGraphSize(Grname)
end
function getGraphSize(gname)
	string gname
	variable/G gGraphWidth, gGraphHeight
	getwindow $gname, gsize
	gGraphWidth=(V_right-V_left)/72     // inches
	gGraphHeight=(V_bottom-V_Top)/72
end
function ExitSizing(ctrlName) : ButtonControl
	string ctrlName
	variable xoffset, yoffset
	setwindow kwTopWin hook(SetGraphSize)=$""
	getwindow kwTopWin, wsize	// get cordinates for top-left
	xoffset=V_left
	yoffset=V_top
	getwindow kwTopWin, gsize		// now get size of graph only (not including control bar)
	KillControl  setvarSetGSize0
	KillControl  setvarSetGSize1
	KillControl  buttonSetGSize0
	Variable/G oldControlBar
	ControlBar oldControlBar
	MoveWindow /W=$"" V_left+xoffset, V_top+yoffset, V_right+xoffset, V_bottom+yoffset+oldControlBar/ScreenResolution*72	// points
end

Forum

Support

Gallery

Igor Pro 10

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More