DatumLegend<D> constructor

DatumLegend<D>({
  1. BehaviorPosition? position,
  2. OutsideJustification? outsideJustification,
  3. InsideJustification? insideJustification,
  4. bool? horizontalFirst,
  5. int? desiredMaxRows,
  6. int? desiredMaxColumns,
  7. EdgeInsets? cellPadding,
  8. bool? showMeasures,
  9. LegendDefaultMeasure? legendDefaultMeasure,
  10. MeasureFormatter? measureFormatter,
  11. MeasureFormatter? secondaryMeasureFormatter,
  12. TextStyleSpec? entryTextStyle,
})

Create a new tabular layout legend.

By default, the legend is place above the chart and horizontally aligned to the start of the draw area.

position the legend will be positioned relative to the chart. Default position is top.

outsideJustification justification of the legend relative to the chart if the position is top, bottom, left, right. Default to start of the draw area.

insideJustification justification of the legend relative to the chart if the position is inside. Default to top of the chart, start of draw area. Start of draw area means left for LTR directionality, and right for RTL.

horizontalFirst if true, legend entries will grow horizontally first instead of vertically first. If the position is top, bottom, or inside, this defaults to true. Otherwise false.

desiredMaxRows the max rows to use before layout out items in a new column. By default there is no limit. The max columns created is the smaller of desiredMaxRows and number of legend entries.

desiredMaxColumns the max columns to use before laying out items in a new row. By default there is no limit. The max columns created is the smaller of desiredMaxColumns and number of legend entries.

showMeasures show measure values for each series.

legendDefaultMeasure if measure should show when there is no selection. This is set to none by default (only shows measure for selected data).

measureFormatter formats measure value if measures are shown.

secondaryMeasureFormatter formats measures if measures are shown for the series that uses secondary measure axis.

Implementation

factory DatumLegend({
  common.BehaviorPosition? position,
  common.OutsideJustification? outsideJustification,
  common.InsideJustification? insideJustification,
  bool? horizontalFirst,
  int? desiredMaxRows,
  int? desiredMaxColumns,
  EdgeInsets? cellPadding,
  bool? showMeasures,
  common.LegendDefaultMeasure? legendDefaultMeasure,
  common.MeasureFormatter? measureFormatter,
  common.MeasureFormatter? secondaryMeasureFormatter,
  common.TextStyleSpec? entryTextStyle,
}) {
  // Set defaults if empty.
  position ??= defaultBehaviorPosition;
  outsideJustification ??= defaultOutsideJustification;
  insideJustification ??= defaultInsideJustification;
  cellPadding ??= defaultCellPadding;

  // Set the tabular layout settings to match the position if it is not
  // specified.
  horizontalFirst ??= position == common.BehaviorPosition.top ||
      position == common.BehaviorPosition.bottom ||
      position == common.BehaviorPosition.inside;
  final layoutBuilder = horizontalFirst
      ? TabularLegendLayout.horizontalFirst(
          desiredMaxColumns: desiredMaxColumns,
          cellPadding: cellPadding,
        )
      : TabularLegendLayout.verticalFirst(
          desiredMaxRows: desiredMaxRows,
          cellPadding: cellPadding,
        );

  return DatumLegend._internal(
    contentBuilder: TabularLegendContentBuilder(legendLayout: layoutBuilder),
    selectionModelType: common.SelectionModelType.info,
    position: position,
    outsideJustification: outsideJustification,
    insideJustification: insideJustification,
    showMeasures: showMeasures ?? false,
    legendDefaultMeasure:
        legendDefaultMeasure ?? common.LegendDefaultMeasure.none,
    measureFormatter: measureFormatter,
    secondaryMeasureFormatter: secondaryMeasureFormatter,
    entryTextStyle: entryTextStyle,
  );
}