Prologue: this is not yet-another "how do you scale node shapes?" question, but a follow-up to the usual answers ("you kind of can, but it's awkward, and you probably shouldn't") in a specific context.
I'm working on a family of diagrams made up of 1D rows of pixels or tasks (represented mostly by rectangles):
Coming from the TikZ tutorials, I started doing this using styled node
s for nearly everything: all the pixels, as well as the borders around groups of them, and deriving positioning boxes around sub-regions of the figure. This made positioning (using, e.g., the positioning
and fit
libraries) relatively straightforward. All the smarts for drawing paths between nodes (picking nice locations on their borders), automatically offsetting to compensate for line width (so, e.g., right = of <last node>, node distance = 0
draws rectangles with perfectly overlapping shared strokes), etc., are quite useful. It becomes incredibly convenient to be able to draw things like the blue dependence arrows seen here, just by naming the corresponding nodes, since these are just classic node to node paths.
One consequence of this is that the size of these pixel rectangles is specified using inner sep
and/or minimum size
.
However, coming from a graphics background where I appreciate transform stacks as an extremely useful way to write simple and composable drawing code. However, once I started trying to use relative coordinates (e.g., inner sep = 0.5
, so each pixel is exactly 1 logical PGF unit in width/height, combined with /tikz/x = 3mm, /tikz/y = 3mm
, to set the unit size for the whole canvas) and coordinate transforms (setting scale
for a scope to slightly shrink the pixels in some region; using shift
to move the location of a sub-drawing) I ran head long into the fact that TikZ applies transforms to everything but intra-node geometry.
I know about the transform shape
option, but (1) that seems to be generally frowned upon (to paraphrase some answers on the subject, transforms + nodes = evil), and (2) even that does not make the simple example of defining x
and y
coordinate vectors to the desired size work correctly with inner sep
/minimum size
, since these are always interpreted as measures with absolute units.
The recommended method for drawing shapes which do conform to the transform stack seems to be to just use paths. Then, a pixel might be something like \draw[pixelstyle] (0,0) rectangle +(1,1);
. This respects the transform context as expected, but loses all the nice behavior of nodes for positioning and drawing connecting paths by reference.
So my question is one of design: how would TikZ experts approach this type of drawing?