- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Creation of the "Value Colors" property
How can I script the creation of a set of value colors for a data table column without having to specify what they actually are?
I'm asking because I have an application that is expecting to find a "Value Colors" property associated with a selected column, and will crash if that property doesn't exist. I don't want to have to define the actual colors themselves because they're irrelevant: I just need there to be a Value Colors property.
I can do this very easily interactively by just right-clicking on the column in question, and selecting "Value Colors" from the list of properties, whereupon a default set is defined automatically for me. It's essentially this operation therefore that I need to script - and I'm guessing that the solution will be a single line of code, but I'm afraid I just can't see it. Can anyone help?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Creation of the "Value Colors" property
The ExprList is not being constructed properly. You need to have the literal values in the list, not calculated values. Here is one way to accomplish that
// Start of script;
Names Default To Here( 1 );
Clear Log();
dt = Open( "$SAMPLE_DATA/Big Class.JMP" );
Summarize( NamesList = by( :Name ) );
Show( NamesList );
// Build the ExprLIst to be exactly what the Value Colors
// list needs to be
ExprList = {};
For( i = 1, i <= N Items( NamesList ), i++,
Eval(
Substitute(
Expr(
Insert Into( ExprList, Expr( __Names__ = __color__ ) )
),
Expr( __Names__ ), NamesList[i],
Expr( __color__ ), 2 + i
)
)
);
Show( ExprList );
// Then insert the resulting expression as the Value Colors property of the :Names column, and I should get what I want.
:Name << set property( "Value Colors", ExprList );
// The Value Colors property is correct;
Show( :Name << get property( "Value Colors" ) );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Creation of the "Value Colors" property
You can use JSL like this:
column(dt, "Column 1") << Set Property( "Value Colors", {2 = 45, 3 = 46, 4 = 47} );
The way to figure this out is to
1. Create a small dummy table with a single numeric column
2. Manually add the Value Colors attribute
3. Click the little red triangle next to the table name and select Copy Table Script
4. Open up a JSL script window and paste the resulting code.
It will look something like this:
New Table( "Untitled 14",
Add Rows( 3 ),
New Column( "Column 1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Property( "Value Colors", {1 = -13977687, 2 = -3780931, 3 = -4222943} ),
Set Selected,
Set Values( [1, 2, 3] )
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Creation of the "Value Colors" property
I was able to put a BS value colors property into a column doing this:
:Column 1 << Set Property("Value Colors",{});
Seems like the application really ought to be updated to work more robustly though. Strange requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Creation of the "Value Colors" property
Many thanks both Peter and CWillden for your help; unfortunately I'm still not there - but I've been able to crystallize the problem a little. The attached script shows where I've got to now: if I can resolve the final difficulty regarding how to create a list of expressions that I can then feed into the Value Colors property, I should be able to get what I need:
// Start of script;
clear log();
dt = Open( "$SAMPLE_DATA/Big Class.JMP" );
// The Value Colors property of the first column is initially empty;
show(:Name << get property("Value Colors"));
/*
I now want to create a Value Colors property for this column,
but I'd prefer to do it without having to identify all the names
beforehand if possible. Try CWillden's suggestion...
*/
:Name << set property("Value Colors", {});
// If I now try to color the cells by value, it DOES actually seem to have worked;
:Name << color cell by value(1);
// But the Value Colors property STILL only contains an empty list;
show(:Name << get property("Value Colors"));
/*
Unfortunately I do actually need a populated list - and it looks like I can't do it
without extracting the names explicity. Here's one way I think I COULD do it...
*/
summarize(NamesList=by(:Name));
show(NamesList);
/*
I now need to put those names into a list of expressions that follow the syntax
shown in PMRoz's post, and use that list to define the Value Colors property I need.
This next bit is WRONG - but you can see what I'm trying to do here.
What I need inside ExprList is a list of names, each coupled with an integer from 3 onwards
(to get some colors starting at red). I suspect I should probably be using the Substitute
and/or Eval Expr functions at this point, but I can't get the correct syntax.
*/
ExprList = {};
for(i=1, i<=nItems(NamesList), i++,
insert into(ExprList, expr(NamesList[i] = (2+i)))
);
show(ExprList);
// Then insert the resulting expression as the Value Colors property of the :Names column, and I should get what I want.
:Name << set property("Value Colors", ExprList);
// End of script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Creation of the "Value Colors" property
The ExprList is not being constructed properly. You need to have the literal values in the list, not calculated values. Here is one way to accomplish that
// Start of script;
Names Default To Here( 1 );
Clear Log();
dt = Open( "$SAMPLE_DATA/Big Class.JMP" );
Summarize( NamesList = by( :Name ) );
Show( NamesList );
// Build the ExprLIst to be exactly what the Value Colors
// list needs to be
ExprList = {};
For( i = 1, i <= N Items( NamesList ), i++,
Eval(
Substitute(
Expr(
Insert Into( ExprList, Expr( __Names__ = __color__ ) )
),
Expr( __Names__ ), NamesList[i],
Expr( __color__ ), 2 + i
)
)
);
Show( ExprList );
// Then insert the resulting expression as the Value Colors property of the :Names column, and I should get what I want.
:Name << set property( "Value Colors", ExprList );
// The Value Colors property is correct;
Show( :Name << get property( "Value Colors" ) );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Creation of the "Value Colors" property
Perfect! Always better to ask the experts than try to get that sort of construction right :)
Many thanks, Jim!