Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/World Demographics.jmp" );
mapxy = Open( "$MAPS/World-XY.jmp" );
mapname = Open( "$MAPS/World-Name.jmp" );
mapname << New Column( "X", Format( "Longitude DDD", "PUNDIR", 14, 4 ) );
mapname << New Column( "Y", Format( "Latitude DDD", "PUNDIR", 14, 4 ) );
For Each( {rw}, Index( 1, N Rows( mapname ) ),
shapeID = mapName:ShapeID[rw];
rws = mapxy << get rows where( :ShapeID == shapeID & :PartID == 1 );
xs = mapxy[rws, "X"];
ys = mapxy[rws, "Y"];
{x, y} = Polygon Centroid( xs, ys );
mapname:x[rw] = x;
mapname:y[rw] = y;
);
dt << Update( With( mapname ), Match Columns( :Territory = :Region ), Add Columns from Update Table( :X, :Y ) );
New Namespace(
"hover"
);
hover:GDP = 0;
hover:x = 0;
hover:y = 0;
gb = Graph Builder(
Variables( Color( :GDP per Capita ), Shape( :Territory ) ),
Elements( Map Shapes() ),
SendToReport(
Dispatch( {}, "", ScaleBox,
{Format( "Longitude DDD", "PUNDIR", 16 ), Min( 0 ), Max( 30 )}
),
Dispatch( {}, "", ScaleBox( 2 ),
{Format( "Latitude DDD", "PUNDIR", 16, 0 ), Min( 40 ), Max( 50 )}
),
Dispatch( {}, "Graph Builder", FrameBox,
{Set Graphlet(
Picture(
hover:GDP = :GDP per Capita[local:_firstrow];
hover:x = :X[local:_firstrow];
hover:y = :y[local:_firstrow];
//approach1: select the current country and trigger an update -> nice, but draggy
//local:_dataTable << Clear Select << select rows(local:_firstrow);
gb << inval;
gb << updatewindow;
)
)}
)
)
);
fb1 = Report( gb )[FrameBox( 1 )];
fb1 << addgraphicsscript(
x = hover:x;
y = hover:y;
Text( center justified, {hover:x, hover:y}, "GDP: " || Char( Round( hover:GDP ) ) );
);
Does Hover Label know the current position of the mouse?
unfortunately, local:_xaxis/_yaxis =0.
As a workaround I used this approach
https://community.jmp.com/t5/Discussions/exporting-x-amp-y-values-coordinates-from-graph-builder-onc... @johnmoore to calculate the centroid of the country - to show the GDP.
As an alternative, one can use Mousetrap (in addition to the Hover Label workaround) to get the position of the mouse.
The disadvantage: less interactive as the user has to press the mouse button.