Repository navigation
Description
Before you start
- I searched the existing issues and the roadmap and did not find a duplicate request.
What problem does this solve?
Renderer::class_order (crates/map/src/symbology.rs, main aa57392) always sorts Unique Values classes:
- by value, when the values read as numbers ([Bug]: Unique Values on a numeric field sorts its classes and legend as text (10153 before 1741) #1340);
- otherwise by label, without regard to case.
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::Uniquegetskeep_order: bool, with#[serde(default, skip_serializing_if = "is_false")].- When it is true,
class_order()returns0..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.
- When it is true,
- 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 andkeep_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"}setskeep_orderback to false.
- Styles:
style.addand.rgisstyletake the field through serde with no extra code. A plugin sends"keep_order": truetogether withclassesin 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:
- A flag, not a sort mode with several options (name, value, count…). "As listed" covers ordinal words, which no automatic rule gets right. The two existing rules stay the default.
- A flag, not a guess at High/Medium/Low words. Guessing is language dependent, and it fails on "Muito alto" and the like.
- Leave out ordering by feature count. It can be a mode later if someone asks.
- This does not overlap [Feature]: A legend's Layers section lists its layers as a tree, with a filter and their classes #3306 (the legend's layer tree).
- It touches [Feature]: Group several Unique Values classes into one legend entry, by command and from the class list #3308 (grouping classes), which PR feat(symbology): group several Unique Values classes into one legend entry #3317 implements. feat(symbology): group several Unique Values classes into one legend entry #3317 gives a group the look of "the first of them in
Renderer::class_order". Withkeep_order, that first class becomes the first one listed, so the grouped entry takes its look and its place from that order. That is the intended result, but this issue should start after feat(symbology): group several Unique Values classes into one legend entry #3317 merges and add a test for a group underkeep_order. Both changecrates/map/src/symbology.rs,cmd/layer.rsandpanes.rs.
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:- With
keep_order, a Unique renderer whose classes are Alta, Média, Baixa givesclass_order() == [0, 1, 2]and itslegend()lists them in that order, with<all other values>last. - Without the flag, the order is the same as today:
[0, 2, 1], and the numeric case of [Bug]: Unique Values on a numeric field sorts its classes and legend as text (10153 before 1741) #1340 is unchanged. - The style's JSON round-trips. A style without the field loads with
keep_order == falseand saves without it.
- With
- Layout: a legend with
all_classesfalse that lists only the classes present keeps the listed order. engine:layer.orderClasseswith["Baixa", "Alta"]on Alta, Média, Baixa gives Baixa, Alta, Média.- An unknown value appears in the notice.
- Undo restores the order and the flag.
{"by": "name"}turns the flag off.- Once feat(symbology): group several Unique Values classes into one legend entry #3317 is in: grouping Baixa and Alta under
keep_orderwith Baixa listed first gives the group Baixa's look.
- By hand: in the 0.8.0 build,
style.addwithkeep_orderon the SGB layer gives the legend Alta, Média, Baixa in the Layers pane and in an exported layout.
Activity
fix(symbology): a kept class order needs a reader that keeps it, and …
fix(symbology): back to by name stores the classes sorted; a saved st…
feat(symbology): Unique Values classes can keep the order they are li…
feat(symbology): order Unique Values classes in the Symbology pane, a…
fix(symbology): kept class order follow-ups from the opengeos#3367 and …