BookmarkSubscribe
Choose Language Hide Translation Bar
wu
wu
Community Trekker

How to retain the cell color after saving the data table into journal or new window

/*
After save dt into Journal, the cell color from data data table was changed into the font color in the journal
*/
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Color by Column( :age);
Wait( 0 );
dt << Color Rows by Row State;
dt<<save();
dt<< Clear column selection();
dt << clear select;
win = New Window( "New Window", dt<<Journal);

 

0 Kudos
4 REPLIES 4
Highlighted
gzmorgan0
Super User

Re: How to retain the cell color after saving the data table into journal or new window

The table message  dt << Color Rows By Row State() seems to be a "view" statement. The table view is changed, but saving the table and opening it or journaling does not maintain the colored cells.  Journaling that table will create a report in the Journal with the table font colors rmatching the row state colors. 

However,  col << Color Cells( clr, rows) is a column message. This message is stored in the  table column's attributes. Also when journaling the cell color is maintained.

 

Below both script and result are displayed below. Note another method (might be more direct) would be to get the unique keys for each group (age), get the rows for each age, then  pick a color and apply it to those rows of each column. 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Color by Column( :age );
Wait( 0 );

//This next command does not save the cell colors.
//dt << Color Rows by Row State; 
dt << Clear column selection();
dt << clear select;

//get the unique colors
nr = N Row( dt );
//make a list the size of the table to get the row colors and locate rows of a given color

_clr = As List( J( nr, 1, 0 ) );  

For( i = 1, i <= N Row( dt ), i++,
	_clr[i] = Color To RGB( Color Of( Row State( i ) ) )
);

//creates a list of unique colors
clr_keys = Associative Array( _clr ) << get keys;

//for each color (j), locate which rows are assigned that color using Loc( _clr, ...)
For( j = 1, j <= N Items( clr_keys ), j++,
	
	idx = Loc( _clr, clr_keys[j] );
//Color the cells in rows idx and each coloumn	
	For( i = 1, i <= N Col( dt ), i++,
		Column( dt, i ) << color cells( RGB Color( clr_keys[j] ), idx )
	);
	
);

//now journal the table
dt << journal;

image.png

 

wu
wu
Community Trekker

Re: How to retain the cell color after saving the data table into journal or new window

Could not duplicate your result of retaining cell color in journal,
Not sure if it is because you use JMP-Pro and mine is not.
Thanks.
0 Kudos
gzmorgan0
Super User

Re: How to retain the cell color after saving the data table into journal or new window

Which version of JMP do you have?  Did you use this script or a modified script? If modified, please attach.

0 Kudos
wu
wu
Community Trekker

Re: How to retain the cell color after saving the data table into journal or new window

Thanks.
My JMP version JMP14, (64bit); Didn't modify the script, run the exact script below:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Color by Column( :age );
Wait( 0 );

//This next command does not save the cell colors.
//dt << Color Rows by Row State;
dt << Clear column selection();
dt << clear select;

//get the unique colors
nr = N Row( dt );
//make a list the size of the table to get the row colors and locate rows of a given color

_clr = As List( J( nr, 1, 0 ) );

For( i = 1, i <= N Row( dt ), i++,
_clr[i] = Color To RGB( Color Of( Row State( i ) ) )
);

//creates a list of unique colors
clr_keys = Associative Array( _clr ) << get keys;

//for each color (j), locate which rows are assigned that color using Loc( _clr, ...)
For( j = 1, j <= N Items( clr_keys ), j++,

idx = Loc( _clr, clr_keys[j] );
//Color the cells in rows idx and each coloumn
For( i = 1, i <= N Col( dt ), i++,
Column( dt, i ) << color cells( RGB Color( clr_keys[j] ), idx )
);

);

//now journal the table
dt << journal;
0 Kudos