Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

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

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
Thank's alot! (Extra letters to pass 15 character limit.) –  Noon Silk Jul 11 '13 at 4:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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