Zoom2D
- To: mathgroup at smc.vnet.net
- Subject: [mg78595] Zoom2D
- From: dh <dh at metrohm.ch>
- Date: Thu, 5 Jul 2007 03:59:20 -0400 (EDT)
Hello All,
here is a slightly improved version of a 2 dimensional zoome utility.
Either copy the code directly into a notebook and execute or put it into
a file with extension *.m and load it by <<"Filename". This will pop up
a palette with a single button "Zoom". Select a 2 dim graphics and hit
the button. This will open a new notebook with 2 panes, the upper pane
contains the original graphics with a transluctance changable rectangle
overlaid. The lower pane contains the zoomed rectangle region. If you
resize the Notebook, the upper pane stays small.
Daniel
(*==== CODE ======*)
(*Creates a Palette with a zoom button*)
Zoom2D[g0_]:=Module[{g,pp1,pp2},
If[!MatchQ[Head[g0],Graphics| GraphicsBox],CreateDialog[{TextCell["Zoom:
No Input available."],DefaultButton[]}];Return[];];
g=If[Head[g0]=!=Graphics,Replace[g0,head_[x1_,x2___]:>Graphics[{x1},{x2}]],g0];
g = g/.NCache[_, x_] :> x;
{pp1,pp2}=FullOptions[g,PlotRange]//Transpose;
g1=DynamicModule[{p1=pp1,p2=pp2,lp={0,0}},
Column[{
LocatorPane[Dynamic[{p1,p2}],Show[{g,Graphics[{Opacity[0.1],Rectangle[Dynamic[p1],Dynamic[p2]]}]},ImageSize->Small]]
,EventHandler[Show[g,PlotRange:>Dynamic[Transpose[{p1,p2}]],Frame->True,ImageSize->Full]
,{"MouseClicked":>(lp=MousePosition["Graphics"])}
]
,Dynamic[lp]
},Center]];
CreateDocument[g1,WindowSize->{Small,All},WindowTitle->"Zoom-DH",WindowElements->{},WindowFrame->"Palette",BoxForm`ClosingSaveDialog->False];
]
CreatePalette[
Button["Zoom",Zoom2D[NotebookRead[SelectedNotebook[]]]
],WindowTitle->""];