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.

Take the following code:

p = {3, 3};
Graphics[Circle[{5, 5}, 5], Epilog -> Dynamic@Locator[Dynamic[p]],
 Axes -> True, GridLines -> {{3}, {3}}]

Mathematica graphics

Whenever I move the locator close to the original coordinates (marked by the grid on the plot), it quickly snaps back to them. This means that I am unable to position the locator at around {3.25, 6}. It will either snap to {3.0, 6} or to {3.5, 6}. (Please see the image, it is at {3.5, 6} there.)

Is this a feature or a bug? If it is a feature, how can I turn it off? If it is a bug, how can I work around it?

Note that I am using Epilog because the graphics in my actual problem are slow to compute/render (large ListDensityPlot).

share|improve this question
    
Hmm.... I cannot reproduce it on Win7 M.8.0.4 - all is smooth. What's your system and version? –  Vitaliy Kaurov Jan 18 '12 at 20:59
    
I also cannot reproduce it –  P. Fonseca Jan 18 '12 at 21:06
    
I'm on WinXP. I got a confirmation in chat that someone else could reproduce it as well (I think on OS X) –  Szabolcs Jan 18 '12 at 21:11
    
@Vitaliy Does that mean that you can easily position the locator to any point between $x=3$ and $x=3.5$ for a given $y$? –  Szabolcs Jan 18 '12 at 21:12
    
I can reproduce it by even simpler code Graphics[Locator[]] (Win7 x64, M.8.0.4) –  Silvia Jan 18 '12 at 21:36
show 8 more comments

1 Answer

up vote 6 down vote accepted

It seems using an EventHandler to simulate a locator will be smooth on my computer ( press Shift instead of press mouse button to active the locator ):

p = {3, 3};
EventHandler[
 EventHandler[
  Graphics[Circle[{5, 5}, 5], Epilog -> Locator[Dynamic[p]], 
   Axes -> True, GridLines -> {{3}, {3}}],
  "MouseMoved" :> Null,
  PassEventsUp :> CurrentValue["ShiftKey"]],
 "MouseMoved" :> (p = MousePosition["Graphics"])
 ]
Dynamic[p]

Update:

I think it's the AlignmentGuidesEnabled feature which causes the snapping.

Here are another two examples which display the problem:

  1. Putting the Locator in the "main part" of Graphics instead of in Epilog:

    p = {3, 3};
    Graphics[{Circle[{5, 5}, 5], Locator[Dynamic[p]]}, Axes -> True, 
     GridLines -> {{3}, {3}}]
    

    On my computer, the snapping occurs near the borders of the Graphics but not near {3, 3} anymore.

  2. Different Locator actions in one Graphics:

    DynamicModule[{v1 = {2, 0}, v2 = {-1, 1}},
     Dynamic@Graphics[{
        Line[{{0, 0}, v1}],
        Locator[Dynamic[v1]],
        Locator[Dynamic[v2]]
        }, PlotRange -> 3, Frame -> True]]
    

    On my computer (Windows 7 x64, Mathematica 8.0.4), the Locator v1 which linked to the Line moves smooth, but the Locator v2 remains snapping.

So it looks like the behavior of AlignmentGuidesEnabled. Use Ctrl+D open the "Drawing Tools" palette, there is a button at the bottom-left, toggle the AlignmentGuidesEnabled option off, the snapping will gone.

share|improve this answer
    
Silvia's example 2 doesn't need DynamicModule: try Module[{v1 = {2, 0}, v2 = {-1, 1}}, Graphics[{Line[{{0, 0}, Dynamic[v1]}], Locator[Dynamic[v1]], Locator[Dynamic[v2]]}, PlotRange -> 3, Frame -> True]]. This runs smoothly. –  Tomas Garza Jan 19 '12 at 2:09
    
Using Module instead of DynamicModule will bring a syntax color which indicates conflict. Anyway, I think the key is the AlignmentGuidesEnabled option. Did you observe any difference on Locator behavior between on/off status of that option? –  Silvia Jan 19 '12 at 2:35
    
It is indeed because of AlignmentGuidesEnabled! –  Szabolcs Jan 19 '12 at 19:53
add comment

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.