9
$\begingroup$

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

$\endgroup$
13
  • $\begingroup$ Hmm.... I cannot reproduce it on Win7 M.8.0.4 - all is smooth. What's your system and version? $\endgroup$ Commented Jan 18, 2012 at 20:59
  • $\begingroup$ I also cannot reproduce it $\endgroup$
    – P. Fonseca
    Commented Jan 18, 2012 at 21:06
  • $\begingroup$ I'm on WinXP. I got a confirmation in chat that someone else could reproduce it as well (I think on OS X) $\endgroup$
    – Szabolcs
    Commented Jan 18, 2012 at 21:11
  • $\begingroup$ @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$? $\endgroup$
    – Szabolcs
    Commented Jan 18, 2012 at 21:12
  • $\begingroup$ I can reproduce it by even simpler code Graphics[Locator[]] (Win7 x64, M.8.0.4) $\endgroup$
    – Silvia
    Commented Jan 18, 2012 at 21:36

1 Answer 1

7
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$ Commented Jan 19, 2012 at 2:09
  • $\begingroup$ 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? $\endgroup$
    – Silvia
    Commented Jan 19, 2012 at 2:35
  • $\begingroup$ It is indeed because of AlignmentGuidesEnabled! $\endgroup$
    – Szabolcs
    Commented Jan 19, 2012 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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