2022_Q1 MakeOverChallenge:以各種方式對鼠標單擊進行操作這是 2022 年第一季度的改造挑戰。
目標是提出一個示例、腳本或指南來完成三個任務之一(所有這些都與您在 JMP 中單擊某些內容後啟動某些操作有關):
- 挑戰一: (用於創建打開圖像的初始數據表的圖像和腳本附件:2022Q1_ChallengeA.zip)
- 您有: 包含圖像或網站或文件鏈接(又名表達式)的數據表列
- 您想要:單擊此列的一個單元格並在 JMP 之外打開鏈接或圖像
- 總體目標:單擊數據表單元格應啟動某些內容
- 挑戰 B : (打開數據表並創建報告的腳本:2022Q1_ChallengeB_starterScript.jsl)
- 您有:Big Class 和 Graph Builder 的身高體重報告(見腳本)
- 您想要:關閉 Graph Builder 報告應該打開一個“年齡”的分佈報告,將此報告保存為圖片並關閉分佈報告。
- 總體目標:關閉窗口應該觸發一些動作
- 挑戰 C: (打開數據表並創建報告的腳本:2022Q1_ChallengeC_starterScript.jsl)
- 您有: 關於增長測量樣本數據的圖表生成器報告。
- 您希望:當單擊一行或選擇多行(或圖例中的類別)時,您希望生成所選行的子集。
- 總體目標:點擊圖表或報告應該觸發一些動作
您可以根據需要應對盡可能多的挑戰。 您可以/應該直接提交您的答案作為對該主題的回复。
!!! 提交時,請在第一行開始您的回复所指的挑戰,例如
挑戰一:
這是我的答案...
// this is my code
...
在下次會議(2022 年 5 月 18 日)中,我們將展示一些答案,我會將最佳答案標記為該主題的解決方案。
期待你的投稿:)
回复:2022_Q1 MakeOverChallenge:以各種方式點擊鼠標的動作挑戰 C
這是我的答案,請參閱下面的完整腳本。
下半部分將行狀態處理程序添加到表中,以觸發操作(參見腳本索引中的示例)。
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 );回复:2022_Q1 MakeOverChallenge:以各種方式點擊鼠標的動作挑戰 C
使用鼠標框無法選擇某些內容,因此我更改為行狀態處理程序
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";
)
);
回复:2022_Q1 MakeOverChallenge:以各種方式點擊鼠標的動作挑戰一:
筆記:我保留了這個舊版本,因為有些人已經看過它,但我發布了一個更清潔的解決方案作為回复到這個。
根本不是一個漂亮的解決方案,但它可以完成工作...... 希望有更優雅的出現!
這要在 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";
)
)
)
)
);
回复:2022_Q1 MakeOverChallenge:以各種方式點擊鼠標的動作挑戰A
很抱歉用我最初的解決方案開槍...... 這是一個更清潔的。
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>回复:2022_Q1 MakeOverChallenge:以各種方式點擊鼠標的動作挑戰 C
不幸的是,就挑戰 A 和 B 而言,沒有什麼可做的了。 提供的解決方案似乎無可挑剔。 相比之下,我覺得挑戰 C 仍有一些改進的可能。 關於我的回答的幾句話
- 我基本上偷了必要的代碼從這裡( @txnelson就像許多其他編劇一樣,對我來說是搖滾明星)
- 我通過包含可見數據點稍微修改了圖表,因此更容易選擇單個行
- 選擇圖形中的點後,不會立即打開帶有子集的數據表。 這是通過在圖表下方添加的按鈕完成的
請參閱下面的完整腳本,包括修改後的圖表。
// 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 );
回复:2022_Q1 MakeOverChallenge:以各種方式點擊鼠標的動作挑戰一:
主要是 JMP 編寫的帶有添加列屬性的代碼。 還添加瞭如何添加和打開 URL 的示例
查看更多...
Names Default To Here(1);
// Challenge A
path = "2022Q1_ChallengeA"; // path to images
{dtx} = Multiple File Import(
<<SET folder=""></SET>
回复:2022_Q1 MakeOverChallenge:以各種方式點擊鼠標的動作挑戰 B
將此添加到腳本的底部:
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 );
);
回复:2022_Q1 MakeOverChallenge:以各種方式點擊鼠標的動作挑戰 B:
查看更多...
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