Mercurial > hg > jslab
diff src/samer/tools/ScatterPlot.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/tools/ScatterPlot.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2001, Samer Abdallah, King's College London. + * All rights reserved. + * + * This software is provided AS iS and WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + */ + +package samer.tools; + +import samer.core.*; +import samer.core.types.*; +import samer.core.util.*; +//import samer.maths.*; +import java.util.*; +import java.awt.*; + +/** + Builds up a 2D joint histogram of 2 elements of a vector. +*/ + +public class ScatterPlot extends Plotter implements Observer { + public VDouble alpha, fade,marksz; + Pen pen; + Color fader; + + public ScatterPlot() + { + exposeMaps(); + + alpha=new VDouble("alpha",0.1); + fade=new VDouble("fade",0.02); + marksz=new VDouble("blob",2); + marksz.addObserver(this); + fade.addObserver(this); + alpha.addObserver(this); + fader=VColor.withAlpha(getBackground(),fade.value); + setForeground(VColor.withAlpha(getForeground(),alpha.value)); + } + + public void update(Graphics g) { Shell.print("update"); } + public void paint(Graphics g) { + Shell.print("paint"); + g.setColor(VColor.withAlpha(getForeground(),255)); + g.fillRect(0,0,width,height); + } + + public void dispose() { + alpha.dispose(); + fade.dispose(); + marksz.dispose(); +// super.dispose(); + } + + public void plot(double x, double y) { + pen.abs(x,y).marker(); + } + + public void fade() { + graphics.setColor(fader); + graphics.fillRect(0,0,width,height); + graphics.setColor(getForeground()); + } + + protected void sized() + { + super.sized(); + + Graphics2D g2=(Graphics2D)graphics; + g2.setComposite(AlphaComposite.SrcOver); + g2.setPaint(getForeground()); + pen=getPen(g2); + pen.setMarkerSize((int)marksz.value); + } + + public void update(Observable o, Object a) + { + if (o==marksz) pen.setMarkerSize((int)marksz.value); + else if (o==fade) fader=VColor.withAlpha(getBackground(),fade.value); + else if (o==alpha) { + setForeground(VColor.withAlpha(getForeground(),alpha.value)); + } + } +/* + public Task vecTask(final Vec v, final int _i, final int _j) { + return new AnonymousTask() { + int i=_i, j=_j; + double [] x=v.array(); + public void run() { plot(x[i],x[j]); } + }; + } + */ +} + +