There's no point in having a legend if you don't have custom colors or styles for the usergroups. So, it only shows the groups that have custom colors or styles.
Although, if you've done the code edit version, you could easily change it to show all of the groups with a display order higher than 0. But, I'll leave that little modification to you as a coding exercise