Ciao a tutti,
Devo modificare le posizioni delle etichette dei punti dati. Il mio problema è che devo definire le nuove posizioni delle etichette (vedere la variabile LabelPosText ) all'interno dell'istruzione di espressione. So che non sarebbe necessario nell'esempio seguente, ma voglio risparmiarti la fatica di lavorare sul mio lungo codice, quindi ti mostro un esempio semplificato.
Ora non riesco a ottenere il contenuto della variabile LabelPosText nella parte dell'espressione del Graph Builder (la riga corrispondente è etichettata con //qui ho bisogno di aiuto
). Ho provato diverse combinazioni di Eval(), Eval Expr(), ecc., ma niente ha funzionato per me.
Grazie mille per il tuo aiuto!
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Eval(
Parse(
"dt << New Script(\!"test script\!",
<BR /> //defining new label positions for some data points
Rows = dt << get rows where( :Sex == \!"F\!" );
LabelPosText = \!"\!";
For Each({row, idx}, Rows,
WeightValue = Column( dt, \!"weight\!")[row];
HeightValue = Column( dt, \!"height\!")[row];
LabelPosText = LabelPosText || \!"{\!"|| char(row-1) ||\!", -5, 12, \!"|| char(WeightValue) ||\!", \!"|| char(HeightValue) ||\!"}\!";
if(idx < N Items(Rows),
LabelPosText = LabelPosText || \!", \!"
)
);
Graph Builder(
Size( 528, 456 ),
Show Control Panel( 0 ),
Variables( X( :weight ), Y( :height ) ),
Elements( Points( X, Y, Legend( 5 ) ) ),
SendToReport(
Dispatch( {}, \!"Graph Builder\!", FrameBox,
{DispatchSeg(
Marker Seg( 1 ),
{Label Offset( LabelPosText ), //here I need help ;)
Set Force Labels( \!"Label by Row\!" )}
)}
)
)
)
)"
)
È possibile calcolarli all'interno. Se c'è la possibilità che cambino tra diverse esecuzioni di script di tabella, dovrebbero essere al suo interno, altrimenti li sposterei all'esterno e valuterei il valore all'interno dello script.
In genere, eviterei sempre di usare EvilParse (Eval(Parse()) perché è un incubo da debuggare e, secondo me, non c'è quasi mai una ragione per usarlo. Sembra complicato, ma lo affronterei con qualcosa del genere
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Label Offset has very annoying format to build as it isn't list with lists
// but just something with lists
table_script = Expr(
Names Default To Here(1);
Rows = Current Data Table() << get rows where(:Sex == "F");
offsets = Expr(Label Offset());
For Each({row, idx}, Rows,
WeightValue = :weight[row];
HeightValue = :height[row];
l = Eval List({row - 1, -5, 12, WeightValue, HeightValue});
Insert Into(offsets, l);
);
Eval(Substitute(
Expr(Graph Builder(
Size(528, 456),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(5))),
SendToReport(
Dispatch({}, "Graph Builder", FrameBox,
{DispatchSeg(
Marker Seg(1),
{_labeloffset_,
Set Force Labels("Label by Row")}
)}
)
)
)),
Expr(_labeloffset_), Name Expr(offsets)
));
);
Eval(EvalExpr(
dt << New Script("test script",
Expr(Name Expr(table_script));
);
));
È anche possibile spostare l'offset dell'etichetta all'esterno del generatore di grafici e inviare il messaggio al generatore di grafici dopo che è stato creato (non sono sicuro che questo imposti correttamente le etichette di forzatura).
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Label Offset has very annoying format to build as it isn't list with lists
// but just something with lists
table_script = Expr(
Names Default To Here(1);
Rows = Current Data Table() << get rows where(:Sex == "F");
offsets = Expr(Label Offset());
For Each({row, idx}, Rows,
WeightValue = :weight[row];
HeightValue = :height[row];
l = Eval List({row - 1, -5, 12, WeightValue, HeightValue});
Insert Into(offsets, l);
);
gb = Graph Builder(
Size(528, 456),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(5))),
SendToReport(
Dispatch({}, "Graph Builder", FrameBox,
{DispatchSeg(
Marker Seg(1),
{Set Force Labels("Label by Row")}
)}
)
)
);
ms = Report(gb)[FrameBox(1)] << Find Seg(MarkerSeg(1));
Eval(EvalExpr(Send(ms, Expr(Name Expr(offsets)))));
wait(0);
);
Eval(EvalExpr(
dt << New Script("test script",
Expr(Name Expr(table_script));
);
));
Lo script della tabella finale dovrebbe apparire così
Names Default To Here(1);
Rows = Current Data Table() << get rows where(:Sex == "F");
offsets = Expr(Label Offset());
For Each({row, idx}, Rows,
WeightValue = :weight[row];
HeightValue = :height[row];
l = Eval List({row - 1, -5, 12, WeightValue, HeightValue});
Insert Into(offsets, l);
);
gb = Graph Builder(
Size(528, 456),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(5))),
SendToReport(
Dispatch({}, "Graph Builder", FrameBox,
{DispatchSeg(Marker Seg(1), {Set Force Labels("Label by Row")})}
)
)
);
ms = Report(gb)[FrameBox(1)] << Find Seg(Marker Seg(1));
Eval(Eval Expr(ms << Expr(Name Expr(offsets))));
Wait(0);
e lo script che ottieni da Graph Builder
Graph Builder(
Size(528, 456),
Show Control Panel(0),
Variables(X(:weight), Y(:height)),
Elements(Points(X, Y, Legend(5))),
SendToReport(
Dispatch({}, "Graph Builder", FrameBox,
{DispatchSeg(
Marker Seg(1),
{Label Offset(
{8, -5, 12, 112, 60},
{0, -5, 12, 95, 59},
{9, -5, 12, 107, 61},
{1, -5, 12, 123, 61},
{10, -5, 12, 67, 56},
{2, -5, 12, 74, 55},
{3, -5, 12, 145, 66},
{4, -5, 12, 64, 52},
{15, -5, 12, 81, 61},
{16, -5, 12, 91, 62},
{17, -5, 12, 142, 65},
{18, -5, 12, 84, 63},
{19, -5, 12, 85, 62},
{27, -5, 12, 92, 62},
{28, -5, 12, 112, 64},
{34, -5, 12, 112, 65},
{35, -5, 12, 115, 60},
{37, -5, 12, 116, 62}
), Set Force Labels("Label by Row")}
)}
)
)
);
molto nuovo, grazie per queste informazioni - soprattutto con No Labels possono essere davvero utili!!
Per Label Offset , non sono riuscito a trovare molta documentazione: sembra che non ci sia alcuna funzionalità pensata per essere utilizzata dagli utenti?
Interessante:
- le coordinate x/y sembrano essere usate solo per un doppio controllo. Questo può essere usato per semplificare il comando:
basta fornire valori errati per MALE per sbarazzartene.
- Quale sistema di coordinate viene utilizzato per gli offset? Un offset costante non determina uno spostamento costante per ogni etichetta.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
LabelPosOffsets = Expr(Label Offset());
For Each row(
Insert Into(LabelPosOffsets,Eval List({row() - 1, -100,100,:weight+if( sex=="F", 0,1),:height}))
);
Eval (Eval Expr(Graph Builder(
Size( 528, 456 ),
Show Control Panel( 0 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 5 ) ) ),
SendToReport(
Dispatch( {}, "Graph Builder", FrameBox,
{DispatchSeg(
Marker Seg( 1 ),
{ Expr(Name Expr(LabelPosOffsets) ), Set Force Labels( "Label by Row" )}
)}
)
)
)));