Choose Language Hide Translation Bar
Highlighted
fowled1
Level I

How do I change a background picture based on selection in a data filter?

I am trting to create an interactive map of my building to find conference rooms.  I created a table with conference room names and gave each an x and y coordinate.  I created a "Fit Y by X" analysis, dragged an image of my floor plan into the background, and added a data filter for room names.  Click a room name and the x and y coordinates are displayed on the map.  It works perfectly, except my building has multiple floors.  I've added a column to my table with floor, and now I'd like to do the same thing, except display the correct floor plan based on the data filter.  Any ideas?  An interactive explanation would be best.

5 REPLIES 5
Highlighted
cwillden
Super User

Re: How do I change a background picture based on selection in a data filter?

Hi @fowled1, welcome to the community!

 

I believe what you're attempting would take a good bit of scripting, but it sounds like a fun challenge.  If it's not too much to ask, can you post what you're working with?

-- Cameron Willden
Highlighted
ian_jmp
Staff

Re: How do I change a background picture based on selection in a data filter?

This shows the mechanics of one way to do it. It's a little indirect since (unless I missed it) there's no way to get the current selection state of the local data filter. So this infers it from the filtered rows.

NamesDefaultToHere(1);

// Open a table and do Bivariate
dt = Open("$SAMPLE_DATA/Big Class.jmp");
biv = dt << Bivariate(X(:height), Y(:weight));

// Add a local data filter (:sex plays the role of floor . . . )
df = biv << Local Data Filter( Add Filter( columns( :sex ) ));

// Get the title of the window
win = (biv << Report) << GetWindowTitle;

// Define a function that will update the background image on the Bivariate plot
f = Function( {a},
		// Infer what value of :sex is currenly selected in the data filter
		levRows = df << getFilteredRows;
		lev = Column(dt, "sex")[levRows];
		lev = lev[1];
		Speak(lev);
		// (Try to) remove an image that might already be there
		Try(
			imgSeg = Window(win)[FrameBox(2)] << FindSeg( PictSeg( 1 ) );
			imgSeg << Remove;
			);
		// Add the 'corresponding' image
		if(
			lev == "M",
				Window(win)[FrameBox(2)] << Add Image(Open("$SAMPLE_IMAGES/tile.jpg"), FillGraph),
			lev == "F",
				Window(win)[FrameBox(2)] << Add Image(Open("$SAMPLE_IMAGES/progress.gif"), FillGraph)
			);
		);

// Add a handler to the data filter so that when the user makes a selection the function 'f' is called
rs = df << Make Filter Change Handler( f );
Highlighted
fowled1
Level I

Re: How do I change a background picture based on selection in a data filter?

Thank you so much.  This worked and really has me hopeful. Based on the data set you used, what I actually wanted to do was filter by a name and have the picture change based on the sex.  I figured out how to do this by adding two data filters so I'm happy with that.  I'm new to JMP and to scripting so while I copied your script and it worked to open the sample pictures, I don't know what the proper syntax is to open a different picture.  Lastly, I want to save this as an html so it can be used by anyone.  Does that change how the different pictures need to be handled.  

Highlighted
ian_jmp
Staff

Re: How do I change a background picture based on selection in a data filter?

If I understand correctly, you don't need two data filters. Just use:

df = biv << Local Data Filter( Add Filter( columns( :name) ));

and change all instances of 'FrameBox(2)' to 'FrameBox(1)'.

 

But I fear that you may be disappointed - 'MakeFilterChangeHandler()' does all the work, and (although I didn't check) I doubt that this will work when you move the report to HTML. 

 

Highlighted
fowled1
Level I

Re: How do I change a background picture based on selection in a data filter?

Thanks again.  You are correct on both points.  So close!!!  I am going to do some work learning the map shapes add-in and see what I can accomplish there.  If you have any other ideas that might work in HTML, please let me know.

Article Labels

    There are no labels assigned to this post.