Mercurial > hg > may
changeset 125:0f362d1de06e
Toward stacked charts
author | Chris Cannam |
---|---|
date | Sat, 20 Apr 2013 12:14:40 +0100 |
parents | 83f127d60c58 |
children | 80eb9b6d4fb9 |
files | yc yetilab/plot/plot.yeti yetilab/plot/test/test_plot.yeti yetilab/test/all.yeti |
diffstat | 4 files changed, 72 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/yc Fri Apr 19 19:33:22 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#!/bin/sh -YETI_LIBDIR=${YETI_LIBDIR:=../yeti} -if [ ! -d "$YETI_LIBDIR" ]; then - YETI_LIBDIR=../other/yeti -fi -rlwrap $JAVA_HOME/bin/java -classpath $YETI_LIBDIR/yeti.jar:$YETI_LIBDIR/yeti-lib.jar:jtransforms-2.4.jar yeti.lang.compiler.yeti "$@"
--- a/yetilab/plot/plot.yeti Fri Apr 19 19:33:22 2013 +0100 +++ b/yetilab/plot/plot.yeti Sat Apr 20 12:14:40 2013 +0100 @@ -2,7 +2,7 @@ import org.jzy3d.plot3d.builder: Mapper; import org.jzy3d.maths: Range, Coord3d; -import org.jzy3d.plot3d.primitives: Shape, HistogramBar, FlatLine2d; +import org.jzy3d.plot3d.primitives: Shape, HistogramBar, FlatLine2d, Polygon, Point; import org.jzy3d.plot3d.primitives.axes.layout.providers: StaticTickProvider; import org.jzy3d.plot3d.primitives.axes.layout.renderers: TickLabelMap; import org.jzy3d.chart: Chart, ChartLauncher; @@ -115,6 +115,50 @@ ChartLauncher#openChart(chart); ()); +stack keys xkeys values = + (stacked = mapIntoHash id \(mapIntoHash id \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; + prev[xk] := height; + done; + done; + stacked); + +plotStacked keys xkeys unit values = + (chart = new Chart(Quality#Nicest); + scene = chart#getScene(); + stacked = stack keys xkeys values; + var z = 0; + for keys do k: + heights = stacked[k]; + poly = new Polygon(); + poly#setWireframeDisplayed(true); + poly#setWireframeColor(Color#random()); + poly#setFaceDisplayed(true); + poly#setColor(Color#random()); + poly#add(new Point(new Coord3d(0, 0, z))); + var x = 0; + for xkeys do xk: + poly#add(new Point(new Coord3d(x, heights[xk], z))); + x := x + 1; + done; + poly#add(new Point(new Coord3d(x - 1, 0, z))); + scene#add(poly); + z := z + 1; + done; + chart#getView()#setViewPoint(new Coord3d(0, 0, 0)); + axes = chart#getAxeLayout(); + axes#setXAxeLabelDisplayed(false); + axes#setYAxeLabelDisplayed(false); + axes#setZAxeLabelDisplayed(true); + axes#setZAxeLabel(unit); + axes#setYTickLabelDisplayed(false); + ChartLauncher#openChart(chart); + ()); plotStructure structure = case structure of @@ -131,6 +175,8 @@ plotMatrix, plotBarChart, plotLines, + stack, + plotStacked, plotStructure, }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yetilab/plot/test/test_plot.yeti Sat Apr 20 12:14:40 2013 +0100 @@ -0,0 +1,23 @@ +module yetilab.plot.test.test_plot; + +p = load yetilab.plot.plot; + +{ compare } = load yetilab.test.test; + +[ + +"stack": \( + compare + (p.stack + [ "Conrad", "Alice", "Bob" ] + [ "Jan", "Feb", "Mar" ] + [ "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 ] ] +), + +] is hash<string, () -> boolean>; +
--- a/yetilab/test/all.yeti Fri Apr 19 19:33:22 2013 +0100 +++ b/yetilab/test/all.yeti Sat Apr 20 12:14:40 2013 +0100 @@ -10,7 +10,8 @@ "framer" : load yetilab.stream.test.test_framer, "fft" : load yetilab.transform.test.test_fft, "vamppost" : load yetilab.vamp.test.test_vamppost, -"matrix" : load yetilab.matrix.test.test_matrix +"matrix" : load yetilab.matrix.test.test_matrix, +"plot" : load yetilab.plot.test.test_plot ]; bad = sum (mapHash do name testHash: runTests name testHash done tests);