Skip to content
Permalink
Browse files

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
members.

Overall this results in more balanced color assignment.
  • Loading branch information
nyalldawson committed Feb 22, 2017
1 parent ff10cf4 commit 2fd78b85bd410cec3871f9fdc1d51d5bfad03626
Showing with 3 additions and 3 deletions.
  1. +3 −3 python/plugins/processing/algs/qgis/TopoColors.py
@@ -203,9 +203,9 @@ def balanced(features, graph, feedback, balance=BalanceMethod.BY_COUNT, min_colo

feature_color=-1
if len(available_colors) == 0:
# no existing colors available for this feature, so add new color to pool
feature_color = len(color_pool) + 1
color_pool.add(feature_color)
# 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)
else:
if balance==BalanceMethod.BY_COUNT:
# choose least used available color

0 comments on commit 2fd78b8

Please sign in to comment.
You can’t perform that action at this time.