Skip to content


Browse files Browse the repository at this point in the history
Make algorithm recursive
When a new color is required, repeat the color assignment process.
This is the fastest part of the algorithm, so there's no noticable
speed drop. Repeating the whole coloring ensures that newly added
colors are properly balanced with respect to other colors, and avoids
the situation where one of the last features to be colored requires
a whole new class to be created, which will only have a few possible

Overall this results in more balanced color assignment.
  • Loading branch information
nyalldawson committed Feb 22, 2017
1 parent ff10cf4 commit 2fd78b8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/
Expand Up @@ -203,9 +203,9 @@ def balanced(features, graph, feedback, balance=BalanceMethod.BY_COUNT, min_colo

if len(available_colors) == 0:
# no existing colors available for this feature, so add new color to pool
feature_color = len(color_pool) + 1
# no existing colors available for this feature, so add new color to pool and repeat
min_colors += 1
return ColoringAlgorithm.balanced(features,graph,feedback,balance,min_colors)
if balance==BalanceMethod.BY_COUNT:
# choose least used available color
Expand Down

0 comments on commit 2fd78b8

Please sign in to comment.