2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiQuesta è la sfida Makeover Q1 2022.
L'obiettivo è fornire un esempio, uno script o una guida per svolgere una delle tre attività (riguardano tutte l'avvio di un'azione dopo aver fatto clic su qualcosa in JMP):
- Sfida A: (immagini e script per creare la tabella dati iniziale per l'apertura delle immagini allegate: 2022Q1_ChallengeA.zip)
- Hai: Una colonna di una tabella di dati con immagini o collegamenti a un sito Web o un file (ovvero espressioni)
- Si desidera: fare clic su una cella di questa colonna e aprire il collegamento o l'immagine al di fuori di JMP
- L'obiettivo generale: fare clic su una cella di una tabella di dati dovrebbe avviare qualcosa
- Sfida B : (script per aprire la tabella dati e creare il report allegato: 2022Q1_ChallengeB_starterScript.jsl)
- Hai: Big Class e un rapporto di Graph Builder di peso per altezza (vedi script)
- Si desidera: la chiusura del rapporto di Generatore di grafici dovrebbe aprire un rapporto di distribuzione di "età", salvare questo rapporto come immagine e chiudere il rapporto di distribuzione.
- L'obiettivo generale: chiudere una finestra dovrebbe attivare qualche azione
- Sfida C: (script per aprire la tabella dati e creare il report allegato: 2022Q1_ChallengeC_starterScript.jsl)
- Hai: Un rapporto di Generatore di grafici sui dati di esempio delle misurazioni della crescita.
- Si desidera: Quando si fa clic su una riga o si selezionano più righe (o categorie nella legenda), si desidera generare un sottoinsieme delle righe selezionate.
- L'obiettivo generale: fare clic su un grafico o un rapporto dovrebbe attivare qualche azione
Puoi lavorare su tutte le sfide che vuoi. Puoi/dovresti inviare le tue risposte direttamente come risposta a questo thread.
!!! Quando si invia, si prega di iniziare dalla prima riga a quale sfida si riferisce la risposta, ad es
SFIDA A:
Questa è la mia risposta...
// this is my code
...
Nella prossima riunione (18 maggio 2022) presenteremo alcune delle risposte e segnerò le migliori risposte come soluzione a questo thread.
Aspetto i tuoi contributi 
Re: 2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiSFIDA C
Questa è la mia risposta, vedi lo script completo di seguito.
La parte inferiore aggiunge un gestore dello stato della riga alla tabella, che attiva l'azione (vedi esempio in Scripting Index).
Names Default To Here( 1 );
// Open Data Table
dt = Open( "$SAMPLE_DATA/Growth Measurements.jmp", invisible );
// Report snapshot: Growth Measurements - Graph Builder
gb = dt << Graph Builder(
Size( 522, 452 ),
Show Control Panel( 0 ),
Legend Position( "Bottom" ),
Graph Spacing( 8 ),
Variables( X( :Age ), Y( :Growth ), Overlay( :Subject ) ),
Elements( Line( X, Y, Legend( 13 ) ) )
);
// This is my code (Georg)
// (see Scripting Index "Make Row State Handler")
// Define a function, that does the action
f = Function( {a},
Current Data Table() << Subset( Selected Rows( 1 ), Selected columns only( 0 ) )
);
// Set up a row state handler, that triggers the execution of a function on any change of row states,
// a change on row selection by clicking on a line in Graph Builder is a change of row states in the table
rs = dt << make row state handler( f );Re: 2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiSFIDA C
Con una casella del mouse non era possibile selezionare qualcosa, quindi sono passato a un gestore dello stato di riga
Names Default To Here( 1 );
// Open Data Table
dt = Open( "$SAMPLE_DATA/Growth Measurements.jmp", invisible );
// Report snapshot: Growth Measurements - Graph Builder
gb = dt << Graph Builder(
Size( 522, 452 ),
Show Control Panel( 0 ),
Legend Position( "Bottom" ),
Graph Spacing( 8 ),
Variables( X( :Age ), Y( :Growth ), Overlay( :Subject ) ),
Elements( Line( X, Y, Legend( 13 ) ) )
);
active_subset = "";
first_subset = "false";
rsh = dt << make row state handler(
Function( {a},
subtbl = dt << Subset( Selected Rows( 1 ) );
gb << Bring Window To Front;
if(
first_subset == "true",
close(active_subset, no save)
);
active_subset = subtbl;
first_subset = "true";
)
);
Re: 2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiSFIDA A:
NOTA: Ho mantenuto questa versione precedente poiché alcune persone l'avevano già vista, ma ho pubblicato una soluzione più pulita come a Rispondere a questo.
Non è affatto una bella soluzione, ma fa il suo lavoro... Sperando che se ne presenti uno più elegante!
Questo da aggiungere dopo lo starterScript:
// Defining the file name for an image placeholder for displaying on the OS when clicking:
pictFileName = Get Default Directory() || "verylonganduselessname.png"; //name for the temp image file (to be deleted at the end)
dtx:Picture << Set Property("tmpFileName", pictFileName); //saving the name so it can be retrieved from within the table
dtx << On Close( Delete File(pictFileName) ); //make sure we erase the temp image file at the end.
// Setting a Click event handler for the column of interest:
dtx:Picture << Set Property(
"Event Handler",
Event Handler(
Click(JSL Quote( Function(
{thisTable, thisColumn, iRow},
pictFileName = thisTable:thisColumn<< Get Property("tmpFileName"); //recover the path for a temp file
thisTable:thisColumn[iRow] << Save Image( pictFileName ); //save cell contents to temp file
Web( "file://" || pictFileName ) // open the image file
)
)
),
Tip(JSL Quote( Function(
{thisTable, thisColumn, iRow},
"click to open";
)
)
)
)
);
Re: 2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiSFIDA A
Scusa se ho saltato la pistola con la mia soluzione iniziale... Eccone uno più pulito.
Names Default to Here ( 1 );
//path = <YOUR full="" path="" to="" where="" the="" images="" have="" been="" saved="">;
// eg.
// path = "C:\EventHandlerImages\";
path = "$DOCUMENTS\Scripting\2022Q1\ChallengeA\2022Q1_ChallengeA\";
//==========================================================================
//Multiple File Import is new in JMP 14
{dtx} = Multiple File Import(
<<SET folder=""></SET></YOUR>Re: 2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiSfida C
Purtroppo c'era poco altro da fare per quanto riguarda le sfide A e B. Le soluzioni fornite sembravano impeccabili. Al contrario, ho sentito che qualche miglioramento era ancora possibile per la sfida C. Poche parole sulla mia risposta
- Ho praticamente rubato il codice necessario da qui ( @txnelson è, come molti altri sceneggiatori, una rock star per me)
- Ho leggermente modificato il grafico includendo punti dati visibili, quindi è più facile selezionare singole righe
- Dopo aver selezionato i punti nel grafico, la tabella dati con il sottoinsieme non viene aperta immediatamente. Questo viene fatto tramite il pulsante aggiunto sotto il grafico
Vedi sotto lo script completo, incluso il grafico modificato.
// Open Data Table
dt = Open( "$SAMPLE_DATA/Growth Measurements.jmp",invisible );
// Report snapshot: Growth Measurements - Graph Builder
gb = dt << Graph Builder(
Size( 522, 452 ),
Show Control Panel( 0 ),
Legend Position( "Bottom" ),
Graph Spacing( 8 ),
Variables( X( :Age ), Y( :Growth ), Overlay( :Subject ) ),
Elements(
Points( X, Y, Legend( 17 ), Jitter Limit( 0 ) ), // added markers
Line( X, Y, Legend( 13 ) ) ),
SendToReport( // increased markers to decent size
Dispatch(
{},
"Graph Builder",
FrameBox,
{Marker Size( 6 ), Marker Drawing Mode( "Normal" )}
)
)
);
// my solution (stolen from here: https://community.jmp.com/t5/Discussions/Creating-a-Subset-from-an-Interactive-Graph/td-p/114459)
subsetButton = Button Box( "Dear user, Please press here to create a Subset of the Selected Points immediately",
If( N Rows( dt << get selected rows ) > 0,
dt << subset( selected rows( 1 ), selected columns( 0 ) )
)
);
Report( gb )["Graph Builder"] << append( subsetButton );
Re: 2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiSfida A:
Per lo più codice scritto JMP con Aggiungi proprietà colonna. Aggiunto anche esempio su come aggiungere e aprire URL
Visualizza di più...
Names Default To Here(1);
// Challenge A
path = "2022Q1_ChallengeA"; // path to images
{dtx} = Multiple File Import(
<<SET folder=""></SET>
Re: 2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiSFIDA B
Aggiungi questo in fondo allo script:
gb << On Close(
dist = dt << Distribution( Nominal Distribution( Column( :age ) ) );
image = dist << Get Picture;
path = "$temp/age_dist.png";
image << Save Picture( path, "png" );
dist << Close Window();
Open( path );
);
Re: 2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiSfida B:
Visualizza di più...
Names Default To Here(1);
// 2022_Q1 MakeOverChallenge: Action on mouse click in various ways
// Challenge B
dt = Open("$SAMPLE_DATA/Big Class.jmp");
//Use expression to make script a bit more clean IF this were to be expanded
create_dist = Expr(
dist = dt << Distribution(Nominal Distribution(Column(:age)), Histograms Only);
wait(1); // add wait so we can see that distribution is created
dist << Save Picture("$TEMP/Big_Class_age_dist.png", png);
dist << Close Window;
);
gb = dt << Graph Builder(
Size(528, 454),
Show Control Panel(0),
Variables(X(:height), Y(:weight)),
Elements(Points(X, Y, Legend(3)), Line Of Fit(X, Y, Legend(5)))
);
gb << On Close(create_dist);
// Open("$TEMP/Big_Class_age_dist.png"); // un-comment to open the image
Re: 2022_Q1 MakeOverChallenge: azione al clic del mouse in vari modiSfida C:
Consiglio vivamente di fare cose del genere con i pulsanti in quanto impedisce la creazione di troppi sottoinsiemi. Ma qui ho seguito la sfida data e ho aggiunto un semplice controllo che non creeremo almeno lo stesso sottoinsieme due volte.
Visualizza di più...
Names Default To Here(1);
// Open Data Table
dt = Open("$SAMPLE_DATA/Growth Measurements.jmp", invisible);
gb = dt << Graph Builder(
Size(522, 452),
Show Control Panel(0),
Legend Position("Bottom"),
Graph Spacing(8),
Variables(X(:Age), Y(:Growth), Overlay(:Subject)),
Elements(Line(X, Y, Legend(13)))
);
//initialize some variables
prev_rows = [];
dt_list = {};
f = Function({rows_changed},
//Rowstate 1 is selected row
cur_rows = Loc(dt << Get Row States, 1);
//if no rows are selected, don't try to create subsets
If(N Items(cur_rows) == 0,
return()
);
//compare to previous to prevent opening extensive abmount of subsets
If(N Items(cur_rows) == N Items(prev_rows),
If(All(cur_rows == prev_rows),
return();
);
);
dt_subset = dt << Subset(Output table("selected_rows"), Rows(cur_rows), invisible);
Insert Into(dt_list, dt_subset); //keep list to make closing easier
//attempt to bring gb to front, this won't work perfectly without wait
gb << Bring Window To Front;
dt_subset << Show Window(1);
//it is enough if we update prev_rows only when subset was created
prev_rows = cur_rows;
);
rs = dt << make row state handler(f);
/* run this to close all data tables
For Each({dt_ref}, dt_list,
Try(Close(dt_ref, no save), Show(exception_msg));
);
Close(dt, no save);
*/
Con Row State Handler non possiamo accedere all'evento di rilascio del mouse, quindi creeremo comunque molti sottoinsiemi se l'utente seleziona più righe una per una dal grafico (potrebbe esserci un modo per farlo con Mouse Box(), ma penso che usare il pulsante sarebbe essere molto più semplice e facile).