TreemapColorMapper class
Collection of TreemapColorMapper which specifies tile’s color based on the data.
The TreemapLevel.colorValueMapper which will be called for each tiles in the respective level, needs to return a color or value based on which tiles color will be updated.
If it returns a color, then this color will be applied to the tiles straightaway. If it returns a value other than the color, then this value will be compared with the TreemapColorMapper.value for the exact value or TreemapColorMapper.from and TreemapColorMapper.to for the range of values. Then the respective TreemapColorMapper.color will be applied to that tile.
The below code snippet represents how color can be applied to the shape based on the TreemapColorMapper.value property of TreemapColorMapper.
late List<SocialMediaUsers> _socialMediaUsersData;
late List<TreemapColorMapper> _colorMappers;
@override
void initState() {
_socialMediaUsersData = <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.value(value: 'India', color: Colors.green),
TreemapColorMapper.value(value: 'USA', color: Colors.blue),
TreemapColorMapper.value(value: 'Japan', color: Colors.red),
];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SfTreemap(
dataCount: _socialMediaUsersData.length,
weightValueMapper: (int index) {
return _socialMediaUsersData[index].usersInMillions;
},
colorMappers: _colorMappers,
levels: [
TreemapLevel(
groupMapper: (int index) {
return _socialMediaUsersData[index].country;
},
colorValueMapper: (TreemapTile tile) => tile.group,
),
],
),
);
}
class SocialMediaUsers {
const SocialMediaUsers(
this.country,
this.socialMedia,
this.usersInMillions,
);
final String country;
final String socialMedia;
final double usersInMillions;
}
The below code snippet represents how color can be applied to the shape based on the range between TreemapColorMapper.from and TreemapColorMapper.to properties of TreemapColorMapper.
late List<SocialMediaUsers> _socialMediaUsersData;
late List<TreemapColorMapper> _colorMappers;
@override
void initState() {
_socialMediaUsersData = <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(0, 100, Colors.green),
TreemapColorMapper.range(101, 200, Colors.blue),
TreemapColorMapper.range(201, 300, Colors.red),
];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SfTreemap(
dataCount: _socialMediaUsersData.length,
weightValueMapper: (int index) {
return _socialMediaUsersData[index].usersInMillions;
},
colorMappers: _colorMappers,
levels: [
TreemapLevel(
groupMapper: (int index) {
return _socialMediaUsersData[index].country;
},
colorValueMapper: (TreemapTile tile) => tile.weight,
),
],
),
);
}
class SocialMediaUsers {
const SocialMediaUsers(
this.country,
this.socialMedia,
this.usersInMillions,
);
final String country;
final String socialMedia;
final double usersInMillions;
}
See also:
- SfTreemap.legend, to enable and customize the legend.
- Inheritance
-
- Object
- DiagnosticableTree
- TreemapColorMapper
Constructors
- TreemapColorMapper.range({required double? from, required double? to, required Color color, double? minSaturation, double? maxSaturation, String? name})
-
Applies color to the tiles which lies between the
TreemapColorMapper.from and TreemapColorMapper.to given range. The
TreemapColorMapper.from and TreemapColorMapper.to must not be null.
const
- TreemapColorMapper.value({required String? value, required Color color})
-
Applies the color to the tiles which is equal to the given
TreemapColorMapper.value. The TreemapColorMapper.value must not be
null.
const
Properties
- color → Color
-
Specifies the color applies to the tile based on the value returned in
the TreemapLevel.colorValueMapper.
final
- from → double?
-
Sets the range start for the color mapping.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxSaturation → double?
-
Specifies the maximum saturation of tiles while using from and to.
final
- minSaturation → double?
-
Specifies the minimum saturation of tiles while using from and to.
final
- name → String?
-
Sets the identifier text to the color mapping. The same will be used
to the legend item text and color will be used as legend item color.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- to → double?
-
Sets the range end for the color mapping.
final
- value → String?
-
Sets the value for the value color mapping.
final
Methods
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited