<?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: GraphBuilder - customize / reorder segs through JSL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/GraphBuilder-customize-reorder-segs-through-JSL/m-p/376514#M62643</link>
    <description>&lt;P&gt;In the JSL representation of Graph Builder, the order of the "segments" seems to be set by the order in which they appear in the &lt;EM&gt;Elements()&lt;/EM&gt; argument.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one idea on how to reorder the elements with JSL in JMP15. It assumes your dt_sampledata is the current data table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Graph Builder
gb = Graph Builder(
	Size( 1040, 562 ),
	Variables(
		X( :Month ),
		Y( :Volume, Side( "Right" ) ),
		Y( :Chem_A, Position( 1 ) ),
		Y( :Chem_B, Position( 1 ) ),
		Overlay( :Product )
	),
	Elements(
		Line( X, Y( 2 ), Y( 3 ), Overlay( 0 ), Legend( 12 ) ),
		Bar( X, Y( 1 ), Legend( 11 ), Bar Style( "Stacked" ) )
	)
);
Wait( 2 );
gbexpr = gb &amp;lt;&amp;lt; get script;
// Find the position of the Elements() argument
i = 1;
While( Head( Arg( gbexpr, i ) ) != Expr( Elements ), i++ );
// Move forward the most background element to front
n = N Arg( Arg( gbexpr, i ) );
reordered_elem = Eval Expr( Elements( Expr( Arg( gbexpr, {i, n} ) ), Expr( Arg( gbexpr, {i, 1} ) ) ) );
// Replace old Elements() with the new re-ordered elements
Substitute Into( gbexpr, Arg( gbexpr, i ), Name Expr( reordered_elem ) );
// Replace the graph builder
gb &amp;lt;&amp;lt; close window;
Eval( gbexpr );
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Apr 2021 22:47:25 GMT</pubDate>
    <dc:creator>ms</dc:creator>
    <dc:date>2021-04-13T22:47:25Z</dc:date>
    <item>
      <title>GraphBuilder - customize / reorder segs through JSL</title>
      <link>https://community.jmp.com/t5/Discussions/GraphBuilder-customize-reorder-segs-through-JSL/m-p/376292#M62614</link>
      <description>&lt;P&gt;In GraphBuilder when multiple components are added to the same graph, some components&amp;nbsp;get hidden or are pushed behind others and are less visible.&lt;/P&gt;&lt;P&gt;Line segments below are behind the bar segments.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rbfinner_0-1618327000327.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32032i3AC3386CE7C79131/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rbfinner_0-1618327000327.png" alt="rbfinner_0-1618327000327.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the graph, there is the option to right-click &amp;gt; customize and re-order components using the up/down arrows and send the bar segments to the back.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rbfinner_1-1618327164317.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32033i7A1E1905C2DB28DC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rbfinner_1-1618327164317.png" alt="rbfinner_1-1618327164317.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rbfinner_2-1618327260718.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32034iC9908A4A1853AEAE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rbfinner_2-1618327260718.png" alt="rbfinner_2-1618327260718.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a way to script this in JMP16 (full code below), but the same solution fails in JMP15.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Is there an equivalent solution for JMP15?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;gbFB1 = report(gb)[Framebox(1)];
gbFB1 &amp;lt;&amp;lt; Reorder Segs({1, 2, 5});&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;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ray&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Full JSL code to recreate:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt_sampledata = New Table( "Exampe Data",
	Add Rows( 24 ),
	New Column( "Month",
		Numeric,
		"Ordinal",
		Format( "Best", 12 ),
		Set Values(
			[202101, 202101, 202101, 202101, 202102, 202102, 202102, 202102, 202103,
			202103, 202103, 202103, 202104, 202104, 202104, 202104, 202105, 202105,
			202105, 202105, 202106, 202106, 202106, 202106]
		)
	),
	New Column( "Product",
		Character( 16 ),
		"Nominal",
		Set Values(
			{"ProductA", "ProductB", "ProductC", "ProductD", "ProductA", "ProductB",
			"ProductC", "ProductD", "ProductA", "ProductB", "ProductC", "ProductD",
			"ProductA", "ProductB", "ProductC", "ProductD", "ProductA", "ProductB",
			"ProductC", "ProductD", "ProductA", "ProductB", "ProductC", "ProductD"}
		)
	),
	New Column( "Volume",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[3869, 4964, 3188, 3109, 2623, 3447, 3179, 1038, 1781, 3195, 1621, 2034,
			3231, 1390, 3187, 1998, 3280, 3570, 4443, 2150, 1638, 4083, 4242, 1186]
		)
	),
	New Column( "Chem_A",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[5, 19, 45, 36, 35, 42, 28, 46, 33, 43, 19, 5, 11, 14, 47, 21, 5, 8, 33,
			32, 7, 6, 9, 33]
		)
	),
	New Column( "Chem_B",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[64, 38, 90, 41, 69, 70, 79, 75, 79, 59, 25, 71, 64, 65, 62, 51, 88, 79,
			41, 47, 22, 62, 57, 38]
		)
	)
);

// Graph Builder
gb = dt_sampledata &amp;lt;&amp;lt; Graph Builder(
	Size( 1040, 562 ),
	Variables(
		X( :Month ),
		Y( :Volume, Side( "Right" ) ),
		Y( :Chem_A, Position( 1 ) ),
		Y( :Chem_B, Position( 1 ) ),
		Overlay( :Product )
	),
	Elements(
		Line( X, Y( 2 ), Y( 3 ), Overlay( 0 ), Legend( 12 ) ),
		Bar( X, Y( 1 ), Legend( 11 ), Bar Style( "Stacked" ) )
	),
	SendToReport(
		Dispatch(
			{},
			"400",
			LegendBox,
			{Legend Position( {12, [4, 5], 11, [0, 1, 2, 3]} )}
		)
	)
);&lt;BR /&gt;gbFB1 = report(gb)[Framebox(1)];&lt;BR /&gt;&lt;BR /&gt;gbFB1 &amp;lt;&amp;lt; Reorder Segs({1, 2, 5});&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2023 11:12:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/GraphBuilder-customize-reorder-segs-through-JSL/m-p/376292#M62614</guid>
      <dc:creator>rbfinner</dc:creator>
      <dc:date>2023-06-11T11:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: GraphBuilder - customize / reorder segs through JSL</title>
      <link>https://community.jmp.com/t5/Discussions/GraphBuilder-customize-reorder-segs-through-JSL/m-p/376514#M62643</link>
      <description>&lt;P&gt;In the JSL representation of Graph Builder, the order of the "segments" seems to be set by the order in which they appear in the &lt;EM&gt;Elements()&lt;/EM&gt; argument.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one idea on how to reorder the elements with JSL in JMP15. It assumes your dt_sampledata is the current data table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Graph Builder
gb = Graph Builder(
	Size( 1040, 562 ),
	Variables(
		X( :Month ),
		Y( :Volume, Side( "Right" ) ),
		Y( :Chem_A, Position( 1 ) ),
		Y( :Chem_B, Position( 1 ) ),
		Overlay( :Product )
	),
	Elements(
		Line( X, Y( 2 ), Y( 3 ), Overlay( 0 ), Legend( 12 ) ),
		Bar( X, Y( 1 ), Legend( 11 ), Bar Style( "Stacked" ) )
	)
);
Wait( 2 );
gbexpr = gb &amp;lt;&amp;lt; get script;
// Find the position of the Elements() argument
i = 1;
While( Head( Arg( gbexpr, i ) ) != Expr( Elements ), i++ );
// Move forward the most background element to front
n = N Arg( Arg( gbexpr, i ) );
reordered_elem = Eval Expr( Elements( Expr( Arg( gbexpr, {i, n} ) ), Expr( Arg( gbexpr, {i, 1} ) ) ) );
// Replace old Elements() with the new re-ordered elements
Substitute Into( gbexpr, Arg( gbexpr, i ), Name Expr( reordered_elem ) );
// Replace the graph builder
gb &amp;lt;&amp;lt; close window;
Eval( gbexpr );
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 22:47:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/GraphBuilder-customize-reorder-segs-through-JSL/m-p/376514#M62643</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2021-04-13T22:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: GraphBuilder - customize / reorder segs through JSL</title>
      <link>https://community.jmp.com/t5/Discussions/GraphBuilder-customize-reorder-segs-through-JSL/m-p/376625#M62650</link>
      <description>Many thanks!&lt;BR /&gt;There's a little bit more to it than JMP16 but still relatively short and neat.&lt;BR /&gt;And, an added bonus for me is that your solution has provided an introduction on how to parse and search the JSL GB script also.</description>
      <pubDate>Wed, 14 Apr 2021 08:56:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/GraphBuilder-customize-reorder-segs-through-JSL/m-p/376625#M62650</guid>
      <dc:creator>rbfinner</dc:creator>
      <dc:date>2021-04-14T08:56:47Z</dc:date>
    </item>
  </channel>
</rss>

