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