applyParentOffset method
Calls super method, then adds the passed offset
to the locally-kept slot
offsetOfPotentiallyRotatedLabel.
In more details: After calling super, rotate the point at which label will start painting -
the offset
+ _tiltedLabelEnvelope.topLeft
- by the tilt angle against the
tilt (this angle is represented by _labelTiltMatrix
inverse).
In non-tilted labels, the _tiltedLabelEnvelope
was created as
ui.Offset.zero & _textPainter.size, // offset & size => Rect
so the _tiltedLabelEnvelope.topLeft
is always origin (0.0, 0.0
).
In addition, the _labelTiltMatrix
is identity, so this method will set
offsetOfPotentiallyRotatedLabel = offset
to the value of offset
(large, after all parent offsets applied).
In the tilted labels, the _tiltedLabelEnvelope.topLeft
is a small value below origin such as 0.0, 30.0
,
and offset
is also large, after all parent offsets applied. In this situation,
the non-zero _tiltedLabelEnvelope.topLeft
represent the needed slight 'shift down'
of the original offset
at which to start painting, as the tilted labels take up a bigger rectangle.
Implementation
// todo-01-morph : this implementation only works for tilting in [XContainer] because first call to it is
// made in [XContainer.layout], after label container is created, as
// `xLabelContainer.applyParentOffset(labelLeftTop + xLabelContainer.tiltedLabelEnvelopeTopLeft)`.
// In this first call(s), the result of offsetOfPotentiallyRotatedLabel is the rotated
// value, which is OVERWRITTEN by the last call described below;
// also, the accumulated non-rotated this.offset is kept on super slot
// This is what we want - we want to keep the non-rotated this.offset on super slot,
// and only do the rotation on the last call (last before paint)
// The last call is made in [ChartTopContainer.layout] inside
// `xContainer.applyParentOffset(xContainerOffset)` as
// as
// for (AxisLabelContainer xLabelContainer in _xLabelContainers) {
// xLabelContainer.applyParentOffset(offset);
// }
// which calculates and stores the rotated value of the accumulated non-rotated this.offset
// into offsetOfPotentiallyRotatedLabel; which value is used by paint.
@override
void applyParentOffset(ui.Offset offset) {
super.applyParentOffset(offset);
// todo-01-morph : This should be part of new method 'findPosition' in the layout process
// Next, _rotateLabelEnvelopeTopLeftToPaintOffset:
// Transform the point where label painting starts against the tilt of labels.
// No-op for non-tilted labels, where _labelTiltMatrix is identity,
// and _tiltedLabelEnvelope.topLeft is center = Offset.zero.
vector_math.Matrix2 canvasTiltMatrix = _labelTiltMatrix.clone();
canvasTiltMatrix.invert();
offsetOfPotentiallyRotatedLabel = geometry.transform(
matrix: canvasTiltMatrix,
offset: (this.offset),
);
}