Skip to content

[Feature]: Unique Values classes keep the order they are listed in, by choice (High, Medium, Low) #3319

Done

Description

@elpidioassinaturas

Before you start

What problem does this solve?

Renderer::class_order (crates/map/src/symbology.rs, main aa57392) always sorts Unique Values classes:

The legend in the Layers pane, the layout legend and the Symbology class list all follow that order. A style can't keep its own order, whether it comes from style.add, a .rgisstyle or a plugin. Neither can a user editing classes in Symbology.

Many classes are ordinal words, which the alphabet scrambles:

Classes in their order Legend today
Alta, Média, Baixa (high, medium, low) Alta, Baixa, Média
Muito alto, Alto, Médio (very high, high, medium) Alto, Médio, Muito alto
Good, Fair, Poor Fair, Good, Poor
Very low … Very high, five classes High, Low, Medium, Very high, Very low

The case behind this: the BrasilData plugin draws the susceptibility charts of the Geological Survey of Brazil (SGB WFS gestao-territorial:suscet_inundacao and suscet_movimento_de_massa) and its geological risk areas (grau_risco). The plugin sends the classes as Alta, Média, Baixa, with the SGB colours, through style.add. In 0.8.0 the legend shows Alta, Baixa, Média, so the middle colour sits last. The same happens with soil suitability groups, hazard grades and any class field coded as words.

Today's workarounds all change what the map says:

  • prefix the values or labels with numbers ("1 Alta", "2 Média");
  • add a sort field and classify on it;
  • draw the legend by hand.

Proposed solution

A Unique Values renderer can keep its classes in the order they are listed. It is a new choice; the default stays the sort we have today.

  • The field: Renderer::Unique gets keep_order: bool, with #[serde(default, skip_serializing_if = "is_false")].
    • When it is true, class_order() returns 0..classes.len(): neither the label sort nor the number sort.
    • When it is false (the default), nothing changes. Projects and styles saved before this load as they do now, and they save without the field.
  • Where the order applies: everywhere class_order() is used already, that is the Layers pane legend, the layout legend (all classes or only the classes present), the Symbology list and the legend swatches. No reader needs its own change. <all other values> stays last.
  • The command: layer.orderClasses {layer?, values: [...]} sets the list order and keep_order: true. One undo reverts it.
    • Listed values come first, in the order given; the classes not listed follow in their current order.
    • A value with no class is named in the notice and skipped.
    • {layer?, "by": "name"} sets keep_order back to false.
  • Styles: style.add and .rgisstyle take the field through serde with no extra code. A plugin sends "keep_order": true together with classes in its order.
  • Symbology: next to the Unique Values class list, an "Order: By name / As listed" choice.
    • "As listed" shows ▲/▼ buttons on each class row, which move the class.
    • Switching back to "By name" keeps the list as it is and only sorts the display again.
  • Classify: pressing Classify again in "As listed" keeps the order of the classes that remain and appends the new values at the end. Rebuilding the classes from scratch would lose the order the user set.

Choices in this issue:

Crates:

  • map: the field, class_order, and the serde test.
  • engine: layer.orderClasses.
  • ui-egui: the order choice and the ▲/▼ buttons.

No new dependency.

Testing:

  • map:
  • Layout: a legend with all_classes false that lists only the classes present keeps the listed order.
  • engine:
  • By hand: in the 0.8.0 build, style.add with keep_order on the SGB layer gives the legend Alta, Média, Baixa in the Layers pane and in an exported layout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions