TreemapLegend.bar constructor

const TreemapLegend.bar({
  1. bool shouldAlwaysShowScrollbar = false,
  2. Widget? title,
  3. TreemapLegendOverflowMode overflowMode = TreemapLegendOverflowMode.scroll,
  4. EdgeInsetsGeometry? padding = const EdgeInsets.all(10.0),
  5. TreemapLegendPosition position = TreemapLegendPosition.top,
  6. Offset? offset,
  7. double spacing = 2.0,
  8. TextStyle? textStyle,
  9. Axis? direction,
  10. Size? segmentSize,
  11. TreemapLegendLabelsPlacement? labelsPlacement,
  12. TreemapLegendEdgeLabelsPlacement edgeLabelsPlacement = TreemapLegendEdgeLabelsPlacement.inside,
  13. TreemapLabelOverflow labelOverflow = TreemapLabelOverflow.visible,
  14. TreemapLegendPaintingStyle segmentPaintingStyle = TreemapLegendPaintingStyle.solid,
  15. bool showPointerOnHover = false,
  16. TreemapLegendPointerBuilder? pointerBuilder,
  17. Color? pointerColor,
  18. Size pointerSize = const Size(16, 12),
})

Creates a bar type legend for the tree map.

Information provided in the legend helps to identify the data rendered in the tree map.

Defaults to null.

By default, legend will not be shown.

late List<SocialMediaUsers> _source;
late List<TreemapColorMapper> _colorMappers;

@override
void initState() {
  _source = <SocialMediaUsers>[
    SocialMediaUsers('India', 'Facebook', 280),
    SocialMediaUsers('India', 'Instagram', 88),
    SocialMediaUsers('USA', 'Facebook', 190),
    SocialMediaUsers('USA', 'Instagram', 120),
    SocialMediaUsers('Japan', 'Twitter', 48),
    SocialMediaUsers('Japan', 'Instagram', 31),
  ];
  _colorMappers = <TreemapColorMapper>[
    TreemapColorMapper.range(
        from: 0, to: 10, color: Colors.red, name: '10'),
    TreemapColorMapper.range(
        from: 11, to: 20, color: Colors.green, name: '20'),
    TreemapColorMapper.range(
        from: 21, to: 30, color: Colors.blue, name: '30'),
  ];
  super.initState();
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: SfTreemap(
      dataCount: _source.length,
      weightValueMapper: (int index) {
        return _source[index].usersInMillions;
      },
      levels: [
        TreemapLevel(
          groupMapper: (int index) {
            return _source[index].country;
          },
        ),
      ],
      legend: TreemapLegend(),
      colorMappers: _colorMappers,
    ),
  );
}

class SocialMediaUsers {
  const SocialMediaUsers(
    this.country,
    this.socialMedia,
    this.usersInMillions,
  );
  final String country;
  final String socialMedia;
  final double usersInMillions;
}

See also:

  • TreemapLegend, for adding default legend type with different icon styles like circle, diamond, rectangle and triangle.

Implementation

const TreemapLegend.bar({
  this.shouldAlwaysShowScrollbar = false,
  this.title,
  this.overflowMode = TreemapLegendOverflowMode.scroll,
  this.padding = const EdgeInsets.all(10.0),
  this.position = TreemapLegendPosition.top,
  this.offset,
  this.spacing = 2.0,
  this.textStyle,
  this.direction,
  this.segmentSize,
  this.labelsPlacement,
  this.edgeLabelsPlacement = TreemapLegendEdgeLabelsPlacement.inside,
  this.labelOverflow = TreemapLabelOverflow.visible,
  this.segmentPaintingStyle = TreemapLegendPaintingStyle.solid,
  this.showPointerOnHover = false,
  this.pointerBuilder,
  this.pointerColor,
  this.pointerSize = const Size(16, 12),
})  : _type = _LegendType.bar,
      iconType = TreemapIconType.circle,
      iconSize = const Size(8.0, 8.0),
      assert(spacing >= 0);