<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I update a script  for variability table to draw reference lines that refer to data filter settings? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-update-a-script-for-variability-table-to-draw-reference/m-p/431283#M68099</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/13992"&gt;@mcastner&lt;/a&gt;, I would say you picked a fairly complicated task to start scripting!&amp;nbsp; Below is a way to do what you asked (if I interpreted you correctly), but I wonder if you could make this easier by using graph builder to draw a box plot and line at the same time.&amp;nbsp; How do you come up with values for the reference lines?&amp;nbsp; Any chance that is a summary of the available data (median, quantile, etc), or could you do that in a formula column?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);

dt = Open( "$Sample_data/big class.jmp" );

//Valeus for ref lines - hopefully populated by your script
reflines = Associative Array({
	{"height", 
		Associative Array({
			{ 12, 62 },
			{ 13, 63 },
			{ 14, 64 },
			{ 15, 65 },
			{ 16, 66 },
			{ 17, 67 }
		})
	},
	{"weight",
		Associative Array({
			{ 12, 112 },
			{ 13, 113 },
			{ 14, 114 },
			{ 15, 115 },
			{ 16, 116 },
			{ 17, 117 }
		})
	}
});

//A window with a single data filter that will be applied to all graphs inside it
New Window("charts",
	Data Filter Context Box(
		H List Box(
			ldf = dt &amp;lt;&amp;lt; Data Filter( Local,
				Add Filter(
					columns( :age ),
					Where( :age == 13 ),
					Display( :age, N Items( 6 ) )
				),
				Mode( Select( 0 ), Show( 1 ), Include( 1 ) )
			),
			vc1 = Variability Chart(
				Y( :height ),
				X( :sex )
			);
			vc2 = Variability Chart(
				Y( :weight ),
				X( :sex )
			);
		)
	)
);

//Function that is called when data filter changes and when the window is first opened, this will redraw lines on charts
UpdateRefLines = function({}, 
	
	//find out what ages were selected, there is probably a better way to do this too
	filteredagelast = filteredage;
	filteredage = median(dt:age[ldf &amp;lt;&amp;lt; get filtered rows()]);
	
	//detect if there was a change in the age (prevents flickering of the screen)
	if(is missing(filteredagelast) | (filteredagelast != filteredage),
		
		//remove any existing ref lines
		(vc1 &amp;lt;&amp;lt; XPath("//AxisBox[@charID=2]"))[1] &amp;lt;&amp;lt; Revert Axis;
		(vc2 &amp;lt;&amp;lt; XPath("//AxisBox[@charID=2]"))[1] &amp;lt;&amp;lt; Revert Axis;
		
		//draw new lines
		(vc1 &amp;lt;&amp;lt; XPath("//ScaleBox[@ID=2]")) &amp;lt;&amp;lt; Add Ref Line( reflines["height"][FilteredAge], "Solid", "Black", "", 1 );
		(vc2 &amp;lt;&amp;lt; XPath("//ScaleBox[@ID=2]")) &amp;lt;&amp;lt; Add Ref Line( reflines["weight"][FilteredAge], "Solid", "Black", "", 1 );
	)
);

//function called when data filter changes, here it only redraws reference lines
UpdatesOnRowStateChanges = function({x}, if(is matrix(x), UpdateRefLines ) );

//variable used to keep track of the last filter applied
filteredage = .;

//Assign function to data filter 
rsh = vc1 &amp;lt;&amp;lt; Make Row State Handler( dt, UpdatesOnRowStateChanges );

//draw initial reference lines
UpdateRefLines();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ih_0-1635442885261.png" style="width: 1029px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/37101iE15DEDF7189581AE/image-dimensions/1029x338?v=v2" width="1029" height="338" role="button" title="ih_0-1635442885261.png" alt="ih_0-1635442885261.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Oct 2021 17:42:50 GMT</pubDate>
    <dc:creator>ih</dc:creator>
    <dc:date>2021-10-28T17:42:50Z</dc:date>
    <item>
      <title>How do I update a script  for variability table to draw reference lines that refer to data filter settings?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-update-a-script-for-variability-table-to-draw-reference/m-p/430849#M68058</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am working on a Variability Chart where I have continuous data that I am plotting by subgroup.&amp;nbsp; I have 3 temperature bands of data "1C to 13C", "16C to 28C" and "30C to 45C".&amp;nbsp; I would like to have reference lines drawn for each filter category I select in the data, there are 3 different reference lines groups.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See the attached file and Variability script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am relatively new to scripting.&amp;nbsp; I have seen how the JMP scripting command allows you to write the command for each reference line.&amp;nbsp; I want to make the command dynamic based on what is selected by the data filter. (bold underlined section of the script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advise,&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Matt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;New Window( "Sample set 1 - Variability Chart by Lot",
	V List Box(
		Variability Chart(
			Y( :Test 1 ),
			X( :Lot ),
			Std Dev Chart( 0 ),
			Local Data Filter( Add Filter( columns( :Temp Band 2 ) ) ),
			SendToReport(
				Dispatch(
					{"Variability Chart for Test 1"},
					"2",
					ScaleBox,
					{Min( 0.814090277777778 ), Max( 1.13166666666667 ), Inc( 0.05 ),
					Minor Ticks( 1 ), Add Ref Line(
						0, "Dotted", "Medium Light Gray", "", 1
					), Add Ref Line( &lt;U&gt;&lt;STRONG&gt;1.1&lt;/STRONG&gt;&lt;/U&gt;, "Solid", "Black", "", 1 ),
					Add Ref Line(&lt;U&gt; &lt;STRONG&gt;0.9&lt;/STRONG&gt;&lt;/U&gt;, "Solid", "Black", "", 1 )}
				)
			)
		),
		Variability Chart(
			Y( :Test 2 ),
			X( :Lot ),
			Std Dev Chart( 0 ),
			Local Data Filter( Add Filter( columns( :Temp Band 2 ) ) )
		),
		Variability Chart(
			Y( :Test3 ),
			X( :Lot ),
			Std Dev Chart( 0 ),
			Local Data Filter( Add Filter( columns( :Temp Band 2 ) ) )
		)
	)
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2023 11:18:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-update-a-script-for-variability-table-to-draw-reference/m-p/430849#M68058</guid>
      <dc:creator>mcastner</dc:creator>
      <dc:date>2023-06-11T11:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update a script  for variability table to draw reference lines that refer to data filter settings?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-update-a-script-for-variability-table-to-draw-reference/m-p/431283#M68099</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/13992"&gt;@mcastner&lt;/a&gt;, I would say you picked a fairly complicated task to start scripting!&amp;nbsp; Below is a way to do what you asked (if I interpreted you correctly), but I wonder if you could make this easier by using graph builder to draw a box plot and line at the same time.&amp;nbsp; How do you come up with values for the reference lines?&amp;nbsp; Any chance that is a summary of the available data (median, quantile, etc), or could you do that in a formula column?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);

dt = Open( "$Sample_data/big class.jmp" );

//Valeus for ref lines - hopefully populated by your script
reflines = Associative Array({
	{"height", 
		Associative Array({
			{ 12, 62 },
			{ 13, 63 },
			{ 14, 64 },
			{ 15, 65 },
			{ 16, 66 },
			{ 17, 67 }
		})
	},
	{"weight",
		Associative Array({
			{ 12, 112 },
			{ 13, 113 },
			{ 14, 114 },
			{ 15, 115 },
			{ 16, 116 },
			{ 17, 117 }
		})
	}
});

//A window with a single data filter that will be applied to all graphs inside it
New Window("charts",
	Data Filter Context Box(
		H List Box(
			ldf = dt &amp;lt;&amp;lt; Data Filter( Local,
				Add Filter(
					columns( :age ),
					Where( :age == 13 ),
					Display( :age, N Items( 6 ) )
				),
				Mode( Select( 0 ), Show( 1 ), Include( 1 ) )
			),
			vc1 = Variability Chart(
				Y( :height ),
				X( :sex )
			);
			vc2 = Variability Chart(
				Y( :weight ),
				X( :sex )
			);
		)
	)
);

//Function that is called when data filter changes and when the window is first opened, this will redraw lines on charts
UpdateRefLines = function({}, 
	
	//find out what ages were selected, there is probably a better way to do this too
	filteredagelast = filteredage;
	filteredage = median(dt:age[ldf &amp;lt;&amp;lt; get filtered rows()]);
	
	//detect if there was a change in the age (prevents flickering of the screen)
	if(is missing(filteredagelast) | (filteredagelast != filteredage),
		
		//remove any existing ref lines
		(vc1 &amp;lt;&amp;lt; XPath("//AxisBox[@charID=2]"))[1] &amp;lt;&amp;lt; Revert Axis;
		(vc2 &amp;lt;&amp;lt; XPath("//AxisBox[@charID=2]"))[1] &amp;lt;&amp;lt; Revert Axis;
		
		//draw new lines
		(vc1 &amp;lt;&amp;lt; XPath("//ScaleBox[@ID=2]")) &amp;lt;&amp;lt; Add Ref Line( reflines["height"][FilteredAge], "Solid", "Black", "", 1 );
		(vc2 &amp;lt;&amp;lt; XPath("//ScaleBox[@ID=2]")) &amp;lt;&amp;lt; Add Ref Line( reflines["weight"][FilteredAge], "Solid", "Black", "", 1 );
	)
);

//function called when data filter changes, here it only redraws reference lines
UpdatesOnRowStateChanges = function({x}, if(is matrix(x), UpdateRefLines ) );

//variable used to keep track of the last filter applied
filteredage = .;

//Assign function to data filter 
rsh = vc1 &amp;lt;&amp;lt; Make Row State Handler( dt, UpdatesOnRowStateChanges );

//draw initial reference lines
UpdateRefLines();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ih_0-1635442885261.png" style="width: 1029px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/37101iE15DEDF7189581AE/image-dimensions/1029x338?v=v2" width="1029" height="338" role="button" title="ih_0-1635442885261.png" alt="ih_0-1635442885261.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 17:42:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-update-a-script-for-variability-table-to-draw-reference/m-p/431283#M68099</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-10-28T17:42:50Z</dc:date>
    </item>
  </channel>
</rss>

