Skip to content

[Bug]: A group of Unique Values classes splits in two when the layer is classified again and a new value moves the classes' places #3378

Done

Description

@elpidioassinaturas

What happens

Line numbers are on main at 713d33a.

layer.groupClasses (#3317) gives the classes it names the symbol of the first of them and one label (Renderer::group_classes, crates/map/src/symbology.rs:2274). A group isn't stored as such: it is only those classes sharing one symbol and one label.

When the layer is classified again on the same field with the same scheme, carry_edits_from (line 2340) keeps a class's colour only if it was edited by hand. It finds that out in carry_class (line 2487), which compares the old colour with the scheme's colour at the class's old place: or.pick(j, n), at line 2390.

In a group, the first class still has the scheme's colour, so it counts as unedited. The others hold a copy of it, so they count as edited. While the places stay the same, both answers give the same colour. When a new value moves the classes' places, the first class takes the scheme's colour at its new place, and the others keep the copied one. Labels, strokes and fills are carried by value, so the group keeps one label but now has two colours: two legend rows with the same label.

This happens without any hand ordering. It was found in the review of #3367.

Steps to reproduce

  1. Make a point or polygon layer whose field v has the values a, b and c.
  2. Classify it as Unique Values on v with any colour scheme (layer.symbology).
  3. Group b and c: layer.groupClasses={"layer":"…","values":["b","c"]}. Both take b's colour.
  4. Add a feature with v = aa, so the classes are now a, aa, b, c.
  5. Classify again on v with the same scheme.

Expected

b and c still share one colour and are still one legend entry.

Actual

b takes the scheme's new colour at its new place, [226, 94, 64] in the case checked, and c keeps the old copied colour [245, 138, 75]. The legend lists the label twice.

Proposed fix

No change to the saved format is needed. In carry_edits_from, after the classes are recoloured, treat as one group the old classes that shared a symbol and an explicit label (class_labels). This is what group_classes leaves behind. Give each such group the new symbol of its first class in class_order(), as group_classes does.

If a group should survive a hand edit of one class's label, a stored group (a list of values per group) is the alternative, but it needs a capability and a schema change. The fix above covers what the command makes.

Test: the steps above as a symbology.rs test, checking that b and c have the same symbol after the second classify, and that a class with only its own label edited still keeps its own colour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions