]> pintos-os.org Git - pspp/commitdiff
add axes
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 25 Jul 2026 15:38:36 +0000 (08:38 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 25 Jul 2026 15:38:36 +0000 (08:38 -0700)
rust/pspp/src/spv/read/graph.rs
rust/pspp/src/spv/testdata/graph2.expected.svg

index 8d5b29f4dc1e8e93e210440c463c19a066a2db58..bf033c0e19ba9746645bd02da75ce03d5ec1d5e0 100644 (file)
@@ -753,6 +753,9 @@ impl Visualization {
             for (y_index, y_facet) in y_facets.clone().enumerate() {
                 let rect = inner.subrect(x_index, nx_facets, y_index, ny_facets);
 
+                // If the graph has a colored cell style, outline the whole
+                // graph in a rectangle with that style.  Otherwise, draw X and
+                // Y axes.
                 if cell_style.color.is_some() {
                     graph_svg.append(
                         Rectangle::new()
@@ -766,6 +769,31 @@ impl Visualization {
                                 cell_style.color2(Color::BLACK).display_css().to_string(),
                             ),
                     );
+                } else {
+                    graph_svg.append(
+                        Line::new()
+                            .set("x1", rect.0[Axis2::X].0)
+                            .set("y1", rect.0[Axis2::Y].0)
+                            .set("x2", rect.0[Axis2::X].0)
+                            .set("y2", rect.0[Axis2::Y].1)
+                            .set("fill", cell_style.fill(&mut patterns))
+                            .set(
+                                "stroke",
+                                cell_style.color2(Color::BLACK).display_css().to_string(),
+                            ),
+                    );
+                    graph_svg.append(
+                        Line::new()
+                            .set("x1", rect.0[Axis2::X].0)
+                            .set("y1", rect.0[Axis2::Y].1)
+                            .set("x2", rect.0[Axis2::X].1)
+                            .set("y2", rect.0[Axis2::Y].1)
+                            .set("fill", cell_style.fill(&mut patterns))
+                            .set(
+                                "stroke",
+                                cell_style.color2(Color::BLACK).display_css().to_string(),
+                            ),
+                    );
                 }
 
                 for element in &elements {
@@ -1638,6 +1666,9 @@ impl<'a> AxisDomain<'a> {
     }
     fn ticks(&self) -> Vec<(f64, String)> {
         let mut ticks = Vec::new();
+        if self.major_ticks.is_none() {
+            return ticks;
+        }
         match &self.domain {
             Domain::Interval {
                 min: Some(min),
index c343ab61ab3225946260118db5cd37742fa48d34..64f75595b1769e207d1aee35a623d042fa0a12ac 100644 (file)
 Title
 </text>
 <g id="graph_11559">
+<line fill="#000000" stroke="#000000" x1="10" x2="10" y1="0" y2="118.20000000000002"/>
+<line fill="#000000" stroke="#000000" x1="10" x2="167.9999935913086" y1="118.20000000000002" y2="118.20000000000002"/>
 <g id="area_11560">
-<polygon fill="#f5f5f5" points="31.499999839782717 95.20000000000002 31.499999839782717 51.93561445783134 38.49999951934814 74.5083373493976 45.49999919891357 87.6757590361446 52.49999887847899 91.43787951807231 59.49999855804444 93.31893975903617 66.49999823760986 93.31893975903617 101.499996635437 93.31893975903617 108.49999631500242 93.31893975903617 115.49999599456787 83.91363855421689 122.49999567413329 48.17349397590362 129.4999953536987 87.6757590361446 136.49999503326416 91.43787951807231 157.49999407196043 91.43787951807231 157.49999407196043 95.20000000000002" stroke="#000000"/>
+<polygon fill="#f5f5f5" points="13.949999839782716 118.20000000000002 13.949999839782716 64.48308433734941 21.849999519348138 92.5093012048193 29.749999198913574 108.8579277108434 37.64999887847898 113.52896385542171 45.54999855804444 115.86448192771086 53.44999823760986 115.86448192771086 92.949996635437 115.86448192771086 100.84999631500241 115.86448192771086 108.74999599456787 104.18689156626509 116.6499956741333 59.81204819277109 124.5499953536987 108.8579277108434 132.44999503326414 113.52896385542171 156.14999407196044 113.52896385542171 156.14999407196044 118.20000000000002" stroke="#000000"/>
 </g>
 <g id="area_11564">
-<polygon fill="rgb(0, 0, 255, 0.50)" points="101.499996635437 95.20000000000002 101.499996635437 91.39200000000001 108.49999631500242 91.39200000000001 115.49999599456787 72.35200000000002 122.49999567413329 0 129.4999953536987 79.96800000000002 136.49999503326416 87.58400000000002 157.49999407196043 87.58400000000002 157.49999407196043 95.20000000000002" stroke="#000000"/>
+<polygon fill="rgb(0, 0, 255, 0.50)" points="92.949996635437 118.20000000000002 92.949996635437 113.47200000000001 100.84999631500241 113.47200000000001 108.74999599456787 89.83200000000001 116.6499956741333 0 124.5499953536987 99.28800000000001 132.44999503326414 108.74400000000001 156.14999407196044 108.74400000000001 156.14999407196044 118.20000000000002" stroke="#000000"/>
 </g>
-<g c:description="X axis facets above graph" transform="translate(28 0)"/>
-<g c:description="X axis facets below graph" transform="translate(28 95.20000000000002)">
-<line stroke="black" x1="40.740135076701314" x2="40.740135076701314" y1="0" y2="10"/>
-<line stroke="black" x1="97.79914778916813" x2="97.79914778916813" y1="0" y2="10"/>
-<text dominant-baseline="hanging" text-anchor="middle" x="40.740135076701314" y="10">
-10
-</text>
-<text dominant-baseline="hanging" text-anchor="middle" x="97.79914778916813" y="10">
-15
-</text>
-<text dominant-baseline="hanging" text-anchor="middle" x="69.9999967956543" y="33">
+<g c:description="X axis facets above graph" transform="translate(10 0)"/>
+<g c:description="X axis facets below graph" transform="translate(10 118.20000000000002)">
+<text dominant-baseline="hanging" text-anchor="middle" x="78.9999967956543" y="10">
 V2
 </text>
 </g>
-<g c:description="Y axis facets on left side of graph" transform="rotate(-90 0 95.20000000000002) translate(0 95.20000000000002)">
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 0 18)" x="0" y="18">
-0
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 15.612800000000004 18)" x="15.612800000000004" y="18">
-10
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 31.225600000000007 18)" x="31.225600000000007" y="18">
-20
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 46.83840000000001 18)" x="46.83840000000001" y="18">
-30
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 62.451200000000014 18)" x="62.451200000000014" y="18">
-40
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 78.06400000000001 18)" x="78.06400000000001" y="18">
-50
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 93.67680000000001 18)" x="93.67680000000001" y="18">
-60
-</text>
-<line stroke="black" x1="0" x2="0" y1="18" y2="28"/>
-<line stroke="black" x1="15.612800000000004" x2="15.612800000000004" y1="18" y2="28"/>
-<line stroke="black" x1="31.225600000000007" x2="31.225600000000007" y1="18" y2="28"/>
-<line stroke="black" x1="46.83840000000001" x2="46.83840000000001" y1="18" y2="28"/>
-<line stroke="black" x1="62.451200000000014" x2="62.451200000000014" y1="18" y2="28"/>
-<line stroke="black" x1="78.06400000000001" x2="78.06400000000001" y1="18" y2="28"/>
-<line stroke="black" x1="93.67680000000001" x2="93.67680000000001" y1="18" y2="28"/>
-</g>
+<g c:description="Y axis facets on left side of graph" transform="rotate(-90 0 118.20000000000002) translate(0 118.20000000000002)"/>
 <g c:description="Y axis facets on right side of graph" transform="rotate(90 167.9999935913086 0) translate(167.9999935913086 0)"/>
 </g>
 <g id="graph_11578">
+<line fill="#000000" stroke="#000000" x1="177.9999935913086" x2="177.9999935913086" y1="0" y2="118.20000000000002"/>
+<line fill="#000000" stroke="#000000" x1="177.9999935913086" x2="335.9999871826172" y1="118.20000000000002" y2="118.20000000000002"/>
 <g id="area_11579">
-<polygon fill="#f5f5f5" points="199.49999343109093 95.20000000000002 199.49999343109093 92.75897435897437 220.49999246978746 82.99487179487181 234.49999182891807 85.43589743589746 241.49999150848402 87.87692307692309 255.49999086761463 92.75897435897437 269.49999022674524 92.75897435897437 276.49998990631116 82.99487179487181 290.49998926544174 90.31794871794872 304.4999886245724 75.67179487179489 311.4999883041383 0 325.49998766326894 73.23076923076925 325.49998766326894 95.20000000000002" stroke="#000000"/>
+<polygon fill="#f5f5f5" points="181.94999343109086 118.20000000000002 181.94999343109086 115.16923076923078 205.64999246978746 103.04615384615386 221.44999182891803 106.0769230769231 229.34999150848404 109.10769230769233 245.1499908676146 115.16923076923078 260.9499902267452 115.16923076923078 268.8499899063112 103.04615384615386 284.6499892654417 112.13846153846156 300.4499886245723 93.95384615384617 308.3499883041384 0 324.1499876632689 90.92307692307695 324.1499876632689 118.20000000000002" stroke="#000000"/>
 </g>
 <g id="area_11583">
-<polygon fill="rgb(0, 0, 255, 0.50)" points="199.49999343109093 95.20000000000002 199.49999343109093 89.91111111111113 220.49999246978746 68.75555555555556 234.49999182891807 74.04444444444447 241.49999150848402 79.33333333333336 255.49999086761463 89.91111111111113 269.49999022674524 89.91111111111113 276.49998990631116 74.04444444444447 304.4999886245724 79.33333333333336 311.4999883041383 63.46666666666668 325.49998766326894 52.8888888888889 325.49998766326894 95.20000000000002" stroke="#000000"/>
+<polygon fill="rgb(0, 0, 255, 0.50)" points="181.94999343109086 118.20000000000002 181.94999343109086 111.63333333333334 205.64999246978746 85.36666666666667 221.44999182891803 91.93333333333335 229.34999150848404 98.50000000000001 245.1499908676146 111.63333333333334 260.9499902267452 111.63333333333334 268.8499899063112 91.93333333333335 300.4499886245723 98.50000000000001 308.3499883041384 78.80000000000003 324.1499876632689 65.66666666666669 324.1499876632689 118.20000000000002" stroke="#000000"/>
 </g>
-<g c:description="X axis facets above graph" transform="translate(195.9999935913086 0)"/>
-<g c:description="X axis facets below graph" transform="translate(195.9999935913086 95.20000000000002)">
-<line stroke="black" x1="11.666666132610345" x2="11.666666132610345" y1="0" y2="10"/>
-<line stroke="black" x1="69.99999679565559" x2="69.99999679565559" y1="0" y2="10"/>
-<line stroke="black" x1="128.33332745870084" x2="128.33332745870084" y1="0" y2="10"/>
-<text dominant-baseline="hanging" text-anchor="middle" x="11.666666132610345" y="10">
-0.575
-</text>
-<text dominant-baseline="hanging" text-anchor="middle" x="69.99999679565559" y="10">
-0.58
-</text>
-<text dominant-baseline="hanging" text-anchor="middle" x="128.33332745870084" y="10">
-0.585
-</text>
-<text dominant-baseline="hanging" text-anchor="middle" x="69.9999967956543" y="33">
+<g c:description="X axis facets above graph" transform="translate(177.9999935913086 0)"/>
+<g c:description="X axis facets below graph" transform="translate(177.9999935913086 118.20000000000002)">
+<text dominant-baseline="hanging" text-anchor="middle" x="78.9999967956543" y="10">
 V1
 </text>
 </g>
-<g c:description="Y axis facets on left side of graph" transform="rotate(-90 167.9999935913086 95.20000000000002) translate(167.9999935913086 95.20000000000002)">
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 0 18)" x="0" y="18">
-0
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 19.040000000000003 18)" x="19.040000000000003" y="18">
-10
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 38.080000000000005 18)" x="38.080000000000005" y="18">
-20
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 57.12000000000001 18)" x="57.12000000000001" y="18">
-30
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 76.16000000000001 18)" x="76.16000000000001" y="18">
-40
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 95.20000000000002 18)" x="95.20000000000002" y="18">
-50
-</text>
-<line stroke="black" x1="0" x2="0" y1="18" y2="28"/>
-<line stroke="black" x1="19.040000000000003" x2="19.040000000000003" y1="18" y2="28"/>
-<line stroke="black" x1="38.080000000000005" x2="38.080000000000005" y1="18" y2="28"/>
-<line stroke="black" x1="57.12000000000001" x2="57.12000000000001" y1="18" y2="28"/>
-<line stroke="black" x1="76.16000000000001" x2="76.16000000000001" y1="18" y2="28"/>
-<line stroke="black" x1="95.20000000000002" x2="95.20000000000002" y1="18" y2="28"/>
-</g>
+<g c:description="Y axis facets on left side of graph" transform="rotate(-90 167.9999935913086 118.20000000000002) translate(167.9999935913086 118.20000000000002)"/>
 <g c:description="Y axis facets on right side of graph" transform="rotate(90 335.9999871826172 0) translate(335.9999871826172 0)"/>
 </g>
 <g id="graph_11597">
+<line fill="#000000" stroke="#000000" x1="345.9999871826172" x2="345.9999871826172" y1="0" y2="118.20000000000002"/>
+<line fill="#000000" stroke="#000000" x1="345.9999871826172" x2="504" y1="118.20000000000002" y2="118.20000000000002"/>
 <g id="area_11598">
-<polygon fill="#f5f5f5" points="367.4999875030518 95.20000000000002 367.4999875030518 87.9651529193698 381.49998878479005 91.58257645968492 388.4999894256592 66.26061167747916 395.4999900665283 33.7037998146432 402.49999070739744 22.851529193697868 409.4999913482666 48.17349397590362 416.49999198913576 59.025764596848944 423.4999926300049 66.26061167747916 430.49999327087403 91.58257645968492 444.4999945526123 91.58257645968492 465.49999647521975 91.58257645968492 486.49999839782714 91.58257645968492 486.49999839782714 95.20000000000002" stroke="#000000"/>
+<polygon fill="#f5f5f5" points="349.9499875030518 118.20000000000002 349.9499875030518 109.21723818350326 365.74998878479005 113.70861909175164 373.64998942565916 82.26895273401298 381.5499900665283 41.846524559777585 389.4499907073975 28.372381835032435 397.3499913482666 59.81204819277109 405.24999198913576 73.28619091751622 413.1499926300049 82.26895273401298 421.04999327087404 113.70861909175164 436.8499945526123 113.70861909175164 460.5499964752197 113.70861909175164 484.24999839782714 113.70861909175164 484.24999839782714 118.20000000000002" stroke="#000000"/>
 </g>
 <g id="area_11602">
-<polygon fill="rgb(0, 0, 255, 0.50)" points="388.4999894256592 95.20000000000002 388.4999894256592 51.26153846153848 395.4999900665283 0 402.49999070739744 14.646153846153839 409.4999913482666 43.93846153846154 416.49999198913576 80.55384615384617 465.49999647521975 87.87692307692309 486.49999839782714 87.87692307692309 486.49999839782714 95.20000000000002" stroke="#000000"/>
+<polygon fill="rgb(0, 0, 255, 0.50)" points="373.64998942565916 118.20000000000002 373.64998942565916 63.646153846153865 381.5499900665283 0 389.4499907073975 18.184615384615377 397.3499913482666 54.55384615384615 405.24999198913576 100.01538461538463 460.5499964752197 109.10769230769233 484.24999839782714 109.10769230769233 484.24999839782714 118.20000000000002" stroke="#000000"/>
 </g>
-<g c:description="X axis facets above graph" transform="translate(363.9999871826172 0)"/>
-<g c:description="X axis facets below graph" transform="translate(363.9999871826172 95.20000000000002)">
-<line stroke="black" x1="14.692559219481844" x2="14.692559219481844" y1="0" y2="10"/>
-<line stroke="black" x1="61.234175256482075" x2="61.234175256482075" y1="0" y2="10"/>
-<line stroke="black" x1="107.7757912934823" x2="107.7757912934823" y1="0" y2="10"/>
-<text dominant-baseline="hanging" text-anchor="middle" x="14.692559219481844" y="10">
-30
-</text>
-<text dominant-baseline="hanging" text-anchor="middle" x="61.234175256482075" y="10">
-35
-</text>
-<text dominant-baseline="hanging" text-anchor="middle" x="107.7757912934823" y="10">
-40
-</text>
-<text dominant-baseline="hanging" text-anchor="middle" x="70.0000064086914" y="33">
+<g c:description="X axis facets above graph" transform="translate(345.9999871826172 0)"/>
+<g c:description="X axis facets below graph" transform="translate(345.9999871826172 118.20000000000002)">
+<text dominant-baseline="hanging" text-anchor="middle" x="79.0000064086914" y="10">
 V3
 </text>
 </g>
-<g c:description="Y axis facets on left side of graph" transform="rotate(-90 335.9999871826172 95.20000000000002) translate(335.9999871826172 95.20000000000002)">
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 0 18)" x="0" y="18">
-0
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 30.024615384615387 18)" x="30.024615384615387" y="18">
-10
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 60.049230769230775 18)" x="60.049230769230775" y="18">
-20
-</text>
-<text dominant-baseline="middle" text-anchor="end" transform="rotate(90 90.07384615384616 18)" x="90.07384615384616" y="18">
-30
-</text>
-<line stroke="black" x1="0" x2="0" y1="18" y2="28"/>
-<line stroke="black" x1="30.024615384615387" x2="30.024615384615387" y1="18" y2="28"/>
-<line stroke="black" x1="60.049230769230775" x2="60.049230769230775" y1="18" y2="28"/>
-<line stroke="black" x1="90.07384615384616" x2="90.07384615384616" y1="18" y2="28"/>
-</g>
+<g c:description="Y axis facets on left side of graph" transform="rotate(-90 335.9999871826172 118.20000000000002) translate(335.9999871826172 118.20000000000002)"/>
 <g c:description="Y axis facets on right side of graph" transform="rotate(90 504 0) translate(504 0)"/>
 </g>
 </svg>