forked from yannrichet/jmathplot
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlot.java
More file actions
274 lines (221 loc) · 7.57 KB
/
Plot.java
File metadata and controls
274 lines (221 loc) · 7.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package org.math.plot.plots;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.LinkedList;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.math.plot.DataPanel;
import org.math.plot.MatrixTablePanel;
import org.math.plot.canvas.PlotCanvas;
import org.math.plot.plotObjects.Editable;
import org.math.plot.plotObjects.Noteable;
import org.math.plot.plotObjects.Plotable;
import org.math.plot.render.AbstractDrawer;
import org.math.plot.utils.Array;
public abstract class Plot implements Plotable, Noteable, Editable {
public String name;
public Color[] colors;
public boolean visible = true;
public LinkedList<LayerPlot> layers;
public boolean noted = false;
public double[] coordNoted;
//public boolean forcenoted = false;
public int note_precision = 5;
public Plot(String n, Color[] c) {
name = n;
colors = c;
layers = new LinkedList<LayerPlot>();
}
public Plot(String n, Color c) {
name = n;
colors = new Color[] { c };
layers = new LinkedList<LayerPlot>();
}
public void clearLayers() {
layers.clear();
}
public void addLayer(LayerPlot q) {
layers.add(q);
}
public void addQuantile(QuantileLayerPlot q) {
layers.add(q);
}
public void addQuantile(int a, double r, double[] q, boolean symetric) {
layers.add(new QuantileLayerPlot(this, a, q, r, symetric));
}
public void addQuantile(int a, double r, double q, boolean symetric) {
layers.add(new QuantileLayerPlot(this, a, q, r, symetric));
}
public void addQuantiles(int a, double[][] q) {
layers.add(new DensityLayerPlot(this, a, q));
}
public void addQuantiles(int a, double[] q) {
layers.add(new DensityLayerPlot(this, a, q));
}
public void addGaussQuantiles(int a, double[] s) {
layers.add(new GaussianDensityLayerPlot(this, a, s));
}
public void addGaussQuantiles(int a, double s) {
layers.add(new GaussianDensityLayerPlot(this, a, s));
}
/*public void addQuantiles(double[][][] q,boolean _symetric) {
for (int i = 0; i < q[0].length; i++) {
addQuantile(i, Array.getColumnCopy(q, i, 0),_symetric);
addQuantile(i, Array.getColumnCopy(q, i, 1),_symetric);
}
}*/
/*public void addQuantiles(double[][] q,boolean _symetric) {
for (int i = 0; i < q[0].length; i++) {
addQuantile(i, Array.getColumnCopy(q, i),_symetric);
}
}*/
public void addVector(double[][] v) {
layers.add(new VectorLayerPlot(this, v));
}
public abstract void setData(double[][] d);
public abstract double[][] getData();
public double[] getBounds(int axis) {
return Array.getColumnCopy(getBounds(), axis);
}
/**This method should be abstract, but for backward compatibility, here is a basic impl.*/
public double[][] getBounds() {
return Array.mergeRows(Array.min(getData()), Array.max(getData()));
}
public void setVisible(boolean v) {
visible = v;
}
public boolean getVisible() {
return visible;
}
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
/*
* public String getType() { return type; }
*/
public Color getColor() {
return colors[0];
}
public void setColor(Color c) {
colors[0] = c;
}
public Color[] getColors() {
return colors;
}
public void setColors(Color[] c) {
colors = c;
}
public abstract double[] isSelected(int[] screenCoordTest, AbstractDrawer draw);
public void note(AbstractDrawer draw) {
Color[] c = new Color [] { PlotCanvas.NOTE_COLOR };
plot(draw, c);
plotLayerPlots(draw, c);
}
public void noteCoord(AbstractDrawer draw, double[] coordNoted) {
if (coordNoted == null) {
return;
}
draw.setColor(PlotCanvas.NOTE_COLOR);
draw.drawCoordinate(coordNoted);
draw.drawShadowedText(Array.cat("\n", draw.canvas.reverseMapedData(coordNoted)), .5f, coordNoted);
}
public abstract void plot(AbstractDrawer draw, Color[] c);
public void plot(AbstractDrawer draw) {
//if (layers.size() > 0)
plotLayerPlots(draw, colors);
//else
plot(draw, colors);
}
public void plotLayerPlots(AbstractDrawer draw, Color[] c) {
for (int i = 0; i < layers.size(); i++) {
layers.get(i).plot(draw, c);
}
}
public void edit(Object src) {
((PlotCanvas) src).displayDataFrame(((PlotCanvas) src).getPlotIndex(this));
}
public void editnote(AbstractDrawer draw) {
Color[] c = new Color [] { PlotCanvas.NOTE_COLOR };
plot(draw, c);
plotLayerPlots(draw, c);
}
public DataPanel datapanel = null;
public PlotCanvas plotCanvas;
public DataPanel getDataPanel(PlotCanvas plotCanvas) {
this.plotCanvas = plotCanvas;
if (datapanel == null) {
datapanel = new DefaultDataPanel(this);
}
return datapanel;
}
public class DefaultDataPanel extends DataPanel {
private static final long serialVersionUID = 1L;
MatrixTablePanel XY;
JCheckBox visible;
JButton color;
JPanel plottoolspanel;
Plot plot;
//DataFrame dframe;
public DefaultDataPanel(/*DataFrame _dframe,*/Plot _plot) {
plot = _plot;
//dframe = _dframe;
visible = new JCheckBox("Visible");
visible.setSelected(plot.getVisible());
color = new JButton();
color.setBackground(plot.getColor());
XY = new MatrixTablePanel(plotCanvas.reverseMapedData(plot.getData()));
visible.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (visible.isSelected()) {
plot.setVisible(true);
} else {
plot.setVisible(false);
}
plotCanvas.linkedLegendPanel.updateLegends();
/*dframe.*/ plotCanvas.repaint();
}
});
color.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Color c = JColorChooser.showDialog(plotCanvas, "Choose plot color", plot.getColor());
color.setBackground(c);
plot.setColor(c);
plotCanvas.linkedLegendPanel.updateLegends();
/*dframe.*/ plotCanvas.linkedLegendPanel.repaint();
/*dframe.*/ plotCanvas.repaint();
}
});
this.setLayout(new BorderLayout());
plottoolspanel = new JPanel();
plottoolspanel.add(visible);
plottoolspanel.add(color);
this.add(plottoolspanel, BorderLayout.NORTH);
this.add(XY, BorderLayout.CENTER);
}
@Override
protected void toWindow() {
XY.toWindow();
}
@Override
public void toClipBoard() {
XY.toClipBoard();
}
@Override
public void toASCIIFile(File file) {
XY.toASCIIFile(file);
}
public String getText() {
return XY.getText();
}
}
}