There are probably a lot of ways to do this, I will just demonstrate a simple, straight forward ways with which you might experiment.
First we set up a global variable that assigns aspect ratio functions:
$aspectRatioFunctions = Function[ func,
Switch[ func,
"ratio2", Function[ {p1,p2}, 2 p1/p2 ],
"ratio3", Function[ {p1,p2}, p1 / (3 p2) ],
_ , Function[ {p1, p2}, p1/p2 ] (* ratio1 as Default *)
]
];
We can now use this in a simple graphics function or whatever custom function you want to build upon:
Options[ myGraphics ] = {
"AspectRatioFunction" -> "ratio1"
};
myGraphics[ graphics_List, aspectPars_ ,
opts : OptionsPattern[{ myGraphics, Graphics }] ] := With[
{
aspectRatio = Apply[
$aspectRatioFunctions@OptionValue["AspectRatioFunction"],
aspectPars
]
},
Graphics[
graphics,
Evaluate@FilterRules[ {opts}, Options[Graphics] ], (* more robust *)
AspectRatio -> aspectRatio
]
]
gr = { Red, Line[{{1, 1}, {2, 2}}] }
myGraphics[ gr, { 1, 1 }, AspectRatioFunction -> "ratio2", Imagesize -> Tiny ]
1
,2
and1/3
right? $\endgroup$AspectRatio->ratio1
works just fine for me, given some arbitrary ranges. $\endgroup$Automatic' and
Full`, something I want to extend. $\endgroup$