<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />I'm curious to see if there is a better way to do the script that is below. Currently I have one function take the input from the user and make a list of all the possible Y values for the graph or graphs to follow. Then the following function gets called to create the graphs. I would like to know if there is some way I could dramatically shorten the amount of code needed by somehow using one or two graph builders instead of the 6 if statements containing their own graph builders
HALTbuildGraph=Function({},{tempcol="", vibcol=""},
if(N Items(LogCheckBox << Get Selected())==1, //if log files were imported
for(i=1, i<= n Col(), i++,
if(contains(char(column name(i)), "Temp") & contains(char(column name(i)), "Setpoint"),
tempcol=char(column name(i)),
/*else if*/ contains(char(column name(i)), "Vib") & contains(char(column name(i)), "Setpoint"),
vibcol=char(column name(i));
);
);
if(tempcol=="", //if the Temperature Setpoint column was not found.
print("Error 111a: Temperature Setpoint not found");
throw()
);
if(vibcol=="", //if the Vibration Setpoint column was not found.
print("Error 111b: Vibration Setpoint not found");
throw();
);
if(N Items(graphlist)==1,
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
Y( column(graphlist[1]) )
),
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 3 ),
Line( X, Y, Legend( 29 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[1])});
);
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave),
/*else if*/ N Items(graphlist)==2,
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
Y( column(graphlist[1]) ),
Y( column(graphlist[2]) )
),
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 3 ),
Line( X, Y, Legend( 29 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 4 ),
Line( X, Y, Legend( 30 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[1]||" & "||graphlist[2])});
);
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave),
/*else if*/ N Items(graphlist)==3,
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
Y( column(graphlist[1]) ),
Y( column(graphlist[2]) ),
Y( column(graphlist[3]) )
),
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 3 ),
Line( X, Y, Legend( 29 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 4 ),
Line( X, Y, Legend( 30 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 5 ),
Line( X, Y, Legend( 31 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[1]||", "||graphlist[2]||", & "||graphlist[3])});
);
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave),
/*else if*/ N Items(graphlist)==4,
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
Y( column(graphlist[1]) ),
Y( column(graphlist[2]) ),
Y( column(graphlist[3]) )
),
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 3 ),
Line( X, Y, Legend( 29 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 4 ),
Line( X, Y, Legend( 30 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 5 ),
Line( X, Y, Legend( 31 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[1]||", "||graphlist[2]||", & "||graphlist[3])});
);
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave);
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
Y( column(graphlist[4]) )
),
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 3 ),
Line( X, Y, Legend( 29 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[4])});
);
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave),
/*else if*/ N Items(graphlist)==5,
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
Y( column(graphlist[1]) ),
Y( column(graphlist[2]) ),
Y( column(graphlist[3]) )
),
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 3 ),
Line( X, Y, Legend( 29 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 4 ),
Line( X, Y, Legend( 30 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 5 ),
Line( X, Y, Legend( 31 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[1]||", "||graphlist[2]||", & "||graphlist[3])});
);
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave);
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
Y( column(graphlist[4]) ),
Y( column(graphlist[5]) )
),
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 3 ),
Line( X, Y, Legend( 29 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 4 ),
Line( X, Y, Legend( 30 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[4]||" & "||graphlist[5])});
);
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave),
/*else if*/ N Items(graphlist)==6,
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
Y( column(graphlist[1]) ),
Y( column(graphlist[2]) ),
Y( column(graphlist[3]) )
),
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 3 ),
Line( X, Y, Legend( 29 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 4 ),
Line( X, Y, Legend( 30 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 5 ),
Line( X, Y, Legend( 31 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[1]||", "||graphlist[2]||", & "||graphlist[3])});
);
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave);
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
Y( column(graphlist[4]) ),
Y( column(graphlist[5]) ),
Y( column(graphlist[6]) )
),
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 3 ),
Line( X, Y, Legend( 29 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 4 ),
Line( X, Y, Legend( 30 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 5 ),
Line( X, Y, Legend( 31 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[4]||" & "||graphlist[5])});
);
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave);
),
It continues but I think you get the picture...
Basically, I've tried using if statements in the Variables section of graph builder but JMP does not seem to like that at all. I'm just looking for a way to shorten my code and make it easier to read.
Thank you again for sharing that example and those commands. Here is what the above code looks like now. I'd say it is much better than it use to be.
HALTbuildGraph=Function({},{tempcol="", vibcol=""}, //11
if(N Items(LogCheckBox << Get Selected())==1, //if log files were imported
for(i=1, i<= n Col(), i++,
if(contains(char(column name(i)), "Temp") & contains(char(column name(i)), "Setpoint"),
tempcol=char(column name(i)),
/*else if*/ contains(char(column name(i)), "Vib") & contains(char(column name(i)), "Setpoint"),
vibcol=char(column name(i));
);
);
if(tempcol=="", //if the Temperature Setpoint column was not found.
print("Error 111a: Temperature Setpoint not found");
throw()
);
if(vibcol=="", //if the Vibration Setpoint column was not found.
print("Error 111b: Vibration Setpoint not found");
throw();
);
gb_expr = evalinsert("\[
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
]\");
for(i=1, i<=N Items(graphlist) & i<=3, i++,
if(i==N Items(graphlist) | i==3,
gb_expr = gb_expr || evalinsert("\[
Y( graphlist[^i^] )
),
]\"),
/*else*/
gb_expr = gb_expr || evalinsert("\[
Y( graphlist[^i^] ),
]\");
);
);
gb_expr = gb_expr || evalinsert("\[
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
]\");
for(i=1, i<=N Items(graphlist) & i<=3, i++,
gb_expr = gb_expr || evalinsert("\[
Elements(
Position( 1, 2+^i^ ),
Line( X, Y, Legend( 28+^i^ ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
]\");
);
gb_expr = gb_expr || evalinsert("\[
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[1]
]\");
if(N Items(graphlist)==1,
gb_expr = gb_expr || evalinsert("\[)});
);
]\");
);
for(i=2, i<=N Items(graphlist) & i<=3, i++,
if(i==N Items(graphlist) | i==3,
gb_expr = gb_expr || evalinsert("\[||", & "||graphlist[^i^])});
);
]\"),
/*else*/
gb_expr = gb_expr || evalinsert("\[||", "||graphlist[^i^]
]\");
);
);
gb_expr = gb_expr || evalinsert("\[
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave)
]\");
eval(parse(gb_expr));
if(N Items(graphlist)>3,
gb_expr = evalinsert("\[
gb=Graph Builder(
Variables(
X( :Test Time ),
Y( column(tempcol) ),
Y( column(vibcol) ),
]\");
for(i=4, i<=N Items(graphlist), i++,
if(i==N Items(graphlist),
gb_expr = gb_expr || evalinsert("\[
Y( graphlist[^i^] )
),
]\"),
/*else*/
gb_expr = gb_expr || evalinsert("\[
Y( graphlist[^i^] ),
]\");
);
);
gb_expr = gb_expr || evalinsert("\[
Elements(
Position( 1, 1 ),
Line( X, Y, Legend( 27 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
Elements(
Position( 1, 2 ),
Line( X, Y, Legend( 28 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
]\");
for(i=4, i<=N Items(graphlist), i++,
gb_expr = gb_expr || evalinsert("\[
Elements(
Position( 1, 2+^i^-3 ),
Line( X, Y, Legend( 28+^i^-3 ), Row order( 0 ), Summary Statistic( "Mean" ) )
),
]\");
);
gb_expr = gb_expr || evalinsert("\[
SendToReport(
Dispatch({}, "graph title", Text Edit Box, {Set Text (graphlist[4]
]\");
if(N Items(graphlist)==4,
gb_expr = gb_expr || evalinsert("\[)});
);
]\");
);
for(i=5, i<=N Items(graphlist), i++,
if(i==N Items(graphlist),
gb_expr = gb_expr || evalinsert("\[||", & "||graphlist[^i^])});
);
]\"),
/*else*/
gb_expr = gb_expr || evalinsert("\[||", "||graphlist[^i^]
]\");
);
);
gb_expr = gb_expr || evalinsert("\[
);
gb_rpt = report(gb);
gb_rpt[LegendBox(1)] << delete;
gb_rpt[PictureBox(1)] << Journal Window;
gb << close window(nosave)
]\");
eval(parse(gb_expr));
),