Update a graph using a slider

Hello,

I am trying to update a graph by choosing the initial and final indices of the data wave using sliders.
I have something like this:

Window graph() : Graph
	Variable start,stop
	PauseUpdate; Silent 1		// building window...
	start = 0
	stop =  DimSize(pos,0)
	display vel[start,stop] vs pos[start,stop] 
	ControlBar 42
	Slider slider0 vert=0,proc=SliderProc,limits={0,DimSize(pos,0),0}	
EndMacro

Function SliderProc(ctrlName,sliderValue,event) : SliderControl
	String ctrlName
	Variable sliderValue
	Variable event	// bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved

	if(event %& 0x1)	// bit 0, value set
		
	endif

	return 0
End

How do I proceed to make the graph update based on the values of start, stop?
Thanks
I typically would use a fixed display wave, e.g."root:DisplayData", which is redefined in the control procedure, e.g., by
duplicate /O /R(Start,Stop) datawave root:displaywave
within your if clause.
(Usually I have a fixed frame size and only use an assignment, but with dynamic ranges overwriting might be better than redefining)

Other opinions?
HJ
You can use ReplaceWave to replace trace with another that is different only in the subrange. Try it first using the Replace Wave item from the Graph menu to see what the command looks like.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
You may be doing unnecessary work if Igor's Graph->Packages->Axis Slider is sufficient.

If not, you can look at that code to see how a slider can change a graph's axis range.


Function WMAxisSliderProc(name, value, event)
	String name	// name of this slider control
	Variable value	// value of slider
	Variable event	// bit field: bit 0: value set; 1: mouse down, //   2: mouse up, 3: mouse moved

	String dfSav= GetDataFolder(1)
	String grfName= WinName(0, 1)
	SetDataFolder root:Packages:WMAxisSlider:$(grfName)

	NVAR gLeftLim,gRightLim
	SVAR gAxisName
	GetAxis/Q $gAxisName
	Variable dx= (V_max-V_min)/2
	Variable x0= value*(gRightLim-gLeftLim)+gLeftLim
	SetAxis $gAxisName,x0-dx,x0+dx
	
	SetDataFolder dfSav
			
	return 0	// other return values reserved
End


--Jim Prouty
Software Engineer, WaveMetrics, Inc.
JimProuty wrote: You may be doing unnecessary work if Igor's Graph->Packages->Axis Slider is sufficient.

If not, you can look at that code to see how a slider can change a graph's axis range.


Function WMAxisSliderProc(name, value, event)
	String name	// name of this slider control
	Variable value	// value of slider
	Variable event	// bit field: bit 0: value set; 1: mouse down, //   2: mouse up, 3: mouse moved

	String dfSav= GetDataFolder(1)
	String grfName= WinName(0, 1)
	SetDataFolder root:Packages:WMAxisSlider:$(grfName)

	NVAR gLeftLim,gRightLim
	SVAR gAxisName
	GetAxis/Q $gAxisName
	Variable dx= (V_max-V_min)/2
	Variable x0= value*(gRightLim-gLeftLim)+gLeftLim
	SetAxis $gAxisName,x0-dx,x0+dx
	
	SetDataFolder dfSav
			
	return 0	// other return values reserved
End


--Jim Prouty
Software Engineer, WaveMetrics, Inc.


Unless I misunderstood your solution I don't want to change the axis range but the number of wave data points that are displayed.
johnweeks wrote: You can use ReplaceWave to replace trace with another that is different only in the subrange. Try it first using the Replace Wave item from the Graph menu to see what the command looks like.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


Thank you for the suggestion.
Here is what I got:

Window phase_space_graph() : Graph
	Variable/G start,stop
	PauseUpdate; Silent 1		// building window...
	start = 0
	stop =  DimSize(pos,0)
	display vel vs pos 
	ControlBar 42
	Slider slider0 vert=0,proc=SliderProc,limits={0,DimSize(pos,0),0},size={300,63},ticks=0, variable=stop
	Slider slider1 vert=0,proc=SliderProc,limits={0,DimSize(pos,0),0},size={300,63},ticks=0, variable=start
EndMacro

Function SliderProc(ctrlName,sliderValue,event) : SliderControl
	String ctrlName
	Variable sliderValue
	Variable event	// bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved
	wave pos,vel
	NVAR start,stop
	if (CmpStr(ctrlName,"slider0"))
		stop = sliderValue
	elseif (CmpStr(ctrlName, "slider1"))
		start = sliderValue
	endif
	if(event %& 0x1)	// bit 0, value set	
		ReplaceWave trace= vel, vel[start,stop];DelayUpdate
		ReplaceWave/X trace= vel, pos[start,stop]
	endif
	return 0
End

However, both sliders become coupled for some reason. i.e changing one also changes the other at the same time.

EDIT:
Nevermind, I figured it out. CmpStr returns "False" if the strings are equal.
igornoob12 wrote:
EDIT:
Nevermind, I figured it out. CmpStr returns "False" if the strings are equal.


Technically, CmpStr returns 0 (not "false") if the strings are equal.
It also returns -1 if the first string is lexically "less than" the second, and it returns +1 if greater.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
StringMatch
has the expected behavior in the above code. The matching criteria is a bit loose, as case sensitivity and such is not included. But by using wildcards one can also write case switches for groups of controls.