cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
SDF1
Super User

Toggle button box or something similar

Hi JMP Community,

 

  I'm trying to set up a window where users can select different months, or quarters, or the entire YTD, that also provides feedback of which button boxes have been selected (or even deselected). My intent is to ultimately use the month/quarter/YTD selection as a way to create a subset of a data table based on the month (year is always set to current year for now).

 

  Here's a window of what I'm thinking about:

SDF1_2-1730819595588.png

 

 

  Whenever a month is selected, the code will define a variable as "01" for Jan, "05" for May, or "1" for Q1, etc. What I'd like is for the button to look like it's either "clicked" by appearing pressed, or better turn a highlighted color, like blue. Something similar to what happens in the Data Filter platform, like when using Big Class and adding a local Data Filter by :name, where the name is highlighted and more than one selection can be made at a time. Along with showing that the button has been selected, I would like it to show if the button has been deselected -- much like a check box showing it's marked or not -- but I don't want to use check boxes as it's less visually appealing.

SDF1_1-1730819129226.png

 

  The code for the window I created looks like (see below), and of course, when the user clicks on "OK", the code will then create the subset data table and then also close the selection window. In setting the variable for the month selected "mo#", is there a less cumbersome way to assign it the 01Jan2024 value than the code AsDate(Date DMY(dd,mm,yyyy))? it works just fine, it's just a bit cumbersome.

 

Names Default To Here( 1 );

yr = Year( Today() );

subwin = New Window( "Select Subset",
	<<Type( "Dialog" ), <<Size(360,200),
	Panel Box( "Select Month(s) in Current Year for Subset",
		LB = Lineup Box( N Col( 5 ),
			Button Box( "Jan", mo1 = AsDate(Date DMY(01,01,eval(yr))) ),
			Button Box( "Feb", mo2 =  AsDate(Date DMY(01,02,eval(yr)))),
			Button Box( "March", mo3 = AsDate(Date DMY(01,03,eval(yr))) ),
			Spacer Box(),
			Button Box( "Q1", q = 1 ),
			Button Box( "April", mo4 = AsDate(Date DMY(01,04,eval(yr))) ),
			Button Box( "May", mo5 = AsDate(Date DMY(01,05,eval(yr))) ),
			Button Box( "June", mo6 = AsDate(Date DMY(01,06,eval(yr))) ),
			Spacer Box(),
			Button Box( "Q2", q = 2 ),
			Button Box( "July", mo7 = AsDate(Date DMY(01,07,eval(yr))) ),
			Button Box( "Aug", mo8 = AsDate(Date DMY(01,08,eval(yr))) ),
			Button Box( "Sep", mo9 = AsDate(Date DMY(01,09,eval(yr))) ),
			Spacer Box(),
			Button Box( "Q3", q = 3 ),
			Button Box( "Oct", m10 = AsDate(Date DMY(01,10,eval(yr))) ),
			Button Box( "Nov", m11 = AsDate(Date DMY(01,11,eval(yr))) ),
			Button Box( "Dec", m12 = AsDate(Date DMY(01,12,eval(yr))) ),
			Spacer Box(),
			Button Box( "Q4", q = 4 ),
			Button Box( "YTD", y = 12 ),
			Spacer Box(),
			Spacer Box(),
			Spacer Box(),
			Spacer Box(),
			Spacer Box(),
			Spacer Box(),
			Spacer Box(),
			Button Box("OK"),
			Button Box("Cancel/Exit", subwin << Close Window)
		)
	)
);

  Any help is much appreciated!

 

Thanks!,

DS

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Toggle button box or something similar

Button Box supports Toggle style

Names Default To Here(1);
New Window("Toggle Button Example",
	ex = Button Box("Start",
		If(ex << Get,
			ex << Set Button Name("Stop"),
			ex << Set Button Name("Start")
		)
	)
);
ex << Style("Toggle");

jthi_0-1730822990356.pngjthi_1-1730822996996.png

 

-Jarmo

View solution in original post

6 REPLIES 6

Re: Toggle button box or something similar

You might use radio buttons for this purpose. You could use one set to define whether the period is months or quarters. You could have another dynamic set to offer either the twelve months or the four quarters. Both options could be created when the window is opened, but one set (not the default) could be invisible. The first set of radio buttons would manage the visibility of the second set as well as the logic.

Re: Toggle button box or something similar

You can also group radio boxes so that only one will be active at any given time:

Names Default To Here( 1 );
r1 = Radio Box( {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} );
r2 = Radio Box( {"Q1", "Q2", "Q3", "Q4"} );
New Window( "Example", H List Box( r1, r2 ) );
r2 << Group( r1 );
jthi
Super User

Re: Toggle button box or something similar

Button Box supports Toggle style

Names Default To Here(1);
New Window("Toggle Button Example",
	ex = Button Box("Start",
		If(ex << Get,
			ex << Set Button Name("Stop"),
			ex << Set Button Name("Start")
		)
	)
);
ex << Style("Toggle");

jthi_0-1730822990356.pngjthi_1-1730822996996.png

 

-Jarmo
SDF1
Super User

Re: Toggle button box or something similar

Hi @jthi ,

 

  This definitely solved the toggle problem I was after. Now, the only challenge is how to set up the logic structure when someone clicks "OK" so that it will select only those mm/yyyy rows in the data table for all possible combinations of months selected or quarters, etc. Trying to think of a way that this doesn't get really big really fast. Any ideas?

 

Thanks!,

DS

jthi
Super User

Re: Toggle button box or something similar

I'm not sure how your data looks like or how you do wish to perform the selections but I would separate the UI and logic. I made modifications to your UI but it isn't necessary, this just makes it a bit easier to collect the buttons. This will just demonstrate how you can build the dates from months, it won't do it for YTD or Quarters as I'm not sure how you will be using those

Names Default To Here(1);

get_dates = Expr(
	months = Loc(m_buttons << get, 1);
	qs = Loc(q_buttons << get, 1);
	ys = Loc(y_buttons << get, 1);

	// loop over as necessary to create the combinations
	dates_to_find = Transform Each({month}, months,
		Date DMY(01, month, yr);
	);
);

yr = Year(Today());

subwin = New Window("Select Subset",
	<<Type("Dialog"),
	<<Size(360, 200),
	Panel Box("Select Month(s) in Current Year for Subset",
			V List Box(align("right"),
				H List Box(
					V List Box(
						lub_m = Lineup Box(N Col(3),
							Button Box("Jan"),
							Button Box("Feb"),
							Button Box("March"),
							Button Box("April"),
							Button Box("May"),
							Button Box("June"),
							Button Box("July"),
							Button Box("Aug"),
							Button Box("Sep"),
							Button Box("Oct"),
							Button Box("Nov"),
							Button Box("Dec")
						),
						lub_y = Lineup Box(N Col(1),
							btn_ytd = Button Box("YTD")							
						)
					),
				Spacer Box(Size(50,0)),
				lub_q = Lineup Box(N Col(1),
					Button Box("Q1"),
					Button Box("Q2"),
					Button Box("Q3"),
					Button Box("Q4")				
				),
			),
			Lineup Box(N Col(2),
				Button Box("OK",
					get_dates;
					show(dates_to_find);
				),
				Button Box("Cancel/Exit", subwin << Close Window)
			)
		)
	)
);

btns = subwin << XPath("//ButtonBox");
Remove From(btns, N Items(btns)-2, 2);
btns << Style("Toggle");

// selections = Loc(btns << get, 1);
// btns[selections] << Get Button Name;

m_buttons = lub_m << XPath("//ButtonBox");
q_buttons = lub_q << XPath("//ButtonBox");
y_buttons = lub_y << XPath("//ButtonBox");
-Jarmo
txnelson
Super User

Re: Toggle button box or something similar

Here is a rework of your JSL.....it really isn't tested, however it should be close enough for you to use it to complete your request

Names Default To Here( 1 );

dt=current data table();

theYear = Year( Today() );

resetbb = Expr(
	For( i = 1, i <= 17, i++,
		Eval( Parse( "bb" || Char( i ) || "<< enable(1);" ) )
	)
);

subwin = New Window( "Select Subset",
	<<Type( "Dialog" ),
	<<Size( 360, 200 ),
	Panel Box( "Select Month(s) in Current Year for Subset",
		LB = Lineup Box( N Col( 5 ),
			bb1 = Button Box( "Jan",
				Sel = "M1";
				resetbb;
				bb1 << enable( 0 );
			),
			bb2 = Button Box( "Feb",
				Sel = "M2";
				resetbb;
				bb2 << enable( 0 );
			),
			bb3 = Button Box( "March",
				Sel = "M3";
				resetbb;
				bb3 << enable( 0 );
			),
			Spacer Box(),
			bb4 = Button Box( "Q1",
				Sel = "Q1";
				resetbb;
				bb4 << enable( 0 );
			),
			bb5 = Button Box( "April",
				Sel = "M4";
				resetbb;
				bb5 << enable( 0 );
			),
			bb6 = Button Box( "May",
				Sel = "M5";
				resetbb;
				bb6 << enable( 0 );
			),
			bb7 = Button Box( "June",
				Sel = "M6";
				resetbb;
				bb7 << enable( 0 );
			),
			Spacer Box(),
			bb8 = Button Box( "Q2",
				Sel = "Q2";
				resetbb;
				bb8 << enable( 0 );
			),
			bb9 = Button Box( "July",
				Sel = "M7";
				resetbb;
				bb9 << enable( 0 );
			),
			bb10 = Button Box( "Aug",
				Sel = "M8";
				resetbb;
				bb10 << enable( 0 );
			),
			bb11 = Button Box( "Sep",
				Sel = "M9";
				resetbb;
				bb11 << enable( 0 );
			),
			Spacer Box(),
			bb12 = Button Box( "Q3",
				Sel = "Q3";
				resetbb;
				bb12 << enable( 0 );
			),
			bb13 = Button Box( "Oct",
				Sel = "M10";
				resetbb;
				bb13 << enable( 0 );
			),
			bb14 = Button Box( "Nov",
				Sel = "M11";
				resetbb;
				bb14 << enable( 0 );
			),
			bb15 = Button Box( "Dec",
				Sel = "M12";
				resetbb;
				bb15 << enable( 0 );
			),
			Spacer Box(),
			bb16 = Button Box( "Q4",
				Sel = "Q4";
				resetbb;
				bb16 << enable( 0 );
			),
			bb17 = Button Box( "YTD",
				Sel = "YTD";
				resetbb;
				bb17 << enable( 0 );
			)
		),
		H List Box(
			Spacer Box(),
			Spacer Box(),
			Spacer Box(),
			Spacer Box(), 
			
			Button Box( "OK",
				If(
					Substr( Sel, 1, 1 ) == "M",
						theMonth = Num( Substr( Sel, 2 ) );
						startDate = Date MDY( theMonth, 1, theYear );
						If( theMonth == 12,
							endDate = Date MDY( 1, 1, theYear + 1 ),
							endDate = Date MDY( theMonth + 1, 1, theYear )
						);,
					Substr( Sel, 1, 1 ) == "Q",
						theMonth = Num(
							Substr( Sel, 2 );
							If(
								theMonth == 2,
									startDate = Date MDY( 4, 1, theYear );
									endDate = Date MDY( 7, 1, theYear );,
								theMonth == 3,
									startDate = Date MDY( 7, 1, theYear );
									endDate = Date MDY( 10, 1, theYear );,
								theMonth == 4,
									startDate = Date MDY( 10, 1, theYear );
									endDate = Date MDY( 1, 1, theYear + 1 );,
								startDate = Date MDY( 1, 1, theYear );
								endDate = Date MDY( 4, 1, theYear );,
							);,
							startDate = Date MDY( 1, 1, theYear );
							endDate = Today() + In Days( 1 );
						)
				);
				dt << select where( startDate >= :Date < endDate );
				dtSubset = dt << subset( selected columns( 0 ), selected rows( 1 ) );
				subwin << Close Window;
			),
			Button Box( "Cancel/Exit", subwin << Close Window )
		)
	)
);
Jim