Scaling edge thicknesses
Update: Could not get CurrentValue[..., "ImageSize"]
to pick up the correct image size.
Based on Sjoerd's update, an alternative approach would be to post process a graphics object to transform the thickness primitives using the aspect ratio, plot range and image size of the input graphics. This can be done in a number of ways using AbsoluteOptions
(getting PlotRange
or AspectRatio
) to calculate a new thickness.
Sjoerd's example (slightly modified)
grpSjrd1 = Graphics[{FaceForm[], EdgeForm[{Thickness[0.1], Blue}], Disk[{0, 0}],
Disk[{3, 0}], Disk[{6, 0}]}, ImageSize -> 300]
grpSjrd2 = Graphics[{FaceForm[], EdgeForm[{Thickness[0.1], Blue}], Disk[{0, 0}]},
ImageSize -> 300]
ClearAll[thicknessUnits];
thicknessUnits[gr_Graphics, sc_] :=
With[{units =
AbsoluteOptions[gr, AspectRatio][[1, 2]]},
gr /. EdgeForm[{beg___, Thickness[thcknss_], end___}] :>
EdgeForm[{beg, Thickness[sc units ], end}]]
Usage examples:
Grid[Transpose[
{thicknessUnits[grpSjrd1, #],thicknessUnits[grpSjrd2, #]} & /@
{.03, .05, .1, .2}], Spacings -> {3, 2}]
Alternatively, one can use the PlotRange
instead of AspectRatio
:
ClearAll[thicknessUnitsB];
thicknessUnitsB[gr_Graphics, sc_] :=
With[{units =-Subtract @@ AbsoluteOptions[gr, PlotRange][[1, 2, #]] & /@
{1, 2} // (#[[2]]/#[[1]]) & },
gr /. EdgeForm[{beg___, Thickness[thcknss_], end___}] :>
EdgeForm[{beg, Thickness[sc units ], end}]]
Leftover from original post ... (holding for now until I give up struggling with CurrentValue[...]
)
Using CurrentValue["Magnification"]
seems more promising:
Column[Style[Graphics[{FaceForm[],
Dynamic@EdgeForm[{Thickness[.02 CurrentValue["Magnification"]], Blue}],
Disk[{0, 0}], Disk[{3, 0}], Disk[{6, 0}]}, ImageSize -> 600],
Magnification -> #] & /@ {.2, .5, 1., 1.5}]
Perhaps you are looking for Inset
?
disk = Graphics[{EdgeForm[{Black, Thickness[0.1]}], LightBlue, Disk[]}];
Graphics[{
Inset[disk, {0, 0}, {0, 0}, 1],
Inset[disk, {2, 0}, {0, 0}, 2],
Inset[disk, {4, 0}, {0, 0}, 1.5]
}]
Show[%, ImageSize -> 200]