Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Dynamic Control of Graphics

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105082] Re: Dynamic Control of Graphics
  • From: dr DanW <dmaxwarren at gmail.com>
  • Date: Fri, 20 Nov 2009 06:39:28 -0500 (EST)
  • References: <he0oae$4ov$1@smc.vnet.net>

Here is a function I wrote that creates a legend based on the tooltips
on the functions being plotted.  Each line swatch in the legend is a
button that lets me dim (lower the opacity) or darken (opacity -> 1)
the associated curve.  I tried very hard to get this to work on the
curves themselves (treating each curve as a button) but could never
get it to work.  However, I find this function is extremely useful,
and I get many surprised gasps from the audience when I use it in a
presentation.  Not quite what you were looking for, but maybe you can
use the technique.

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}]]


  • Prev by Date: Re: Define a function as a graphics directive?
  • Next by Date: Re: Dynamic Control of Graphics
  • Previous by thread: Dynamic Control of Graphics
  • Next by thread: Re: Dynamic Control of Graphics