changeset 127:9baaaf37a008

Stacked charts that actually work
author Chris Cannam
date Sat, 20 Apr 2013 17:28:10 +0100
parents 80eb9b6d4fb9
children c5dd12a15993
files yetilab/plot/plot.yeti yetilab/plot/test/test_plot.yeti
diffstat 2 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/plot/plot.yeti	Sat Apr 20 16:33:32 2013 +0100
+++ b/yetilab/plot/plot.yeti	Sat Apr 20 17:28:10 2013 +0100
@@ -116,13 +116,13 @@
     ());
 
 stack keys xkeys values =
-   (stacked = mapIntoHash id \(mapIntoHash id \0 xkeys) keys;
+   (stacked = mapIntoHash id \(mapIntoHash id \{ y0 = 0, y1 = 0 } xkeys) keys;
     prev = mapIntoHash id \0 xkeys;
     for xkeys do xk:
         for keys do k:
             value = if xk in values[k] then values[k][xk] else 0 fi;
             height = prev[xk] + value;
-            stacked[k][xk] := height;
+            stacked[k][xk] := { y0 = prev[xk], y1 = height };
             prev[xk] := height;
         done;
     done;
@@ -133,29 +133,29 @@
     scene = chart#getScene();
     stacked = stack keys xkeys values;
     var z = 0;
-    newRect x height z colour is number -> number -> number -> ~Color -> 'a =
+    newRect x y0 y1 z colour is number -> number -> number -> number -> ~Color -> 'a =
        (poly = new Quad();
-        poly#add(new Point(new Coord3d(x + 0.5, z, 0)));
-        poly#add(new Point(new Coord3d(x + 0.5, z, height)));
-        poly#add(new Point(new Coord3d(x - 0.5, z, height)));
-        poly#add(new Point(new Coord3d(x - 0.5, z, 0)));
+        poly#add(new Point(new Coord3d(x + 0.5, z, y0)));
+        poly#add(new Point(new Coord3d(x + 0.5, z, y1)));
+        poly#add(new Point(new Coord3d(x - 0.5, z, y1)));
+        poly#add(new Point(new Coord3d(x - 0.5, z, y0)));
         poly#setWireframeDisplayed(true);
         poly#setWireframeColor(colour);
         poly#setFaceDisplayed(true);
         poly#setColor(colour);
         poly);
     for keys do k:
-        heights = stacked[k];
+        ranges = stacked[k];
         var x = 0;
         c = Color#random();
         for xkeys do xk:
-            poly = newRect x heights[xk] z c;
-            scene#add(poly);
+            rect = newRect x ranges[xk].y0 ranges[xk].y1 z c;
+            scene#add(rect);
             x := x + 1;
         done;
         z := z - 1;
     done;
-//    chart#getView()#setViewPoint(new Coord3d(0, 0, 0));
+    chart#getView()#setViewPoint(new Coord3d(pi/2, 0, 0));
     axes = chart#getAxeLayout();
     axes#setXAxeLabelDisplayed(false);
     axes#setYAxeLabelDisplayed(false);
--- a/yetilab/plot/test/test_plot.yeti	Sat Apr 20 16:33:32 2013 +0100
+++ b/yetilab/plot/test/test_plot.yeti	Sat Apr 20 17:28:10 2013 +0100
@@ -14,9 +14,15 @@
             [ "Alice":  [ "Jan": 3, "Mar": 2 ],
               "Bob":    [ "Jan": 0, "Feb": 1, "Mar": 4 ],
               "Conrad": [ "Feb": 2, "Mar": 1 ] ])
-        [ "Conrad": [ "Jan": 0, "Feb": 2, "Mar": 1 ],
-          "Alice":  [ "Jan": 3, "Feb": 2, "Mar": 3 ],
-          "Bob":    [ "Jan": 3, "Feb": 3, "Mar": 7 ] ]
+        [ "Conrad": [ "Jan": { y0 = 0, y1 = 0 },
+                      "Feb": { y0 = 0, y1 = 2 },
+                      "Mar": { y0 = 0, y1 = 1 } ],
+          "Alice":  [ "Jan": { y0 = 0, y1 = 3 },
+                      "Feb": { y0 = 2, y1 = 2 },
+                      "Mar": { y0 = 1, y1 = 3 } ],
+          "Bob":    [ "Jan": { y0 = 3, y1 = 3 },
+                      "Feb": { y0 = 2, y1 = 3 },
+                      "Mar": { y0 = 3, y1 = 7 } ] ]
 ),
 
 ] is hash<string, () -> boolean>;