Suppose I make a BoundedDiagram via the following code

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.)

  • $\begingroup$ That code does not work for me. $\endgroup$ – C. E. Jul 11 '13 at 3:40
  • $\begingroup$ @Anon - Sorry, it's probably because I forgot to add the 'Needs' statement there; this question is within the ComputationalGeometry package. $\endgroup$ – Noon Silk Jul 11 '13 at 3:41
  • $\begingroup$ Yes, that was it. :) $\endgroup$ – C. E. Jul 11 '13 at 3:42

This will get you started:

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

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.

  • $\begingroup$ Thank's alot! (Extra letters to pass 15 character limit.) $\endgroup$ – Noon Silk Jul 11 '13 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.