I can't figure out why an expression isn't evaluating, even though there's no Hold*
in its FullForm
:
Plus[Dynamic[a$65712],Dynamic[Part[MousePosition[List["Graphics",Graphics],List[0,0]],1]]]
I've been stuck for hours now, and have gone through all kinds of threads including the one about Trott-Strzebonski and HoldCondition
, but I'm afraid I may have missed the answer even if it was staring me in the face, due to lacking experience.
After reading How to | Evaluate Expressions inside Dynamic or Manipulate, I began to think it must have something to do with Dynamic
or perhaps MousePosition
, but my understanding is weak.
Here's the full code, before I continue explaining:
opts = {Axes -> False, Frame -> True, ImageSize -> {600, 400}, AspectRatio -> 1/GoldenRatio};
testdata1 = Table[{i, 5 Sin[i/10] + RandomReal[]}, {i, 100}];
testdata2 = {Log[#], #2} & @@@ testdata;
map1 = MapIndexed[Rule[testdata1[[First@#2, 1]], #] &, testdata2[[All, 1]]];
map2 = MapIndexed[Rule[testdata2[[First@#2, 1]], #] &, testdata1[[All, 1]]];
Deploy@DynamicModule[{x1, x2, a, b}, Column[{
Graphics[{PointSize@Tiny, Point /@ testdata}, GridLines -> {{
x1 = test1 = Dynamic[MousePosition[{"Graphics", Graphics}, {0, 0}][[1]]] + Dynamic[a];
b = ((test2 = Nearest[map1[[All, 1]], x1]) /. map1)[[1, 1]];
x1
}, {}}, opts],
Graphics[{PointSize@Tiny, Point /@ testdata2}, GridLines -> {{
x2 = test3 = Dynamic[MousePosition[{"Graphics", Graphics}, {0, 0}][[1]]] + Dynamic[b];
a = ((test4 = Nearest[map2[[All, 1]], x2]) /. map2)[[1, 1]];
x2
}, {}}, opts]
}]]
The line in question is this one:
x1 = test1 = Dynamic[MousePosition[{"Graphics", Graphics}, {0, 0}][[1]]] + Dynamic[a];
Instead of adding up the two Dynamic
ed expressions, it's passing the held form to Nearest
, which, of course, doesn't know what to do with such an input. That is, debug1
and debug2
output, respectively,
Plus[Dynamic[a$69525], Dynamic[Part[MousePosition[List["Graphics", Graphics], List[0, 0]], 1]]]
and
Nearest[{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100},1+0]
I'd greatly appreciate it if someone could point out where I went wrong.
Dynamic
but it not working, and indeed I can't get it to work now either with just that change---I could be doing something else wrong as well. $\endgroup$