diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 418b033f17..5e72382859 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -580,7 +580,7 @@ fn step_list(ui: &mut egui::Ui, d: &mut Draft, height: f32) -> Option { fn create_params(s: &Session, d: &Draft) -> Result { d.arrangement.held(s)?; if d.mosaic() { - panels_held(&d.panels)?; + panels_held(s, &d.panels)?; } let extent = area_extent(s, &d.area, d.coords.as_ref())?; let mut params = d.sent(s); diff --git a/crates/ui-egui/src/publicationwizard/panels.rs b/crates/ui-egui/src/publicationwizard/panels.rs index 0bf89c9665..9046aaf2ca 100644 --- a/crates/ui-egui/src/publicationwizard/panels.rs +++ b/crates/ui-egui/src/publicationwizard/panels.rs @@ -1,15 +1,28 @@ //! The wizard's panels step: the detail maps of a mosaic sheet. use super::map::{Coords, coordinate_fields, framed, in_degrees, ordered}; use super::*; +use crate::dialogs::MapOwner; use rustgis_engine::cmd::workspace::view_extent; use rustgis_engine::map::layout::{MAX_FRAME_SCALE, MIN_FRAME_SCALE}; /// What a panel's scale starts on once checked, in the denominator of 1:N. const START_SCALE: f64 = 25_000.0; +/// The widest a panel's bookmark list is drawn: a longer name is cut in its box. +const BOOKMARK_LIST_WIDTH: f32 = 180.0; + +/// Where a panel's area comes from: the sides typed, or a bookmark of the map (by name: a bookmark +/// has no other identity), tied to the map it was picked in as the map step ties a layer. +#[derive(Clone, Debug, PartialEq)] +pub enum Origin { + Coordinates, + Bookmark { map: MapOwner, name: String }, +} + /// One detail map of a mosaic: the area it shows, in degrees (longitude and latitude, whatever -/// the map's system, as `layout.publication` takes `panels`), its label, and the scale it is drawn -/// at when `scale_on`. `coords` is the map step's own type, with no system: the fields are shared. +/// the map's system, as `layout.publication` takes `panels`) or a bookmark's, its label, and the +/// scale it is drawn at when `scale_on`. `coords` is the map step's own type, with no system: the +/// fields are shared, and kept while the panel is on a bookmark, for the way back. #[derive(Clone, Debug, PartialEq)] pub struct PanelDraft { /// Its identity while the wizard is open: the widgets of a panel are scoped by it, not by its @@ -17,6 +30,7 @@ pub struct PanelDraft { /// when one above is removed. pub id: u64, pub coords: Coords, + pub origin: Origin, pub label: String, pub scale_on: bool, pub scale: f64, @@ -28,7 +42,7 @@ impl PanelDraft { pub fn from_view(s: &Session, id: u64) -> Self { let whole = [-180.0, -90.0, 180.0, 90.0]; let sides = if s.map().projection.is_globe() { whole } else { framed(view_extent(s)).map_or(whole, in_degrees) }; - PanelDraft { id, coords: sides.into(), label: String::new(), scale_on: false, scale: START_SCALE } + PanelDraft { id, coords: sides.into(), origin: Origin::Coordinates, label: String::new(), scale_on: false, scale: START_SCALE } } /// The label as the command keeps it: its white space, line breaks included, as one space. @@ -38,7 +52,10 @@ impl PanelDraft { /// The panel as `layout.publication` takes it. pub fn value(&self) -> Value { - let mut p = json!({"extent": self.coords.sides}); + let mut p = match &self.origin { + Origin::Coordinates => json!({"extent": self.coords.sides}), + Origin::Bookmark { name, .. } => json!({"bookmark": name}), + }; if let Some(label) = self.label_sent() { p["label"] = json!(label); } @@ -48,19 +65,42 @@ impl PanelDraft { p } - /// The panel's line in the review, the number counted from 1; none when its sides are out of - /// order, which the command refuses. - pub(super) fn line(&self, n: usize) -> String { + /// Why the panel isn't one `layout.publication` takes now: sides out of order, or a bookmark + /// that is gone or of another map. It scans the map's bookmark names but resolves no area, as + /// it runs every frame: a bookmark showing no place on the Earth is refused by the command, at + /// Create. + fn held(&self, s: &Session) -> Result<(), &'static str> { + match &self.origin { + Origin::Coordinates if ordered(self.coords.sides) => Ok(()), + Origin::Coordinates => Err(tl!("West must be less than East, and South less than North.")), + Origin::Bookmark { map, .. } if !map.holds(s) => { + Err(tl!("The map was switched or renamed since the bookmark was picked: pick it again.")) + } + Origin::Bookmark { name, .. } if !s.map().bookmarks.iter().any(|b| b.name == *name) => { + Err(tl!("The bookmark is no longer in the map (deleted or renamed): pick another.")) + } + Origin::Bookmark { .. } => Ok(()), + } + } + + /// The panel's line in the review, the number counted from 1; none when it isn't one the + /// command takes. + pub(super) fn line(&self, n: usize, s: &Session) -> String { let number = n.to_string(); - if !ordered(self.coords.sides) { + if self.held(s).is_err() { return i18n::fmt("{n}. {none}", &[("n", &number), ("none", tl!("(none)"))]); } - let [west, south, east, north] = self.coords.sides.map(|v| v.to_string()); - // The sides as the Map step's review says them: one catalogue key for both. - let sides = i18n::fmt( - "West {west}, South {south}, East {east}, North {north}", - &[("west", &west), ("south", &south), ("east", &east), ("north", &north)], - ); + let sides = match &self.origin { + Origin::Coordinates => { + let [west, south, east, north] = self.coords.sides.map(|v| v.to_string()); + // The sides as the Map step's review says them: one catalogue key for both. + i18n::fmt( + "West {west}, South {south}, East {east}, North {north}", + &[("west", &west), ("south", &south), ("east", &east), ("north", &north)], + ) + } + Origin::Bookmark { name, .. } => i18n::fmt("Bookmark \"{name}\"", &[("name", name)]), + }; let mut line = i18n::fmt("{n}. {sides}", &[("n", &number), ("sides", &sides)]); if let Some(label) = self.label_sent() { line = i18n::fmt("{line} · {label}", &[("line", &line), ("label", &label)]); @@ -72,20 +112,20 @@ impl PanelDraft { } } -/// Whether every panel is one `layout.publication` takes, or what the first that isn't lacks. -pub(super) fn panels_held(panels: &[PanelDraft]) -> Result<(), String> { - match panels.iter().position(|p| !ordered(p.coords.sides)) { - None => Ok(()), - Some(at) => Err(i18n::fmt( - "Panel {n}: {reason}", - &[("n", &(at + 1).to_string()), ("reason", tl!("West must be less than East, and South less than North."))], - )), +/// Whether every panel is one `layout.publication` takes, or what the first that isn't lacks: the +/// one check the step, the review and Create share. +pub(super) fn panels_held(s: &Session, panels: &[PanelDraft]) -> Result<(), String> { + for (at, p) in panels.iter().enumerate() { + if let Err(reason) = p.held(s) { + return Err(i18n::fmt("Panel {n}: {reason}", &[("n", &(at + 1).to_string()), ("reason", reason)])); + } } + Ok(()) } /// The review's Panels row: one line a panel. -pub(super) fn panels_value(d: &Draft) -> String { - d.panels.iter().enumerate().map(|(at, p)| p.line(at + 1)).collect::>().join("\n") +pub(super) fn panels_value(s: &Session, d: &Draft) -> String { + d.panels.iter().enumerate().map(|(at, p)| p.line(at + 1, s)).collect::>().join("\n") } /// The panels step: each panel's area in degrees, its label and its scale, with a button to add a @@ -107,6 +147,7 @@ pub(super) fn panels_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { d.next_panel += 1; } ui.add_space(4.0); + let marks: Vec<&str> = s.map().bookmarks.iter().map(|b| b.name.as_str()).collect(); let count = d.panels.len(); let mut remove = None; for (at, p) in d.panels.iter_mut().enumerate() { @@ -126,15 +167,49 @@ pub(super) fn panels_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { remove = Some(at); } }); - coordinate_fields(ui, &mut p.coords, "", 1.0, Some(&panel)); - if !ordered(p.coords.sides) { - ui.add( - egui::Label::new( - egui::RichText::new(tl!("West must be less than East, and South less than North.")) - .color(ui.visuals().warn_fg_color), - ) - .wrap(), - ); + let on_mark = matches!(p.origin, Origin::Bookmark { .. }); + ui.horizontal_wrapped(|ui| { + let coordinates = ui.radio(!on_mark, tl!("Coordinates")); + let name = named(tl!("Coordinates")); + coordinates.widget_info(|| egui::WidgetInfo::selected(egui::Role::RadioButton, true, !on_mark, &name)); + if coordinates.clicked() { + p.origin = Origin::Coordinates; + } + // Off while there is nothing to pick; a panel already on a bookmark keeps the radio + // on whatever the map has, so it is seen and can be left. + let pickable = on_mark || !marks.is_empty(); + let bookmark = ui + .add_enabled(pickable, egui::RadioButton::new(on_mark, tl!("Bookmark"))) + .on_disabled_hover_text(tl!("The map has no bookmarks.")); + let name = named(tl!("Bookmark")); + bookmark.widget_info(|| egui::WidgetInfo::selected(egui::Role::RadioButton, pickable, on_mark, &name)); + if bookmark.clicked() + && !on_mark + && let Some(first) = marks.first() + { + p.origin = Origin::Bookmark { map: MapOwner::of(s), name: (*first).to_string() }; + } + }); + if let Origin::Bookmark { map, name } = &mut p.origin { + // The box cuts its text at the width of its row, so the row is held to the box's width. + let list = ui.horizontal(|ui| { + ui.set_max_width(ui.available_width().min(BOOKMARK_LIST_WIDTH)); + egui::ComboBox::from_id_salt("panel_bookmark").selected_text(name.as_str()).truncate().show_ui(ui, |ui| { + for mark in &marks { + // Picked from the list of the map in view: it is that map's now. + if ui.selectable_label(name == mark, *mark).clicked() { + (*map, *name) = (MapOwner::of(s), (*mark).to_string()); + } + } + }) + }); + let label = named(tl!("Bookmark")); + list.inner.response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ComboBox, true, &label)); + } else { + coordinate_fields(ui, &mut p.coords, "", 1.0, Some(&panel)); + } + if let Err(why) = p.held(s) { + ui.add(egui::Label::new(egui::RichText::new(why).color(ui.visuals().warn_fg_color)).wrap()); } egui::Grid::new("publication_wizard_panel_texts").num_columns(2).spacing(egui::vec2(8.0, 4.0)).show(ui, |ui| { let label = ui.label(tl!("Label")); @@ -234,7 +309,7 @@ mod tests { } fn panel(sides: [f64; 4]) -> PanelDraft { - PanelDraft { id: 0, coords: sides.into(), label: String::new(), scale_on: false, scale: 25_000.0 } + PanelDraft { id: 0, coords: sides.into(), origin: Origin::Coordinates, label: String::new(), scale_on: false, scale: 25_000.0 } } /// The panels step comes after the style step on a mosaic sheet only, and a figure never has it. @@ -429,7 +504,7 @@ mod tests { d.panels[0].scale_on = true; d.panels[0].scale = 25_000.6; assert_eq!(d.params()["panels"][0]["scale"], json!(25_001.0)); - assert!(d.panels[0].line(1).ends_with(" · 1:25001")); + assert!(d.panels[0].line(1, &app.session).ends_with(" · 1:25001")); } /// A scale typed with a fraction is kept whole, as the step shows it and the review and the @@ -489,7 +564,10 @@ mod tests { assert_eq!(app.session.project.layouts.len(), before); assert_eq!(app.session.notice_mark(), said + 1); assert_eq!(app.dialogs.open, Some("publicationWizard")); - assert_eq!(panels_held(&draft(&h).panels), Err("Panel 2: West must be less than East, and South less than North.".to_string())); + assert_eq!( + panels_held(&app.session, &draft(&h).panels), + Err("Panel 2: West must be less than East, and South less than North.".to_string()) + ); } /// On a mosaic the map step's View is the area around the panels, and the review says so; on @@ -539,4 +617,213 @@ mod tests { assert_eq!(panel_frames, 2, "a frame for each panel"); assert_eq!(h.state().dialogs.open, None); } + + /// The map's bookmarks, by name, after the ones a new map starts with (its own "World") are + /// removed. + fn add_marks(a: &mut RustGisApp, names: &[&str]) { + clear_marks(a); + for n in names { + a.run("bookmark.add", json!({"name": n})).unwrap(); + } + } + + /// A panel on the bookmark `name` of the map in view now. + fn on_mark(a: &RustGisApp, name: &str) -> PanelDraft { + PanelDraft { origin: Origin::Bookmark { map: MapOwner::of(&a.session), name: name.into() }, ..panel([0.0, 0.0, 1.0, 1.0]) } + } + + fn clear_marks(a: &mut RustGisApp) { + let names: Vec = a.session.map().bookmarks.iter().map(|b| b.name.clone()).collect(); + for n in names { + a.run("bookmark.remove", json!({"name": n})).unwrap(); + } + } + + fn radio<'a>(h: &'a Wizard, name: &'a str) -> egui_kittest::Node<'a> { + h.get_by_role_and_label(Role::RadioButton, name) + } + + fn is_on(n: &egui_kittest::Node<'_>) -> bool { + n.accesskit_node().toggled() == Some(egui::accesskit::Toggled::True) + } + + /// A map with no bookmarks has nothing to pick: the radio is off, and the panel stays on + /// its coordinates. + #[test] + fn a_map_without_bookmarks_offers_no_bookmark() { + let h = wizard_on(Step::Panels, clear_marks); + assert!(radio(&h, "Panel 1: Bookmark").accesskit_node().is_disabled()); + assert!(is_on(&radio(&h, "Panel 1: Coordinates"))); + assert_eq!(panels_of(&h)[0].origin, Origin::Coordinates); + } + + /// Bookmark starts on the first bookmark and sends it by name; Coordinates takes the panel + /// back to what was typed. + #[test] + fn a_panel_picks_a_bookmark_and_goes_back_to_its_coordinates() { + let mut h = wizard_on(Step::Panels, |a| { + add_marks(a, &["Old town", "Harbour"]); + a.dialogs.publication.as_mut().unwrap().panels = vec![panel([2.0, 3.0, 4.0, 5.0])]; + }); + radio(&h, "Panel 1: Bookmark").click(); + h.run_steps(4); + let owner = MapOwner::of(&h.state().session); + assert_eq!(panels_of(&h)[0].origin, Origin::Bookmark { map: owner, name: "Old town".into() }); + assert_eq!(draft(&h).sent(&h.state().session)["panels"], json!([{"bookmark": "Old town"}])); + assert!(h.query_by_label_contains("West").is_none(), "the sides are not asked for"); + radio(&h, "Panel 1: Coordinates").click(); + h.run_steps(4); + assert_eq!(panels_of(&h)[0].origin, Origin::Coordinates); + assert_eq!(panels_of(&h)[0].coords.sides, [2.0, 3.0, 4.0, 5.0], "what was typed is kept"); + assert_eq!(draft(&h).sent(&h.state().session)["panels"], json!([{"extent": [2.0, 3.0, 4.0, 5.0]}])); + } + + /// Panels are their own: one on a bookmark and another on coordinates each send their kind, + /// with the label and the scale as before. + #[test] + fn panels_on_a_bookmark_and_on_coordinates_send_each_their_own() { + let h = wizard_on(Step::Review, |a| { + add_marks(a, &["Old town"]); + let mut first = on_mark(a, "Old town"); + first.label = "Centre".into(); + first.scale_on = true; + let d = a.dialogs.publication.as_mut().unwrap(); + d.panels = vec![first, panel([4.0, 5.0, 6.0, 7.0])]; + }); + assert_eq!( + draft(&h).sent(&h.state().session)["panels"], + json!([{"bookmark": "Old town", "label": "Centre", "scale": 25000.0}, {"extent": [4.0, 5.0, 6.0, 7.0]}]) + ); + h.get_by_label("1. Bookmark \"Old town\" · Centre · 1:25000\n2. West 4, South 5, East 6, North 7"); + } + + /// A bookmark that is gone, renamed, or of another map or project is said in the step, is none + /// in the review and stops Create, saying which. + #[test] + fn a_bookmark_that_is_no_longer_there_is_said_in_the_step_the_review_and_create() { + const GONE: &str = "The bookmark is no longer in the map (deleted or renamed): pick another."; + const SWITCHED: &str = "The map was switched or renamed since the bookmark was picked: pick it again."; + type Change = fn(&mut RustGisApp); + let cases: [(&str, Change, &str); 5] = [ + ("deleted", |a| a.run("bookmark.remove", json!({"name": "Old town"})).map(drop).unwrap(), GONE), + ("renamed", |a| a.run("bookmark.rename", json!({"name": "Old town", "newName": "Centre"})).map(drop).unwrap(), GONE), + ("the map in view renamed", |a| a.run("map.rename", json!({"name": "Renamed"})).map(drop).unwrap(), SWITCHED), + ( + "another project with a bookmark of that name", + |a| { + let name = a.session.map().name.clone(); + a.run("project.new", json!({})).unwrap(); + a.run("map.rename", json!({"name": name})).unwrap(); + add_marks(a, &["Old town"]); + }, + SWITCHED, + ), + ( + "another map with a bookmark of that name", + |a| { + a.run("map.new", json!({"name": "Other"})).unwrap(); + add_marks(a, &["Old town"]); + }, + SWITCHED, + ), + ]; + for (case, change, why) in cases { + let mut app = app(); + add_marks(&mut app, &["Old town"]); + let first = on_mark(&app, "Old town"); + change(&mut app); + open(&mut app); + let d = app.dialogs.publication.as_mut().unwrap(); + d.style = "mosaic".into(); + d.panels = vec![panel([0.0, 0.0, 1.0, 1.0]), first]; + d.step = Step::Panels; + let h = harness(app); + assert_eq!(h.get_all_by_label(why).count(), 1, "{case}: said in the step, in that panel only"); + let mut app = h.into_state(); + app.dialogs.publication.as_mut().unwrap().step = Step::Review; + let mut h = harness(app); + assert!(h.query_by_label_contains("2. (none)").is_some(), "{case}: the review"); + let before = h.state().session.project.layouts.len(); + let said = h.state().session.notice_mark(); + click(&mut h, "Create"); + let app = h.state(); + assert_eq!(app.session.project.layouts.len(), before, "{case}"); + assert_eq!(app.session.notice_mark(), said + 1, "{case}"); + assert_eq!(app.dialogs.open, Some("publicationWizard"), "{case}"); + assert_eq!(panels_held(&app.session, &draft(&h).panels), Err(format!("Panel 2: {why}")), "{case}"); + } + } + + /// A map left with no bookmarks keeps the panel on Bookmark, with its warning, and Coordinates + /// takes it back. + #[test] + fn a_map_left_without_bookmarks_still_lets_the_panel_go_back() { + let mut h = wizard_on(Step::Panels, |a| { + add_marks(a, &["Old town"]); + let p = on_mark(a, "Old town"); + a.run("bookmark.remove", json!({"name": "Old town"})).unwrap(); + a.dialogs.publication.as_mut().unwrap().panels = vec![p]; + }); + assert!(is_on(&radio(&h, "Panel 1: Bookmark"))); + h.get_by_label("The bookmark is no longer in the map (deleted or renamed): pick another."); + radio(&h, "Panel 1: Coordinates").click(); + h.run_steps(4); + assert_eq!(panels_of(&h)[0].origin, Origin::Coordinates); + assert!(h.query_by_label("The bookmark is no longer in the map (deleted or renamed): pick another.").is_none()); + } + + /// Another bookmark picked from the list is the one sent. + #[test] + fn another_bookmark_picked_from_the_list_is_the_one_sent() { + let mut h = wizard_on(Step::Panels, |a| { + add_marks(a, &["Old town", "Harbour"]); + let p = on_mark(a, "Old town"); + a.dialogs.publication.as_mut().unwrap().panels = vec![p]; + }); + h.get_by_role_and_label(Role::ComboBox, "Panel 1: Bookmark").click(); + h.run_steps(4); + h.get_by_label("Harbour").click(); + h.run_steps(4); + assert_eq!(draft(&h).sent(&h.state().session)["panels"], json!([{"bookmark": "Harbour"}])); + } + + /// The sides a panel keeps while it is on a bookmark aren't sent, so they aren't checked. + #[test] + fn the_sides_kept_behind_a_bookmark_are_not_checked() { + let mut app = app(); + add_marks(&mut app, &["Old town"]); + let p = PanelDraft { coords: [5.0, 0.0, 3.0, 1.0].into(), ..on_mark(&app, "Old town") }; + assert_eq!(panels_held(&app.session, &[p]), Ok(())); + } + + /// A bookmark's name at its longest is cut in the list's box, which stays one line inside the + /// window, as the Map step's layer list. + #[test] + fn a_long_bookmark_name_is_cut_in_its_list() { + let list = |name: &str| { + let h = wizard_on(Step::Panels, |a| { + add_marks(a, &[name]); + let p = on_mark(a, name); + a.dialogs.publication.as_mut().unwrap().panels = vec![p]; + }); + h.get_by_role_and_label(Role::ComboBox, "Panel 1: Bookmark").rect() + }; + let (short, long) = (list("Old town"), list("Old town of the harbour ".repeat(5).trim())); + assert_eq!(long.height(), short.height(), "{long:?}"); + assert!(long.width() <= BOOKMARK_LIST_WIDTH, "{long:?}"); + } + + /// Create makes the mosaic with a frame for a panel on a bookmark too. + #[test] + fn create_makes_a_frame_for_a_panel_on_a_bookmark() { + let mut h = wizard_on(Step::Review, |a| { + add_marks(a, &["Old town"]); + let p = on_mark(a, "Old town"); + a.dialogs.publication.as_mut().unwrap().panels = vec![p]; + }); + click(&mut h, "Create"); + let l = h.state().session.project.layouts.last().expect("a layout is made"); + let frames = l.elements.iter().filter(|e| matches!(e.kind, ElementKind::MapFrame { .. }) && e.name.starts_with("Panel ")).count(); + assert_eq!(frames, 1); + } } diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index 1a39ae2edc..8482f51c8d 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -53,7 +53,7 @@ fn picked_rows(ui: &mut egui::Ui, s: &Session, d: &Draft) { let style = crate::ribbon::publication_style(&d.style).map(|s| s.0.to_string()).unwrap_or_else(|| d.style.clone()); row(tl!("Style"), style); if d.mosaic() { - row(tl!("Panels"), panels_value(d)); + row(tl!("Panels"), panels_value(s, d)); } row(tl!("Elements"), elements_value(s, d)); placement_rows(&mut row, s, d); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index d1e86bc95b..59c08c6e6e 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -296,10 +296,12 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu around them; the panels whose middle lies outside what the key map shows, which it can't number, are named in one warning. Panels stay in degrees where `"extent"` is given with `"crs"`. The Layout Wizard offers it as the eighth style, with a **Panels** step after it: 1 to 6 panels, - each its west, south, east and north in degrees (on any map), an optional label and an optional - scale. On a mosaic its Map step's first choice reads **Around the panels**, and the review lists - the panels; one whose sides are out of order is said in its step, and Create says which and makes - nothing. + each its west, south, east and north in degrees (on any map) or a bookmark of the map, an + optional label and an optional scale. A bookmark is followed by its name, as `layout.publication` + takes it: one updated, or made again under that name, moves the panel. On a mosaic its Map + step's first choice reads **Around the panels**, and the review lists the panels; one whose + sides are out of order, or whose bookmark was deleted or renamed, or was picked in a map or + project since switched or renamed, is said in its step, and Create says which and makes nothing. A panel may also be an object: `{"extent": [w, s, e, n]}` or `{"bookmark": "name"}` (what that bookmark of the map covers, as a map view of the app's size shows it: the sheet can differ where the view's size does), with a `"label"` and a `"scale"` if it