DynamicModule[ { lineWidth = Thin, textColor = Blue},
Dynamic @ EventHandler[ Show[ Plot[Sin[x], {x, 0, \[Pi]} ],
Graphics[{ textColor, Text["XXX", {1, 1}]}],
Graphics[{ lineWidth, Line[{{0, 0}, {2, 1}}]}]],
"MouseClicked" :> (textColor = Red, lineWidth )]]
The question is, how can one control the wdth and the color
individually?
More broadly, I need to perform the following tasks: upon mouseover to
change the appearance of a single graphics element (line, text, etc.);
then, upon mouse click, to store in a variable which elements was
selected (clicked over); and, upon pressing of the Delete key, to
remove that element from the combined graphics.
I would be most greatful for any and all of the help you could give
me.
Peter.
Code follows. Enjoy.
--------------------
Attributes[DynamicLegend] = {HoldFirst};
DynamicLegend[(plotfnc_)[f_, args___, (opts___)?OptionQ]] :=
Module[{tags, ps, op, dim, makeLegend}, tags = Flatten[{f}][[All,
2]];
ps = MapIndexed[Directive[ColorData[1, #2[[1]]], Thick,
Opacity[op[#1]]] & , tags]; op[_] = 1; dim = 0.3;
makeLegend[s_, t_] := {Toggler[Dynamic[op[t]],
{1 -> Graphics[Flatten[{s, Line[{{0, 0}, {1, 0}}]}],
ImageSize -> 72/3, AspectRatio -> 0.1], Dynamic[dim] ->
Graphics[Flatten[{s, Line[{{0, 0}, {1, 0}}]}],
ImageSize -> 72/3, AspectRatio -> 0.1]}], Text[t]};
Column[{Dynamic[Row[{plotfnc[f, args, PlotStyle -> ps,
ImageSize -> Medium, opts], Grid[MapThread[makeLegend,
{ps, tags}], Alignment -> {Left, Right}]}]],
ButtonBar[{"Dim All" :> (Clear[op]; op[_] = Dynamic[dim]),
"Darken All" :> (Clear[op]; op[_] = 1)}],
Slider[Dynamic[dim], {0, 1}]}]];
DynamicLegend[
Plot[{
Tooltip[x^2, TraditionalForm[x^2]],
Tooltip[x^3, TraditionalForm[x^3]],
Tooltip[x^4, TraditionalForm[x^4]]}, {x, -3, 3}]]
PeterSF wrote:
> Specifically, we are given
> ["Test"] } ],
> Graphics[ { lineWidth,
> Line[{ {0,0}, {0,2}] } ] ]
> over that text;
> mouse is
> over that line.
>
>
> individually?
>
>
> me.
> Peter.
>
>
Hi Peter,
an event handler handles the whole region of the corresponding graphics
object. It can not distinguish between parts of it.
Daniel
I think the following is doing what you described, except that I am
using the "d" key instead of the delete key. Unfortunatly there seems to
be no documented way to get ahold of the Delete key pressed events, or
am I missing something? I am using a combination of Mouseover, Dynamic
and Eventhandler:
DynamicModule[{
selected = None, highlighted = None,
lineWidth = Thin, textColor = Blue,
curve, text, line
},
curve = Plot[Sin[x], {x, 0, \[Pi]}] /. Line[points_] :> Mouseover[
Dynamic[highlighted = None; Line[points]],
Dynamic[highlighted = Hold[curve]; Line[points]]
];
text = Graphics[Mouseover[
Dynamic[{highlighted = None; Blue, Text["XXX", {1, 1}]}],
Dynamic[{highlighted = Hold[text]; Red, Text["XXX", {1, 1}]}]
]];
line = Graphics[Mouseover[
Dynamic[{highlighted = None; Thin, Line[{{0, 0}, {2, 1}}]}],
Dynamic[{highlighted = Hold[line]; Thick, Line[{{0, 0}, {2, 1}}]}]
]];
EventHandler[
Column[{
Dynamic[Show[curve, text, line]],
Dynamic[highlighted],
Dynamic[selected]
}],
{
"MouseClicked" :> (selected = highlighted),
{"KeyDown", "d"} :> (
Print["deleting: " <> ToString[selected]];
Set @@ Append[selected, Graphics[]]
)
},
PassEventsDown -> True
]]
hth,
albert