4

Suppose I make a BoundedDiagram via the following code

Needs["ComputationalGeometry`"];
data2D = RandomReal[{0, 10}, {10, 2}];
b1 = {{0, 0}, {11, 0}, {11, 11}, {0, 11}};
convexhull = ConvexHull[data2D];
delval = DelaunayTriangulation[data2D];
{vorvert, vorval} = VoronoiDiagram[data2D];
{dvert1, dval1} = BoundedDiagram[b1, data2D, delval, convexhull];
DiagramPlot[data2D, dvert1, dval1]

How would I go about making each region clickable, i.e. open some link that I associated with the data?

-- Edit:

I should note, all I really want is a to be able to click on regions of a Voronoi-Like diagram, it doesn't have to be done via BoundedDiagram, this is just my first attempt at doing that ... (and is basically straight from the documentation.)

Noon Silk
  • 523
  • 3
  • 11

1 Answers1

7

This will get you started:

nf = Nearest[data2D -> Automatic];
ClickPane[DiagramPlot[data2D, dvert1, dval1], (foo = nf[#]) &]
Dynamic@foo

Click on any region and foo is set equal to that region. The ClickPane function (foo = nf[#]) & can be any function. The NearestFunction given by nf returns the index of the point in data2D nearest the mouse click, whose coordinates are passed to the argument # of the ClickPane function. That index is same as the index of the region.

A similar approach can be taken for any polygonal tiling, except Nearest works only for a Vononoi. In other tilings, you have to write a function to find the polygon containing the mouse click. This question can give you a start on that, if desired.

Michael E2
  • 235,386
  • 17
  • 334
  • 747