you can use function arguments instead of x,y
Names Default To Here( 1 );
New Window( "Example",
trapx = 20;
trapy = 50;
handx = 70;
handy = 80;
trapcolor="blue";
handcolor="blue";
Graph Box(
Frame Size( 200, 200 ),
handle( handx, handy, // any handle(s) must come before Mousetrap
Function( {a, b}, handx=a; handy=b;
Write( Eval Insert( "\!nhand drag ^a^ ^b^" ) );
handcolor="magenta"; )
, // the mouse-up handler
Function( {a, b}, handx=a; handy=b;
Write( Eval Insert( "\!nhand release ^a^ ^b^" ) );
handcolor="cyan"; )
);
Mousetrap( // should not be more than one Mousetrap, the first one captures all clicks
Function( {a, b}, trapx=a; trapy=b;
Write( Eval Insert( "\!ntrap drag ^a^ ^b^" ) );
trapcolor="red"; )
, // the mouse-up handler
Function( {a, b}, trapx=a; trapy=b;
Write( Eval Insert( "\!ntrap release ^a^ ^b^" ) );
trapcolor="green"; )
);
// the drawing occurs outside of the mousetrap or handle
pencolor(trapcolor);
pensize(3);
Circle( {0, 0}, Sqrt( trapx * trapx + trapy * trapy ) );
pencolor(handcolor);
pensize(3);
Circle( {0, 0}, Sqrt( handx * handx + handy * handy ) );
)
);
If you need one or more handles, they must appear before the mousetrap because a click will be consumed by the mousetrap if no previous handle took it.
Interesting. Why is the handle not tied to the x/y coordinate system?
It still works after resizing the plot, but there is a significant offset:
The handle is. The circle is not. I *think* the perfectly round circle on the non-square grid has its radius defined in Y axis coordinates.
Ouch, sure - How Do You Draw a Circle?
@hogi wrote:
How do I access this namespace?
Both:
Report(gb)[FrameBox(1)] << get namespace() ; (Report(gb)[FrameBox(1)] << find seg(TopSeg (1))) << get namespace();
produce a new namespace.
... I asked JMP support: TS-00173810
unfortunately:
You cannot access the graphics script namespace externally.
-
Looks like adding a hover drill script.
For(iFrame=1,iFrame<=N Items(framelist),iFrame+=1,frame=framelist[iFrame]; Eval(Eval Expr(frame<<Addgraphicsscript(Mousetrap({},
……//??
)))););
Thanks Experts!
Slightly changed the script to display weight values instead of more:
names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
);
fb = Report( gb )[FrameBox( 1 )];
xx = yy = 0;
valuesMatrix = :height << Get Values; //***new*** Get column values for height
fb << addgraphicsscript(//
Mousetrap(
xx = x;
yy = y;
);
V Line( xx );
// at this point you can highlight all the values near xx
For( irow = 1, irow <= N Rows( dt ), irow += 1,
If( Abs( dt:height[irow] - xx ) < 0.5, // big class height step is 1, <.5 selects a single column of weights
Marker( Marker State( 4 ), {dt:height[irow], dt:weight[irow]} )
)
);
valuesRows = char(:weight[loc(valuesMatrix,round(xx))]); //***new*** write to char weight values for all rows of height at position round(xx)
xwidth = X Range();
xmidpoint = X Origin() + xwidth / 2;
If( xx < xmidpoint,
Text( {xx + xwidth / 100, yy}, "height " || Char( Round( xx ) ) || "\!nweight " || valuesRows )////***new*** exchanged "more" with weigth and list of weight values for that location of height
,
Text( right justified, {xx - xwidth / 100, yy}, "height " || Char( Round( xx ) ) || "\!nweight " || valuesRows )
);
//
);
you may even could add sorting the values ascending/descending.