Mercurial > hg > jslab
comparison src/samer/tools/ScatterPlot.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 /* | |
2 * Copyright (c) 2001, Samer Abdallah, King's College London. | |
3 * All rights reserved. | |
4 * | |
5 * This software is provided AS iS and WITHOUT ANY WARRANTY; | |
6 * without even the implied warranty of MERCHANTABILITY or | |
7 * FITNESS FOR A PARTICULAR PURPOSE. | |
8 */ | |
9 | |
10 package samer.tools; | |
11 | |
12 import samer.core.*; | |
13 import samer.core.types.*; | |
14 import samer.core.util.*; | |
15 //import samer.maths.*; | |
16 import java.util.*; | |
17 import java.awt.*; | |
18 | |
19 /** | |
20 Builds up a 2D joint histogram of 2 elements of a vector. | |
21 */ | |
22 | |
23 public class ScatterPlot extends Plotter implements Observer { | |
24 public VDouble alpha, fade,marksz; | |
25 Pen pen; | |
26 Color fader; | |
27 | |
28 public ScatterPlot() | |
29 { | |
30 exposeMaps(); | |
31 | |
32 alpha=new VDouble("alpha",0.1); | |
33 fade=new VDouble("fade",0.02); | |
34 marksz=new VDouble("blob",2); | |
35 marksz.addObserver(this); | |
36 fade.addObserver(this); | |
37 alpha.addObserver(this); | |
38 fader=VColor.withAlpha(getBackground(),fade.value); | |
39 setForeground(VColor.withAlpha(getForeground(),alpha.value)); | |
40 } | |
41 | |
42 public void update(Graphics g) { Shell.print("update"); } | |
43 public void paint(Graphics g) { | |
44 Shell.print("paint"); | |
45 g.setColor(VColor.withAlpha(getForeground(),255)); | |
46 g.fillRect(0,0,width,height); | |
47 } | |
48 | |
49 public void dispose() { | |
50 alpha.dispose(); | |
51 fade.dispose(); | |
52 marksz.dispose(); | |
53 // super.dispose(); | |
54 } | |
55 | |
56 public void plot(double x, double y) { | |
57 pen.abs(x,y).marker(); | |
58 } | |
59 | |
60 public void fade() { | |
61 graphics.setColor(fader); | |
62 graphics.fillRect(0,0,width,height); | |
63 graphics.setColor(getForeground()); | |
64 } | |
65 | |
66 protected void sized() | |
67 { | |
68 super.sized(); | |
69 | |
70 Graphics2D g2=(Graphics2D)graphics; | |
71 g2.setComposite(AlphaComposite.SrcOver); | |
72 g2.setPaint(getForeground()); | |
73 pen=getPen(g2); | |
74 pen.setMarkerSize((int)marksz.value); | |
75 } | |
76 | |
77 public void update(Observable o, Object a) | |
78 { | |
79 if (o==marksz) pen.setMarkerSize((int)marksz.value); | |
80 else if (o==fade) fader=VColor.withAlpha(getBackground(),fade.value); | |
81 else if (o==alpha) { | |
82 setForeground(VColor.withAlpha(getForeground(),alpha.value)); | |
83 } | |
84 } | |
85 /* | |
86 public Task vecTask(final Vec v, final int _i, final int _j) { | |
87 return new AnonymousTask() { | |
88 int i=_i, j=_j; | |
89 double [] x=v.array(); | |
90 public void run() { plot(x[i],x[j]); } | |
91 }; | |
92 } | |
93 */ | |
94 } | |
95 | |
96 |