]> pintos-os.org Git - pspp/commitdiff
work on styles
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 6 May 2026 16:50:31 +0000 (09:50 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 6 May 2026 16:50:31 +0000 (09:50 -0700)
rust/pspp/src/spv/read/graph/style.rs
rust/pspp/src/spv/testdata/graph2.expected.svg

index c7dcdfb078302ed0ce9ded04311f60c400cc20d7..9140a21c162fb3cba9049f38b4efd2a10293c58a 100644 (file)
@@ -60,112 +60,47 @@ pub struct Style {
     #[serde(rename = "@pattern")]
     pub pattern: Option<u32>,
 
-    #[serde(flatten)]
-    pub symbol_style: SymbolStyle,
-
-    #[serde(flatten)]
-    pub stroke_style: StrokeStyle,
-
-    #[serde(flatten)]
-    pub label_style: LabelStyle,
-
-    #[serde(default, rename = "$value")]
-    pub children: Vec<Style>,
-}
-
-impl Style {
-    /// Updates this style with the overrides in `override`.
-    pub fn overridden_with(self, overrides: &Style) -> Self {
-        Self {
-            id: overrides.id.clone().or(self.id),
-            color: overrides.color.or(self.color),
-            color2: overrides.color2.or(self.color2),
-            visible: overrides.visible.or(self.visible),
-            padding: overrides.padding.or(self.padding),
-            pattern: overrides.pattern.or(self.pattern),
-            symbol_style: self.symbol_style.overridden_with(&overrides.symbol_style),
-            stroke_style: self.stroke_style.overridden_with(&overrides.stroke_style),
-            label_style: self.label_style.overridden_with(&overrides.label_style),
-            children: self.children,
-        }
-    }
-}
-
-#[derive(Clone, Deserialize, Debug, Default)]
-#[serde(default, rename_all = "camelCase")]
-pub struct SymbolStyle {
     #[serde(rename = "@symbol")]
     pub symbol: Option<String>,
 
     #[serde(rename = "@glyph-sides")]
-    pub sides: Option<usize>,
+    pub symbol_sides: Option<usize>,
 
     #[serde(rename = "@glyph-angle")]
-    pub angle: Option<f64>,
+    pub symbol_angle: Option<f64>,
 
     #[serde(rename = "@size")]
-    pub size: Option<LocationLength>,
+    pub symbol_size: Option<LocationLength>,
 
     #[serde(rename = "@glyph-aspect")]
-    pub aspect: Option<f64>,
-}
-
-impl SymbolStyle {
-    pub fn overridden_with(self, overrides: &Self) -> Self {
-        Self {
-            symbol: overrides.symbol.clone().or(self.symbol),
-            sides: overrides.sides.or(self.sides),
-            angle: overrides.angle.or(self.angle),
-            size: overrides.size.clone().or(self.size),
-            aspect: overrides.aspect.or(self.aspect),
-        }
-    }
-}
+    pub symbol_aspect: Option<f64>,
 
-#[derive(Clone, Deserialize, Default, Debug)]
-#[serde(default, rename_all = "camelCase")]
-pub struct StrokeStyle {
     #[serde(rename = "@stroke-dasharray")]
-    dasharray: Option<String>,
+    stroke_dasharray: Option<String>,
 
     #[serde(rename = "@stroke-linecap")]
-    linecap: Option<StrokeLinecap>,
+    stroke_linecap: Option<StrokeLinecap>,
 
     #[serde(rename = "@stroke-width")]
-    width: Option<Length>,
+    stroke_width: Option<Length>,
 
     #[serde(rename = "@stroke-decoration")]
-    decoration: Option<StrokeDecoration>,
-}
+    stroke_decoration: Option<StrokeDecoration>,
 
-impl StrokeStyle {
-    pub fn overridden_with(self, overrides: &Self) -> Self {
-        Self {
-            dasharray: overrides.dasharray.clone().or(self.dasharray),
-            linecap: overrides.linecap.or(self.linecap),
-            width: overrides.width.or(self.width),
-            decoration: overrides.decoration.or(self.decoration),
-        }
-    }
-}
-
-#[derive(Clone, Deserialize, Default, Debug)]
-#[serde(default, rename_all = "camelCase")]
-pub struct LabelStyle {
     #[serde(rename = "@font-family")]
-    family: Option<String>,
+    font_family: Option<String>,
 
     #[serde(rename = "@font-size")]
-    size: Option<LocationLengthRange>,
+    font_size: Option<LocationLengthRange>,
 
     #[serde(rename = "@font-weight")]
     weight: Option<FontWeight>,
 
     #[serde(rename = "@font-style")]
-    slant: Option<FontSlant>,
+    font_slant: Option<FontSlant>,
 
     #[serde(rename = "@font-underline")]
-    underline: Option<FontUnderline>,
+    font_underline: Option<FontUnderline>,
 
     #[serde(rename = "@textAlignment")]
     text_alignment: Option<TextAlignment>,
@@ -175,20 +110,56 @@ pub struct LabelStyle {
 
     #[serde(rename = "@labelLocationVertical")]
     #[serde(deserialize_with = "deserialize_vert_align")]
-    vert_align: Option<VertAlign>,
-
-    #[serde(rename = "@text-fit")]
-    text_fit: Option<bool>,
+    label_vert_align: Option<VertAlign>,
 
     #[serde(rename = "@ignoreNewLines")]
     ignore_new_lines: Option<bool>,
 
     #[serde(rename = "@labelInside")]
-    placement: Option<LabelPlacement>,
+    label_placement: Option<LabelPlacement>,
+
+    #[serde(default, rename = "$value")]
+    pub children: Vec<Style>,
+
+    #[serde(rename = "@text-fit")]
+    text_fit: Option<bool>,
 }
 
-impl LabelStyle {
-    pub fn horz_align(&self) -> Option<HorzAlign> {
+impl Style {
+    /// Updates this style with the overrides in `override`.
+    pub fn overridden_with(self, overrides: &Style) -> Self {
+        Self {
+            id: overrides.id.clone().or(self.id),
+            color: overrides.color.or(self.color),
+            color2: overrides.color2.or(self.color2),
+            visible: overrides.visible.or(self.visible),
+            padding: overrides.padding.or(self.padding),
+            pattern: overrides.pattern.or(self.pattern),
+            symbol: overrides.symbol.clone().or(self.symbol),
+            symbol_sides: overrides.symbol_sides.or(self.symbol_sides),
+            symbol_angle: overrides.symbol_angle.or(self.symbol_angle),
+            symbol_size: overrides.symbol_size.clone().or(self.symbol_size),
+            symbol_aspect: overrides.symbol_aspect.or(self.symbol_aspect),
+            stroke_dasharray: overrides.stroke_dasharray.clone().or(self.stroke_dasharray),
+            stroke_linecap: overrides.stroke_linecap.or(self.stroke_linecap),
+            stroke_width: overrides.stroke_width.or(self.stroke_width),
+            stroke_decoration: overrides.stroke_decoration.or(self.stroke_decoration),
+            font_family: overrides.font_family.clone().or(self.font_family),
+            font_size: overrides.font_size.clone().or(self.font_size),
+            weight: overrides.weight.or(self.weight),
+            font_slant: overrides.font_slant.or(self.font_slant),
+            font_underline: overrides.font_underline.or(self.font_underline),
+            text_alignment: overrides.text_alignment.or(self.text_alignment),
+            label_vert_align: overrides.label_vert_align.or(self.label_vert_align),
+            decimal_offset: overrides.decimal_offset.or(self.decimal_offset),
+            ignore_new_lines: overrides.ignore_new_lines.or(self.ignore_new_lines),
+            label_placement: overrides.label_placement.or(self.label_placement),
+            text_fit: overrides.text_fit.or(self.text_fit),
+            children: self.children,
+        }
+    }
+
+    pub fn label_horz_align(&self) -> Option<HorzAlign> {
         match self.text_alignment.unwrap_or_default() {
             TextAlignment::Left => Some(HorzAlign::Left),
             TextAlignment::Right => Some(HorzAlign::Right),
@@ -202,22 +173,6 @@ impl LabelStyle {
             TextAlignment::Mixed => None,
         }
     }
-
-    pub fn overridden_with(self, overrides: &Self) -> Self {
-        Self {
-            family: overrides.family.clone().or(self.family),
-            size: overrides.size.clone().or(self.size),
-            weight: overrides.weight.or(self.weight),
-            slant: overrides.slant.or(self.slant),
-            underline: overrides.underline.or(self.underline),
-            text_alignment: overrides.text_alignment.or(self.text_alignment),
-            vert_align: overrides.vert_align.or(self.vert_align),
-            decimal_offset: overrides.decimal_offset.or(self.decimal_offset),
-            text_fit: overrides.text_fit.or(self.text_fit),
-            ignore_new_lines: overrides.ignore_new_lines.or(self.ignore_new_lines),
-            placement: overrides.placement.or(self.placement),
-        }
-    }
 }
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
index 807b5c8da1e03be288436dbf32bde88d92a8a854..621915534c71ec6d3aec9a4b834457807d7d94d3 100644 (file)
@@ -1,6 +1,6 @@
 <svg height="168" style="font-family: &quot;Sans Serif&quot;" viewBox="0 0 504 168" width="504" xmlns="http://www.w3.org/2000/svg">
 <text dominant-baseline="hanging" font-family="sans-serif" id="frame_subtitle_1" x="0" y="0">
-Technology : Virtual
+Title
 </text>
 <g id="graph_11559">
 <line stroke="black" x1="41" x2="167.9999935913086" y1="95.20000000000002" y2="95.20000000000002"/>
@@ -22,20 +22,35 @@ V2
 <text dominant-baseline="middle" text-anchor="end" x="31" y="95.20000000000002">
 0.0
 </text>
-<line stroke="black" x1="41" x2="31" y1="63.593600000000016" y2="63.593600000000016"/>
-<text dominant-baseline="middle" text-anchor="end" x="31" y="63.593600000000016">
+<line stroke="black" x1="41" x2="31" y1="79.58720000000001" y2="79.58720000000001"/>
+<text dominant-baseline="middle" text-anchor="end" x="31" y="79.58720000000001">
 10.0
 </text>
-<line stroke="black" x1="41" x2="31" y1="31.987200000000012" y2="31.987200000000012"/>
-<text dominant-baseline="middle" text-anchor="end" x="31" y="31.987200000000012">
+<line stroke="black" x1="41" x2="31" y1="63.9744" y2="63.9744"/>
+<text dominant-baseline="middle" text-anchor="end" x="31" y="63.9744">
 20.0
 </text>
-<line stroke="black" x1="41" x2="31" y1="0.3808000000000004" y2="0.3808000000000004"/>
-<text dominant-baseline="middle" text-anchor="end" x="31" y="0.3808000000000004">
+<line stroke="black" x1="41" x2="31" y1="48.36160000000001" y2="48.36160000000001"/>
+<text dominant-baseline="middle" text-anchor="end" x="31" y="48.36160000000001">
 30.0
 </text>
+<line stroke="black" x1="41" x2="31" y1="32.7488" y2="32.7488"/>
+<text dominant-baseline="middle" text-anchor="end" x="31" y="32.7488">
+40.0
+</text>
+<line stroke="black" x1="41" x2="31" y1="17.136000000000006" y2="17.136000000000006"/>
+<text dominant-baseline="middle" text-anchor="end" x="31" y="17.136000000000006">
+50.0
+</text>
+<line stroke="black" x1="41" x2="31" y1="1.5232000000000017" y2="1.5232000000000017"/>
+<text dominant-baseline="middle" text-anchor="end" x="31" y="1.5232000000000017">
+60.0
+</text>
 <g id="area_11560">
-<polygon fill="black" points="44.174999839782714 95.20000000000002 44.174999839782714 7.6160000000000085 50.52499951934814 53.31200000000001 56.87499919891357 79.96800000000002 63.224998878478985 87.58400000000002 69.57499855804444 91.39200000000001 75.92499823760986 91.39200000000001 107.674996635437 91.39200000000001 114.02499631500243 91.39200000000001 120.37499599456787 72.35200000000002 126.7249956741333 0 133.0749953536987 79.96800000000002 139.42499503326417 87.58400000000002 158.47499407196045 87.58400000000002 158.47499407196045 95.20000000000002" stroke="black"/>
+<polygon fill="black" points="44.174999839782714 95.20000000000002 44.174999839782714 51.93561445783134 50.52499951934814 74.5083373493976 56.87499919891357 87.6757590361446 63.224998878478985 91.43787951807231 69.57499855804444 93.31893975903617 75.92499823760986 93.31893975903617 107.674996635437 93.31893975903617 114.02499631500243 93.31893975903617 120.37499599456787 83.91363855421689 126.7249956741333 48.17349397590362 133.0749953536987 87.6757590361446 139.42499503326417 91.43787951807231 158.47499407196045 91.43787951807231 158.47499407196045 95.20000000000002" stroke="black"/>
+</g>
+<g id="area_11564">
+<polygon fill="black" points="107.674996635437 95.20000000000002 107.674996635437 91.39200000000001 114.02499631500243 91.39200000000001 120.37499599456787 72.35200000000002 126.7249956741333 0 133.0749953536987 79.96800000000002 139.42499503326417 87.58400000000002 158.47499407196045 87.58400000000002 158.47499407196045 95.20000000000002" stroke="black"/>
 </g>
 </g>
 <g id="graph_11578">