decorate method
void
decorate(
- TreeMapRendererElement<
D> rendererElement, - ChartCanvas canvas,
- GraphicsFactory graphicsFactory, {
- required Rectangle<
num> drawBounds, - required double animationPercent,
- bool rtl = false,
- bool renderVertically = false,
- bool renderMultiline = false,
Paints decorator on top of rendererElement
.
Implementation
@override
void decorate(TreeMapRendererElement<D> rendererElement, ChartCanvas canvas,
GraphicsFactory graphicsFactory,
{required Rectangle drawBounds,
required double animationPercent,
bool rtl = false,
bool renderVertically = false,
bool renderMultiline = false}) {
// Decorates the renderer elements when animation is completed.
if (animationPercent != 1.0) return;
// Creates [TextStyle] from [TextStyleSpec] to be used by all the elements.
// The [GraphicsFactory] is needed since it cannot be created earlier.
final labelStyle = _asTextStyle(graphicsFactory, labelStyleSpec);
final labelFn = rendererElement.series.labelAccessorFn;
final datumIndex = rendererElement.index;
final label = labelFn != null ? labelFn(datumIndex) : null;
// Skips if this element has no label.
if (label == null || label.isEmpty) return;
// Uses datum specific label style if provided.
final datumLabelStyle = _datumStyle(
rendererElement.series.insideLabelStyleAccessorFn,
datumIndex,
graphicsFactory,
defaultStyle: labelStyle);
final rect = rendererElement.boundingRect;
final labelElement = graphicsFactory.createTextElement(label)
..textStyle = datumLabelStyle
..textDirection = rtl ? TextDirection.rtl : TextDirection.ltr;
final labelHeight = labelElement.measurement.verticalSliceWidth;
final maxLabelHeight =
(renderVertically ? rect.width : rect.height) - (labelPadding * 2);
final maxLabelWidth =
(renderVertically ? rect.height : rect.width) - (labelPadding * 2);
final multiline = enableMultiline && renderMultiline;
final parts = wrapLabelLines(
labelElement, graphicsFactory, maxLabelWidth, maxLabelHeight,
allowLabelOverflow: allowLabelOverflow, multiline: multiline);
for (var index = 0; index < parts.length; index++) {
final segment = _createLabelSegment(
rect, labelHeight, parts[index], index,
rtl: rtl, rotate: renderVertically);
// Draws a label inside of a treemap renderer element.
canvas.drawText(segment.text, segment.xOffet, segment.yOffset,
rotation: segment.rotationAngle);
}
}