I have a LocatorPane
within a Manipulate
such that the range of the plot behind the Locator
can vary. When it does, this naturally causes the Locator
to move on-screen to remain at a constant position with respect to the plot data. However, for my purposes, I need to prevent it from doing that. Ideally, it should stay at the same spot on-screen when the plot range is changed.
Here's a minimal example of the situation. Dragging the slider causes the Locator
to move on-screen. Calculating the approximate position of the Locator
as a fraction of the total plot size is easy, and a Dynamic
displaying that is included. As mentioned in the Manipulate
code, that value will ideally not change when the plot range is modified.
(* I need "point" (the locator's position) to always remain at the
same position on-screen when end is changed. *)
Manipulate[
Row[{
LocatorPane[
Dynamic[point],
Plot[x, {x, 0, end}, ImageSize -> 400]
],
"This value should change ONLY when the Locator is dragged: ",
Dynamic[point / end]
}],
{end, 1, 2}
]
Notes:
- Using a
Locator
directly or via aManipulate
control is not allowed -- the locator must come from aLocatorPane
. (Reason: I also need to be able to restrict theLocator
to a certain rectangular region, and doing that with a rawLocator
is possible but relatively slow.) - Preventing the range of the plot within the
LocatorPane
from changing is also impossible (although wrapping it in another plot somehow is fine, if that is possible and helps). - Using intermediate variables is fine: my attempts to solve the problem thus far have mainly involved separate
abspt
andrelpt
(absolute/relative point position) variables.
I have a feeling that there's some clever way to accomplish this with Dynamic
, but I'm not familiar enough with Dynamic
to know how.