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