Using variables in path nameHello,
Please forgive me if this is a trivial question, I do not have much experience working with JSL.
I am trying to add a picture to the hover label using JSL code, and want to define the picture path using a variable. I have a folder of pictures, and want them to be called using a variable in my table.
For example, my pictures are labeled 1 to 100, and I have a column in my table called "picture number". I want to be able to call them, like this:
PictureBox(Open("c:/iris/"picture number" .jpg", jpg));
is this possible?
Many thanks!
Mass CustomizationRe: Using variables in path nameWow, excellent example, @jthi ! Thank you for sharing it!
The trick here is that when you are building the image fine name from a table column, you have to indicate the column name AND the row. Inside the Local namespace populated by the graphlet execution context, the current row is available in the variable local:_firstRow. Thus the construct:
Picture Box(Open(Column("PicAdress")[local:_firstRow],jpg))
For more information on this and other variables, see Hover Label Execution Context.
Re: Using variables in path nameThanks a lot, this works great.
Re: Using variables in path nameTry checking out the log to see what errors you are getting. Most likely something like this: "The namespace "local_" is not defined in access or evaluation of 'local_:PicAdress'".
Try out something like this:
Picture Box(Open(Column("PicAdress")[local:_firstRow],jpg))
More info possibly from: How to run a query on mouseover, using data from the underlying datapoint?
Edit:
I added example script. It will create couple of files (10 by default) to $TEMP (and attempt to delete them on window close) and create window with two graph builders:
- First will build path from the data in graph builder using this idea:
PictureBox(Open("c:/iris/" || local:_PicAdress || ".jpg", jpg))
- Second is using only the row information from graph builder and getting data based on row from datatable
Picture Box(Open(Column("PicAdress")[local:_firstRow],jpg))
Re: Using variables in path nameThanks for the responses.
I have a follow up question. I want the hover label to get the file address from a column. My column has the address itself, for example, the text in my Colum (named PicAdress) is "c:/iris/picNumber.jpg" .
However, I cannot get the hovel label to accept this variable. i have tried using:
PictureBox(Open(local:_PicAdress, jpg))
with no success.
When I simply enter the address in the column there is no problem.
PictureBox(Open("c:/iris/" || local:_PicAdress || ".jpg", jpg))
Any advice?
Re: Using variables in path nameYou might want to check this thread. They had the same use case. The thread contains many script examples that you should find useful.
Hover label
Re: Using variables in path nameCheck the log for messages. One or more of the following might help.
Build the path name in a variable and print it to the log, then pass the variable to open.
Add quotation marks around the 2nd parameter to open.
Add the data table scope before the column name.
Add a row number subscript after the column name.
edit: use the char() function to convert numeric to character!
filename = "c:/iris/" || char(dt:picture number[1]) || ".jpg";
show(filename);
PictureBox(Open( filename, "jpg"));
Re: Using variables in path nameIf you check out the example Hover Label Editor gives for Picture Graphlet
// Example:
// Graph Builder(Variables(Y(local:_measurements[1])), Elements(Histogram(Y)))
// Example:
// PictureBox(Open("c:/iris/" || local:_Species || ".jpg", jpg));the syntax seems be a bit special. Maybe it would work with something like this:
PictureBox(Open("c:/iris/" || char(local:_picture number)|| ".jpg", jpg));Re: Using variables in path nameUsing a specific picture number works fine, but I cannot insert a variable name (the variable column is "picture number") to this path, for example, the following does not work. Any idea how to fix this?
PictureBox(Open("c:/iris/" || :picture number|| ".jpg", jpg));
Re: Using variables in path namethanks! i'll give it a try.
Re: Using variables in path nameYes, some variation of this:
img << saveimage( "f:/path/x" || Char( imagenumber ) || ".png", "png" );
x is the prefix before the number and is not required by the operating system.