drawLegend static method

void drawLegend(
  1. Canvas canvas,
  2. Size size,
  3. ChartContext context
)

Implementation

static void drawLegend(Canvas canvas, Size size, ChartContext context) {
  if (!context.config.showLegend) return;

  final items = _legendItems(context);
  if (items.isEmpty) return;

  final style = context.theme.legendTextStyle ?? context.theme.axisTextStyle;

  switch (context.config.legendPosition) {
    case LegendPosition.bottom:
      _drawLegendHorizontal(
        canvas,
        size,
        context,
        items,
        style,
        y: context.bounds.bottom + 10,
      );
    case LegendPosition.top:
      _drawLegendHorizontal(
        canvas,
        size,
        context,
        items,
        style,
        y: context.bounds.top - _legendHeight + 6,
      );
    case LegendPosition.left:
      _drawLegendVertical(
        canvas,
        context,
        items,
        style,
        x: context.theme.padding.left,
        y: context.bounds.top,
      );
    case LegendPosition.right:
      _drawLegendVertical(
        canvas,
        context,
        items,
        style,
        x: context.bounds.right + 8,
        y: context.bounds.top,
      );
  }
}