Chris@108: module yetilab.plot.plot; Chris@108: Chris@108: import org.jzy3d.plot3d.builder: Mapper; Chris@128: import org.jzy3d.plot3d.text.drawable: DrawableTextBillboard, DrawableTextBitmap; Chris@119: import org.jzy3d.maths: Range, Coord3d; Chris@126: import org.jzy3d.plot3d.primitives: Shape, HistogramBar, FlatLine2d, Polygon, Quad, Point; Chris@119: import org.jzy3d.plot3d.primitives.axes.layout.providers: StaticTickProvider; Chris@119: import org.jzy3d.plot3d.primitives.axes.layout.renderers: TickLabelMap; Chris@108: import org.jzy3d.chart: Chart, ChartLauncher; Chris@108: import org.jzy3d.plot3d.builder: Builder; Chris@108: import org.jzy3d.plot3d.builder.concrete: OrthonormalGrid; Chris@108: import org.jzy3d.colors.colormaps: ColorMapRainbow; Chris@119: import org.jzy3d.colors: ColorMapper, Color; Chris@108: import org.jzy3d.plot3d.rendering.canvas: Quality; Chris@119: import org.jzy3d.plot3d.rendering.view.modes: ViewPositionMode; Chris@108: Chris@108: newMatrixMapper matrix = Chris@108: (class MMapper extends Mapper Chris@108: double f(double x, double y) Chris@117: result = matrix.getAt y x; Chris@117: println "f(\(x),\(y)) -> \(result)"; Chris@117: result Chris@108: end; Chris@108: new MMapper()); Chris@108: Chris@108: newMatrixLogMapper matrix = Chris@108: (class MMapper extends Mapper Chris@108: double f(double x, double y) Chris@108: ln (matrix.getAt y x) Chris@108: end; Chris@108: new MMapper()); Chris@108: Chris@108: newMapper mapFunction = Chris@108: (class FMapper extends Mapper Chris@108: double f(double x, double y) Chris@108: mapFunction x y Chris@108: end; Chris@108: new FMapper()); Chris@108: Chris@115: plotMatrix matrix = Chris@117: (mapper = newMatrixMapper matrix; Chris@108: size = matrix.size; Chris@119: xrange = new Range(0, size.columns - 1); Chris@119: yrange = new Range(0, size.rows - 1); Chris@108: grid = new OrthonormalGrid(xrange, size.columns, yrange, size.rows); Chris@112: println "Matrix size: \(size)"; Chris@117: surface = Builder#buildOrthonormal(grid, mapper); //??? big? Chris@117: println "Z Bounds: \(surface#getBounds()#getZmin()) -> \(surface#getBounds()#getZmax())"; Chris@121: surface#setFaceDisplayed(true); Chris@108: surface#setWireframeDisplayed(true); Chris@108: surface#setWireframeColor(Color#BLACK); Chris@112: // chart = new Chart(Quality#Fastest, "swing"); Chris@112: chart = new Chart(Quality#Nicest); Chris@108: chart#getScene()#getGraph()#add(surface); Chris@115: ChartLauncher#openChart(chart); Chris@115: ()); Chris@108: Chris@119: plotBarChart keys unit values = Chris@119: (chart = new Chart(Quality#Nicest); Chris@119: var n = 0; Chris@119: scene = chart#getScene(); Chris@119: ticks = new float[length keys]; Chris@119: tickLabels = new TickLabelMap(); Chris@119: for keys do k: Chris@119: bar = new HistogramBar(); Chris@119: bar#setData(new Coord3d(n, 0, 0), values[k], 0.45, Color#random()); Chris@119: bar#setWireframeDisplayed(false); Chris@119: scene#add(bar); Chris@119: ticks[n] := n; Chris@119: tickLabels#register(n, k); Chris@119: n := n + 1; Chris@119: done; Chris@119: chart#getView()#setViewPoint(new Coord3d(pi/2, 0, 0)); Chris@119: axes = chart#getAxeLayout(); Chris@119: axes#setXAxeLabelDisplayed(false); Chris@119: axes#setYAxeLabelDisplayed(false); Chris@119: axes#setZAxeLabelDisplayed(true); Chris@119: axes#setZAxeLabel(unit); Chris@119: axes#setXTickProvider(new StaticTickProvider(ticks)); Chris@119: axes#setXTickRenderer(tickLabels); Chris@119: axes#setYTickLabelDisplayed(false); Chris@119: ChartLauncher#openChart(chart); Chris@119: ()); Chris@119: Chris@124: plotLines xkeys unit values = Chris@124: (chart = new Chart(Quality#Nicest); Chris@124: scene = chart#getScene(); Chris@124: keys = keys values; Chris@124: n = length xkeys; Chris@124: var z = 0; Chris@124: for keys do k: Chris@124: v = values[k]; Chris@124: x = new float[n]; Chris@124: y = new float[n]; Chris@124: var i = 0; Chris@124: for xkeys do xk: Chris@124: x[i] := i; Chris@124: y[i] := if xk in v then v[xk] else 0 fi; Chris@124: i := i + 1; Chris@124: done; Chris@124: line = new FlatLine2d(x, y, z); Chris@124: line#setWireframeDisplayed(true); Chris@124: line#setWireframeColor(Color#random()); Chris@124: line#setWireframeWidth(2); Chris@124: line#setFaceDisplayed(false); Chris@124: scene#add(line); Chris@124: z := z + 1; Chris@124: done; Chris@124: chart#getView()#setViewPoint(new Coord3d(0, 0, 0)); Chris@124: axes = chart#getAxeLayout(); Chris@124: axes#setXAxeLabelDisplayed(false); Chris@124: axes#setYAxeLabelDisplayed(false); Chris@124: axes#setZAxeLabelDisplayed(true); Chris@124: axes#setZAxeLabel(unit); Chris@124: axes#setYTickLabelDisplayed(false); Chris@124: ChartLauncher#openChart(chart); Chris@124: ()); Chris@124: Chris@125: stack keys xkeys values = Chris@127: (stacked = mapIntoHash id \(mapIntoHash id \{ y0 = 0, y1 = 0 } xkeys) keys; Chris@125: prev = mapIntoHash id \0 xkeys; Chris@125: for xkeys do xk: Chris@125: for keys do k: Chris@125: value = if xk in values[k] then values[k][xk] else 0 fi; Chris@125: height = prev[xk] + value; Chris@127: stacked[k][xk] := { y0 = prev[xk], y1 = height }; Chris@125: prev[xk] := height; Chris@125: done; Chris@125: done; Chris@125: stacked); Chris@125: Chris@125: plotStacked keys xkeys unit values = Chris@128: (quality = Quality#Nicest; Chris@128: quality#setAnimated(false); Chris@128: chart = new Chart(quality); Chris@125: scene = chart#getScene(); Chris@125: stacked = stack keys xkeys values; Chris@125: var z = 0; Chris@127: newRect x y0 y1 z colour is number -> number -> number -> number -> ~Color -> 'a = Chris@126: (poly = new Quad(); Chris@127: poly#add(new Point(new Coord3d(x + 0.5, z, y0))); Chris@127: poly#add(new Point(new Coord3d(x + 0.5, z, y1))); Chris@127: poly#add(new Point(new Coord3d(x - 0.5, z, y1))); Chris@127: poly#add(new Point(new Coord3d(x - 0.5, z, y0))); Chris@126: poly#setWireframeDisplayed(true); Chris@126: poly#setWireframeColor(colour); Chris@126: poly#setFaceDisplayed(true); Chris@126: poly#setColor(colour); Chris@126: poly); Chris@125: for keys do k: Chris@127: ranges = stacked[k]; Chris@125: var x = 0; Chris@128: var ty = 0; Chris@126: c = Color#random(); Chris@125: for xkeys do xk: Chris@127: rect = newRect x ranges[xk].y0 ranges[xk].y1 z c; Chris@127: scene#add(rect); Chris@125: x := x + 1; Chris@125: done; Chris@128: text = new DrawableTextBitmap(k, new Coord3d(0, z, ty), c); Chris@128: scene#add(text); Chris@126: z := z - 1; Chris@128: ty := ty + 10; Chris@125: done; Chris@127: chart#getView()#setViewPoint(new Coord3d(pi/2, 0, 0)); Chris@125: axes = chart#getAxeLayout(); Chris@125: axes#setXAxeLabelDisplayed(false); Chris@125: axes#setYAxeLabelDisplayed(false); Chris@125: axes#setZAxeLabelDisplayed(true); Chris@125: axes#setZAxeLabel(unit); Chris@125: axes#setYTickLabelDisplayed(false); Chris@125: ChartLauncher#openChart(chart); Chris@125: ()); Chris@124: Chris@110: plotStructure structure = Chris@110: case structure of Chris@110: Grid matrix: Chris@115: plotMatrix matrix; Chris@110: //!!! Chris@110: _: failWith "Cannot plot this structure (only grids implemented so far)"; Chris@110: esac; Chris@108: Chris@115: { Chris@119: newMatrixMapper, Chris@119: newMatrixLogMapper, Chris@119: newMapper, Chris@115: plotMatrix, Chris@124: plotBarChart, Chris@124: plotLines, Chris@125: stack, Chris@125: plotStacked, Chris@119: plotStructure, Chris@115: } Chris@110: