assignMissingColors method
void
assignMissingColors(
- Iterable<
MutableSeries< seriesList, {D> > - required bool emptyCategoryUsesSinglePalette,
Assigns one color pallet for each subtree from the children of the root node, and one shade for each node of the subtree to series that are missing their colorFn.
Implementation
@override
void assignMissingColors(Iterable<MutableSeries<D>> seriesList,
{required bool emptyCategoryUsesSinglePalette}) {
seriesList.forEach((series) {
if (series.colorFn == null) {
final root = series.data.first as TreeNode<D>;
final firstLevelChildren = (series.data.first as TreeNode<D>).children;
// Create number of palettes based on the first level children of root.
final colorPalettes =
StyleFactory.style.getOrderedPalettes(root.children.length);
final nodeToColorMap = {};
// Create shades base on number of Nodes in the subtree
if (config.colorAssignmentStrategy ==
SunburstColorStrategy.newShadePerArc) {
for (var i = 0; i < firstLevelChildren.length; i++) {
var numOfNodeInSubTree = 0;
firstLevelChildren.elementAt(i).visit((node) {
numOfNodeInSubTree++;
});
final colorList = colorPalettes[i].makeShades(numOfNodeInSubTree);
// Fill in node to color map to be used in the colorFn
numOfNodeInSubTree = 0;
firstLevelChildren.elementAt(i).visit((node) {
nodeToColorMap[node] = colorList[numOfNodeInSubTree];
numOfNodeInSubTree++;
});
}
} else {
// Create number of shades based on the full depth of the tree instead
// of each subtree, so the shades of each branch looks more aligned
// at each level.
var depthOfTree = 0;
root.visit((node) {
depthOfTree = max(depthOfTree, node.depth);
});
for (var i = 0; i < firstLevelChildren.length; i++) {
final colorList = colorPalettes[i].makeShades(depthOfTree);
// Fill in node to color map to be used in the colorFn
firstLevelChildren.elementAt(i).visit((node) {
nodeToColorMap[node] = colorList[node.depth - 1];
});
}
}
series.colorFn ??=
(index) => nodeToColorMap[series.data[index!]] ?? Color.black;
}
});
}