forked from yannrichet/jmathplot
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBoxPlot3D.java
More file actions
170 lines (145 loc) · 6.52 KB
/
BoxPlot3D.java
File metadata and controls
170 lines (145 loc) · 6.52 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
package org.math.plot.plots;
import java.awt.*;
import javax.swing.JFrame;
import org.math.plot.FrameView;
import org.math.plot.Plot3DPanel;
import org.math.plot.PlotPanel;
import org.math.plot.render.*;
import org.math.plot.utils.Array;
public class BoxPlot3D extends Plot {
double[] Xmin;
double[] Xmax;
double[] Ymin;
double[] Ymax;
double[] Zmin;
double[] Zmax;
double[][] widths;
double[][] XY;
public BoxPlot3D(double[][] _XY, double[][] w, Color c, String n) {
this(_XY, w, new Color[] { c }, n);
}
public BoxPlot3D(double[][] _XY, double[][] w, Color[] c, String n) {
super(n, c);
XY = _XY;
widths = w;
// double[] datasMin = Array.min(XY);
// double[] datasMax = Array.max(XY);
// double[] widthsMax = Array.max(widths);
// double[] min = { datasMin[0] - widthsMax[0] / 2, datasMin[1] -
// widthsMax[1] / 2, datasMin[2] - widthsMax[2] / 2 };
// double[] max = { datasMax[0] + widthsMax[0] / 2, datasMax[1] +
// widthsMax[1] / 2, datasMax[2] + widthsMax[2] / 2 };
// base.includeInBounds(min);
// base.includeInBounds(max);
Xmin = new double[XY.length];
Xmax = new double[XY.length];
Ymin = new double[XY.length];
Ymax = new double[XY.length];
Zmin = new double[XY.length];
Zmax = new double[XY.length];
for (int i = 0; i < XY.length; i++) {
Xmin[i] = XY[i][0] - widths[i][0] / 2;
Xmax[i] = XY[i][0] + widths[i][0] / 2;
Ymin[i] = XY[i][1] - widths[i][1] / 2;
Ymax[i] = XY[i][1] + widths[i][1] / 2;
Zmin[i] = XY[i][2] - widths[i][2] / 2;
Zmax[i] = XY[i][2] + widths[i][2] / 2;
}
}
public void plot(AbstractDrawer draw, Color[] c) {
if (!visible) {
return;
}
boolean monoColor = false;
if (c.length == 1) {
monoColor = true;
}
else if (c.length != XY.length) {
throw new IllegalArgumentException("Color array length must match length of data array length. ");
}
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length; i++) {
draw.setColor(monoColor ? c[0] : c[i]);
draw.drawLine(new double[]{Xmin[i], Ymin[i], Zmin[i]}, new double[]{Xmax[i], Ymin[i], Zmin[i]});
draw.drawLine(new double[]{Xmax[i], Ymin[i], Zmin[i]}, new double[]{Xmax[i], Ymax[i], Zmin[i]});
draw.drawLine(new double[]{Xmax[i], Ymax[i], Zmin[i]}, new double[]{Xmin[i], Ymax[i], Zmin[i]});
draw.drawLine(new double[]{Xmin[i], Ymax[i], Zmin[i]}, new double[]{Xmin[i], Ymin[i], Zmin[i]});
draw.drawLine(new double[]{Xmin[i], Ymin[i], Zmax[i]}, new double[]{Xmax[i], Ymin[i], Zmax[i]});
draw.drawLine(new double[]{Xmax[i], Ymin[i], Zmax[i]}, new double[]{Xmax[i], Ymax[i], Zmax[i]});
draw.drawLine(new double[]{Xmax[i], Ymax[i], Zmax[i]}, new double[]{Xmin[i], Ymax[i], Zmax[i]});
draw.drawLine(new double[]{Xmin[i], Ymax[i], Zmax[i]}, new double[]{Xmin[i], Ymin[i], Zmax[i]});
draw.drawLine(new double[]{Xmin[i], Ymin[i], Zmin[i]}, new double[]{Xmin[i], Ymin[i], Zmax[i]});
draw.drawLine(new double[]{Xmax[i], Ymin[i], Zmin[i]}, new double[]{Xmax[i], Ymin[i], Zmax[i]});
draw.drawLine(new double[]{Xmin[i], Ymax[i], Zmin[i]}, new double[]{Xmin[i], Ymax[i], Zmax[i]});
draw.drawLine(new double[]{Xmax[i], Ymax[i], Zmin[i]}, new double[]{Xmax[i], Ymax[i], Zmax[i]});
draw.drawDot(XY[i]);
}
}
@Override
public void setData(double[][] d) {
datapanel = null;
XY = d;
}
@Override
public double[][] getData() {
return XY;
}
@Override
public double[][] getBounds() {
return new double[][]{{Array.min(Xmin), Array.min(Ymin), Array.min(Zmin)}, {Array.max(Xmax), Array.max(Ymax), Array.max(Zmax)}};
}
public void setDataWidth(double[][] w) {
widths = w;
}
public double[][] getDataWidth() {
return widths;
}
public void setData(double[][] d, double[][] w) {
setData(d);
widths = w;
}
public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
for (int i = 0; i < XY.length; i++) {
int[] screenCoord = draw.project(XY[i]);
if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
&& (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1])) {
return XY[i];
}
}
return null;
}
public static void main(String[] args) {
Plot3DPanel plotpanel = new Plot3DPanel();
for (int i = 0; i < 1; i++) {
double[][] receiverXYZ = new double[100][6];
for (int j = 0; j < receiverXYZ.length; j++) {
receiverXYZ[j][0] = /*1 + */ Math.random();
receiverXYZ[j][1] = /*100 * */ Math.random();
receiverXYZ[j][2] = /*100 * */ Math.random();
receiverXYZ[j][3] = /*1 + */ Math.random() / 10;
receiverXYZ[j][4] = /*100 * */ Math.random() / 10;
receiverXYZ[j][5] = /*100 * */ Math.random() / 10;
}
int receiverPlotDataIndex = plotpanel.addBoxPlot("Receivers", Color.orange, receiverXYZ);
}
plotpanel.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(plotpanel).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
plotpanel = new Plot3DPanel();
for (int i = 0; i < 1; i++) {
double[][] receiverXYZ = new double[100][6];
Color[] c = new Color[100];
for (int j = 0; j < receiverXYZ.length; j++) {
receiverXYZ[j][0] = /*1 + */ Math.random();
receiverXYZ[j][1] = /*100 * */ Math.random();
receiverXYZ[j][2] = /*100 * */ Math.random();
receiverXYZ[j][3] = /*1 + */ Math.random() / 10;
receiverXYZ[j][4] = /*100 * */ Math.random() / 10;
receiverXYZ[j][5] = /*100 * */ Math.random() / 10;
c[j] = new Color((int)(Math.random() * 0x1000000));
}
int receiverPlotDataIndex = plotpanel.addBoxPlot("Receivers", c, receiverXYZ);
}
plotpanel.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(plotpanel).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}