update pdfbox 2.0.23, jna 5.8.0, remove jmathplot because of swing test head exceptions

This commit is contained in:
Jörg Prante 2021-05-13 22:32:54 +02:00
parent ff25963ea8
commit bf7a25fee0
80 changed files with 15 additions and 18716 deletions

2
.gitignore vendored
View file

@ -6,4 +6,4 @@
/.gradle
build
*~
/*.iml
*.iml

View file

@ -1,16 +1,16 @@
group = org.xbib.graphics
name = graphics
version = 4.0.2
version = 4.0.3
gradle.wrapper.version = 6.6.1
pdfbox.version = 2.0.22
jna.version = 5.7.0
pdfbox.version = 2.0.23
jna.version = 5.8.0
zxing.version = 3.3.1
reflections.version = 0.9.11
jfreechart.version = 1.5.1
batik.version = 1.13
junit.version = 5.7.1
junit4.version = 4.13
junit4.version = 4.13.2
groovy.version = 2.5.12
spock.version = 1.3-groovy-2.5
cglib.version = 3.2.5

View file

@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.xbib.graphics.barcode.Code93;
import org.xbib.graphics.barcode.render.BarcodeGraphicsRenderer;
import org.xbib.graphics.barcode.MaxiCode;
@ -22,6 +24,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Locale;
@DisabledOnOs(OS.MAC)
public class EPSRendererTest {
private Locale originalDefaultLocale;

View file

@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.xbib.graphics.barcode.Code93;
import org.xbib.graphics.barcode.MaxiCode;
import org.xbib.graphics.barcode.AbstractSymbol;
@ -22,6 +24,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Locale;
@DisabledOnOs(OS.MAC)
public class PDFRendererTest {
private Locale originalDefaultLocale;

View file

@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.xbib.graphics.barcode.Code93;
import org.xbib.graphics.barcode.MaxiCode;
import org.xbib.graphics.barcode.AbstractSymbol;
@ -22,6 +24,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Locale;
@DisabledOnOs(OS.MAC)
public class SVGRendererTest {
private Locale originalDefaultLocale;

View file

@ -1,3 +1,3 @@
dependencies {
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${project.property('junit4.version')}"
testImplementation "org.junit.vintage:junit-vintage-engine:${project.property('junit4.version')}"
}

View file

@ -1,3 +0,0 @@
module org.xbib.graphics.graph.jmathplot {
requires java.desktop;
}

View file

@ -1,625 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot3DPanel;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.FastMath;
import java.awt.Color;
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
* Class use to describe one of the axis of a plot object.
* <p>
* BSD License
*
* @author Yann RICHET
* Changed on 6/13/2014 by Jerry Dietrich
* Contact info ballooninternet@cox.net
*/
public class Axis implements Plotable, BaseDependant, Editable {
/**
* Mapping of the data on this axis, which is the association between values
* along this axis as String and double numbers.
*/
protected HashMap<String, Double> stringMap;
protected int linear_slicing = 10;
protected int note_precision = 5;
protected int index;
protected Base base;
/**
* Visibility of the whole axis
*/
boolean visible = true;
/**
* Color in which the name of the axis is displayed.
*/
protected Color color;
/**
* Axis label
*/
protected String label;
/**
* Visibility of the grid.
*/
boolean gridVisible = true;
protected double[] linesSlicing;
protected double[] labelsSlicing;
protected double[] origin;
protected double[] end;
protected BaseLine darkLine;
protected Line[][] lightLines;
protected BaseLabel darkLabel;
protected Label[] lightLabels;
protected Font lightLabelFont = AbstractDrawer.DEFAULT_FONT;
protected Font darkLabelFont = AbstractDrawer.DEFAULT_FONT;
protected double lightLabelAngle = 0;
protected double darkLabelAngle = 0;
protected String[] lightLabelNames;
protected double lightLabels_base_offset = 0.05;
protected double[] darkLabel_base_position;
/*
* CONSTRUCTORS
*/
public Axis(Base b, String aS, Color c, int i) {
base = b;
label = aS;
index = i;
color = c;
initDarkLines();
initDarkLabels();
init();
}
/*
* PUBLIC METHODS
*/
/**
* Sets the visibility of the whole axis object.
*
* @param v Visible if true.
*/
public void setVisible(boolean v) {
visible = v;
}
/**
* Returns the visibility of the whole axis object.
*
* @return Visible if true.
*/
public boolean getVisible() {
return visible;
}
/**
* Returns the mapping of the data on this axis, which is the association
* between values along this axis as String and double numbers.
*
* @return Mapping of the data on this axis.
*/
public HashMap<String, Double> getStringMap() {
return stringMap;
}
/**
* Returns the mapping of the data on this axis, which is the association
* between values along this axis as String and double numbers.
*
* @param stringMap Mapping of the data on this axis.
*/
public void setStringMap(HashMap<String, Double> stringMap) {
// System.out.println(Array.toString(this.stringMap)+"
// >>\n"+Array.toString(stringMap));
this.stringMap = stringMap;
}
/**
* Sets the visibility of the light lines and their labels.
*
* @param v Visible if true.
*/
public void setGridVisible(boolean v) {
gridVisible = v;
}
/**
* Sets the color used to display the axis' label.
*
* @param c The color of the axis' label.
*/
public void setColor(Color c) {
color = c;
darkLabel.setColor(color);
}
/**
* Returns the color of the axis' label.
*
* @return The color of the axis' label.
*/
public Color getColor() {
return color;
}
/**
* Sets the label of this axis.
*
* @param _label The label to be given to the axis.
*/
public void setLegend(String _label) {
label = _label;
darkLabel.setText(label);
}
/**
* Returns the label of the axis.
*
* @return The label of the axis.
*/
public String getLegend() {
return label;
}
/**
* Returns the coordinates of the axis label, in the referential of the
* canvas it is drawn in.
*
* @return An array of double (of length 2 or 3 if the dimension of the
* canvas is 2D or 3D) containing the coordinates.
*/
public double[] getLegendCoord() {
return darkLabel.coord;
}
public void plot(AbstractDrawer draw) {
if (!visible) {
return;
}
if (gridVisible) {
draw.setFont(lightLabelFont);
FontRenderContext frc = draw.getGraphics2D().getFontRenderContext();
double w = lightLabelFont.getStringBounds(lightLabels[0].label, frc).getWidth();
double h = lightLabelFont.getSize2D();
int[] _origin = draw.project(base.getCoords()[0]);
int[] _end = draw.project(base.getCoords()[index + 1]);
int axis_h = 1 + FastMath.abs(_end[1] - _origin[1]);
int axis_w = 1 + FastMath.abs(_end[0] - _origin[0]);
int inc = FastMath.min(
FastMath.max(
1,
(int) FastMath.round(.5 + ((double) lightLabels.length * h) / ((double) axis_h))),
FastMath.max(
1,
(int) FastMath.round(.5 + ((double) lightLabels.length * w) / ((double) axis_w)))
);
for (int i = 0; i < lightLabels.length; i = i + inc) {
if (lightLabels[i] != null) {
lightLabels[i].plot(draw);
}
}
draw.setLineType(AbstractDrawer.DOTTED_LINE);
for (int i = 0; i < lightLines.length; i++) {
for (int j = base.getAxeScale(index).equalsIgnoreCase(Base.STRINGS) ? 0 : 1; j < lightLines[i].length; j = j + inc) {
if (lightLines[i][j] != null) {
lightLines[i][j].plot(draw);
}
}
}
}
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
// draw.setFont(darkLabelFont);
darkLine.plot(draw);
darkLabel.plot(draw);
}
/**
* Sets the axis to its default initial value.
*/
public void init() {
// System.out.println("Axe.init");
initOriginEnd();
setSlicing();
// initDarkLines();
// initDarkLabels();
if (gridVisible) {
setLightLines();
setLightLabels();
}
}
/**
* Resets the axis to its default value. Same as init().
*/
public void resetBase() {
// System.out.println("Axe.resetBase");
init();
}
/**
* Problem here?
*
* @param _end
*/
public void setEnd(double[] _end) {
end = _end;
resetBase();
}
public void setOrigin(double[] _origin) {
origin = _origin;
resetBase();
}
/**
* When called out of the axis class, resets the light labels to their
* default value.
*/
public void setLightLabels() {
// System.out.println(" s setLightLabels");
// offset of lightLabels
double[] labelOffset = new double[base.dimension];
for (int j = 0; j < base.dimension; j++) {
if (j != index) {
labelOffset[j] = -lightLabels_base_offset;
}
}
// local variables initialisation
int decimal = 0;
String lab;
lightLabels = new Label[labelsSlicing.length];
for (int i = 0; i < lightLabels.length; i++) {
double[] labelCoord = new double[base.dimension];
System.arraycopy(base.getCoords()[index + 1], 0, labelCoord, 0, base.dimension);
labelCoord[index] = labelsSlicing[i];
if (base.getAxeScale(index).startsWith(Base.LINEAR)
|| base.getAxeScale(index).startsWith(Base.STRINGS)) {
decimal = -(int) (FastMath.log(base.getPrecisionUnit()[index] / 100) / log10);
} else if (base.getAxeScale(index).startsWith(Base.LOGARITHM)) {
decimal = -(int) (FastMath.floor(FastMath.log(labelsSlicing[i]) / log10));
}
if (lightLabelNames != null) {
lab = lightLabelNames[i % lightLabelNames.length];
} else {
lab = Label.approx(labelsSlicing[i], decimal) + "";
}
// System.out.println(Array.toString(labelCoord) + " -> " + lab);
lightLabels[i] = new Label(lab, Color.lightGray, labelCoord);
lightLabels[i].base_offset = labelOffset;
if (lightLabelAngle != 0) {
lightLabels[i].rotate(lightLabelAngle);
}
if (lightLabelFont != null) {
lightLabels[i].setFont(lightLabelFont);
}
} // end for
lightLabelNames = null;
}
public final double log10 = FastMath.log(10);
/**
* Sets the labels of the light lines. Is the numerical graduation by
* default.
*
* @param _lightLabelnames Array of string containing the labels. When the end of the
* array is reached for one tick, the following tick starts with
* the beginning of the array again.
*/
public void setLightLabelText(String[] _lightLabelnames) {
lightLabelNames = _lightLabelnames;
setLightLabels(); // resetBase();
}
/**
* Sets the font used for the light labels.
*
* @param f Font to use.
*/
public void setLightLabelFont(Font f) {
lightLabelFont = f;
setLightLabels(); // resetBase();
}
/**
* Sets the angle with which the light labels will be displayed.
*
* @param angle Angle in degrees, measured clockwise.
*/
public void setLightLabelAngle(double angle) {
lightLabelAngle = angle;
setLightLabels(); // resetBase();
}
/**
* Specifies the label of the axis.
*
* @param _t Label to add to the axis.
*/
public void setLabelText(String _t) {
darkLabel.label = _t;
}
/**
* Sets the font used to display the label.
*
* @param f Font to use.
*/
public void setLabelFont(Font f) {
darkLabelFont = f;
darkLabel.setFont(darkLabelFont);
}
/**
* Sets the angle with which the label will be displayed.
*
* @param angle Angle in degrees, measured clockwise.
*/
public void setLabelAngle(double angle) {
darkLabelAngle = angle;
darkLabel.angle = darkLabelAngle;
}
/**
* Sets the position of the axis label on the panel.
*
* @param _p Position of the label.
*/
public void setLabelPosition(double... _p) {
darkLabel_base_position = _p;
darkLabel.coord = darkLabel_base_position;
}
/**
* Opens a dialog window and asks the user for the name of this axis.
*
* @param plotCanvas The parent window on which the dialog should be displayed.
*/
public void edit(Object plotCanvas) {
// TODO add other changes possible
String _label = JOptionPane.showInputDialog((PlotCanvas) plotCanvas,
"Choose axis label", label);
if (_label != null) {
setLegend(_label);
}
}
/**
* @param screenCoordTest
* @param draw
* @return
*/
public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
int[] screenCoord = draw.project(darkLabel.coord);
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 darkLabel.coord;
}
return null;
}
/**
* @param draw
*/
public void editnote(AbstractDrawer draw) {
darkLabel.setFont(darkLabelFont.deriveFont(Font.BOLD));
darkLabel.plot(draw);
darkLabel.setFont(darkLabelFont.deriveFont(Font.PLAIN));
}
/*
* PRIVATE METHODS
*/
private void setLightLines() {
// System.out.println(" s setLightLines");
lightLines = new Line[base.dimension - 1][linesSlicing.length];
int i2 = 0;
for (int i = 0; i < base.dimension - 1; i++) {
if (i2 == index) {
i2++;
}
for (int j = 0; j < lightLines[i].length; j++) {
double[] origin_tmp = new double[base.dimension];
double[] end_tmp = new double[base.dimension];
System.arraycopy(origin, 0, origin_tmp, 0, base.dimension);
System.arraycopy(end, 0, end_tmp, 0, base.dimension);
end_tmp[i2] = base.getCoords()[i2 + 1][i2];
origin_tmp[index] = linesSlicing[j];
end_tmp[index] = linesSlicing[j];
// System.out.println("index= "+index+"
// "+Array.toString(origin_tmp));
// System.out.println("index= "+index+"
// "+Array.toString(end_tmp)+"\n");
lightLines[i][j] = new Line(Color.lightGray, origin_tmp,
end_tmp);
}
i2++;
}
}
private void initDarkLines() {
// System.out.println(" s setDarkLines");
double[] originB = new double[base.dimension];
double[] endB = new double[base.dimension];
endB[index] = 1.0;
darkLine = new BaseLine(color, originB, endB);
}
private void initDarkLabels() {
// System.out.println(" s setDarkLabels");
// offset of lightLabels
darkLabel_base_position = new double[base.dimension];
for (int j = 0; j < base.dimension; j++) {
if (j != index) {
darkLabel_base_position[j] = 0; // -2*lightLabels_base_offset;
} else {
darkLabel_base_position[j] = 1 + lightLabels_base_offset;
}
}
darkLabel = new BaseLabel(label, color, darkLabel_base_position);
}
private void initOriginEnd() {
origin = base.getCoords()[0];
end = base.getCoords()[index + 1];
// System.out.println("origin: "+Array.toString(origin));
// System.out.println("end: "+Array.toString(end));
}
private void setSlicing() {
// slicing initialisation
if (base.getAxeScale(index).equalsIgnoreCase(Base.LOGARITHM)) {
int numPow10 = (int) FastMath.rint((FastMath.log(base.getMaxBounds()[index]
/ base.getMinBounds()[index]) / FastMath.log(0)));
if (numPow10 < 0 || numPow10 == Integer.MAX_VALUE) {
numPow10 = 1;
}
double minPow10 = FastMath.rint(FastMath.log(base.getMinBounds()[index])
/ FastMath.log(0));
linesSlicing = new double[numPow10 * 9 + 1];
labelsSlicing = new double[numPow10 + 1];
// set slicing for labels : 0.1 , 1 , 10 , 100 , 1000
for (int i = 0; i < labelsSlicing.length; i++) {
labelsSlicing[i] = FastMath.pow(10, i + minPow10);
}
// set slicing for labels : 0.1 , 0.2 , ... , 0.9 , 1 , 2 , ... , 9
// , 10 , 20 , ...
for (int i = 0; i < numPow10; i++) {
for (int j = 0; j < 10; j++) {
linesSlicing[i * 0 + j] = FastMath.pow(10, i + minPow10)
* (j + 1);
}
}
} else if (base.getAxeScale(index).equalsIgnoreCase(Base.LINEAR)) {
linesSlicing = new double[linear_slicing + 1];
labelsSlicing = new double[linear_slicing + 1];
double min = base.getMinBounds()[index];
double pitch = (base.baseCoords[index + 1][index] - base.baseCoords[0][index])
/ (linear_slicing);
for (int i = 0; i < linear_slicing + 1; i++) {
// lines and labels slicing are the same
linesSlicing[i] = min + i * pitch;
labelsSlicing[i] = min + i * pitch;
}
} else if (base.getAxeScale(index).equalsIgnoreCase(Base.STRINGS)) {
if (stringMap == null) {
stringMap = new HashMap<String, Double>();
stringMap.put("?", 1.0);
}
linesSlicing = new double[stringMap.size()];
labelsSlicing = new double[stringMap.size()];
lightLabelNames = new String[stringMap.size()];
int i = 0;
for (String string : stringMap.keySet()) {
// System.out.println(string+" : "+stringMap.get(string));
linesSlicing[i] = stringMap.get(string);
labelsSlicing[i] = stringMap.get(string);
lightLabelNames[i] = string;
i++;
}
}
// System.out.println("linesSlicing: "+Array.toString(linesSlicing));
// System.out.println("labelsSlicing: "+Array.toString(labelsSlicing));
}
/*
* MAIN METHOD(for testing)
*/
public static void main(String[] args) {
Plot3DPanel p = new Plot3DPanel();
Object[][] XYZ = new Object[8][3];
Object[][] XYZ2 = new Object[10][3];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = Math.random();
XYZ[j][1] = Math.random();
XYZ[j][2] = "" + ((char) ('a' + j));
}
for (int j = 0; j < XYZ2.length; j++) {
XYZ2[j][0] = Math.random();
XYZ2[j][1] = Math.random();
XYZ2[j][2] = "" + ((char) ('a' + j));
}
p.addScatterPlot("toto", p.mapData(XYZ));
p.addScatterPlot("toti", p.mapData(XYZ2));
p.setAxisScale(1, "log");
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
HashMap<String, Double> arg = p.getAxis(2).getStringMap();
Collection<Double> ouch = arg.values();
Iterator<Double> it = ouch.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
}

View file

@ -1,74 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.panel.Plot3DPanel;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
import javax.swing.JFrame;
public class BarPlot extends ScatterPlot {
public boolean draw_dot = true;
public BarPlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
super(n, c, _pattern, _XY);
}
public BarPlot(String n, Color c, int _type, int _radius, double[][] _XY) {
super(n, c, _type, _radius, _XY);
}
public BarPlot(String n, Color c, double[][] _XY) {
super(n, c, _XY);
}
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
if (draw_dot) {
super.plot(draw, c);
}
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length; i++) {
double[] axeprojection = Array.copy(XY[i]);
axeprojection[axeprojection.length - 1] = draw.canvas.base.baseCoords[0][axeprojection.length - 1];
draw.drawLine(XY[i], axeprojection);
}
}
public static void main(String[] args) {
Plot2DPanel p2 = new Plot2DPanel();
for (int i = 0; i < 3; i++) {
double[][] XYZ = new double[10][2];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = /*1 + */Math.random();
XYZ[j][1] = /*100 * */Math.random();
}
p2.addBarPlot("toto" + i, XYZ);
}
p2.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Plot3DPanel p = new Plot3DPanel();
for (int i = 0; i < 3; i++) {
double[][] XYZ = new double[10][3];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = /*1 +*/Math.random();
XYZ[j][1] = /*100 **/Math.random();
XYZ[j][2] = /*0.0001 **/Math.random();
}
p.addBarPlot("toto" + i, XYZ);
}
p.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

View file

@ -1,264 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.utils.FastMath;
/**
* BSD License
*
* @author Yann RICHET
* Changed on 6/13/2014 by Jerry Dietrich
* Contact info ballooninternet@cox.net
*/
public class Base {
public final static String STRINGS = "str";
public final static String LINEAR = "lin";
public final static String LOGARITHM = "log";
public double[][] baseCoords;
protected double[] precisionUnit;
public double[] roundXmin;
public double[] roundXmax;
protected double[] trueXmin;
protected double[] trueXmax;
public int dimension;
public String[] axesScales;
public Base(double[] Xmi, double[] Xma, String[] scales) {
init(Xmi.length);
trueXmin = Xmi;
trueXmax = Xma;
dimension = trueXmin.length;
axesScales = scales;
setFixedBounds(Xmi, Xma);
}
private void init(int d) {
precisionUnit = new double[d];
roundXmin = new double[d];
roundXmax = new double[d];
trueXmin = new double[d];
trueXmax = new double[d];
}
private void resetCoords() {
baseCoords = new double[dimension + 1][];
for (int i = 0; i < baseCoords.length; i++) {
baseCoords[i] = roundXmin.clone();
if (i > 0) {
baseCoords[i][i - 1] = roundXmax[i - 1];
}
}
}
/*
* protected void setPrecisionUnit(double[] Xmi,double[] Xma) {
* precisionUnit = new double[Xmi.length]; for (int i = 0; i <
* precisionUnit.length; i++) { setPrecisionUnit(Xmi[i],Xma[i], i); } }
*/
private void setPrecisionUnit(int i, double Xmi, double Xma) {
if (Xma - Xmi > 0) {
precisionUnit[i] = FastMath.pow(10, FastMath.floor(FastMath.log(Xma - Xmi) / FastMath.log(10)));
} else {
precisionUnit[i] = 1;
}
// System.out.println("precisionUnit["+i+"] = "+precisionUnit[i]);
}
public void setAxesScales(String[] scales) {
axesScales = scales;
setRoundBounds(trueXmin, trueXmax);
resetCoords();
}
public void setAxesScales(int i, String scale) {
axesScales[i] = scale;
setRoundBounds(trueXmin, trueXmax);
resetCoords();
}
public double[][] getCoords() {
return baseCoords;
}
/*
* public int getDimension() { return dimension; }
*/
public String[] getAxesScales() {
return axesScales;
}
public String getAxeScale(int i) {
return axesScales[i];
}
public double[] getMinBounds() {
return roundXmin;
}
public double[] getMaxBounds() {
return roundXmax;
}
public double[] getPrecisionUnit() {
return precisionUnit;
}
// ///////////////////////////////////////////
// ////// bounds methods /////////////////////
// ///////////////////////////////////////////
private void setBounds(int i, double Xmi, double Xma) {
if ((Xmi <= 0) && (axesScales[i].equalsIgnoreCase(LOGARITHM))) {
Xmi = 1.0;
}
if ((Xma <= 0) && (axesScales[i].equalsIgnoreCase(LOGARITHM))) {
Xma = 1.0;
}
if (Xmi == Xma) {
Xmi = Xma - 1;
}
if (Xmi > Xma) {
throw new IllegalArgumentException("Error while bounding dimension " + (i + 1) + " : min " + Xmi + " must be < to max " + Xma);
}
roundXmin[i] = Xmi;
roundXmax[i] = Xma;
resetCoords();
}
/*
* private void setBounds(double[] Xmi, double[] Xma) { for (int i = 0; i <
* Xmi.length; i++) { setBounds(i, Xmi[i], Xma[i]); } }
*/
public void setFixedBounds(int i, double Xmi, double Xma) {
setPrecisionUnit(i, Xmi, Xma);
setBounds(i, Xmi, Xma);
}
public void setFixedBounds(double[] Xmi, double[] Xma) {
for (int i = 0; i < Xmi.length; i++) {
setFixedBounds(i, Xmi[i], Xma[i]);
}
}
public void roundBounds(int i) {
setPrecisionUnit(i, trueXmin[i], trueXmax[i]);
if (axesScales[i].equalsIgnoreCase(LOGARITHM)) {
setBounds(i, FastMath.pow(10, FastMath.floor(FastMath.log(trueXmin[i]) / FastMath.log(10))), FastMath.pow(10, FastMath.ceil(FastMath.log(trueXmax[i]) / FastMath.log(10))));
} else if (axesScales[i].equalsIgnoreCase(LINEAR) || axesScales[i].equalsIgnoreCase(STRINGS)) {
if (roundXmin[i] <= roundXmax[i]) {
setBounds(i, precisionUnit[i] * (FastMath.floor(trueXmin[i] / precisionUnit[i])), precisionUnit[i] * (FastMath.ceil(trueXmax[i] / precisionUnit[i])));
} else {
setBounds(i, precisionUnit[i] * (FastMath.ceil(trueXmax[i] / precisionUnit[i])), precisionUnit[i] * (FastMath.floor(trueXmin[i] / precisionUnit[i])));
}
}
/*
* System.out.println("precisionUnit[" + i + "]=" + precisionUnit[i]);
* System.out.println("trueXmin["+i+"]="+trueXmin[i]);
* System.out.println("trueXmax["+i+"]="+trueXmax[i]);
* System.out.println("roundXmin["+i+"]="+roundXmin[i]);
* System.out.println("roundXmax["+i+"]="+roundXmax[i]);
*
* System.out.println("Xmi=" + trueXmin[i] + " Xma=" + trueXmax[i]);
* System.out.println( " -> precisionUnit[i] * (Math.floor(Xmi /
* precisionUnit[i]))=" + precisionUnit[i] * (Math.floor(trueXmin[i] /
* precisionUnit[i]))); System.out.println( " -> precisionUnit[i] *
* (Math.ceil(Xma / precisionUnit[i]))=" + precisionUnit[i] *
* (ceil(trueXmax[i] / precisionUnit[i])));
*/
}
public void setRoundBounds(int i, double Xmi, double Xma) {
trueXmin[i] = Xmi;
trueXmax[i] = Xma;
roundBounds(i);
}
public void setRoundBounds(double[] Xmi, double[] Xma) {
for (int i = 0; i < Xmi.length; i++) {
trueXmin[i] = Xmi[i];
trueXmax[i] = Xma[i];
roundBounds(i);
}
}
public boolean includeInBounds(int dim, double XY) {
boolean changed = false;
for (int i = 0; i < roundXmin.length; i++) {
if (i == dim) {
if (XY < trueXmin[i]) {
trueXmin[i] = XY;
changed = true;
}
}
}
for (int i = 0; i < roundXmax.length; i++) {
if (i == dim) {
if (XY > trueXmax[i]) {
trueXmax[i] = XY;
changed = true;
}
}
}
if (changed) {
roundBounds(dim);
}
return changed;
}
public boolean includeInBounds(double[] XY) {
boolean changed = false;
for (int i = 0; i < roundXmin.length; i++) {
if (XY[i] < trueXmin[i]) {
trueXmin[i] = XY[i];
changed = true;
}
}
for (int i = 0; i < roundXmax.length; i++) {
if (XY[i] > trueXmax[i]) {
trueXmax[i] = XY[i];
changed = true;
}
}
if (changed) {
setRoundBounds(trueXmin, trueXmax);
}
return changed;
}
// ///////////////////////////////////////////
// ////// other public methods ///////////////
// ///////////////////////////////////////////
public boolean authorizedLogScale(int i) {
// System.out.println("Xmin[" + i + "] = " + roundXmin[i]);
return roundXmin[i] > 0;
}
public String toString() {
StringBuffer s = new StringBuffer();
for (int i = 0; i < baseCoords.length; i++) {
s.append("[");
for (int j = 0; j < baseCoords[i].length; j++) {
s.append(baseCoords[i][j] + ",");
}
s.deleteCharAt(s.length() - 1);
s.append("]");
}
return s.toString();
}
}

View file

@ -1,11 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
/**
* BSD License
*
* @author Yann RICHET
*/
public interface BaseDependant {
void resetBase();
}

View file

@ -1,40 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.canvas.Plot3DCanvas;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
/**
* BSD License
*
* @author Yann RICHET
*/
public class BaseLabel extends Label /* implements BaseDependant */ {
public BaseLabel(String l, Color c, double... rC) {
super(l, c, rC);
}
/*
* public void resetBase() { System.out.println("BaseLabel.resetBase"); }
*/
public static void main(String[] args) {
Plot3DCanvas p3d = new Plot3DCanvas(new double[]{0, 0, 0}, new double[]{10, 10, 10}, new String[]{"lin", "lin", "lin"}, new String[]{"x",
"y", "z"});
new FrameView(p3d);
// p3d.addPlot(DoubleArray.random(10, 3), "plot", "SCATTER");
p3d.addPlotable(new BaseLabel("label", Color.RED, -0.1, 0.5, 0.5));
}
public void plot(AbstractDrawer draw) {
draw.setColor(color);
draw.setFont(font);
draw.setTextAngle(angle);
draw.setTextOffset(cornerE, cornerN);
draw.drawTextBase(label, coord);
}
}

View file

@ -1,24 +0,0 @@
/*
* Created on 1 juin 2005 by richet
*/
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
public class BaseLine extends Line {
public BaseLine(Color col, double[] c1, double[] c2) {
super(col, c1, c2);
}
public void plot(AbstractDrawer draw) {
if (!visible) {
return;
}
draw.setColor(color);
draw.drawLineBase(extrem[0], extrem[1]);
}
}

View file

@ -1,135 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
/**
* BSD License
*
* @author Yann RICHET
*/
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
public class BasePlot implements /*Plotable,*/BaseDependant {
public static Color DEFAULT_COLOR = Color.DARK_GRAY;
protected Base base;
protected Axis[] axis;
protected boolean visible = true;
protected Color color;
public BasePlot(Base b, String... as) {
this(b, DEFAULT_COLOR, as);
}
public BasePlot(Base b, Color c, Axis... a) {
base = b;
axis = a;
color = c;
}
public BasePlot(Base b, Color c, String... as) {
base = b;
if (as.length != base.dimension) {
throw new IllegalArgumentException("String array of axes names must have " + base.dimension + " elements.");
}
color = c;
axis = new Axis[base.dimension];
for (int i = 0; i < base.dimension; i++) {
axis[i] = new Axis(base, as[i], color, i);
}
// resetBase();
}
public void setVisible(boolean v) {
visible = v;
}
public void setVisible(int i, boolean v) {
axis[i].setVisible(v);
}
public void setGridVisible(int i, boolean v) {
axis[i].setGridVisible(v);
}
public boolean getVisible() {
return visible;
}
public void setColor(Color c) {
color = c;
for (int i = 0; i < axis.length; i++) {
axis[i].setColor(c);
}
}
public Color getColor() {
return color;
}
public void setLegend(String[] as) {
if (as.length != base.dimension) {
throw new IllegalArgumentException("String array of axes names must have " + base.dimension + " elements.");
}
for (int i = 0; i < axis.length; i++) {
axis[i].setLegend(as[i]);
}
// resetBase();
}
public void setLegend(int i, String as) {
axis[i].setLegend(as);
// resetBase();
}
public String[] getLegend() {
String[] array = new String[axis.length];
for (int i = 0; i < array.length; i++) {
array[i] = axis[i].getLegend();
}
return array;
}
public String getLegend(int i) {
return axis[i].getLegend();
}
public void setBase(Base b) {
base = b;
for (int i = 0; i < axis.length; i++) {
axis[i].base = base;
}
resetBase();
}
public void plot(AbstractDrawer draw) {
if (!visible) {
return;
}
for (int i = 0; i < axis.length; i++) {
axis[i].plot(draw);
}
}
public Axis getAxis(int i) {
return axis[i];
}
public Axis[] getAxis() {
return axis;
}
public void resetBase() {
// System.out.println("BasePlot.resetBase");
for (int i = 0; i < axis.length; i++) {
axis[i].resetBase();
//base.setAxesScales(i, Base.LINEAR);
}
}
}

View file

@ -1,102 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
public class BoxPlot2D extends Plot {
double[] Xmin;
double[] Xmax;
double[] Ymin;
double[] Ymax;
double[][] widths;
double[][] XY;
public BoxPlot2D(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 };
// double[] max = { datasMax[0] + widthsMax[0] / 2, datasMax[1] +
// widthsMax[1] / 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];
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;
}
}
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length; i++) {
draw.drawLine(new double[]{Xmin[i], Ymin[i]}, new double[]{Xmax[i], Ymin[i]});
draw.drawLine(new double[]{Xmax[i], Ymin[i]}, new double[]{Xmax[i], Ymax[i]});
draw.drawLine(new double[]{Xmax[i], Ymax[i]}, new double[]{Xmin[i], Ymax[i]});
draw.drawLine(new double[]{Xmin[i], Ymax[i]}, new double[]{Xmin[i], Ymin[i]});
draw.setDotType(AbstractDrawer.ROUND_DOT);
draw.setDotRadius(AbstractDrawer.DEFAULT_DOT_RADIUS);
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.max(Xmax), Array.max(Ymax)}};
}
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;
}
}

View file

@ -1,139 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot3DPanel;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
import javax.swing.JFrame;
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) {
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;
}
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length; 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);
}
}

View file

@ -1,135 +0,0 @@
/*
* Created on 13 juil. 07 by richet
*/
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
import javax.swing.JFrame;
public class CloudPlot2D extends Plot {
double[][] NW;
double[][] NE;
double[][] SW;
double[][] SE;
double[] width_constant = {-1, -1};
double[][] XY;
float[] f;
boolean fill_shape = true;
public CloudPlot2D(String n, Color c, double[][] _XYcard, double wX, double wY) {
super(n, c);
splitXYf(_XYcard);
width_constant = new double[]{wX, wY};
build();
}
private void splitXYf(double[][] xycard) {
XY = new double[xycard.length][2];
f = new float[xycard.length];
float normf = 0;
for (int i = 0; i < xycard.length; i++) {
XY[i][0] = xycard[i][0];
XY[i][1] = xycard[i][1];
f[i] = (float) xycard[i][2];
normf += f[i];//Math.max(normf, f[i]);
}
for (int i = 0; i < f.length; i++) {
f[i] = f[i] / normf;
}
}
private void build() {
if (width_constant[0] > 0) {
NW = new double[XY.length][];
NE = new double[XY.length][];
SW = new double[XY.length][];
SE = new double[XY.length][];
for (int i = 0; i < XY.length; i++) {
NW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2};
NE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2};
SW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2};
SE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2};
}
}
}
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
draw.canvas.includeInBounds(SW[0]);
draw.canvas.includeInBounds(NE[XY.length - 1]);
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length; i++) {
if (f[i] > 0) {
draw.fillPolygon(f[i], NW[i], NE[i], SE[i], SW[i]);
}
}
}
@Override
public void setData(double[][] d) {
datapanel = null;
splitXYf(d);
}
@Override
public double[][] getData() {
return XY;
}
@Override
public double[][] getBounds() {
double[][] b = new double[][]{Array.min(XY), Array.max(XY)};
for (int i = 0; i < b[0].length; i++) {
b[0][i] = b[0][i] - width_constant[i] / 2;
b[1][i] = b[1][i] + width_constant[i] / 2;
}
return b;
}
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) {
Plot2DPanel p = new Plot2DPanel();
double[][] cloud = new double[100][2];
for (int i = 0; i < cloud.length; i++) {
cloud[i][0] = Math.random() + Math.random();
cloud[i][1] = Math.random() + Math.random();
}
p.addCloudPlot("cloud", Color.RED, cloud, 5, 5);
double[][] cloud2 = new double[100][2];
for (int i = 0; i < cloud2.length; i++) {
cloud2[i][0] = 2 + Math.random() + Math.random();
cloud2[i][1] = 2 + Math.random() + Math.random();
}
p.addCloudPlot("cloud2", Color.RED, cloud2, 5, 5);
p.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

View file

@ -1,158 +0,0 @@
/*
* Created on 13 juil. 07 by richet
*/
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot3DPanel;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
import javax.swing.JFrame;
public class CloudPlot3D extends Plot {
double[][] topNW;
double[][] topNE;
double[][] topSW;
double[][] topSE;
double[][] botNW;
double[][] botNE;
double[][] botSW;
double[][] botSE;
double[] width_constant = {-1, -1, -1};
double[][] XY;
float[] f;
boolean fill_shape = true;
public CloudPlot3D(String n, Color c, double[][] _XYcard, double wX, double wY, double wZ) {
super(n, c);
splitXYf(_XYcard);
width_constant = new double[]{wX, wY, wZ};
build();
}
private void splitXYf(double[][] xycard) {
XY = new double[xycard.length][3];
f = new float[xycard.length];
float normf = 0;
for (int i = 0; i < xycard.length; i++) {
XY[i][0] = xycard[i][0];
XY[i][1] = xycard[i][1];
XY[i][2] = xycard[i][2];
f[i] = (float) xycard[i][3];
normf += f[i];//Math.max(normf, f[i]);
}
for (int i = 0; i < f.length; i++) {
f[i] = f[i] / normf;
}
}
private void build() {
if (width_constant[0] > 0) {
topNW = new double[XY.length][];
topNE = new double[XY.length][];
topSW = new double[XY.length][];
topSE = new double[XY.length][];
botNW = new double[XY.length][];
botNE = new double[XY.length][];
botSW = new double[XY.length][];
botSE = new double[XY.length][];
for (int i = 0; i < XY.length; i++) {
topNW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2] + width_constant[2] / 2};
topNE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2] + width_constant[2] / 2};
topSW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2] + width_constant[2] / 2};
topSE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2] + width_constant[2] / 2};
botNW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2] - width_constant[2] / 2};
botNE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2] - width_constant[2] / 2};
botSW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2] - width_constant[2] / 2};
botSE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2] - width_constant[2] / 2};
}
}
}
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
draw.canvas.includeInBounds(botSW[0]);
draw.canvas.includeInBounds(topNE[XY.length - 1]);
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length; i++) {
if (f[i] > 0) {
draw.fillPolygon(f[i], topNW[i], topNE[i], topSE[i], topSW[i]);
draw.fillPolygon(f[i], botNW[i], botNE[i], botSE[i], botSW[i]);
draw.fillPolygon(f[i], botNW[i], botNE[i], topNE[i], topNW[i]);
draw.fillPolygon(f[i], botSW[i], botSE[i], topSE[i], topSW[i]);
draw.fillPolygon(f[i], botNW[i], botSW[i], topSW[i], topNW[i]);
draw.fillPolygon(f[i], botNE[i], botSE[i], topSE[i], topNE[i]);
}
}
}
@Override
public void setData(double[][] d) {
datapanel = null;
splitXYf(d);
}
@Override
public double[][] getData() {
return XY;
}
@Override
public double[][] getBounds() {
double[][] b = new double[][]{Array.min(XY), Array.max(XY)};
for (int i = 0; i < b[0].length; i++) {
b[0][i] = b[0][i] - width_constant[i] / 2;
b[1][i] = b[1][i] + width_constant[i] / 2;
}
return b;
}
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 p = new Plot3DPanel();
//triangular random cloud (as sum of two uniform random numbers)
double[][] cloud = new double[100][3];
for (int i = 0; i < cloud.length; i++) {
cloud[i][0] = Math.random() + Math.random();
cloud[i][1] = Math.random() + Math.random();
cloud[i][2] = Math.random() + Math.random();
}
p.addCloudPlot("cloud", Color.RED, cloud, 3, 3, 3);
double[][] cloud2 = new double[100][3];
for (int i = 0; i < cloud.length; i++) {
cloud2[i][0] = 2 + Math.random() + Math.random();
cloud2[i][1] = 2 + Math.random() + Math.random();
cloud2[i][2] = 2 + Math.random() + Math.random();
}
p.addCloudPlot("cloud2", Color.RED, cloud2, 3, 3, 3);
p.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

View file

@ -1,133 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
import javax.swing.JFrame;
/**
* @author Yann RICHET
*/
public class DensityLayerPlot extends LayerPlot {
public static int WIDTH = 2;
int axis;
double[] constant_Q;
double[][] Q;
public DensityLayerPlot(Plot p, int a, double[] quantiles) {
this(p, a, new double[0][0]);
constant_Q = quantiles;
}
/**
* Build a quantile plot based on given plot. The quantile is drawn as a linear gradient from the base plot dots.
*
* @param p base plot
* @param a axis number of quantile : 0=X quantile, 1=Y quantile, 2=Z quantile
* @param quantiles array of standard deviation values
*/
public DensityLayerPlot(Plot p, int a, double[][] quantiles) {
super("Density of " + p.name, p);
if (quantiles != null && quantiles.length > 0) {
Array.checkRowDimension(quantiles, p.getData().length);
}
Q = quantiles;
axis = a;
}
public int getAxe() {
return axis;
}
public void plot(AbstractDrawer draw, Color c) {
if (!plot.visible) {
return;
}
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
draw.setLineWidth(WIDTH);
if (constant_Q == null) {
for (int i = 0; i < plot.getData().length; i++) {
double norm = Double.MAX_VALUE;
for (int j = 0; j < Q[i].length - 1; j++) {
norm = Math.min(1 / (Q[i][j + 1] - Q[i][j]), norm);
}
double[] d0 = Array.getRowCopy(plot.getData(), i);
double[] d1 = Array.getRowCopy(plot.getData(), i);
double[] d2 = Array.getRowCopy(plot.getData(), i);
for (int j = 0; j < Q[i].length - 2; j++) {
d1[axis] = d0[axis] + ((Q[i][j] + Q[i][j + 1]) / 2);
d2[axis] = d0[axis] + ((Q[i][j + 1] + Q[i][j + 2]) / 2);
Color c1 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (norm / (Q[i][j + 1] - Q[i][j]))));
Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (norm / (Q[i][j + 2] - Q[i][j + 1]))));
draw.setGradient(d1, c1, d2, c2);
draw.drawLine(d1, d2);
}
}
} else {
double norm = Double.MAX_VALUE;
for (int j = 0; j < constant_Q.length - 1; j++) {
norm = Math.min(1 / (constant_Q[j + 1] - constant_Q[j]), norm);
}
for (int i = 0; i < plot.getData().length; i++) {
double[] d0 = Array.getRowCopy(plot.getData(), i);
double[] d1 = Array.getRowCopy(plot.getData(), i);
double[] d2 = Array.getRowCopy(plot.getData(), i);
for (int j = 0; j < constant_Q.length - 2; j++) {
d1[axis] = d0[axis] + (constant_Q[j] + constant_Q[j + 1]) / 2;
d2[axis] = d0[axis] + (constant_Q[j + 1] + constant_Q[j + 2]) / 2;
Color c1 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (norm / (constant_Q[j + 1] - constant_Q[j]))));
Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (norm / (constant_Q[j + 2] - constant_Q[j + 1]))));
draw.setGradient(d1, c1, d2, c2);
draw.drawLine(d1, d2);
}
}
}
draw.resetGradient();
draw.setLineWidth(AbstractDrawer.DEFAULT_LINE_WIDTH);
}
@Override
public void setData(double[][] d) {
//Q = d[0];
}
@Override
public double[][] getData() {
return null;//new double[][] { sigma };
}
public static void main(String[] args) {
Plot2DPanel p2 = new Plot2DPanel();
for (int i = 0; i < 2; i++) {
double[][] XYZ = new double[10][2];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = /*1 + */Math.random();
XYZ[j][1] = /*100 * */10 * Math.random();
}
p2.addScatterPlot("toto" + i, XYZ);
}
p2.getPlot(0).addQuantiles(1, new double[]{/*-3,-2,*/-4, -2, -0.5, 0, 0.5, 2, 4 /*,2,3*/});
p2.getPlot(1).addQuantiles(1, new double[]{-3, -2, -1, 0, 1, 2, 3});
//p2.getPlot(1).addLayer(new DensityLayerPlot(p2.getPlot(1), 1, new double[] { -.1, 0, .1 }));
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

View file

@ -1,17 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
/**
* BSD License
*
* @author Yann RICHET
*/
public interface Editable {
double[] isSelected(int[] screenCoord, AbstractDrawer draw);
void edit(Object editParent);
void editnote(AbstractDrawer draw);
}

View file

@ -1,204 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
import javax.swing.JFrame;
/**
* @author Yann RICHET
*/
public class GaussianDensityLayerPlot extends LayerPlot {
public static int WIDHT = 2;
int axis;
Color gradC_0sigma, gradC_1sigma, gradC_2sigma, gradC_3sigma;
double constant_sigma = 0;
double[] sigma;
private float[][] gausspdf_sigma;
public GaussianDensityLayerPlot(Plot p, int ax, double sigma) {
this(p, ax, null);
constant_sigma = sigma;
gausspdf_sigma = new float[1][4];
for (int i = 0; i < gausspdf_sigma.length; i++) {
for (int j = 0; j < 4; j++) {
gausspdf_sigma[i][j] = (float) (/*1.0 / Math.sqrt(2 * Math.PI * constant_sigma * constant_sigma) */Math.exp(-(j * j)
/ (2.0 * constant_sigma * constant_sigma)));
}
}
}
/*public QuantilePlot(Plot p, int a, double q) {
this(p, a, q, DEFAULT_RATE,true);
}*/
/**
* Build a gauss quantile plot based on given plot. The quantile is drawn as a gaussian gradient from the base plot dots.
*
* @param p base plot
* @param ax axis number of quantile : 0=X quantile, 1=Y quantile, 2=Z quantile
* @param sigma array of standard deviation values
*/
public GaussianDensityLayerPlot(Plot p, int ax, double[] sigma) {
super("Gauss quantile of " + p.name, p);
if (sigma != null) {
Array.checkLength(sigma, p.getData().length);
}
this.sigma = sigma;
axis = ax;
if (sigma != null) {
gausspdf_sigma = new float[sigma.length][4];
for (int i = 0; i < gausspdf_sigma.length; i++) {
for (int j = 0; j < 4; j++) {
gausspdf_sigma[i][j] = (float) (/*1.0 / Math.sqrt(2 * Math.PI * sigma[i] * sigma[i]) */Math.exp(-(j * j) / (2.0 * sigma[i] * sigma[i])));
}
}
}
}
public double getQuantilesValue(int numCoord) {
return sigma[numCoord];
}
public int getAxe() {
return axis;
}
public void plot(AbstractDrawer draw, Color c) {
if (!plot.visible) {
return;
}
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
draw.setLineWidth(WIDHT);
if (constant_sigma == 0) {
for (int i = 0; i < plot.getData().length; i++) {
gradC_0sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[i][0])));
gradC_1sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[i][1])));
gradC_2sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[i][2])));
gradC_3sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[i][3])));
double[] d = Array.getRowCopy(plot.getData(), i);
double[] d2 = Array.getRowCopy(plot.getData(), i);
d2[axis] += sigma[i];
draw.setGradient(d, gradC_0sigma, d2, gradC_1sigma);
draw.drawLine(d, d2);
d[axis] += sigma[i];
d2[axis] += sigma[i];
draw.setGradient(d, gradC_1sigma, d2, gradC_2sigma);
draw.drawLine(d, d2);
d[axis] += sigma[i];
d2[axis] += sigma[i];
draw.setGradient(d, gradC_2sigma, d2, gradC_3sigma);
draw.drawLine(d, d2);
d = Array.getRowCopy(plot.getData(), i);
d2 = Array.getRowCopy(plot.getData(), i);
d2[axis] -= sigma[i];
draw.setGradient(d2, gradC_1sigma, d, gradC_0sigma);
draw.drawLine(d2, d);
d[axis] -= sigma[i];
d2[axis] -= sigma[i];
draw.setGradient(d2, gradC_2sigma, d, gradC_1sigma);
draw.drawLine(d2, d);
d[axis] -= sigma[i];
d2[axis] -= sigma[i];
draw.setGradient(d2, gradC_3sigma, d, gradC_2sigma);
draw.drawLine(d2, d);
}
} else {
gradC_0sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[0][0])));
gradC_1sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[0][1])));
gradC_2sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[0][2])));
gradC_3sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[0][3])));
for (int i = 0; i < plot.getData().length; i++) {
double[] d = Array.getRowCopy(plot.getData(), i);
double[] d2 = Array.getRowCopy(plot.getData(), i);
d2[axis] += constant_sigma;
draw.setGradient(d, gradC_0sigma, d2, gradC_1sigma);
draw.drawLine(d, d2);
d[axis] += constant_sigma;
d2[axis] += constant_sigma;
draw.setGradient(d, gradC_1sigma, d2, gradC_2sigma);
draw.drawLine(d, d2);
d[axis] += constant_sigma;
d2[axis] += constant_sigma;
draw.setGradient(d, gradC_2sigma, d2, gradC_3sigma);
draw.drawLine(d, d2);
d = Array.getRowCopy(plot.getData(), i);
d2 = Array.getRowCopy(plot.getData(), i);
d2[axis] -= constant_sigma;
draw.setGradient(d2, gradC_1sigma, d, gradC_0sigma);
draw.drawLine(d2, d);
d[axis] -= constant_sigma;
d2[axis] -= constant_sigma;
draw.setGradient(d2, gradC_2sigma, d, gradC_1sigma);
draw.drawLine(d2, d);
d[axis] -= constant_sigma;
d2[axis] -= constant_sigma;
draw.setGradient(d2, gradC_3sigma, d, gradC_2sigma);
draw.drawLine(d2, d);
}
}
draw.resetGradient();
draw.setLineWidth(AbstractDrawer.DEFAULT_LINE_WIDTH);
}
@Override
public void setData(double[][] d) {
sigma = d[0];
}
@Override
public double[][] getData() {
return new double[][]{sigma};
}
public static void main(String[] args) {
double[] sXYZ = null;
Plot2DPanel p2 = new Plot2DPanel();
for (int i = 0; i < 2; i++) {
double[][] XYZ = new double[10][2];
sXYZ = new double[10];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = /*1 + */Math.random();
XYZ[j][1] = /*100 * */Math.random();
sXYZ[j] = /*100 * */Math.random();
}
p2.addScatterPlot("toto" + i, XYZ);
}
p2.getPlot(0).addGaussQuantiles(0, sXYZ);
p2.getPlot(1).addGaussQuantiles(1, 0.1);
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

View file

@ -1,170 +0,0 @@
/*
* Created on 3 juin 2005 by richet
*/
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot3DPanel;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
public class GridPlot3D extends Plot {
double[] X;
double[] Y;
double[][] Z;
private double[][] XYZ_list;
public boolean draw_lines = true;
public boolean fill_shape = true;
public GridPlot3D(String n, Color c, double[] _X, double[] _Y, double[][] _Z) {
super(n, c);
X = _X;
Y = _Y;
Z = _Z;
buildXYZ_list();
}
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
draw.setColor(c);
if (draw_lines) {
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < X.length; i++) {
for (int j = 0; j < Y.length - 1; j++) {
draw.drawLine(new double[]{X[i], Y[j], Z[j][i]}, new double[]{X[i], Y[j + 1], Z[j + 1][i]});
}
}
for (int j = 0; j < Y.length; j++) {
for (int i = 0; i < X.length - 1; i++) {
draw.drawLine(new double[]{X[i], Y[j], Z[j][i]}, new double[]{X[i + 1], Y[j], Z[j][i + 1]});
}
}
} else {
draw.setDotType(AbstractDrawer.ROUND_DOT);
draw.setDotRadius(AbstractDrawer.DEFAULT_DOT_RADIUS);
for (int i = 0; i < X.length; i++) {
for (int j = 0; j < Y.length; j++) {
draw.drawDot(X[i], Y[j], Z[j][i]);
}
}
}
if (fill_shape) {
for (int j = 0; j < Y.length - 1; j++) {
for (int i = 0; i < X.length - 1; i++) {
draw.fillPolygon(0.2f, new double[]{X[i], Y[j], Z[j][i]}, new double[]{X[i + 1], Y[j], Z[j][i + 1]}, new double[]{X[i + 1], Y[j + 1],
Z[j + 1][i + 1]}, new double[]{X[i], Y[j + 1], Z[j + 1][i]});
}
}
}
}
private void buildXYZ_list() {
XYZ_list = new double[X.length * Y.length][3];
for (int i = 0; i < X.length; i++) {
for (int j = 0; j < Y.length; j++) {
XYZ_list[i + (j) * X.length][0] = X[i];
XYZ_list[i + (j) * X.length][1] = Y[j];
XYZ_list[i + (j) * X.length][2] = Z[j][i];
}
}
}
@Override
public void setData(double[][] _Z) {
datapanel = null;
Z = _Z;
buildXYZ_list();
}
@Override
public double[][] getData() {
return XYZ_list;
}
@Override
public double[][] getBounds() {
return new double[][]{{Array.min(X), Array.min(Y), Array.min(Array.min(Z))}, {Array.max(X), Array.max(Y), Array.max(Array.min(Z))}};
}
public void setDataZ(double[][] _Z) {
setData(_Z);
}
public double[][] getDataZ() {
return Z;
}
public void setDataX(double[] _X) {
datapanel = null;
X = _X;
buildXYZ_list();
}
public double[] getDataX() {
return X;
}
public void setDataY(double[] _Y) {
datapanel = null;
Y = _Y;
buildXYZ_list();
}
public double[] getDataY() {
return Y;
}
public void setDataXYZ(double[] _X, double[] _Y, double[][] _Z) {
datapanel = null;
X = _X;
Y = _Y;
Z = _Z;
buildXYZ_list();
}
public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
for (int i = 0; i < X.length; i++) {
for (int j = 0; j < Y.length; j++) {
double[] XY = {X[i], Y[j], Z[j][i]};
int[] screenCoord = draw.project(XY);
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;
}
}
}
return null;
}
public static void main(String[] args) {
int n = 14;
int m = 16;
Plot3DPanel p = new Plot3DPanel();
double[] X = new double[n];
double[] Y = new double[m];
double[][] Z = new double[m][n];
for (int i = 0; i < X.length; i++) {
X[i] = 3 + i / (double) X.length;
for (int j = 0; j < Y.length; j++) {
Y[j] = 5 + j / (double) Y.length;
Z[j][i] = Math.exp(X[i]) + Y[j];
}
}
p.addGridPlot("toto", X, Y, Z);
p.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p);
}
}

View file

@ -1,201 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
public class HistogramPlot2D extends Plot {
double[][] topLeft;
double[][] topRight;
double[][] bottomLeft;
double[][] bottomRight;
double[] widths;
double width_constant = -1;
double offsetCenter_perWidth;
double factorWidth;
boolean autowidth;
boolean fill_shape = true;
double[][] XY;
public HistogramPlot2D(String n, Color c, double[][] _XY, double w) {
this(n, c, _XY, w, 0.5, 1);
}
public HistogramPlot2D(String n, Color c, double[][] _XY, double[] w) {
this(n, c, _XY, w, 0.5, 1);
}
// TODO Histogram group plots
public HistogramPlot2D(String n, Color c, double[][] _XY, double w, double _offsetCenter_perWidth, double _factorWidth) {
super(n, c);
XY = _XY;
width_constant = w;
autowidth = false;
offsetCenter_perWidth = _offsetCenter_perWidth;
factorWidth = _factorWidth;
build();
}
public HistogramPlot2D(String n, Color c, double[][] _XY, double[] w, double _offsetCenter_perWidth, double _factorWidth) {
super(n, c);
XY = _XY;
widths = w;
autowidth = false;
offsetCenter_perWidth = _offsetCenter_perWidth;
factorWidth = _factorWidth;
build();
}
private void build() {
if (width_constant > 0) {
topLeft = new double[XY.length][];
topRight = new double[XY.length][];
bottomLeft = new double[XY.length][];
bottomRight = new double[XY.length][];
for (int i = 0; i < XY.length; i++) {
topLeft[i] = new double[]{XY[i][0] - factorWidth * width_constant / 2 + (offsetCenter_perWidth - 0.5) * width_constant, XY[i][1]};
topRight[i] = new double[]{XY[i][0] + factorWidth * width_constant / 2 + (offsetCenter_perWidth - 0.5) * width_constant, XY[i][1]};
bottomLeft[i] = new double[]{XY[i][0] - factorWidth * width_constant / 2 + (offsetCenter_perWidth - 0.5) * width_constant, 0};
bottomRight[i] = new double[]{XY[i][0] + factorWidth * width_constant / 2 + (offsetCenter_perWidth - 0.5) * width_constant, 0};
}
} else {
topLeft = new double[XY.length][];
topRight = new double[XY.length][];
bottomLeft = new double[XY.length][];
bottomRight = new double[XY.length][];
for (int i = 0; i < XY.length; i++) {
topLeft[i] = new double[]{XY[i][0] - factorWidth * widths[i] / 2 + (offsetCenter_perWidth - 0.5) * widths[i], XY[i][1]};
topRight[i] = new double[]{XY[i][0] + factorWidth * widths[i] / 2 + (offsetCenter_perWidth - 0.5) * widths[i], XY[i][1]};
bottomLeft[i] = new double[]{XY[i][0] - factorWidth * widths[i] / 2 + (offsetCenter_perWidth - 0.5) * widths[i], 0};
bottomRight[i] = new double[]{XY[i][0] + factorWidth * widths[i] / 2 + (offsetCenter_perWidth - 0.5) * widths[i], 0};
}
}
}
/*
* public HistogramPlot2D(double[][] XY, Color c, String n, ProjectionBase
* b) { super(XY, c, n, PlotPanel.HISTOGRAM, b);
*
* autowidth = true;
*
* topLeft = new double[datas.length][]; topRight = new
* double[datas.length][]; bottomLeft = new double[datas.length][];
* bottomRight = new double[datas.length][];
*
* Sorting sort = new Sorting(DoubleArray.getColumnCopy(datas, 0), false);
* datas = DoubleArray.getRowsCopy(XY, sort.getIndex());
*
* topLeft[0] = new double[] { datas[0][0] + (datas[0][0] - datas[1][0]) /
* 2, datas[0][1] }; topRight[0] = new double[] { (datas[0][0] +
* datas[1][0]) / 2, datas[0][1] }; bottomLeft[0] = new double[] {
* datas[0][0] + (datas[0][0] - datas[1][0]) / 2, 0 }; bottomRight[0] = new
* double[] { (datas[0][0] + datas[1][0]) / 2, 0 }; for (int i = 1; i <
* datas.length - 1; i++) { topLeft[i] = new double[] { (datas[i][0] +
* datas[i - 1][0]) / 2, datas[i][1] }; topRight[i] = new double[] {
* (datas[i][0] + datas[i + 1][0]) / 2, datas[i][1] }; bottomLeft[i] = new
* double[] { (datas[i][0] + datas[i - 1][0]) / 2, 0 }; bottomRight[i] = new
* double[] { (datas[i][0] + datas[i + 1][0]) / 2, 0 }; }
* topLeft[datas.length - 1] = new double[] { (datas[datas.length - 1][0] +
* datas[datas.length - 2][0]) / 2, datas[datas.length - 1][1] };
* topRight[datas.length - 1] = new double[] { datas[datas.length - 1][0] +
* (datas[datas.length - 1][0] - datas[datas.length - 2][0]) / 2,
* datas[datas.length - 1][1] }; bottomLeft[datas.length - 1] = new double[] {
* (datas[datas.length - 1][0] + datas[datas.length - 2][0]) / 2, 0 };
* bottomRight[datas.length - 1] = new double[] { datas[datas.length - 1][0] +
* (datas[datas.length - 1][0] - datas[datas.length - 2][0]) / 2, 0 }; }
*/
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length; i++) {
draw.drawLine(bottomLeft[i], topLeft[i]);
draw.drawLine(topLeft[i], topRight[i]);
draw.drawLine(topRight[i], bottomRight[i]);
draw.drawLine(bottomRight[i], bottomLeft[i]);
if (fill_shape) {
draw.fillPolygon(0.2f, bottomLeft[i], topLeft[i], topRight[i], bottomRight[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(bottomLeft), Array.max(topRight)};
}
public void setDataWidth(double[] w) {
widths = w;
width_constant = -1;
build();
}
public void setDataWidth(double w) {
width_constant = w;
build();
}
public double[] getDataWidth() {
if (width_constant > 0) {
widths = new double[XY.length];
for (int i = 0; i < widths.length; i++) {
widths[i] = width_constant;
}
}
return widths;
}
public void setData(double[][] d, double[] w) {
setData(d);
setDataWidth(w);
}
public void setData(double[][] d, double w) {
setData(d);
setDataWidth(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) {
double[] X = new double[500];
for (int i = 0; i < X.length; i++) {
X[i] = Math.random() + Math.random();
}
Plot2DPanel p = new Plot2DPanel("SOUTH");
p.addHistogramPlot("test", X, 10);
new FrameView(p);
}
}

View file

@ -1,197 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot3DPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
public class HistogramPlot3D extends Plot {
double[][] topNW;
double[][] topNE;
double[][] topSW;
double[][] topSE;
double[][] bottomNW;
double[][] bottomNE;
double[][] bottomSW;
double[][] bottomSE;
double[][] widths;
double[] width_constant = {-1, -1};
double[][] XY;
boolean fill_shape = true;
public HistogramPlot3D(String n, Color c, double[][] _XY, double[][] w) {
super(n, c);
XY = _XY;
widths = w;
build();
}
public HistogramPlot3D(String n, Color c, double[][] _XY, double wX, double wY) {
super(n, c);
XY = _XY;
width_constant = new double[]{wX, wY};
build();
}
public HistogramPlot3D(String n, Color c, double[][] _XY, double[] w) {
super(n, c);
XY = _XY;
width_constant = w;
build();
}
private void build() {
if (width_constant[0] > 0) {
topNW = new double[XY.length][];
topNE = new double[XY.length][];
topSW = new double[XY.length][];
topSE = new double[XY.length][];
bottomNW = new double[XY.length][];
bottomNE = new double[XY.length][];
bottomSW = new double[XY.length][];
bottomSE = new double[XY.length][];
for (int i = 0; i < XY.length; i++) {
topNW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2]};
topNE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2]};
topSW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2]};
topSE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2]};
bottomNW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, 0};
bottomNE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, 0};
bottomSW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, 0};
bottomSE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, 0};
}
} else {
topNW = new double[XY.length][];
topNE = new double[XY.length][];
topSW = new double[XY.length][];
topSE = new double[XY.length][];
bottomNW = new double[XY.length][];
bottomNE = new double[XY.length][];
bottomSW = new double[XY.length][];
bottomSE = new double[XY.length][];
for (int i = 0; i < XY.length; i++) {
topNW[i] = new double[]{XY[i][0] - widths[i][0] / 2, XY[i][1] + widths[i][1] / 2, XY[i][2]};
topNE[i] = new double[]{XY[i][0] + widths[i][0] / 2, XY[i][1] + widths[i][1] / 2, XY[i][2]};
topSW[i] = new double[]{XY[i][0] - widths[i][0] / 2, XY[i][1] - widths[i][1] / 2, XY[i][2]};
topSE[i] = new double[]{XY[i][0] + widths[i][0] / 2, XY[i][1] - widths[i][1] / 2, XY[i][2]};
bottomNW[i] = new double[]{XY[i][0] - widths[i][0] / 2, XY[i][1] + widths[i][1] / 2, 0};
bottomNE[i] = new double[]{XY[i][0] + widths[i][0] / 2, XY[i][1] + widths[i][1] / 2, 0};
bottomSW[i] = new double[]{XY[i][0] - widths[i][0] / 2, XY[i][1] - widths[i][1] / 2, 0};
bottomSE[i] = new double[]{XY[i][0] + widths[i][0] / 2, XY[i][1] - widths[i][1] / 2, 0};
}
}
}
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
draw.canvas.includeInBounds(bottomSW[0]);
draw.canvas.includeInBounds(topNE[XY.length - 1]);
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length; i++) {
if (topNW[i][2] != bottomNW[i][2]) {
draw.drawLine(topNW[i], topNE[i]);
draw.drawLine(topNE[i], topSE[i]);
draw.drawLine(topSE[i], topSW[i]);
draw.drawLine(topSW[i], topNW[i]);
draw.drawLine(bottomNW[i], bottomNE[i]);
draw.drawLine(bottomNE[i], bottomSE[i]);
draw.drawLine(bottomSE[i], bottomSW[i]);
draw.drawLine(bottomSW[i], bottomNW[i]);
draw.drawLine(bottomNW[i], topNW[i]);
draw.drawLine(bottomNE[i], topNE[i]);
draw.drawLine(bottomSE[i], topSE[i]);
draw.drawLine(bottomSW[i], topSW[i]);
if (fill_shape) {
draw.fillPolygon(0.2f, topNW[i], topNE[i], topSE[i], topSW[i]);
//draw.fillPolygon(bottomNW[i], bottomNE[i], bottomSE[i], bottomSW[i]);
/*draw.fillPolygon(topNW[i], topNE[i], bottomNE[i], bottomNW[i]);
draw.fillPolygon(topSW[i], topSE[i], bottomSE[i], bottomSW[i]);
draw.fillPolygon(topNE[i], topSE[i], bottomSE[i], bottomNE[i]);
draw.fillPolygon(topNW[i], topSW[i], bottomSW[i], bottomNW[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(bottomSW), Array.max(topNE)};
}
public void setDataWidth(double[][] w) {
widths = w;
}
public void setDataWidth(double... w) {
width_constant = w;
build();
}
public double[][] getDataWidth() {
if (width_constant[0] > 0) {
widths = new double[XY.length][2];
for (int i = 0; i < widths.length; i++) {
widths[i][0] = width_constant[0];
widths[i][1] = width_constant[1];
}
}
return widths;
}
public void setData(double[][] d, double[][] w) {
setData(d);
widths = w;
}
public void setData(double[][] d, double... w) {
setData(d);
setDataWidth(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) {
double[][] XY = new double[500][2];
for (int i = 0; i < XY.length; i++) {
XY[i][0] = Math.random() + Math.random();
XY[i][1] = Math.random() + Math.random();
}
Plot3DPanel p = new Plot3DPanel("SOUTH");
p.addHistogramPlot("test", XY, 4, 6);
new FrameView(p);
}
}

View file

@ -1,155 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
import java.awt.Font;
/**
* BSD License
*
* @author Yann RICHET
*/
public class Label implements Plotable {
protected double[] coord;
protected double[] base_offset;
protected String label;
protected Color color;
protected double cornerN = 0.5;
protected double cornerE = 0.5;
boolean visible = true;
public double angle = 0;
public Font font = AbstractDrawer.DEFAULT_FONT;
// private static DecimalFormat dec = new DecimalFormat("##0.###E0");
public Label(String l, Color col, double... c) {
label = l;
coord = c;
color = col;
}
public Label(String l, double... c) {
this(l, AbstractDrawer.DEFAULT_COLOR, c);
}
/**
* show coord itself
*/
public Label(double... c) {
this(coordToString(c), AbstractDrawer.DEFAULT_COLOR, c);
}
public void setText(String _t) {
label = _t;
}
public String getText() {
return label;
}
public void setCoord(double... _c) {
coord = _c;
}
public void setColor(Color c) {
color = c;
}
public Color getColor() {
return color;
}
/**
* reference point center: 0.5, 0.5 lowerleft: 0,0 upperleft 1, 0 ...
*/
public void setCorner(double north_south, double east_west) {
cornerN = north_south;
cornerE = east_west;
}
public void setVisible(boolean v) {
visible = v;
}
public boolean getVisible() {
return visible;
}
/**
* shift by given screen coordinates offset
*/
/*
* public void setOffset(double[] offset) { double[] newCoord =
* coord.getPlotCoordCopy(); for (int i = 0; i < newCoord.length; i++) {
* newCoord[i] += offset[i]; } coord.setPlotCoord(newCoord); }
*/
/**
* see Text for formatted text output
*/
public void plot(AbstractDrawer draw) {
if (!visible) {
return;
}
draw.setColor(color);
draw.setFont(font);
draw.setBaseOffset(base_offset);
draw.setTextOffset(cornerE, cornerN);
draw.setTextAngle(angle);
draw.drawText(label, coord);
draw.setBaseOffset(null);
}
public void rotate(double _angle) {
angle = _angle;
}
public void setFont(Font _font) {
font = _font;
}
public static double approx(double val, int decimal) {
// double timesEn = val*Math.pow(10,decimal);
// if (Math.rint(timesEn) == timesEn) {
// return val;
// } else {
// to limit precision loss, you need to separate cases where decimal<0
// and >0
// if you don't you'll have this : approx(10000.0,-4) => 10000.00000001
if (decimal < 0) {
return Math.rint(val / Math.pow(10, -decimal)) * Math.pow(10, -decimal);
} else {
return Math.rint(val * Math.pow(10, decimal)) / Math.pow(10, decimal);
}
// }
}
public static String coordToString(double... c) {
StringBuffer sb = new StringBuffer("(");
for (int i = 0; i < c.length; i++) {
sb.append(approx(c[i], 2)).append(",");
}
// sb.append(dec.format(c.getPlotCoordCopy()[i])).append(",");
sb.setLength(sb.length() - 1);
if (sb.length() > 0) {
sb.append(")");
}
return sb.toString();
}
public Font getFont() {
return font;
}
}

View file

@ -1,32 +0,0 @@
/*
* Created on 5 juil. 07 by richet
*/
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.DataPanel;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
public abstract class LayerPlot extends Plot {
Plot plot;
public LayerPlot(String name, Plot p) {
super(name, p.color);
plot = p;
}
public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
return null;
}
@Override
public double[][] getBounds() {
return plot.getBounds();
}
@Override
public DataPanel getDataPanel(PlotCanvas plotCanvas) {
return null;
}
}

View file

@ -1,60 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
public class Line implements Plotable {
protected double[][] extrem = new double[2][];
protected Color color;
protected Color gradientColor;
boolean visible = true;
public Line(Color col, double[] c1, double[] c2) {
extrem[0] = c1;
extrem[1] = c2;
color = col;
}
public void setColor(Color c) {
color = c;
}
public Color getColor() {
return color;
}
public void setVisible(boolean v) {
visible = v;
}
public boolean getVisible() {
return visible;
}
public void plot(AbstractDrawer draw) {
if (!visible) {
return;
}
draw.setColor(color);
if (gradientColor != null) {
draw.setGradient(extrem[0], color, extrem[1], gradientColor);
}
draw.drawLine(extrem[0], extrem[1]);
if (gradientColor != null) {
draw.resetGradient();
}
}
public Color getGradientColor() {
return gradientColor;
}
public void setGradientColor(Color c) {
this.gradientColor = c;
}
}

View file

@ -1,82 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.panel.Plot3DPanel;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
import javax.swing.JFrame;
public class LinePlot extends ScatterPlot {
public boolean draw_dot = false;
public LinePlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
super(n, c, _pattern, _XY);
}
public LinePlot(String n, Color c, int _type, int _radius, double[][] _XY) {
super(n, c, _type, _radius, _XY);
}
public LinePlot(String n, Color c, double[][] _XY) {
super(n, c, _XY);
}
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
if (draw_dot) {
super.plot(draw, c);
}
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length - 1; i++) {
if (!anyNaN(XY[i]) && !anyNaN(XY[i + 1])) {
draw.drawLine(XY[i], XY[i + 1]);
}
}
}
boolean anyNaN(double[] xy) {
for (int i = 0; i < xy.length; i++) {
if (Double.isNaN(xy[i])) {
return true;
}
}
return false;
}
public static void main(String[] args) {
Plot2DPanel p2 = new Plot2DPanel();
double[][] XYZ = new double[100][2];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = 2 * Math.PI * (double) j / XYZ.length;
XYZ[j][1] = Math.sin(XYZ[j][0]);
}
XYZ[50][0] = Double.NaN;
p2.addLinePlot("sin", XYZ);
p2.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Plot3DPanel p = new Plot3DPanel();
XYZ = new double[100][3];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = 2 * Math.PI * (double) j / XYZ.length;
XYZ[j][1] = Math.sin(XYZ[j][0]);
XYZ[j][2] = Math.sin(XYZ[j][0]) * Math.cos(XYZ[j][1]);
}
p.addLinePlot("toto", XYZ);
p.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

View file

@ -1,10 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
public interface Noteable {
double[] isSelected(int[] screenCoord, AbstractDrawer draw);
void note(AbstractDrawer draw);
}

View file

@ -1,61 +0,0 @@
/*
* Created on 5 sept. 2005 by richet
*/
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
public class PaintImage implements Plotable {
public interface Paintable {
void paint(Graphics g);
}
protected Paintable source;
protected Image img;
protected double[] xyzSW, xyzSE, xyzNW;
protected boolean visible = true;
protected float alpha;
public PaintImage(Paintable _source, float _alpha, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) {
source = _source;
xyzSW = _xyzSW;
xyzSE = _xyzSE;
xyzNW = _xyzNW;
alpha = _alpha;
}
public void plot(AbstractDrawer draw) {
if (!visible) {
return;
}
if (img == null) {
img = draw.canvas.createImage(draw.canvas.getWidth(), draw.canvas.getHeight());
source.paint(img.getGraphics());
}
draw.drawImage(img, alpha, xyzSW, xyzSE, xyzNW);
}
public void setVisible(boolean v) {
visible = v;
}
public boolean getVisible() {
return visible;
}
public void setColor(Color c) {
throw new IllegalArgumentException("method not available for this Object: PlotImage");
}
public Color getColor() {
return null;
}
}

View file

@ -1,255 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.DataPanel;
import org.xbib.graphics.graph.jmathplot.panel.MatrixTablePanel;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
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;
public abstract class Plot implements Plotable, Noteable, Editable {
public String name;
public Color color;
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;
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 color;
}
public void setColor(Color c) {
color = c;
}
public abstract double[] isSelected(int[] screenCoordTest, AbstractDrawer draw);
public void note(AbstractDrawer draw) {
plot(draw, PlotCanvas.NOTE_COLOR);
plotLayerPlots(draw, PlotCanvas.NOTE_COLOR);
}
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, color);
//else
plot(draw, color);
}
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) {
plot(draw, PlotCanvas.EDIT_COLOR);
plotLayerPlots(draw, PlotCanvas.EDIT_COLOR);
}
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) {
plot.setVisible(visible.isSelected());
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();
}
}
}

View file

@ -1,18 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
public interface Plotable {
void plot(AbstractDrawer draw);
void setVisible(boolean v);
boolean getVisible();
void setColor(Color c);
Color getColor();
}

View file

@ -1,129 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
public class QuantileLayerPlot extends LayerPlot {
public static int WIDTH = 2;
int axe;
double quantileRate;
Color gradC;
double main_data_constant = 0;
public boolean symetric = false;
double[] Q;
//public static double DEFAULT_RATE=1.0;
/*public QuantilePlot(Plot p, int a, double[] q, boolean _symetric) {
this(p, a, q, DEFAULT_RATE,_symetric);
}*/
public QuantileLayerPlot(Plot p, int a, double q, double r, boolean _symetric) {
this(p, a, null, r, true);
main_data_constant = q;
}
/*public QuantilePlot(Plot p, int a, double q) {
this(p, a, q, DEFAULT_RATE,true);
}*/
/**
* Build a quantile plot based on given plot. The quantile is drawn as a linear gradient from the base plot dots.
*
* @param p base plot
* @param a axis number of quantile : 0=X quantile, 1=Y quantile, 2=Z quantile
* @param q array of quantiles values
* @param r rate of the quantile. The gradient line length is q/r
* @param _symetric if yes, quantiles are drawn on both negative and positive sides of base plot dots
*/
public QuantileLayerPlot(Plot p, int a, double[] q, double r, boolean _symetric) {
super(r + " quantile of " + p.name, p);
if (q != null) {
Array.checkLength(q, p.getData().length);
}
Q = q;
axe = a;
quantileRate = r;
symetric = _symetric;
}
public double getQuantilesValue(int numCoord) {
return Q[numCoord];
}
public int getAxe() {
return axe;
}
public double getQuantileRate() {
return quantileRate;
}
public void plot(AbstractDrawer draw, Color c) {
if (!plot.visible) {
return;
}
draw.setColor(c);
gradC = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255 * (1 - quantileRate)));
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
draw.setLineWidth(WIDTH);
if (main_data_constant == 0) {
for (int i = 0; i < plot.getData().length; i++) {
double[] d = Array.getRowCopy(plot.getData(), i);
d[axe] += Q[i];///quantileRate;
draw.setGradient(plot.getData()[i], c, d, gradC);
draw.drawLine(plot.getData()[i], d);
// draw.drawDot(d, RADIUS/*(int)(RADIUS*quantileRate)*/);
if (symetric) {
d[axe] -= 2 * Q[i];///quantileRate;
draw.setGradient(plot.getData()[i], c, d, gradC);
draw.drawLine(plot.getData()[i], d);
// draw.drawDot(d, RADIUS/*(int)(RADIUS*quantileRate)*/);
}
}
} else {
for (int i = 0; i < plot.getData().length; i++) {
double[] d = Array.getRowCopy(plot.getData(), i);
d[axe] += main_data_constant;///quantileRate;
draw.setGradient(plot.getData()[i], c, d, gradC);
draw.drawLine(plot.getData()[i], d);
// draw.drawDot(d, shape/*RADIUS/*(int)(RADIUS*quantileRate)*/);
if (symetric) {
d[axe] -= 2 * main_data_constant;///quantileRate;
draw.setGradient(plot.getData()[i], c, d, gradC);
draw.drawLine(plot.getData()[i], d);
// draw.drawDot(d, RADIUS/*(int)(RADIUS*quantileRate)*/);
}
}
}
draw.resetGradient();
draw.setLineWidth(AbstractDrawer.DEFAULT_LINE_WIDTH);
}
@Override
public void setData(double[][] d) {
Q = d[0];
}
@Override
public double[][] getData() {
return new double[][]{Q};
}
}

View file

@ -1,98 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.panel.Plot3DPanel;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.JFrame;
public class RasterImage implements Plotable {
File source;
Image img;
double[] xyzSW, xyzSE, xyzNW;
boolean visible = true;
float alpha;
public RasterImage(File _source, float _alpha, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) {
source = _source;
img = Toolkit.getDefaultToolkit().getImage(source.getPath());
xyzSW = _xyzSW;
xyzSE = _xyzSE;
xyzNW = _xyzNW;
alpha = _alpha;
}
public void plot(AbstractDrawer draw) {
if (!visible) {
return;
}
draw.drawImage(img, alpha, xyzSW, xyzSE, xyzNW);
}
public void setVisible(boolean v) {
visible = v;
}
public boolean getVisible() {
return visible;
}
public void setColor(Color c) {
throw new IllegalArgumentException("method not available for this Object: PlotImage");
}
public Color getColor() {
return null;
}
public static void main(String[] args) {
Plot2DPanel p2 = new Plot2DPanel();
for (int i = 0; i < 1; i++) {
double[][] XYZ = new double[10][2];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] =/*1 + */Math.random();
XYZ[j][1] = /*100 * */Math.random();
}
p2.addScatterPlot("toto" + i, XYZ);
}
p2.addPlotable(new RasterImage(new File("test.gif"), 0.8f, new double[]{0.2, 0.5}, new double[]{1.2, 0.8}, new double[]{0.2, 1.1}));
p2.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Plot3DPanel p = new Plot3DPanel();
for (int i = 0; i < 1; i++) {
double[][] XYZ = new double[10][3];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = /*1 +*/ Math.random();
XYZ[j][1] = /*100 **/ Math.random();
XYZ[j][2] = /*0.0001 **/ Math.random();
}
p.addScatterPlot("toto" + i, XYZ);
}
p.addPlotable(new RasterImage(new File("test.gif"), 0.5f, new double[]{0.0, 0.0, 0.0}, new double[]{1, 0, 0.0}, new double[]{0.0, 0, 1}));
p.addPlotable(new RasterImage(new File("test.gif"), 0.5f, new double[]{0.0, 0.0, 0.0}, new double[]{0, 1, 0.0}, new double[]{0, 0.0, 1}));
p.addPlotable(new RasterImage(new File("test.gif"), 0.5f, new double[]{0.0, 0.0, 0.0}, new double[]{1, 0, 0}, new double[]{0, 1, 0}));
// TODO this following case is not totally supported...
//p.addPlotable(new PlotImage(new File("test.jpg"),0.5f, new double[] {1,0,0},new double[] {1,1,0},new double[] {0,0,1}));
p.setLegendOrientation(PlotPanel.SOUTH);
p.setPreferredSize(new Dimension(600, 600));
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

View file

@ -1,164 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.panel.Plot3DPanel;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import org.xbib.graphics.graph.jmathplot.utils.FastMath;
import java.awt.Color;
import javax.swing.JFrame;
public class ScatterPlot extends Plot {
private int type;
private int radius;
private boolean[][] pattern;
private boolean use_pattern;
double[][] XY;
private String[] tags;
public ScatterPlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
super(n, c);
XY = _XY;
use_pattern = true;
pattern = _pattern;
}
public ScatterPlot(String n, Color c, int _type, int _radius, double[][] _XY) {
super(n, c);
XY = _XY;
use_pattern = false;
type = _type;
radius = _radius;
}
public ScatterPlot(String n, Color c, double[][] _XY) {
this(n, c, AbstractDrawer.ROUND_DOT, AbstractDrawer.DEFAULT_DOT_RADIUS, _XY);
}
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
draw.setColor(c);
if (use_pattern) {
draw.setDotType(AbstractDrawer.PATTERN_DOT);
draw.setDotPattern(pattern);
} else {
draw.setDotRadius(radius);
if (type == AbstractDrawer.CROSS_DOT) {
draw.setDotType(AbstractDrawer.CROSS_DOT);
} else {
draw.setDotType(AbstractDrawer.ROUND_DOT);
}
}
for (int i = 0; i < XY.length; i++) {
draw.drawDot(XY[i]);
}
}
public void setDotPattern(int t) {
type = t;
use_pattern = false;
}
public void setDotPattern(boolean[][] t) {
use_pattern = true;
pattern = t;
}
@Override
public void setData(double[][] d) {
datapanel = null;
XY = d;
}
@Override
public double[][] getData() {
return XY;
}
@Override
public double[][] getBounds() {
return Array.mergeRows(Array.min(XY), Array.max(XY));
}
public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
for (int i = 0; i < XY.length; i++) {
int[] screenCoord = draw.project(XY[i]);
if (FastMath.abs(screenCoord[0] - screenCoordTest[0]) < note_precision && FastMath.abs(screenCoord[1] - screenCoordTest[1]) < note_precision) {
return XY[i];
}
}
return null;
}
public static void main(String[] args) {
Plot2DPanel p2 = new Plot2DPanel();
for (int i = 0; i < 3; i++) {
double[][] XYZ = new double[10][2];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = /*1 + */ Math.random();
XYZ[j][1] = /*100 * */ Math.random();
}
p2.addScatterPlot("toto" + i, XYZ);
}
p2.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Plot3DPanel p = new Plot3DPanel();
String[] tags = null;
for (int i = 0; i < 3; i++) {
double[][] XYZ = new double[10][3];
tags = new String[10];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = /*1 +*/ 2.5 * Math.random();
XYZ[j][1] = /*100 **/ Math.random();
XYZ[j][2] = /*0.0001 **/ Math.random();
tags[j] = "tags " + j;
}
p.addScatterPlot("toto" + i, XYZ);
}
((ScatterPlot) p.getPlot(0)).setTags(tags);
p.setLegendOrientation(PlotPanel.SOUTH);
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* @param tags the tags to set
*/
public void setTags(String[] tags) {
datapanel = null;
this.tags = tags;
}
@Override
public void noteCoord(AbstractDrawer draw, double[] coordNoted) {
if (coordNoted == null) {
return;
}
if (tags == null) {
super.noteCoord(draw, coordNoted);
} else {
draw.setColor(PlotCanvas.NOTE_COLOR);
for (int i = 0; i < XY.length; i++) {
if (tags.length > i) {
if (Array.equals(XY[i], coordNoted)) {
draw.drawShadowedText(tags[i], .5f, coordNoted);
}
}
}
}
//draw.drawCoordinate(coordNoted);
//draw.drawText(Array.cat(draw.canvas.reverseMapedData(coordNoted)), coordNoted);
}
}

View file

@ -1,69 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import java.awt.Color;
import javax.swing.JFrame;
public class StaircasePlot extends ScatterPlot {
public boolean link = true;
public StaircasePlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
super(n, c, _pattern, _XY);
}
public StaircasePlot(String n, Color c, int _type, int _radius, double[][] _XY) {
super(n, c, _type, _radius, _XY);
}
public StaircasePlot(String n, Color c, double[][] _XY) {
super(n, c, _XY);
}
public void plot(AbstractDrawer draw, Color c) {
if (!visible) {
return;
}
//System.out.println(Array.toString(XY));
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < XY.length - 1; i++) {
double[] begin = XY[i].clone();
double[] end = XY[i + 1].clone();
end[end.length - 1] = XY[i][end.length - 1];
draw.drawLine(begin, end);
}
//System.out.println(Array.toString(XY));
if (link) {
for (int i = 0; i < XY.length - 2; i++) {
double[] begin = XY[i + 1].clone();
double[] end = XY[i + 1].clone();
begin[begin.length - 1] = XY[i][begin.length - 1];
draw.drawLine(begin, end);
}
}
//System.out.println(Array.toString(XY));
}
public static void main(String[] args) {
Plot2DPanel p = new Plot2DPanel();
double[] X = new double[10];
double[] Y = new double[10];
for (int j = 0; j < X.length; j++) {
X[j] = j;
Y[j] = Math.random();
}
p.addStaircasePlot("toto", X, Y);
new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

View file

@ -1,87 +0,0 @@
package org.xbib.graphics.graph.jmathplot;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
import javax.swing.JFrame;
/**
* @author Yann RICHET
* @version 1.0
*/
/**
* Layer to add a vector field to an existing Plot
*/
public class VectorLayerPlot extends LayerPlot {
public static int RADIUS = 5;
double[][] V;
/**
* Create a vector fiels based on data of a plot
*
* @param p Base plot to support vector field
* @param v Vector field of same lenght that p data
*/
public VectorLayerPlot(Plot p, double[][] v) {
super("Vector of " + p.name, p);
if (v != null) {
Array.checkRowDimension(v, p.getData().length);
Array.checkColumnDimension(v, p.getData()[0].length);
}
V = v;
}
@Override
public void setData(double[][] v) {
V = v;
}
@Override
public double[][] getData() {
return V;
}
public void plot(AbstractDrawer draw, Color c) {
if (!plot.visible) {
return;
}
draw.setColor(c);
draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
for (int i = 0; i < plot.getData().length; i++) {
double[] d = Array.getRowCopy(plot.getData(), i);
for (int j = 0; j < d.length; j++) {
d[j] += V[i][j];
}
draw.drawLine(plot.getData()[i], d);
//TODO: draw arrow at position d
}
}
public static void main(String[] args) {
Plot2DPanel p2 = new Plot2DPanel();
double[][] XYZ = new double[100][2];
double[][] dXYZ = new double[100][2];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = Math.random() * 10;
XYZ[j][1] = Math.random() * 10;
dXYZ[j][0] = 1.0 / Math.sqrt(1 + Math.log(XYZ[j][0]) * Math.log(XYZ[j][0]));
dXYZ[j][1] = Math.log(XYZ[j][0]) / Math.sqrt(1 + Math.log(XYZ[j][0]) * Math.log(XYZ[j][0]));
}
p2.addScatterPlot("toto", XYZ);
p2.addVectortoPlot(0, dXYZ);
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

View file

@ -1,171 +0,0 @@
package org.xbib.graphics.graph.jmathplot.canvas;
import static org.xbib.graphics.graph.jmathplot.Base.LINEAR;
import static org.xbib.graphics.graph.jmathplot.utils.Array.getColumnCopy;
import static org.xbib.graphics.graph.jmathplot.utils.Array.getColumnsRangeCopy;
import static org.xbib.graphics.graph.jmathplot.utils.Array.increment;
import static org.xbib.graphics.graph.jmathplot.utils.Array.mergeColumns;
import static org.xbib.graphics.graph.jmathplot.utils.Histogram.histogram_classes;
import static org.xbib.graphics.graph.jmathplot.utils.Histogram.histogram_classes_2D;
import org.xbib.graphics.graph.jmathplot.Base;
import org.xbib.graphics.graph.jmathplot.BasePlot;
import org.xbib.graphics.graph.jmathplot.BarPlot;
import org.xbib.graphics.graph.jmathplot.BoxPlot2D;
import org.xbib.graphics.graph.jmathplot.CloudPlot2D;
import org.xbib.graphics.graph.jmathplot.HistogramPlot2D;
import org.xbib.graphics.graph.jmathplot.LinePlot;
import org.xbib.graphics.graph.jmathplot.ScatterPlot;
import org.xbib.graphics.graph.jmathplot.StaircasePlot;
import org.xbib.graphics.graph.jmathplot.render.AWTDrawer2D;
import java.awt.Color;
/**
* BSD License
*
* @author Yann RICHET
*/
public class Plot2DCanvas extends PlotCanvas {
// public final static String PARALLELHISTOGRAM = "PARALLELHISTOGRAM";
private static final long serialVersionUID = 1L;
public Plot2DCanvas() {
super();
ActionMode = ZOOM;
}
public Plot2DCanvas(Base b, BasePlot bp) {
super(b, bp);
ActionMode = ZOOM;
}
public Plot2DCanvas(double[] min, double[] max, String[] axesScales, String[] axesLabels) {
super(min, max, axesScales, axesLabels);
ActionMode = ZOOM;
}
public void initDrawer() {
draw = new AWTDrawer2D(this);
}
public void initBasenGrid(double[] min, double[] max) {
initBasenGrid(min, max, new String[]{LINEAR, LINEAR}, new String[]{"X", "Y"});
}
public void initBasenGrid() {
initBasenGrid(new double[]{0, 0}, new double[]{1, 1});
}
private static double[][] convertY(double[] XY) {
double[] x = increment(XY.length, 1, 1);
return mergeColumns(x, XY);
}
private static double[][] convertXY(double[]... XY) {
if (XY.length == 2 && XY[0].length != 2) {
return mergeColumns(XY[0], XY[1]);
} else {
return XY;
}
}
public int addScatterPlot(String name, Color c, double[] Y) {
return addPlot(new ScatterPlot(name, c, convertY(Y)));
}
public int addScatterPlot(String name, Color c, double[][] XY) {
return addPlot(new ScatterPlot(name, c, convertXY(XY)));
}
public int addScatterPlot(String name, Color c, double[] X, double[] Y) {
return addPlot(new ScatterPlot(name, c, convertXY(X, Y)));
}
public int addLinePlot(String name, Color c, double[] Y) {
return addPlot(new LinePlot(name, c, convertY(Y)));
}
public int addLinePlot(String name, Color c, double[][] XY) {
return addPlot(new LinePlot(name, c, convertXY(XY)));
}
public int addLinePlot(String name, Color c, double[] X, double[] Y) {
return addPlot(new LinePlot(name, c, convertXY(X, Y)));
}
public int addBarPlot(String name, Color c, double[] Y) {
return addPlot(new BarPlot(name, c, convertY(Y)));
}
public int addBarPlot(String name, Color c, double[][] XY) {
return addPlot(new BarPlot(name, c, convertXY(XY)));
}
public int addBarPlot(String name, Color c, double[] X, double[] Y) {
return addPlot(new BarPlot(name, c, convertXY(X, Y)));
}
public int addStaircasePlot(String name, Color c, double[] Y) {
return addPlot(new StaircasePlot(name, c, convertY(Y)));
}
public int addStaircasePlot(String name, Color c, double[][] XY) {
return addPlot(new StaircasePlot(name, c, convertXY(XY)));
}
public int addStaircasePlot(String name, Color c, double[] X, double[] Y) {
return addPlot(new StaircasePlot(name, c, convertXY(X, Y)));
}
public int addBoxPlot(String name, Color c, double[][] XY, double[][] dX) {
return addPlot(new BoxPlot2D(XY, dX, c, name));
}
public int addBoxPlot(String name, Color c, double[][] XYdX) {
return addPlot(new BoxPlot2D(getColumnsRangeCopy(XYdX, 0, 1), getColumnsRangeCopy(XYdX, 2, 3), c, name));
}
public int addHistogramPlot(String name, Color c, double[][] XY, double[] dX) {
return addPlot(new HistogramPlot2D(name, c, XY, dX));
}
public int addHistogramPlot(String name, Color c, double[][] XY, double dX) {
return addPlot(new HistogramPlot2D(name, c, XY, dX));
}
public int addHistogramPlot(String name, Color c, double[][] XYdX) {
return addPlot(new HistogramPlot2D(name, c, getColumnsRangeCopy(XYdX, 0, 1), getColumnCopy(XYdX, 2)));
}
public int addHistogramPlot(String name, Color c, double[] X, int n) {
double[][] XY = histogram_classes(X, n);
return addPlot(new HistogramPlot2D(name, c, XY, XY[1][0] - XY[0][0]));
}
public int addHistogramPlot(String name, Color c, double[] X, double... bounds) {
double[][] XY = histogram_classes(X, bounds);
return addPlot(new HistogramPlot2D(name, c, XY, XY[1][0] - XY[0][0]));
}
public int addHistogramPlot(String name, Color c, double[] X, double min, double max, int n) {
double[][] XY = histogram_classes(X, min, max, n);
return addPlot(new HistogramPlot2D(name, c, XY, XY[1][0] - XY[0][0]));
}
public int addCloudPlot(String name, Color c, double[][] sampleXY, int nX, int nY) {
double[][] XYh = histogram_classes_2D(sampleXY, nX, nY);
return addPlot(new CloudPlot2D(name, c, XYh, XYh[1][0] - XYh[0][0], XYh[nX][1] - XYh[0][1]));
}
public static void main(String[] args) {
/*
* Plot2DPanel p2d = new Plot2DPanel(DoubleArray.random(10, 2), "plot
* 1", PlotPanel.SCATTER); new FrameView(p2d);
* p2d.addPlot(DoubleArray.random(10, 2), "plot 2", PlotPanel.SCATTER);
* p2d.grid.getAxe(0).darkLabel.setCorner(0.5, -10);
* p2d.grid.getAxe(1).darkLabel.setCorner(0, -0.5);
*/
}
}

View file

@ -1,182 +0,0 @@
package org.xbib.graphics.graph.jmathplot.canvas;
import static org.xbib.graphics.graph.jmathplot.Base.LINEAR;
import static org.xbib.graphics.graph.jmathplot.utils.Array.getColumnsRangeCopy;
import static org.xbib.graphics.graph.jmathplot.utils.Array.getSubMatrixRangeCopy;
import static org.xbib.graphics.graph.jmathplot.utils.Array.mergeColumns;
import static org.xbib.graphics.graph.jmathplot.utils.Histogram.histogram_classes_2D;
import static org.xbib.graphics.graph.jmathplot.utils.Histogram.histogram_classes_3D;
import org.xbib.graphics.graph.jmathplot.Base;
import org.xbib.graphics.graph.jmathplot.BasePlot;
import org.xbib.graphics.graph.jmathplot.BarPlot;
import org.xbib.graphics.graph.jmathplot.BoxPlot3D;
import org.xbib.graphics.graph.jmathplot.CloudPlot3D;
import org.xbib.graphics.graph.jmathplot.GridPlot3D;
import org.xbib.graphics.graph.jmathplot.HistogramPlot3D;
import org.xbib.graphics.graph.jmathplot.LinePlot;
import org.xbib.graphics.graph.jmathplot.ScatterPlot;
import org.xbib.graphics.graph.jmathplot.render.AWTDrawer;
import org.xbib.graphics.graph.jmathplot.render.AWTDrawer3D;
import org.xbib.graphics.graph.jmathplot.render.Projection3D;
import java.awt.Color;
import java.awt.event.MouseEvent;
/**
* BSD License
*
* @author Yann RICHET
*/
public class Plot3DCanvas extends PlotCanvas {
private static final long serialVersionUID = 1L;
public final static int ROTATION = 2;
public Plot3DCanvas() {
super();
ActionMode = ROTATION;
}
public Plot3DCanvas(Base b) {
super(b, new BasePlot(b, "X", "Y", "Z"));
ActionMode = ROTATION;
}
public Plot3DCanvas(Base b, BasePlot bp) {
super(b, bp);
ActionMode = ROTATION;
}
public Plot3DCanvas(double[] min, double[] max, String[] axesScales, String[] axesLabels) {
super(min, max, axesScales, axesLabels);
ActionMode = ROTATION;
}
public void initDrawer() {
draw = new AWTDrawer3D(this);
}
public void initBasenGrid(double[] min, double[] max) {
initBasenGrid(min, max, new String[]{LINEAR, LINEAR, LINEAR}, new String[]{"X", "Y", "Z"});
}
public void initBasenGrid() {
initBasenGrid(new double[]{0, 0, 0}, new double[]{1, 1, 1});
}
private static double[][] convertXYZ(double[]... XYZ) {
if (XYZ.length == 3 && XYZ[0].length != 3) {
return mergeColumns(XYZ[0], XYZ[1], XYZ[2]);
} else {
return XYZ;
}
}
public void setDefaultZoom(double zoom_factor) {
((Projection3D) ((AWTDrawer3D) draw).projection).factor = zoom_factor;
}
public int addScatterPlot(String name, Color c, double[][] XYZ) {
return addPlot(new ScatterPlot(name, c, convertXYZ(XYZ)));
}
public int addScatterPlot(String name, Color c, double[] X, double[] Y, double[] Z) {
return addPlot(new ScatterPlot(name, c, convertXYZ(X, Y, Z)));
}
public int addLinePlot(String name, Color c, double[][] XYZ) {
return addPlot(new LinePlot(name, c, convertXYZ(XYZ)));
}
public int addLinePlot(String name, Color c, double[] X, double[] Y, double[] Z) {
return addPlot(new LinePlot(name, c, convertXYZ(X, Y, Z)));
}
public int addBarPlot(String name, Color c, double[][] XYZ) {
return addPlot(new BarPlot(name, c, convertXYZ(XYZ)));
}
public int addBarPlot(String name, Color c, double[] X, double[] Y, double[] Z) {
return addPlot(new BarPlot(name, c, convertXYZ(X, Y, Z)));
}
public int addBoxPlot(String name, Color c, double[][] XY, double[][] dX) {
return addPlot(new BoxPlot3D(XY, dX, c, name));
}
public int addBoxPlot(String name, Color c, double[][] XYdX) {
return addPlot(new BoxPlot3D(getColumnsRangeCopy(XYdX, 0, 2), getColumnsRangeCopy(XYdX, 3, 5), c, name));
}
public int addHistogramPlot(String name, Color c, double[][] XY, double[][] dX) {
return addPlot(new HistogramPlot3D(name, c, XY, dX));
}
public int addHistogramPlot(String name, Color c, double[][] XYdX) {
return addPlot(new HistogramPlot3D(name, c, getColumnsRangeCopy(XYdX, 0, 2), getColumnsRangeCopy(XYdX, 3, 4)));
}
public int addHistogramPlot(String name, Color c, double[][] XY, int nX, int nY) {
double[][] XYZ = histogram_classes_2D(XY, nX, nY);
return addPlot(new HistogramPlot3D(name, c, XYZ, XYZ[1][0] - XYZ[0][0], XYZ[nX][1] - XYZ[0][1]));
}
public int addHistogramPlot(String name, Color c, double[][] XY, double[] boundsX, double[] boundsY) {
double[][] XYZ = histogram_classes_2D(XY, boundsX, boundsY);
return addPlot(new HistogramPlot3D(name, c, XYZ, XYZ[1][0] - XYZ[0][0], XYZ[boundsX.length - 1][1] - XYZ[0][1]));
}
public int addHistogramPlot(String name, Color c, double[][] XY, double minX, double maxX, int nX, double minY, double maxY, int nY) {
double[][] XYZ = histogram_classes_2D(XY, minX, maxX, nX, minY, maxY, nY);
return addPlot(new HistogramPlot3D(name, c, XYZ, XYZ[1][0] - XYZ[0][0], XYZ[nX][1] - XYZ[0][1]));
}
public int addGridPlot(String name, Color c, double[] X, double[] Y, double[][] Z) {
return addPlot(new GridPlot3D(name, c, X, Y, Z));
}
public int addGridPlot(String name, Color c, double[][] XYZMatrix) {
double[] X = new double[XYZMatrix[0].length - 1];
System.arraycopy(XYZMatrix[0], 1, X, 0, XYZMatrix[0].length - 1);
double[] Y = new double[XYZMatrix.length - 1];
for (int i = 0; i < Y.length; i++) {
Y[i] = XYZMatrix[i + 1][0];
}
double[][] Z = getSubMatrixRangeCopy(XYZMatrix, 1, XYZMatrix.length - 1, 1, XYZMatrix[0].length - 1);
return addGridPlot(name, c, X, Y, Z);
}
public int addCloudPlot(String name, Color c, double[][] sampleXYZ, int nX, int nY, int nZ) {
double[][] XYZh = histogram_classes_3D(sampleXYZ, nX, nY, nZ);
return addPlot(new CloudPlot3D(name, c, XYZh, XYZh[1][0] - XYZh[0][0], XYZh[nX][1] - XYZh[0][1], XYZh[nX][2] - XYZh[0][2]));
}
public void mouseDragged(MouseEvent e) {
//System.out.println("PlotCanvas.mouseDragged");
if (ActionMode == ROTATION) {
dragging = true;
/*
* System.out.println("PlotCanvas.mouseDragged"); System.out.println("
* mouseClick = [" + mouseClick[0] + " " + mouseClick[1] + "]");
* System.out.println(" mouseCurent = [" + mouseCurent[0] + " " +
* mouseCurent[1] + "]");
*/
mouseCurent[0] = e.getX();
mouseCurent[1] = e.getY();
e.consume();
int[] t = new int[]{mouseCurent[0] - mouseClick[0], mouseCurent[1] - mouseClick[1]};
((AWTDrawer3D) draw).rotate(t, new int[]{getWidth(), getHeight()});
mouseClick[0] = mouseCurent[0];
mouseClick[1] = mouseCurent[1];
repaint();
} else {
super.mouseDragged(e);
}
}
public void rotate(double theta, double phi) {
Projection3D proj3d = ((Projection3D) ((AWTDrawer) draw).projection);
proj3d.rotate(proj3d.theta + theta, proj3d.phi + phi);
}
}

View file

@ -1,970 +0,0 @@
package org.xbib.graphics.graph.jmathplot.canvas;
import static org.xbib.graphics.graph.jmathplot.Base.LINEAR;
import static org.xbib.graphics.graph.jmathplot.Base.LOGARITHM;
import static org.xbib.graphics.graph.jmathplot.Base.STRINGS;
import org.xbib.graphics.graph.jmathplot.BaseLabel;
import org.xbib.graphics.graph.jmathplot.Label;
import org.xbib.graphics.graph.jmathplot.frame.DataFrame;
import org.xbib.graphics.graph.jmathplot.frame.LegendPanel;
import org.xbib.graphics.graph.jmathplot.frame.ScalesFrame;
import org.xbib.graphics.graph.jmathplot.Base;
import org.xbib.graphics.graph.jmathplot.BaseDependant;
import org.xbib.graphics.graph.jmathplot.BasePlot;
import org.xbib.graphics.graph.jmathplot.Plotable;
import org.xbib.graphics.graph.jmathplot.Plot;
import org.xbib.graphics.graph.jmathplot.render.AWTDrawer;
import org.xbib.graphics.graph.jmathplot.render.AbstractDrawer;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import org.xbib.graphics.graph.jmathplot.utils.FastMath;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Set;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public abstract class PlotCanvas extends JPanel implements MouseListener, MouseMotionListener, ComponentListener, BaseDependant, MouseWheelListener {
//public int[] panelSize = new int[] { 400, 400 };
public Base base;
protected AbstractDrawer draw;
protected BasePlot grid;
public LegendPanel linkedLegendPanel;
public LinkedList<Plot> plots;
public LinkedList<Plotable> objects;
// ///////////////////////////////////////////
// ////// Constructor & inits ////////////////
// ///////////////////////////////////////////
public PlotCanvas() {
initPanel();
initBasenGrid();
initDrawer();
}
public PlotCanvas(Base b, BasePlot bp) {
initPanel();
initBasenGrid(b, bp);
initDrawer();
}
public PlotCanvas(double[] min, double[] max) {
initPanel();
initBasenGrid(min, max);
initDrawer();
}
public PlotCanvas(double[] min, double[] max, String[] axesScales, String[] axesLabels) {
initPanel();
initBasenGrid(min, max, axesScales, axesLabels);
initDrawer();
}
@Override
public boolean isOptimizedDrawingEnabled() {
return true;
}
public void attachLegend(LegendPanel lp) {
linkedLegendPanel = lp;
}
private void initPanel() {
objects = new LinkedList<Plotable>();
plots = new LinkedList<Plot>();
setDoubleBuffered(true);
//setSize(panelSize[0], panelSize[1]);
//setPreferredSize(new Dimension(panelSize[0], panelSize[1]));
setBackground(Color.white);
addComponentListener(this);
addMouseListener(this);
addMouseMotionListener(this);
addMouseWheelListener(this);
}
public abstract void initDrawer();
public void initBasenGrid(double[] min, double[] max, String[] axesScales, String[] axesLabels) {
base = new Base(min, max, axesScales);
grid = new BasePlot(base, axesLabels);
// grid.getAxe(0).getDarkLabel().setCorner(0.5,-1);
// grid.getAxe(1).getDarkLabel().setCorner(0,-0.5);
}
public abstract void initBasenGrid(double[] min, double[] max);
public abstract void initBasenGrid();
public void initBasenGrid(Base b, BasePlot bp) {
base = b;
grid = bp;
}
// ///////////////////////////////////////////
// ////// set actions ////////////////////////
// ///////////////////////////////////////////
public void setActionMode(int am) {
ActionMode = am;
}
public void setNoteCoords(boolean b) {
allowNoteCoord = b;
}
public void setEditable(boolean b) {
allowEdit = b;
}
public boolean getEditable() {
return allowEdit;
}
public void setNotable(boolean b) {
allowNote = b;
}
public boolean getNotable() {
return allowNote;
}
// ///////////////////////////////////////////
// ////// set/get elements ///////////////////
// ///////////////////////////////////////////
public LinkedList<Plot> getPlots() {
return plots;
}
public Plot getPlot(int i) {
return plots.get(i);
}
public int getPlotIndex(Plot p) {
for (int i = 0; i < plots.size(); i++) {
if (getPlot(i) == p) {
return i;
}
}
return -1;
}
public LinkedList<Plotable> getPlotables() {
return objects;
}
public Plotable getPlotable(int i) {
return objects.get(i);
}
public BasePlot getGrid() {
return grid;
}
public String[] getAxisScales() {
return base.getAxesScales();
}
public void setAxisLabels(String... labels) {
grid.setLegend(labels);
repaint();
}
public void setAxisLabel(int axe, String label) {
grid.setLegend(axe, label);
repaint();
}
public void setAxisScales(String... scales) {
base.setAxesScales(scales);
setAutoBounds();
}
public void setAxiScale(int axe, String scale) {
base.setAxesScales(axe, scale);
setAutoBounds(axe);
}
public void setFixedBounds(double[] min, double[] max) {
base.setFixedBounds(min, max);
resetBase();
repaint();
}
public void setFixedBounds(int axe, double min, double max) {
base.setFixedBounds(axe, min, max);
resetBase();
repaint();
}
public void includeInBounds(double... into) {
boolean changed = base.includeInBounds(into);
if (!changed) {
return;
}
grid.resetBase();
repaint();
}
public void includeInBounds(Plot plot) {
boolean changed = base.includeInBounds(Array.min(plot.getBounds()));
changed = changed | base.includeInBounds(Array.max(plot.getBounds()));
if (!changed) {
return;
}
resetBase();
repaint();
}
public void setAutoBounds() {
if (plots.size() > 0) {
Plot plot0 = this.getPlot(0);
base.setRoundBounds(Array.min(plot0.getBounds()), Array.max(plot0.getBounds()));
} else { // build default min and max bounds
double[] min = new double[base.dimension];
double[] max = new double[base.dimension];
for (int i = 0; i < base.dimension; i++) {
if (base.getAxeScale(i).equalsIgnoreCase(LINEAR)) {
min[i] = 0.0;
max[i] = 1.0;
} else if (base.getAxeScale(i).equalsIgnoreCase(LOGARITHM)) {
min[i] = 1.0;
max[i] = 10.0;
}
}
base.setRoundBounds(min, max);
}
for (int i = 1; i < plots.size(); i++) {
Plot ploti = this.getPlot(i);
base.includeInBounds(Array.min(ploti.getBounds()));
base.includeInBounds(Array.max(ploti.getBounds()));
}
resetBase();
repaint();
}
public void setAutoBounds(int axe) {
if (plots.size() > 0) {
Plot plot0 = this.getPlot(0);
base.setRoundBounds(axe, Array.min(plot0.getBounds())[axe], Array.max(plot0.getBounds())[axe]);
} else { // build default min and max bounds
double min = 0.0;
double max = 0.0;
if (base.getAxeScale(axe).equalsIgnoreCase(LINEAR) | base.getAxeScale(axe).equalsIgnoreCase(STRINGS)) {
min = 0.0;
max = 1.0;
} else if (base.getAxeScale(axe).equalsIgnoreCase(LOGARITHM)) {
min = 1.0;
max = 10.0;
}
base.setRoundBounds(axe, min, max);
}
for (int i = 1; i < plots.size(); i++) {
Plot ploti = this.getPlot(i);
base.includeInBounds(axe, Array.min(ploti.getBounds())[axe]);
base.includeInBounds(axe, Array.max(ploti.getBounds())[axe]);
}
resetBase();
repaint();
}
public void resetBase() {
// System.out.println("PlotCanvas.resetBase");
draw.resetBaseProjection();
grid.resetBase();
for (int i = 0; i < objects.size(); i++) {
if (objects.get(i) instanceof BaseDependant) {
((BaseDependant) (objects.get(i))).resetBase();
}
}
repaint();
}
// ///////////////////////////////////////////
// ////// add/remove elements ////////////////
// ///////////////////////////////////////////
public void addLabel(String text, Color c, double... where) {
addPlotable(new Label(text, c, where));
}
public void addBaseLabel(String text, Color c, double... where) {
addPlotable(new BaseLabel(text, c, where));
}
public void addPlotable(Plotable p) {
objects.add(p);
// resetBase();
repaint();
}
public void removePlotable(Plotable p) {
objects.remove(p);
repaint();
}
public void removePlotable(int i) {
objects.remove(i);
repaint();
}
public void removeAllPlotables() {
objects.clear();
repaint();
}
boolean adjustBounds = true;
public void setAdjustBounds(boolean adjust) {
adjustBounds = adjust;
}
public boolean getAdjustBounds() {
return adjustBounds;
}
public int addPlot(Plot newPlot) {
plots.add(newPlot);
if (linkedLegendPanel != null) {
linkedLegendPanel.updateLegends();
}
if (plots.size() == 1) {
setAutoBounds();
} else {
if (adjustBounds) {
includeInBounds(newPlot);
} else {
repaint();
}
}
return plots.size() - 1;
}
public void setPlot(int I, Plot p) {
plots.set(I, p);
if (linkedLegendPanel != null) {
linkedLegendPanel.updateLegends();
}
repaint();
}
public void changePlotData(int I, double[]... XY) {
getPlot(I).setData(XY);
if (adjustBounds) {
includeInBounds(getPlot(I));
} else {
repaint();
}
}
public void changePlotName(int I, String name) {
getPlot(I).setName(name);
if (linkedLegendPanel != null) {
linkedLegendPanel.updateLegends();
}
repaint();
}
public void changePlotColor(int I, Color c) {
getPlot(I).setColor(c);
if (linkedLegendPanel != null) {
linkedLegendPanel.updateLegends();
}
repaint();
}
public void removePlot(int I) {
plots.remove(I);
if (linkedLegendPanel != null) {
linkedLegendPanel.updateLegends();
}
if (plots.size() != 0) {
if (adjustBounds) {
setAutoBounds();
} else {
repaint();
}
}
}
public void removePlot(Plot p) {
plots.remove(p);
if (linkedLegendPanel != null) {
linkedLegendPanel.updateLegends();
}
if (plots.size() != 0) {
if (adjustBounds) {
setAutoBounds();
}
}
}
public void removeAllPlots() {
plots.clear();
if (linkedLegendPanel != null) {
linkedLegendPanel.updateLegends();
}
clearNotes();
}
public void addVectortoPlot(int numPlot, double[][] v) {
getPlot(numPlot).addVector(v);
}
/*public void addQuantiletoPlot(int numPlot, boolean _symetric, double[]... q) {
getPlot(numPlot).addQuantiles(q, _symetric);
}*/
public void addQuantiletoPlot(int numPlot, int numAxe, double rate, boolean symetric, double[] q) {
getPlot(numPlot).addQuantile(numAxe, rate, q, symetric);
}
public void addQuantiletoPlot(int numPlot, int numAxe, double rate, boolean symetric, double q) {
getPlot(numPlot).addQuantile(numAxe, rate, q, symetric);
}
public void addQuantilestoPlot(int numPlot, int numAxe, double[][] q) {
getPlot(numPlot).addQuantiles(numAxe, q);
}
public void addQuantilestoPlot(int numPlot, int numAxe, double[] q) {
getPlot(numPlot).addQuantiles(numAxe, q);
}
public void addGaussQuantilestoPlot(int numPlot, int numAxe, double[] s) {
getPlot(numPlot).addGaussQuantiles(numAxe, s);
}
public void addGaussQuantilestoPlot(int numPlot, int numAxe, double s) {
getPlot(numPlot).addGaussQuantiles(numAxe, s);
}
// ///////////////////////////////////////////
// ////// call for toolbar actions ///////////
// ///////////////////////////////////////////
public void toGraphicFile(File file) throws IOException {
Image image = createImage(getWidth(), getHeight());
paint(image.getGraphics());
image = new ImageIcon(image).getImage();
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = bufferedImage.createGraphics();
g.drawImage(image, 0, 0, Color.WHITE, null);
g.dispose();
try {
ImageIO.write(bufferedImage, "PNG", file);
} catch (IllegalArgumentException ex) {
}
}
JFrame scalesFrame = new ScalesFrame(this);
public void setScalesFrame(JFrame scalesFrame) {
this.scalesFrame = scalesFrame;
}
public void displayScalesFrame() {
scalesFrame.setVisible(true);
}
DataFrame dataFrame = new DataFrame(this);
public void setDataFrame(DataFrame dataFrame) {
this.dataFrame = dataFrame;
}
public void displayDataFrame(int i) {
dataFrame.selectIndex(i);
}
public void displayDataFrame() {
displayDataFrame(0);
}
boolean mapset = false;
public void resetMapData() {
for (int i = 0; i < grid.getAxis().length; i++) {
grid.getAxis()[i].setStringMap(null);
setAxiScale(i, Base.LINEAR);
}
mapset = false;
}
public double[][] mapData(Object[][] data) {
//System.out.println("mapData:" + Array.cat(data));
double[][] mapeddata = new double[data.length][data[0].length];
if (!mapset) {
for (int j = 0; j < data[0].length; j++) {
if (!Array.isDouble(data[0][j].toString())) {
//System.out.println(data[0][j].toString() + " is not a double");
setAxiScale(j, Base.STRINGS);
ArrayList<String> string_array_j = new ArrayList<String>(data.length);
for (int i = 0; i < data.length; i++) {
string_array_j.add(data[i][j].toString());
}
grid.getAxis(j).setStringMap(Array.mapStringArray(string_array_j));
grid.getAxis(j).init();
for (int i = 0; i < data.length; i++) {
mapeddata[i][j] = grid.getAxis(j).getStringMap().get(data[i][j].toString());
}
//System.out.println("Axe " + j + ":" + Array.toString(grid.getAxe(j).getStringMap()));
initReverseMap(j);
} else {
//System.out.println(data[0][j].toString() + " is a double");
//System.out.println("Axe " + j + ": double[]");
for (int i = 0; i < data.length; i++) {
mapeddata[i][j] = Double.valueOf(data[i][j].toString());
}
}
}
mapset = true;
} else {
for (int j = 0; j < data[0].length; j++) {
if (!Array.isDouble(data[0][j].toString())) {
//System.out.println(data[0][j].toString() + " is not a double");
if (base.getAxeScale(j).equals(Base.STRINGS)) {
for (int i = 0; i < data.length; i++) {
if (!grid.getAxis(j).getStringMap().containsKey(data[i][j].toString())) {
Set<String> s = grid.getAxis(j).getStringMap().keySet();
ArrayList<String> string_array_j = new ArrayList<String>(s.size() + 1);
string_array_j.addAll(s);
string_array_j.add(data[i][j].toString());
grid.getAxis(j).setStringMap(Array.mapStringArray(string_array_j));
//System.out.println("Axe " + j + ":" + Array.toString(grid.getAxe(j).getStringMap()));
initReverseMap(j);
}
mapeddata[i][j] = grid.getAxis(j).getStringMap().get(data[i][j].toString());
}
} else {
throw new IllegalArgumentException("The mapping of this PlotPanel was not set on axis " + j);
}
} else {
//System.out.println(data[0][j].toString() + " is a double");
//System.out.println("Axe " + j + ": double[]");
for (int i = 0; i < data.length; i++) {
mapeddata[i][j] = Double.valueOf(data[i][j].toString());
}
}
}
}
return mapeddata;
}
public Object[][] reverseMapedData(double[][] mapeddata) {
Object[][] stringdata = new Object[mapeddata.length][mapeddata[0].length];
for (int i = 0; i < mapeddata.length; i++) {
stringdata[i] = reverseMapedData(mapeddata[i]);
}
return stringdata;
}
public Object[] reverseMapedData(double[] mapeddata) {
Object[] stringdata = new Object[mapeddata.length];
if (reversedMaps == null) {
reversedMaps = new HashMap[grid.getAxis().length];
}
for (int j = 0; j < mapeddata.length; j++) {
if (reversedMaps[j] != null) {
stringdata[j] = reversedMaps[j].get(mapeddata[j]);
} else {
stringdata[j] = mapeddata[j];
}
}
return stringdata;
}
HashMap<Double, String>[] reversedMaps;
private void initReverseMap(int j) {
if (reversedMaps == null) {
reversedMaps = new HashMap[grid.getAxis().length];
}
if (grid.getAxis(j) != null) {
reversedMaps[j] = Array.reverseStringMap(grid.getAxis(j).getStringMap());
}
}
// ///////////////////////////////////////////
// ////// Paint method ///////////////////////
// ///////////////////////////////////////////
// anti-aliasing constant
final protected static RenderingHints AALIAS = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
public static Color NOTE_COLOR = Color.DARK_GRAY;
public static Color EDIT_COLOR = Color.BLACK;
public boolean allowEdit = true;
public boolean allowNote = true;
public boolean allowNoteCoord = true;
public void paint(Graphics gcomp) {
// System.out.println("PlotCanvas.paint");
Graphics2D gcomp2D = (Graphics2D) gcomp;
// anti-aliasing methods
gcomp2D.addRenderingHints(AALIAS);
gcomp2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
gcomp2D.setColor(getBackground());
gcomp2D.fillRect(0, 0, getSize().width, getSize().height);
draw.initGraphics(gcomp2D);
// draw plot
grid.plot(draw);
for (int i = 0; i < plots.size(); i++) {
getPlot(i).plot(draw);
if (linkedLegendPanel != null) {
linkedLegendPanel.nonote(i);
}
}
for (int i = 0; i < objects.size(); i++) {
getPlotable(i).plot(draw);
}
if (drawRect != null) {
gcomp2D.setColor(Color.black);
gcomp2D.setStroke(rectStroke);
gcomp2D.drawRect(drawRect[0], drawRect[1], drawRect[2], drawRect[3]);
}
// draw note
if (allowNote) {
/*if (allowNoteCoord && coordNoted != null) {
draw.setColor(NOTE_COLOR);
draw.drawCoordinate(coordNoted);
draw.drawText(Array.cat(reverseMapedData(coordNoted)), coordNoted);
}*/
for (int i = 0; i < plots.size(); i++) {
if (getPlot(i).noted) {
if (linkedLegendPanel != null) {
linkedLegendPanel.note(i);
}
getPlot(i).note(draw);
//return;
}
if (allowNoteCoord && getPlot(i).coordNoted != null) {
getPlot(i).noteCoord(draw, getPlot(i).coordNoted);
}
}
}
}
// ///////////////////////////////////////////
// ////// Listeners //////////////////////////
// ///////////////////////////////////////////
public final static int ZOOM = 0;
public final static int TRANSLATION = 1;
public int ActionMode;
protected boolean dragging = false;
protected int[] mouseCurent = new int[2];
protected int[] mouseClick = new int[2];
public void clearNotes() {
for (int i = 0; i < plots.size(); i++) {
getPlot(i).coordNoted = null;
}
repaint();
}
public void mousePressed(MouseEvent e) {
//System.out.println("PlotCanvas.mousePressed");
/*
* System.out.println("PlotCanvas.mousePressed"); System.out.println("
* mouseClick = [" + mouseClick[0] + " " + mouseClick[1] + "]");
* System.out.println(" mouseCurent = [" + mouseCurent[0] + " " +
* mouseCurent[1] + "]");
*/
mouseCurent[0] = e.getX();
mouseCurent[1] = e.getY();
e.consume();
mouseClick[0] = mouseCurent[0];
mouseClick[1] = mouseCurent[1];
}
int[] drawRect = null;
final Stroke rectStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
public void mouseDragged(MouseEvent e) {
//System.out.println("PlotCanvas.mouseDragged");
dragging = true;
/*
* System.out.println("PlotCanvas.mouseDragged"); System.out.println("
* mouseClick = [" + mouseClick[0] + " " + mouseClick[1] + "]");
* System.out.println(" mouseCurent = [" + mouseCurent[0] + " " +
* mouseCurent[1] + "]");
*/
mouseCurent[0] = e.getX();
mouseCurent[1] = e.getY();
e.consume();
switch (ActionMode) {
case TRANSLATION:
draw.translate(mouseCurent[0] - mouseClick[0], mouseCurent[1] - mouseClick[1]);
mouseClick[0] = mouseCurent[0];
mouseClick[1] = mouseCurent[1];
repaint();
break;
case ZOOM:
int x = FastMath.min(mouseClick[0], mouseCurent[0]);
int y = FastMath.min(mouseClick[1], mouseCurent[1]);
int w = FastMath.abs(mouseCurent[0] - mouseClick[0]);
int h = FastMath.abs(mouseCurent[1] - mouseClick[1]);
if (drawRect == null) {
drawRect = new int[4];
}
drawRect[0] = x;
drawRect[1] = y;
drawRect[2] = w;
drawRect[3] = h;
repaint(); //repaint(x - 1, y - 1, w + 2, h + 2);
break;
}
//repaint();
}
public void mouseReleased(MouseEvent e) {
//System.out.println("PlotCanvas.mouseReleased");
/*
* System.out.println("PlotCanvas.mouseReleased"); System.out.println("
* mouseClick = [" + mouseClick[0] + " " + mouseClick[1] + "]");
* System.out.println(" mouseCurent = [" + mouseCurent[0] + " " +
* mouseCurent[1] + "]");
*/
mouseCurent[0] = e.getX();
mouseCurent[1] = e.getY();
e.consume();
switch (ActionMode) {
case ZOOM:
if (FastMath.abs(mouseCurent[0] - mouseClick[0]) > 10 && FastMath.abs(mouseCurent[1] - mouseClick[1]) > 10) {
int[] origin = {FastMath.min(mouseClick[0], mouseCurent[0]), FastMath.min(mouseClick[1], mouseCurent[1])};
double[] ratio = {FastMath.abs((double) (mouseCurent[0] - mouseClick[0]) / (double) getWidth()),
FastMath.abs((double) (mouseCurent[1] - mouseClick[1]) / (double) getHeight())
};
draw.dilate(origin, ratio);
drawRect = null;
repaint();
} else {
drawRect = null;
repaint();
}
break;
}
//repaint();
dragging = false;
}
public void mouseClicked(MouseEvent e) {
//System.out.println("PlotCanvas.mouseClicked");
/*
* System.out.println("PlotCanvas.mouseClicked"); System.out.println("
* mouseClick = [" + mouseClick[0] + " " + mouseClick[1] + "]");
* System.out.println(" mouseCurent = [" + mouseCurent[0] + " " +
* mouseCurent[1] + "]");
*/
mouseCurent[0] = e.getX();
mouseCurent[1] = e.getY();
e.consume();
mouseClick[0] = mouseCurent[0];
mouseClick[1] = mouseCurent[1];
if (allowEdit) {
if (e.getModifiers() == MouseEvent.BUTTON1_MASK && e.getClickCount() > 1) {
for (int i = 0; i < grid.getAxis().length; i++) {
if (grid.getAxis(i).isSelected(mouseClick, draw) != null) {
grid.getAxis(i).edit(this);
return;
}
}
for (int i = 0; i < plots.size(); i++) {
if (getPlot(i).isSelected(mouseClick, draw) != null) {
getPlot(i).edit(this);
return;
}
}
}
}
if (!dragging && allowNote) {
for (int i = 0; i < plots.size(); i++) {
double[] _coordNoted = getPlot(i).isSelected(mouseClick, draw);
if (e.getModifiers() == MouseEvent.BUTTON1_MASK) {
if (_coordNoted != null) {
getPlot(i).noted = !getPlot(i).noted;
} else {
getPlot(i).noted = false;
}
} else if (e.getModifiers() == MouseEvent.BUTTON3_MASK) {
if (_coordNoted != null) {
if (getPlot(i).coordNoted != null) {
boolean alreadyNoted = true;
for (int j = 0; j < _coordNoted.length; j++) {
alreadyNoted = alreadyNoted && _coordNoted[j] == getPlot(i).coordNoted[j];
}
if (alreadyNoted) {
getPlot(i).coordNoted = null;
} else {
getPlot(i).coordNoted = _coordNoted;
}
} else {
getPlot(i).coordNoted = _coordNoted;
}
}
}
}
repaint();
} else {
dragging = false;
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
mouseCurent[0] = e.getX();
mouseCurent[1] = e.getY();
e.consume();
for (int i = 0; i < plots.size(); i++) {
if (getPlot(i).noted) {
double[] _coordNoted = getPlot(i).isSelected(mouseCurent, draw);
if (_coordNoted != null) {
getPlot(i).coordNoted = _coordNoted;
repaint();
}
}
}
//System.out.println("PlotCanvas.mouseMoved");
/*
* System.out.println("PlotCanvas.mouseClicked"); System.out.println("
* mouseClick = [" + mouseClick[0] + " " + mouseClick[1] + "]");
* System.out.println(" mouseCurent = [" + mouseCurent[0] + " " +
* mouseCurent[1] + "]");
*/
/*mouseCurent[0] = e.getX();
mouseCurent[1] = e.getY();
e.consume();
if (allowNote) {
for (int i = 0; i < plots.size(); i++) {
double[] _coordNoted = getPlot(i).isSelected(mouseCurent, draw);
if (_coordNoted != null) {
getPlot(i).noted = !getPlot(i).noted;
} else {
getPlot(i).noted = false;
}
}
repaint();
}*/
}
public void mouseWheelMoved(MouseWheelEvent e) {
//System.out.println("PlotCanvas.mouseWheelMoved");
/*
* System.out.println("PlotCanvas.mouseWheelMoved");
* System.out.println(" mouseClick = [" + mouseClick[0] + " " +
* mouseClick[1] + "]"); System.out.println(" mouseCurent = [" +
* mouseCurent[0] + " " + mouseCurent[1] + "]");
*/
mouseCurent[0] = e.getX();
mouseCurent[1] = e.getY();
e.consume();
int[] origin;
double[] ratio;
// double factor = 1.5;
//switch (ActionMode) {
// case ZOOM:
if (e.getWheelRotation() == -1) {
if (Array.max(((AWTDrawer) draw).projection.totalScreenRatio) > .01) {
/* (2*factor) */
/* (2*factor) */
origin = new int[]{mouseCurent[0] - getWidth() / 3,
mouseCurent[1] - getHeight() / 3};
ratio = new double[]{0.666/* 1/factor, 1/factor */, 0.666};
draw.dilate(origin, ratio);
}
} else {
if (Array.max(((AWTDrawer) draw).projection.totalScreenRatio) < 1) {
origin = new int[]{(int) (mouseCurent[0] - getWidth() / 1.333/* (2/factor) */),
(int) (mouseCurent[1] - getHeight() / 1.333/* (2/factor) */)
};
ratio = new double[]{1.5, 1.5 /* factor, factor */};
draw.dilate(origin, ratio);
} else /* (Array.max(((AWTDrawer) draw).projection.totalScreenRatio) >= 1)*/ {
((AWTDrawer) draw).projection.initBaseCoordsProjection(true);
}
}
repaint();
// break;
//}
}
public void componentHidden(ComponentEvent e) {
}
public void componentMoved(ComponentEvent e) {
}
public void componentResized(ComponentEvent e) {
//System.out.println("PlotCanvas.componentResized");
//panelSize = new int[] { (int) (getSize().getWidth()), (int) (getSize().getHeight()) };
if (draw != null) {
draw.resetBaseProjection();
}
//System.out.println("PlotCanvas : "+panelSize[0]+" x "+panelSize[1]);
repaint();
if (linkedLegendPanel != null) {
linkedLegendPanel.componentResized(e);
}
}
public void componentShown(ComponentEvent e) {
}
}

View file

@ -1,53 +0,0 @@
package org.xbib.graphics.graph.jmathplot.frame;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.Plot;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
/**
* BSD License
*
* @author Yann RICHET
*/
public class DataFrame extends JFrame {
private static final long serialVersionUID = 1L;
private final PlotCanvas plotCanvas;
private final JTabbedPane panels;
public DataFrame(PlotCanvas p) {
super("Data");
plotCanvas = p;
JPanel panel = new JPanel();
panels = new JTabbedPane();
panel.add(panels);
setContentPane(panel);
//setVisible(true);
}
@Override
public void setVisible(boolean b) {
if (b) {
setPanel();
}
super.setVisible(b);
}
private void setPanel() {
panels.removeAll();
for (Plot plot : plotCanvas.getPlots()) {
panels.add(plot.getDataPanel(plotCanvas), plot.getName());
}
pack();
}
public void selectIndex(int i) {
setVisible(true);
if (panels.getTabCount() > i) {
panels.setSelectedIndex(i);
}
}
}

View file

@ -1,86 +0,0 @@
package org.xbib.graphics.graph.jmathplot.frame;
import org.xbib.graphics.graph.jmathplot.panel.DataPanel;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.AccessControlException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JToolBar;
/**
* BSD License
*
* @author Yann RICHET
*/
public class DataToolBar extends JToolBar {
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 1L;
protected JButton buttonPasteToClipboard;
protected JButton buttonSaveFile;
private boolean denySaveSecurity;
private JFileChooser fileChooser;
private final DataPanel dataPanel;
public DataToolBar(DataPanel dp) {
dataPanel = dp;
try {
fileChooser = new JFileChooser();
} catch (AccessControlException ace) {
denySaveSecurity = true;
}
buttonPasteToClipboard = new JButton(new ImageIcon(PlotPanel.class.getResource("icons/toclipboard.png")));
buttonPasteToClipboard.setToolTipText("Copy data to clipboard");
buttonSaveFile = new JButton(new ImageIcon(PlotPanel.class.getResource("icons/tofile.png")));
buttonSaveFile.setToolTipText("Save data into ASCII file");
buttonPasteToClipboard.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dataPanel.toClipBoard();
}
});
buttonSaveFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
chooseFile();
}
});
add(buttonPasteToClipboard, null);
add(buttonSaveFile, null);
if (!denySaveSecurity) {
fileChooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
saveFile();
}
});
} else {
buttonSaveFile.setEnabled(false);
}
}
void saveFile() {
java.io.File file = fileChooser.getSelectedFile();
dataPanel.toASCIIFile(file);
}
void chooseFile() {
fileChooser.showSaveDialog(this);
}
}

View file

@ -1,106 +0,0 @@
package org.xbib.graphics.graph.jmathplot.frame;
import org.xbib.graphics.graph.jmathplot.panel.MatrixTablePanel;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.Plot;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* BSD License
*
* @author Yann RICHET
*/
public class DatasFrame extends JFrame {
private static final long serialVersionUID = 1L;
private final PlotCanvas plotCanvas;
private final LegendPanel legend;
public JTabbedPane panels;
public DatasFrame(PlotCanvas p, LegendPanel l) {
super("Data");
plotCanvas = p;
legend = l;
JPanel panel = new JPanel();
panels = new JTabbedPane();
for (Plot plot : plotCanvas.getPlots()) {
panels.add(new DataPanel(/*this, */plot), plot.getName());
}
panel.add(panels);
setContentPane(panel);
pack();
setVisible(true);
}
public class DataPanel extends JPanel {
private static final long serialVersionUID = 1L;
MatrixTablePanel XY;
JCheckBox visible;
JButton color;
JPanel plottoolspanel;
Plot plot;
DatasFrame dframe;
public DataPanel(/*DatasFrame _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) {
plot.setVisible(visible.isSelected());
/*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);
legend.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);
}
}
}

View file

@ -1,270 +0,0 @@
package org.xbib.graphics.graph.jmathplot.frame;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.Plot;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.LinkedList;
import javax.swing.BorderFactory;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.Border;
/**
* BSD License
*
* @author Yann RICHET
*/
public class LegendPanel extends JPanel implements ComponentListener {
private static final long serialVersionUID = 1L;
PlotCanvas plotCanvas;
PlotPanel plotPanel;
LinkedList<Legend> legends;
public static int INVISIBLE = -1;
public static int VERTICAL = 0;
public static int HORIZONTAL = 1;
int orientation;
private int maxHeight;
private int maxWidth;
JPanel container;
private final int inset = 5;
public LegendPanel(PlotPanel _plotPanel, int _orientation) {
plotPanel = _plotPanel;
plotCanvas = plotPanel.plotCanvas;
plotCanvas.attachLegend(this);
orientation = _orientation;
container = new JPanel();
container.setBackground(plotCanvas.getBackground());
container.setLayout(new GridLayout(1, 1, inset, inset));
container.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.GRAY, 1), null));
updateLegends();
setBackground(plotCanvas.getBackground());
addComponentListener(this);
setLayout(new GridBagLayout());
add(container);
}
public void updateLegends() {
if (orientation != INVISIBLE) {
container.removeAll();
maxHeight = 1;
maxWidth = 1;
legends = new LinkedList<Legend>();
for (Plot plot : plotCanvas.getPlots()) {
if (!plot.getVisible()) {
continue;
}
Legend l = new Legend(plot);
legends.add(l);
maxWidth = (int) Math.max(maxWidth, l.getPreferredSize().getWidth());
maxHeight = (int) Math.max(maxHeight, l.getPreferredSize().getHeight());
container.add(l);
}
updateSize();
//repaint();
}
}
private void updateSize() {
//System.out.println("LegendPanel.updateSize");
if (orientation == VERTICAL) {
int nh = 1;
if (maxHeight < plotCanvas.getHeight()) {
nh = plotCanvas.getHeight() / (maxHeight + inset);
}
int nw = 1 + legends.size() / nh;
((GridLayout) (container.getLayout())).setColumns(nw);
((GridLayout) (container.getLayout())).setRows(1 + legends.size() / nw);
container.setPreferredSize(new Dimension((maxWidth + inset) * nw, (maxHeight + inset) * (1 + legends.size() / nw)));
} else if (orientation == HORIZONTAL) {
int nw = 1;
if (maxWidth < plotCanvas.getWidth()) {
nw = plotCanvas.getWidth() / (maxWidth + inset);
}
int nh = 1 + legends.size() / nw;
((GridLayout) (container.getLayout())).setRows(nh);
((GridLayout) (container.getLayout())).setColumns(1 + legends.size() / nh);
container.setPreferredSize(new Dimension((maxWidth + inset) * (1 + legends.size() / nh), (maxHeight + inset) * nh));
}
container.updateUI();
}
public void note(int i) {
if (orientation != INVISIBLE && legends != null && legends.size() > i) {
legends.get(i).setBackground(PlotCanvas.NOTE_COLOR);
legends.get(i).name.setForeground(plotPanel.getBackground());
}
}
public void nonote(int i) {
if (orientation != INVISIBLE && legends != null && legends.size() > i) {
legends.get(i).setBackground(plotPanel.getBackground());
legends.get(i).name.setForeground(PlotCanvas.NOTE_COLOR);
}
}
public void componentResized(ComponentEvent e) {
//System.out.println("LegendPanel.componentResized");
//System.out.println("PlotCanvas : "+plotCanvas.panelSize[0]+" x "+plotCanvas.panelSize[1]);
if (orientation != INVISIBLE) {
updateSize();
}
}
public void componentMoved(ComponentEvent e) {
}
public void componentShown(ComponentEvent e) {
}
public void componentHidden(ComponentEvent e) {
}
public class Legend extends JPanel {
private static final long serialVersionUID = 1L;
JPanel color;
JLabel name;
Plot plot;
Border colorborder;
public Legend(Plot p) {
plot = p;
setLayout(new BorderLayout(2, 2));
color = new JPanel();
colorborder = BorderFactory.createMatteBorder(2, 1, 2, 1, Color.WHITE);
color.setBorder(colorborder);
name = new JLabel();
name.setFont(plotPanel.getFont());
setBackground(Color.WHITE);
update();
add(color, BorderLayout.WEST);
add(name, BorderLayout.CENTER);
name.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
if (e.getModifiers() == MouseEvent.BUTTON1_MASK) {
if (plotCanvas.allowEdit && e.getClickCount() > 1) {
editText();
}
}
if (plotCanvas.allowNote && e.getClickCount() <= 1) {
note_nonote();
}
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
});
color.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
if (e.getModifiers() == MouseEvent.BUTTON1_MASK) {
if (plotCanvas.allowEdit && e.getClickCount() > 1) {
editColor();
}
}
if (plotCanvas.allowNote && e.getClickCount() <= 1) {
note_nonote();
}
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
});
}
public void editText() {
String name1 = JOptionPane.showInputDialog(plotCanvas, "Choose name", plot.getName());
if (name1 != null) {
plot.setName(name1);
update();
updateLegends();
}
}
public void editColor() {
Color c = JColorChooser.showDialog(plotCanvas, "Choose plot color", plot.getColor());
if (c != null) {
plot.setColor(c);
update();
plotCanvas.repaint();
}
}
public void update() {
int size = name.getFont().getSize();
color.setSize(new Dimension(size, size));
color.setPreferredSize(new Dimension(size, size));
// TODO change legend when plot is invisible
/*if (!plot.visible)
color.setBackground(Color.LIGHT_GRAY);
else*/
color.setBackground(plot.getColor());
/*if (!plot.visible) {
name.setFont(name.getFont().deriveFont(Font.ITALIC));
name.setForeground(Color.LIGHT_GRAY);
}*/
name.setText(plot.getName());
repaint();
}
public void note_nonote() {
plot.noted = !plot.noted;
plotCanvas.repaint();
}
}
}

View file

@ -1,250 +0,0 @@
package org.xbib.graphics.graph.jmathplot.frame;
import org.xbib.graphics.graph.jmathplot.panel.PlotPanel;
import org.xbib.graphics.graph.jmathplot.canvas.Plot3DCanvas;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.security.AccessControlException;
import javax.imageio.ImageIO;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.filechooser.FileFilter;
public class PlotToolBar extends JToolBar {
// TODO redesign icons...
private static final long serialVersionUID = 1L;
protected ButtonGroup buttonGroup;
protected JToggleButton buttonCenter;
//protected JToggleButton buttonEdit;
protected JToggleButton buttonZoom;
protected JToggleButton buttonRotate;
//protected JToggleButton buttonViewCoords;
protected JButton buttonSetScales;
protected JButton buttonDatas;
protected JButton buttonSavePNGFile;
protected JButton buttonReset;
protected JButton buttonAdjustBounds;
private boolean denySaveSecurity;
private JFileChooser pngFileChooser;
/**
* the currently selected PlotPanel
*/
private final PlotCanvas plotCanvas;
private final PlotPanel plotPanel;
public PlotToolBar(PlotPanel pp) {
plotPanel = pp;
plotCanvas = pp.plotCanvas;
try {
pngFileChooser = new JFileChooser();
pngFileChooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().endsWith(".png");
}
public String getDescription() {
return "Portable Network Graphic file";
}
});
} catch (AccessControlException ace) {
denySaveSecurity = true;
}
try {
buttonGroup = new ButtonGroup();
buttonCenter = new JToggleButton(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("icons/center.png"))));
buttonCenter.setToolTipText("Center axis");
buttonCenter.setSelected(plotCanvas.ActionMode == PlotCanvas.TRANSLATION);
buttonZoom = new JToggleButton(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("icons/zoom.png"))));
buttonZoom.setToolTipText("Zoom");
buttonZoom.setSelected(plotCanvas.ActionMode == PlotCanvas.ZOOM);
//buttonEdit = new JToggleButton(new ImageIcon(PlotPanel.class.getResource("icons/edit.png")));
//buttonEdit.setToolTipText("Edit mode");
//buttonViewCoords = new JToggleButton(new ImageIcon(PlotPanel.class.getResource("icons/position.png")));
//buttonViewCoords.setToolTipText("Highlight coordinates / Highlight plot");
buttonSetScales = new JButton(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("icons/scale.png"))));
buttonSetScales.setToolTipText("Edit axis scales");
buttonDatas = new JButton(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("icons/data.png"))));
buttonDatas.setToolTipText("Get data");
buttonSavePNGFile = new JButton(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("icons/topngfile.png"))));
buttonSavePNGFile.setToolTipText("Save graphics in a .PNG File");
buttonReset = new JButton(new ImageIcon(getClass().getResource("icons/back.png")));
buttonReset.setToolTipText("Reset zoom & axis");
buttonAdjustBounds = new JButton(new ImageIcon(ImageIO.read(getClass().getResourceAsStream(plotCanvas.getAdjustBounds() ? "icons/adjustbounds.png" : "icons/noadjustbounds.png"))));
buttonAdjustBounds.setToolTipText("Auto-update/fix bounds");
/*buttonEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = PlotCanvas.EDIT;
}
});*/
buttonZoom.setSelected(true);
buttonZoom.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = PlotCanvas.ZOOM;
}
});
buttonCenter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = PlotCanvas.TRANSLATION;
}
});
/*buttonViewCoords.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.setNoteCoords(buttonViewCoords.isSelected());
}
});*/
buttonSetScales.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.displayScalesFrame();
}
});
buttonDatas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.displayDataFrame();
}
});
buttonSavePNGFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
choosePNGFile();
}
});
buttonReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.resetBase();
}
});
buttonAdjustBounds.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.setAdjustBounds(!plotCanvas.getAdjustBounds());
ajustBoundsChanged();
}
});
buttonGroup.add(buttonCenter);
buttonGroup.add(buttonZoom);
//buttonGroup.add(buttonEdit);
add(buttonCenter, null);
add(buttonZoom, null);
add(buttonReset, null);
//add(buttonViewCoords, null);
add(buttonSetScales, null);
if (adjustBoundsVisible) {
add(buttonAdjustBounds, null);
}
//add(buttonEdit, null);
add(buttonSavePNGFile, null);
add(buttonDatas, null);
if (!denySaveSecurity) {
pngFileChooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
saveGraphicFile();
}
});
} else {
buttonSavePNGFile.setEnabled(false);
}
//buttonEdit.setEnabled(plotCanvas.getEditable());
//buttonViewCoords.setEnabled(plotCanvas.getNotable());
// allow mixed (2D/3D) plots managed by one toolbar
if (plotCanvas instanceof Plot3DCanvas) {
if (buttonRotate == null) {
buttonRotate = new JToggleButton(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("icons/rotation.png"))));
buttonRotate.setToolTipText("Rotate axes");
buttonRotate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = Plot3DCanvas.ROTATION;
}
});
buttonGroup.add(buttonRotate);
add(buttonRotate, null, 2);
buttonRotate.setSelected(plotCanvas.ActionMode == Plot3DCanvas.ROTATION);
} else {
buttonRotate.setEnabled(true);
}
} else {
if (buttonRotate != null) {
// no removal/disabling just disable
if (plotCanvas.ActionMode == Plot3DCanvas.ROTATION) {
plotCanvas.ActionMode = PlotCanvas.ZOOM;
}
buttonRotate.setEnabled(false);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
void choosePNGFile() {
pngFileChooser.showSaveDialog(this);
}
void saveGraphicFile() {
File file = pngFileChooser.getSelectedFile();
try {
plotPanel.toGraphicFile(file);
} catch (IOException e) {
JOptionPane.showConfirmDialog(null, "Save failed : " + e.getMessage(), "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
}
}
boolean adjustBoundsVisible = true;
public void viewAdjustBounds(boolean visible) {
if (visible && !adjustBoundsVisible) {
add(buttonAdjustBounds, null);
adjustBoundsVisible = true;
}
if (!visible && adjustBoundsVisible) {
remove(buttonAdjustBounds);
adjustBoundsVisible = false;
}
ajustBoundsChanged();
}
public void ajustBoundsChanged() {
try {
buttonAdjustBounds.setIcon(new ImageIcon(ImageIO.read(getClass().getResourceAsStream(plotCanvas.getAdjustBounds() ? "icons/adjustbounds.png" : "icons/noadjustbounds.png"))));
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -1,393 +0,0 @@
package org.xbib.graphics.graph.jmathplot.frame;
import org.xbib.graphics.graph.jmathplot.io.StringPrintable;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.Base;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
/**
* BSD License
*
* @author Yann RICHET
* Changed on 6/13/2014 by Jerry Dietrich
* Contact info ballooninternet@cox.net
*/
public class ScalesFrame extends JFrame implements WindowFocusListener, WindowListener {
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 1L;
private PlotCanvas plotCanvas;
private JPanel scalespanel;
private ScalePanel[] scalepanels;
public ScalesFrame(PlotCanvas p) {
super("scales settings");
plotCanvas = p;
setPanel();
setContentPane(scalespanel);
setResizable(false);
//setVisible(true);
addWindowFocusListener(this);
addWindowListener(this);
}
boolean editable = true;
public void setEditable(boolean e) {
editable = e;
}
@Override
public void setVisible(boolean b) {
if (b) {
setPanel();
}
super.setVisible(b);
}
private void setPanel() {
scalespanel = new JPanel();
if (plotCanvas.base == null) {
return;
}
int nbAxes = plotCanvas.base.dimension;
this.setSize(nbAxes * 300, 200);
scalespanel.setLayout(new GridLayout(1, nbAxes));
scalepanels = new ScalePanel[nbAxes];
for (int i = 0; i < nbAxes; i++) {
scalepanels[i] = new ScalePanel(plotCanvas, i);
scalespanel.add(scalepanels[i]);
scalepanels[i].max_field.setEditable(editable);
scalepanels[i].min_field.setEditable(editable);
scalepanels[i].bounds_auto.setEnabled(editable);
scalepanels[i].log_check.setEnabled(editable);
scalepanels[i].linear_check.setEnabled(editable);
scalepanels[i].title_field.setEnabled(editable);
}
setContentPane(scalespanel);
}
/*
* private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int
* gw, int gh, int wx, int wy) { gbc.gridx = gx; gbc.gridy = gy;
* gbc.gridwidth = gw; gbc.gridheight = gh; gbc.weightx = wx; gbc.weighty =
* wy; }
*/
public void setDefaultCloseOperation(int operation) {
for (int i = 0; i < scalepanels.length; i++) {
scalepanels[i].updateBoundsFields();
}
super.setDefaultCloseOperation(operation);
}
public void windowGainedFocus(WindowEvent e) {
for (int i = 0; i < scalepanels.length; i++) {
scalepanels[i].update();
}
}
public void windowLostFocus(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
for (int i = 0; i < scalepanels.length; i++) {
scalepanels[i].update();
}
}
public void windowDeactivated(WindowEvent e) {
}
public class ScalePanel extends JPanel implements StringPrintable {
private static final long serialVersionUID = 1L;
// private PlotCanvas plotCanvas;
private final int numAxe;
private String title;
private String scaleType;
private double min;
private double max;
private final JLabel title_label = new JLabel("Title");
private final JTextField title_field = new JTextField();
private final JLabel scale_label = new JLabel("Scale");
private final ButtonGroup scale_group = new ButtonGroup();
private final JRadioButton linear_check = new JRadioButton("Linear");
private final JRadioButton log_check = new JRadioButton("Logarithmic");
// private JCheckBox gridVisible = new JCheckBox("Grid visible");
private final JLabel bounds_label = new JLabel("Bounds");
private final JLabel min_label = new JLabel("Min");
private final JLabel max_label = new JLabel("Max");
private final JTextField min_field = new JTextField();
private final JTextField max_field = new JTextField();
private final JButton bounds_auto = new JButton("Automatic");
public ScalePanel(PlotCanvas p, int i) {
numAxe = i;
plotCanvas = p;
update();
addComponents();
setListeners();
}
public void update() {
title = plotCanvas.getGrid().getAxis(numAxe).getLegend();// getLegend(numAxe);
title_field.setText(title);
scaleType = plotCanvas.getAxisScales()[numAxe];
log_check.setSelected(scaleType.equalsIgnoreCase(Base.LOGARITHM));
linear_check.setSelected(scaleType.equalsIgnoreCase(Base.LINEAR));
if (scaleType.equalsIgnoreCase(Base.STRINGS)) {
log_check.setEnabled(false);
linear_check.setEnabled(false);
}
updateBoundsFields();
}
private void addComponents() {
this.setSize(300, 200);
scale_group.add(linear_check);
scale_group.add(log_check);
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
this.setLayout(gbl);
buildConstraints(c, 0, 0, 1, 1, 40, 20);
c.fill = GridBagConstraints.CENTER;
c.anchor = GridBagConstraints.CENTER;
gbl.setConstraints(title_label, c);
this.add(title_label);
buildConstraints(c, 1, 0, 2, 1, 60, 20);
c.fill = GridBagConstraints.HORIZONTAL;
gbl.setConstraints(title_field, c);
this.add(title_field);
buildConstraints(c, 0, 1, 1, 1, 40, 20);
c.fill = GridBagConstraints.CENTER;
c.anchor = GridBagConstraints.CENTER;
gbl.setConstraints(scale_label, c);
this.add(scale_label);
buildConstraints(c, 1, 1, 2, 1, 60, 20);
c.fill = GridBagConstraints.HORIZONTAL;
gbl.setConstraints(linear_check, c);
this.add(linear_check);
buildConstraints(c, 1, 2, 2, 1, 60, 20);
c.fill = GridBagConstraints.HORIZONTAL;
gbl.setConstraints(log_check, c);
this.add(log_check);
buildConstraints(c, 0, 3, 1, 1, 40, 20);
c.fill = GridBagConstraints.CENTER;
c.anchor = GridBagConstraints.CENTER;
gbl.setConstraints(bounds_label, c);
this.add(bounds_label);
buildConstraints(c, 1, 3, 1, 1, 20, 20);
c.fill = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.CENTER;
gbl.setConstraints(min_label, c);
this.add(min_label);
buildConstraints(c, 2, 3, 1, 1, 50, 20);
c.fill = GridBagConstraints.HORIZONTAL;
gbl.setConstraints(min_field, c);
this.add(min_field);
buildConstraints(c, 1, 4, 1, 1, 20, 20);
c.fill = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.CENTER;
gbl.setConstraints(max_label, c);
this.add(max_label);
buildConstraints(c, 2, 4, 1, 1, 50, 20);
c.fill = GridBagConstraints.HORIZONTAL;
gbl.setConstraints(max_field, c);
this.add(max_field);
buildConstraints(c, 1, 5, 2, 1, 60, 20);
c.fill = GridBagConstraints.CENTER;
gbl.setConstraints(bounds_auto, c);
this.add(bounds_auto);
// this.add(gridVisible);
}
private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) {
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
}
private void setListeners() {
title_field.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
setTitle();
}
public void keyPressed(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
});
log_check.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setScale();
updateBoundsFields();
}
});
linear_check.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setScale();
updateBoundsFields();
}
});
/*
* gridVisible.addChangeListener(new ChangeListener() { public void
* stateChanged(ChangeEvent e) {
* plotPanel.getGrid().getAxe(numAxe).setVisible(
* gridVisible.isSelected()); plotPanel.repaint(); } });
*/
min_field.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
setBounds();
}
public void keyPressed(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
});
max_field.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
setBounds();
}
public void keyPressed(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
});
bounds_auto.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setBoundsAuto();
}
});
}
public String getText() {
return "title = " + title + "\nscaleType = " + scaleType + "\nmin = " + min + "\nmax = " + max;
}
private void setTitle() {
// System.out.println("title setting n<>" + numAxe + " : " +
// title_field.getText());
plotCanvas.setAxisLabel(numAxe, title_field.getText());
}
private void setBounds() {
// System.out.println("bounds setting n<>" + numAxe + " : " +
// min_field.getText() + " - " + max_field.getText());
try {
double min1 = Double.parseDouble(min_field.getText());
double max1 = Double.parseDouble(max_field.getText());
plotCanvas.setFixedBounds(numAxe, min1, max1);
} catch (IllegalArgumentException iae) {
// JOptionPane.showConfirmDialog(null, iae.getMessage(),
// "Error", JOptionPane.DEFAULT_OPTION,
// JOptionPane.ERROR_MESSAGE);
// updateBoundsFields();
}
}
private void setScale() {
// System.out.println("scale setting n<>" + numAxe + " : " + (
// (log_check.isSelected()) ? ("LOG") : ("LINEAR")));
try {
plotCanvas.setAxiScale(numAxe, (log_check.isSelected()) ? (Base.LOGARITHM) : (Base.LINEAR));
} catch (IllegalArgumentException iae) {
JOptionPane.showConfirmDialog(null, iae.getMessage(), "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
updateBoundsFields();
}
}
private void setBoundsAuto() {
plotCanvas.setAutoBounds(numAxe);
updateBoundsFields();
// System.out.println("auto-Bounds setting n<>"+numAxe+" :
// "+plotPanel.getBase().getMinBounds()[numAxe]+" -
// "+plotPanel.getBase().getMaxBounds()[numAxe]);
}
private void updateBoundsFields() {
min = plotCanvas.base.getMinBounds()[numAxe];
max = plotCanvas.base.getMaxBounds()[numAxe];
min_field.setText("" + min);
max_field.setText("" + max);
// log_check.setSelected(plotCanvas.base.getAxeScale(numAxe)==Base.LOG);
}
}
}

View file

@ -1,5 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io;
public interface ClipBoardPrintable {
void toClipBoard();
}

View file

@ -1,7 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io;
import java.io.File;
public interface FilePrintable {
void toASCIIFile(File f);
}

View file

@ -1,5 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io;
public interface StringPrintable {
String getText();
}

View file

@ -1,276 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io.files;
import org.xbib.graphics.graph.jmathplot.io.parser.ArrayString;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.Vector;
/**
* BSD License
*
* @author Yann RICHET
*/
public class ASCIIFile extends DataFile {
public ASCIIFile(File f) {
super(f);
}
public static String read(File f) {
ASCIIFile af = new ASCIIFile(f);
return af.read();
}
public static String[] readLines(File f) {
ASCIIFile af = new ASCIIFile(f);
return af.readLines();
}
public static String readLine(File f, int i) {
ASCIIFile af = new ASCIIFile(f);
return af.readLine(i);
}
public static double[] readDouble1DArray(File f) {
return ArrayString.readString1DDouble(ASCIIFile.read(f));
}
public static double[][] readDoubleArray(File f) {
return ArrayString.readStringDouble(ASCIIFile.read(f));
}
public static int[] readInt1DArray(File f) {
return ArrayString.readString1DInt(ASCIIFile.read(f));
}
public static int[][] readIntArray(File f) {
return ArrayString.readStringInt(ASCIIFile.read(f));
}
public static void write(File f, String t) {
ASCIIFile af = new ASCIIFile(f);
af.write(t, false);
}
public static void writeDoubleArray(File f, double[] array) {
write(f, ArrayString.printDoubleArray(array));
}
public static void writeDoubleArray(File f, double[][] array) {
write(f, ArrayString.printDoubleArray(array));
}
public static void writeIntArray(File f, int[] array) {
write(f, ArrayString.printIntArray(array));
}
public static void writeIntArray(File f, int[][] array) {
write(f, ArrayString.printIntArray(array));
}
public static void append(File f, String t) {
ASCIIFile af = new ASCIIFile(f);
af.write(t, true);
}
/**
* Read an ASCII File
*
* @return String
*/
public String read() {
StringBuffer text = new StringBuffer((int) file.length());
BufferedReader b = null;
try {
FileReader fr = new FileReader(file);
b = new BufferedReader(fr);
boolean eof = false;
String line;
String ret = "\n";
while (!eof) {
line = b.readLine();
if (line == null) {
eof = true;
} else {
text.append(line);
text.append(ret);
}
}
} catch (IOException e) {
throw new IllegalArgumentException("File " + file.getName()
+ " is unreadable : " + e.toString());
} finally {
try {
b.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return text.toString();
}
/**
* Read lines of an ASCII File
*
* @return an Array of String
*/
public String[] readLines() {
Vector<String> linesVector = new Vector<String>();
BufferedReader b = null;
try {
FileReader fr = new FileReader(file);
b = new BufferedReader(fr);
boolean eof = false;
while (!eof) {
String line = b.readLine();
if (line == null) {
eof = true;
} else {
linesVector.add(line);
}
}
} catch (IOException e) {
throw new IllegalArgumentException("File " + file.getName()
+ " is unreadable : " + e.toString());
} finally {
try {
b.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
String[] lines = new String[linesVector.size()];
for (int i = 0; i < lines.length; i++) {
lines[i] = linesVector.get(i);
}
return lines;
}
/**
* Read only one line in an ASCII File
*
* @param i line index
* @return String
*/
public String readLine(int i) {
String line = "";
BufferedReader b = null;
try {
FileReader fr = new FileReader(file);
b = new BufferedReader(fr);
boolean eof = false;
for (int j = 0; j < i; j++) {
if (eof) {
throw new IllegalArgumentException("Line " + i
+ " is not found in the file " + file.getName()
+ ".");
}
line = b.readLine();
if (line == null) {
eof = true;
}
}
line = b.readLine();
} catch (IOException e) {
throw new IllegalArgumentException("File " + file.getName()
+ " is unreadable : " + e.toString());
} finally {
try {
b.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return line;
}
/**
* Write a text in an ASCII File
*
* @param text String
* @param append boolean
*/
public void write(String text, boolean append) {
if (file.exists() && !append) {
System.out.println("Warning : the file " + file.getName()
+ " already exists !");
}
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter(file, append);
bw = new BufferedWriter(fw);
bw.write(text);
} catch (IOException e) {
throw new IllegalArgumentException("File " + file.getName()
+ " is unwritable : " + e.toString());
} finally {
try {
bw.close();
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public static void concatenate(File f1, File f2) {
FileInputStream fis = null;
BufferedInputStream bis = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try {
fis = new FileInputStream(f2);
bis = new BufferedInputStream(fis);
fos = new FileOutputStream(f1, true);
bos = new BufferedOutputStream(fos);
int c;
while ((c = bis.read()) != -1) {
bos.write(c);
}
} catch (IOException e) {
System.err.println("Concatenate: " + e);
} finally {
try {
bis.close();
fis.close();
bos.close();
fos.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public static void main(String[] args) {
File f = new File("read.txt");
System.out.println(ASCIIFile.read(f));
String[] lines = ASCIIFile.readLines(f);
for (int i = 0; i < lines.length; i++) {
System.out.println("line " + i + " : " + lines[i]);
}
System.out.println(ASCIIFile.readLine(f, 0));
System.out.println(ASCIIFile.readLine(f, lines.length - 1));
ASCIIFile.append(new File("write.txt"), Calendar.getInstance().getTime().toString());
}
}

View file

@ -1,402 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io.files;
import org.xbib.graphics.graph.jmathplot.io.stream.BinaryInputStream;
import org.xbib.graphics.graph.jmathplot.io.stream.BinaryOutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
/**
* BSD License
*
* @author Yann RICHET
*/
public class BinaryFile {
public static String LITTLE_ENDIAN = "LITTLE_ENDIAN";
public static String BIG_ENDIAN = "BIG_ENDIAN";
private final boolean bigEndian;
private final File file;
public BinaryFile(File f, String endian) {
file = f;
bigEndian = isBigEndian(endian);
}
private boolean isBigEndian(String endian) {
boolean be;
if (endian.equals(LITTLE_ENDIAN)) {
be = false;
} else if (endian.equals(BIG_ENDIAN)) {
be = true;
} else {
throw new IllegalArgumentException(
"The Endian type : "
+ endian
+ "is unknown. You must specify LITTLE_ENDIAN or BIG_ENDIAN.");
}
return be;
}
public static double[] readDoubleArray(File f, String endian) {
BinaryFile bf = new BinaryFile(f, endian);
return bf.readDoubleArray();
}
public static float[] readFloatArray(File f, String endian) {
BinaryFile bf = new BinaryFile(f, endian);
return bf.readFloatArray();
}
public static int[] readIntArray(File f, String endian) {
BinaryFile bf = new BinaryFile(f, endian);
return bf.readIntArray();
}
public static void writeDoubleArray(File f, double[] array, String endian) {
BinaryFile bf = new BinaryFile(f, endian);
bf.writeDoubleArray(array, false);
}
public static void appendDoubleArray(File f, double[] array, String endian) {
BinaryFile bf = new BinaryFile(f, endian);
bf.writeDoubleArray(array, true);
}
public static void writeFloatArray(File f, float[] array, String endian) {
BinaryFile bf = new BinaryFile(f, endian);
bf.writeFloatArray(array, false);
}
public static void appendFloatArray(File f, float[] array, String endian) {
BinaryFile bf = new BinaryFile(f, endian);
bf.writeFloatArray(array, true);
}
public static void writeIntArray(File f, int[] array, String endian) {
BinaryFile bf = new BinaryFile(f, endian);
bf.writeIntArray(array, false);
}
public static void appendIntArray(File f, int[] array, String endian) {
BinaryFile bf = new BinaryFile(f, endian);
bf.writeIntArray(array, true);
}
/**
* Read a binary File
*
* @return int[]
*/
public int[] readIntArray() {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException(ex.toString());
}
BufferedInputStream bis = new BufferedInputStream(fis);
BinaryInputStream bs = new BinaryInputStream(bis, bigEndian);
return bs.readIntArray();
}
/**
* Read a binary File
*
* @return float[]
*/
public float[] readFloatArray() {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException(ex.toString());
}
BufferedInputStream bis = new BufferedInputStream(fis);
BinaryInputStream bs = new BinaryInputStream(bis, bigEndian);
return bs.readFloatArray();
}
/**
* Read a binary File
*
* @return double[]
*/
public double[] readDoubleArray() {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException(ex.toString());
}
BufferedInputStream bis = new BufferedInputStream(fis);
BinaryInputStream bs = new BinaryInputStream(bis, bigEndian);
return bs.readDoubleArray();
}
/**
* Read a binary File
*
* @return byte[]
*/
public byte[] readByteArray() {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException(ex.toString());
}
BufferedInputStream bis = new BufferedInputStream(fis);
BinaryInputStream bs = new BinaryInputStream(bis, bigEndian);
return bs.readByteArray();
}
/**
* Write an int array in a binary File
*
* @param array int[]
* @param append boolean
*/
public void writeIntArray(int[] array, boolean append) {
if (file.exists()) {
System.out.println("Warning : the file " + file.getName()
+ " already exists !");
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file, append);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException(ex.toString());
}
BufferedOutputStream bos = new BufferedOutputStream(fos);
BinaryOutputStream bs = new BinaryOutputStream(bos, bigEndian);
bs.writeIntArray(array, append);
}
/**
* Write a float array in a binary File
*
* @param array float[]
* @param append boolean
*/
public void writeFloatArray(float[] array, boolean append) {
if (file.exists()) {
System.out.println("Warning : the file " + file.getName()
+ " already exists !");
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file, append);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException(ex.toString());
}
BufferedOutputStream bos = new BufferedOutputStream(fos);
BinaryOutputStream bs = new BinaryOutputStream(bos, bigEndian);
bs.writeFloatArray(array, append);
//TODO add try/catch/finally !!!
}
/**
* Write a double array in a binary File
*
* @param array float[]
* @param append boolean
*/
public void writeDoubleArray(double[] array, boolean append) {
if (file.exists()) {
System.out.println("Warning : the file " + file.getName()
+ " already exists !");
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file, append);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException(ex.toString());
}
BufferedOutputStream bos = new BufferedOutputStream(fos);
BinaryOutputStream bs = new BinaryOutputStream(bos, bigEndian);
bs.writeDoubleArray(array, append);
}
/**
* Write a text in a binary File
*
* @param bytes byte[]
* @param append boolean
*/
public void writeByteArray(byte[] bytes, boolean append) {
if (file.exists()) {
System.out.println("Warning : the file " + file.getName()
+ " already exists !");
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file, append);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException(ex.toString());
}
BufferedOutputStream bos = new BufferedOutputStream(fos);
BinaryOutputStream bs = new BinaryOutputStream(bos, bigEndian);
bs.writeByteArray(bytes, append);
}
/**
* Read a binary File
*
* @return int
*/
public int readInt() {
return readIntArray()[0];
}
/**
* Read a binary File
*
* @return float
*/
public float readFloat() {
return readFloatArray()[0];
}
/**
* Read a binary File
*
* @return double
*/
public double readDouble() {
return readDoubleArray()[0];
}
/**
* Read a binary File
*
* @return byte
*/
public byte readByte() {
return readByteArray()[0];
}
/**
* Write an int in a binary File
*
* @param i int
* @param append boolean
*/
public void writeInt(int i, boolean append) {
writeIntArray(new int[]{i}, append);
}
/**
* Write a float in a binary File
*
* @param f float
* @param append boolean
*/
public void writeFloat(float f, boolean append) {
writeFloatArray(new float[]{f}, append);
}
/**
* Write a double in a binary File
*
* @param d double
* @param append boolean
*/
public void writeDouble(double d, boolean append) {
writeDoubleArray(new double[]{d}, append);
}
/**
* Write a text in a binary File
*
* @param b byte
* @param append boolean
*/
public void writeByte(byte b, boolean append) {
writeByteArray(new byte[]{b}, append);
}
public static void main(String[] args) {
if (args[0].equals("-readarray")) {
String man = "Usage: BinaryFile -readarray file [option]\n[options] are:\n -endian <big|little, default = big>\n -data <double|float|int, default = double>";
File file = null;
String data = "double";
String endian = BIG_ENDIAN;
for (int i = 1; i < args.length; i++) {
if (args[i].equals("-endian")) {
if (args[i + 1].equals("little")) {
endian = LITTLE_ENDIAN;
}
i++;
} else if (args[i].equals("-data")) {
data = args[i + 1];
i++;
} else {
file = new File(args[i]);
if (!file.exists()) {
System.out.println("File " + file
+ " doesn't exists.\n" + man);
}
i++;
}
}
if (data.equals("double")) {
double[] d = readDoubleArray(file, endian);
for (int j = 0; j < d.length; j++) {
System.out.println(d[j] + "");
}
} else if (data.equals("float")) {
float[] d = readFloatArray(file, endian);
for (int j = 0; j < d.length; j++) {
System.out.println(d[j] + "");
}
} else if (data.equals("int")) {
int[] d = readIntArray(file, endian);
for (int j = 0; j < d.length; j++) {
System.out.println(d[j] + "");
}
} else {
System.out.println(man);
}
} else {
System.out.println("Option not implemented.");
}
}
}

View file

@ -1,34 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io.files;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* BSD License
*
* @author Yann RICHET
*/
public abstract class DataFile {
protected File file;
public DataFile(File f) {
file = f;
}
public static void copyFile(File in, File out) throws IOException {
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
}
}

View file

@ -1,111 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io.littleendian;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* This class was designed on the base of Roedy Green LEDataInputStream
* <p>
* Thanks to Roedy Green, Canadian Mind Products mailto:roedy@mindprod.com
* http://mindprod.com
*
* @author Yann RICHET
*/
public class LEDataInputStream implements DataInput {
protected DataInputStream d;
protected InputStream in;
byte[] w;
public LEDataInputStream(InputStream in) {
this.in = in;
this.d = new DataInputStream(in);
w = new byte[8];
}
public short readShort() throws IOException {
d.readFully(w, 0, 2);
return (short) ((w[1] & 0xff) << 8 | (w[0] & 0xff));
}
public int readUnsignedShort() throws IOException {
d.readFully(w, 0, 2);
return ((w[1] & 0xff) << 8 | (w[0] & 0xff));
}
public char readChar() throws IOException {
d.readFully(w, 0, 2);
return (char) ((w[1] & 0xff) << 8 | (w[0] & 0xff));
}
public int readInt() throws IOException {
d.readFully(w, 0, 4);
return (w[3]) << 24 | (w[2] & 0xff) << 16 | (w[1] & 0xff) << 8
| (w[0] & 0xff);
}
public long readLong() throws IOException {
d.readFully(w, 0, 8);
return (long) (w[7]) << 56 | (long) (w[6] & 0xff) << 48
| (long) (w[5] & 0xff) << 40 | (long) (w[4] & 0xff) << 32
| (long) (w[3] & 0xff) << 24 | (long) (w[2] & 0xff) << 16
| (long) (w[1] & 0xff) << 8 | (long) (w[0] & 0xff);
}
public float readFloat() throws IOException {
return Float.intBitsToFloat(readInt());
}
public double readDouble() throws IOException {
return Double.longBitsToDouble(readLong());
}
public int read(byte[] b, int off, int len) throws IOException {
return in.read(b, off, len);
}
public void readFully(byte[] b) throws IOException {
d.readFully(b, 0, b.length);
}
public void readFully(byte[] b, int off, int len) throws IOException {
d.readFully(b, off, len);
}
public int skipBytes(int n) throws IOException {
return d.skipBytes(n);
}
public boolean readBoolean() throws IOException {
return d.readBoolean();
}
public byte readByte() throws IOException {
return d.readByte();
}
public int readUnsignedByte() throws IOException {
return d.readUnsignedByte();
}
public String readLine() throws IOException {
return null;// d.readLine();
}
public String readUTF() throws IOException {
return d.readUTF();
}
public static String readUTF(DataInput in) throws IOException {
return DataInputStream.readUTF(in);
}
public void close() throws IOException {
d.close();
}
}

View file

@ -1,116 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io.littleendian;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* This class was designed on the base of Roedy Green LEDataInputStream
* <p>
* Thanks to Roedy Green, Canadian Mind Products mailto:roedy@mindprod.com
* http://mindprod.com
*
* @author Yann RICHET
*/
public class LEDataOutputStream implements DataOutput {
protected DataOutputStream d;
byte[] w;
public LEDataOutputStream(OutputStream out) {
this.d = new DataOutputStream(out);
w = new byte[8];
}
public final void writeShort(int v) throws IOException {
w[0] = (byte) v;
w[1] = (byte) (v >> 8);
d.write(w, 0, 2);
}
public final void writeChar(int v) throws IOException {
w[0] = (byte) v;
w[1] = (byte) (v >> 8);
d.write(w, 0, 2);
}
public final void writeInt(int v) throws IOException {
w[0] = (byte) v;
w[1] = (byte) (v >> 8);
w[2] = (byte) (v >> 16);
w[3] = (byte) (v >> 24);
d.write(w, 0, 4);
}
public final void writeLong(long v) throws IOException {
w[0] = (byte) v;
w[1] = (byte) (v >> 8);
w[2] = (byte) (v >> 16);
w[3] = (byte) (v >> 24);
w[4] = (byte) (v >> 32);
w[5] = (byte) (v >> 40);
w[6] = (byte) (v >> 48);
w[7] = (byte) (v >> 56);
d.write(w, 0, 8);
}
public final void writeFloat(float v) throws IOException {
writeInt(Float.floatToIntBits(v));
}
public final void writeDouble(double v) throws IOException {
writeLong(Double.doubleToLongBits(v));
}
public final void writeChars(String s) throws IOException {
int len = s.length();
for (int i = 0; i < len; i++) {
writeChar(s.charAt(i));
}
}
public final synchronized void write(int b) throws IOException {
d.write(b);
}
public final synchronized void write(byte[] b, int off, int len)
throws IOException {
d.write(b, off, len);
}
public void flush() throws IOException {
d.flush();
}
public final void writeBoolean(boolean v) throws IOException {
d.writeBoolean(v);
}
public final void writeByte(int v) throws IOException {
d.writeByte(v);
}
public final void writeBytes(String s) throws IOException {
d.writeBytes(s);
}
public final void writeUTF(String str) throws IOException {
d.writeUTF(str);
}
public final int size() {
return d.size();
}
public final void write(byte[] b) throws IOException {
d.write(b, 0, b.length);
}
public final void close() throws IOException {
d.close();
}
}

View file

@ -1,278 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io.littleendian;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* This class was designed on the base of Roedy Green LEDataInputStream
* <p>
* Thanks to Roedy Green, Canadian Mind Products mailto:roedy@mindprod.com
* http://mindprod.com
*
* @author Yann RICHET
*/
public class LERandomAccessFile implements DataInput, DataOutput {
/**
* constructors
*/
public LERandomAccessFile(String f, String rw) throws IOException {
r = new RandomAccessFile(f, rw);
w = new byte[8];
}
public LERandomAccessFile(File f, String rw) throws IOException {
r = new RandomAccessFile(f, rw);
w = new byte[8];
}
// L I T T L E E N D I A N R E A D E R S
// Little endian methods for multi-byte numeric types.
// Big-endian do fine for single-byte types and strings.
/**
* like RandomAcessFile.readShort except little endian.
*/
public final short readShort() throws IOException {
r.readFully(w, 0, 2);
return (short) ((w[1] & 0xff) << 8 | (w[0] & 0xff));
}
/**
* like RandomAcessFile.readUnsignedShort except little endian. Note,
* returns int even though it reads a short.
*/
public final int readUnsignedShort() throws IOException {
r.readFully(w, 0, 2);
return ((w[1] & 0xff) << 8 | (w[0] & 0xff));
}
/**
* like RandomAcessFile.readChar except little endian.
*/
public final char readChar() throws IOException {
r.readFully(w, 0, 2);
return (char) ((w[1] & 0xff) << 8 | (w[0] & 0xff));
}
/**
* like RandomAcessFile.readInt except little endian.
*/
public final int readInt() throws IOException {
r.readFully(w, 0, 4);
return (w[3]) << 24 | (w[2] & 0xff) << 16 | (w[1] & 0xff) << 8
| (w[0] & 0xff);
}
/**
* like RandomAcessFile.readLong except little endian.
*/
public final long readLong() throws IOException {
r.readFully(w, 0, 8);
return (long) (w[7]) << 56 | /*
* long cast necessary or shift done
* modulo 32
*/
(long) (w[6] & 0xff) << 48 | (long) (w[5] & 0xff) << 40
| (long) (w[4] & 0xff) << 32 | (long) (w[3] & 0xff) << 24
| (long) (w[2] & 0xff) << 16 | (long) (w[1] & 0xff) << 8
| (long) (w[0] & 0xff);
}
/**
* like RandomAcessFile.readFloat except little endian.
*/
public final float readFloat() throws IOException {
return Float.intBitsToFloat(readInt());
}
/**
* like RandomAcessFile.readDouble except little endian.
*/
public final double readDouble() throws IOException {
return Double.longBitsToDouble(readLong());
}
// L I T T L E E N D I A N W R I T E R S
// Little endian methods for multi-byte numeric types.
// Big-endian do fine for single-byte types and strings.
/**
* like RandomAcessFile.writeShort. also acts as a writeUnsignedShort
*/
public final void writeShort(int v) throws IOException {
w[0] = (byte) v;
w[1] = (byte) (v >> 8);
r.write(w, 0, 2);
}
/**
* like RandomAcessFile.writeChar. Note the parm is an int even though this
* as a writeChar
*/
public final void writeChar(int v) throws IOException {
// same code as writeShort
w[0] = (byte) v;
w[1] = (byte) (v >> 8);
r.write(w, 0, 2);
}
/**
* like RandomAcessFile.writeInt.
*/
public final void writeInt(int v) throws IOException {
w[0] = (byte) v;
w[1] = (byte) (v >> 8);
w[2] = (byte) (v >> 16);
w[3] = (byte) (v >> 24);
r.write(w, 0, 4);
}
/**
* like RandomAcessFile.writeLong.
*/
public final void writeLong(long v) throws IOException {
w[0] = (byte) v;
w[1] = (byte) (v >> 8);
w[2] = (byte) (v >> 16);
w[3] = (byte) (v >> 24);
w[4] = (byte) (v >> 32);
w[5] = (byte) (v >> 40);
w[6] = (byte) (v >> 48);
w[7] = (byte) (v >> 56);
r.write(w, 0, 8);
}
/**
* like RandomAcessFile.writeFloat.
*/
public final void writeFloat(float v) throws IOException {
writeInt(Float.floatToIntBits(v));
}
/**
* like RandomAcessFile.writeDouble.
*/
public final void writeDouble(double v) throws IOException {
writeLong(Double.doubleToLongBits(v));
}
/**
* like RandomAcessFile.writeChars, has to flip each char.
*/
public final void writeChars(String s) throws IOException {
int len = s.length();
for (int i = 0; i < len; i++) {
writeChar(s.charAt(i));
}
} // end writeChars
// p u r e l y w r a p p e r m e t h o d s
public final FileDescriptor getFD() throws IOException {
return r.getFD();
}
public final long getFilePointer() throws IOException {
return r.getFilePointer();
}
public final long length() throws IOException {
return r.length();
}
public final int read(byte[] b, int off, int len) throws IOException {
return r.read(b, off, len);
}
public final int read(byte[] b) throws IOException {
return r.read(b);
}
public final int read() throws IOException {
return r.read();
}
public final void readFully(byte[] b) throws IOException {
r.readFully(b, 0, b.length);
}
public final void readFully(byte[] b, int off, int len) throws IOException {
r.readFully(b, off, len);
}
public final int skipBytes(int n) throws IOException {
return r.skipBytes(n);
}
/* OK, reads only only 1 byte */
public final boolean readBoolean() throws IOException {
return r.readBoolean();
}
public final byte readByte() throws IOException {
return r.readByte();
}
// note: returns an int, even though says Byte.
public final int readUnsignedByte() throws IOException {
return r.readUnsignedByte();
}
public final String readLine() throws IOException {
return r.readLine();
}
public final String readUTF() throws IOException {
return r.readUTF();
}
public final void seek(long pos) throws IOException {
r.seek(pos);
}
/* Only writes one byte even though says int */
public final synchronized void write(int b) throws IOException {
r.write(b);
}
public final synchronized void write(byte[] b, int off, int len)
throws IOException {
r.write(b, off, len);
}
public final void writeBoolean(boolean v) throws IOException {
r.writeBoolean(v);
}
public final void writeByte(int v) throws IOException {
r.writeByte(v);
}
public final void writeBytes(String s) throws IOException {
r.writeBytes(s);
}
public final void writeUTF(String str) throws IOException {
r.writeUTF(str);
}
public final void write(byte[] b) throws IOException {
r.write(b, 0, b.length);
}
public final void close() throws IOException {
r.close();
}
// i n s t a n c e v a r i a b l e s
protected RandomAccessFile r;
byte[] w; // work array for buffering input/output
} // end class LERandomAccessFile

View file

@ -1,165 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io.parser;
/**
* BSD License
*
* @author Yann RICHET
*/
public class ArrayString {
//private static int decimalSize = 10;
public static String defaultColumnDelimiter = " ";
public static String defaultRowDelimiter = "\n";
public static String NotFoundDelimiter = "ZYXWV";
public static String printDoubleArray(double[] m) {
return printDoubleArray(new double[][]{m});
}
public static String printDoubleArray(double[][] m) {
return printDoubleArray(m, defaultColumnDelimiter, defaultRowDelimiter);
}
public static String printDoubleArray(double[][] m, String wordDelimiter, String sentenceDelimiter) {
StringBuffer str = new StringBuffer(25 * m.length * m[0].length);
// //can't use format because of infinty which become "?" strings...
// DecimalFormat format = new DecimalFormat();
// format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
// format.setMinimumIntegerDigits(1);
// format.setMaximumFractionDigits(decimalSize);
// format.setMinimumFractionDigits(decimalSize);
// format.setGroupingUsed(false);
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[i].length - 1; j++) {
// String s = format.format(m[i][j]); // format the number
str = str.append(m[i][j]);
str = str.append(wordDelimiter);
}
str = str.append(m[i][m[i].length - 1]);
if (i < m.length - 1) {
str = str.append(sentenceDelimiter);
}
}
return str.toString();
}
public static String printIntArray(int[] m) {
return printIntArray(new int[][]{m});
}
public static String printIntArray(int[][] m) {
return printIntArray(m, defaultColumnDelimiter, defaultRowDelimiter);
}
public static String printIntArray(int[][] m, String wordDelimiter, String sentenceDelimiter) {
StringBuffer str = new StringBuffer(25 * m.length * m[0].length);
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[i].length - 1; j++) {
str = str.append(m[i][j]);
str = str.append(wordDelimiter);
}
str = str.append(m[i][m[i].length - 1]);
if (i < m.length - 1) {
str = str.append(sentenceDelimiter);
}
}
return str.toString();
}
public static double[] readString1DDouble(String s) {
return readString1DDouble(s, defaultColumnDelimiter);
}
public static double[] readString1DDouble(String s, String columnDelimiter) {
double[][] d = readStringDouble(s, columnDelimiter, NotFoundDelimiter);
double[] d1D = null;
if (d.length > 1) {
d1D = new double[d.length];
for (int i = 0; i < d1D.length; i++) {
d1D[i] = d[i][0];
}
} else {
d1D = d[0];
}
return d1D;
}
public static int[] readString1DInt(String s) {
return readString1DInt(s, defaultColumnDelimiter);
}
public static int[] readString1DInt(String s, String columnDelimiter) {
int[][] d = readStringInt(s, columnDelimiter, NotFoundDelimiter);
int[] d1D = null;
if (d.length > 1) {
d1D = new int[d.length];
for (int i = 0; i < d1D.length; i++) {
d1D[i] = d[i][0];
}
} else {
d1D = d[0];
}
return d1D;
}
public static double[][] readStringDouble(String s) {
return readStringDouble(s, defaultColumnDelimiter, defaultRowDelimiter);
}
public static double[][] readStringDouble(String s, String columnDelimiter, String rowDelimiter) {
double[][] array;
String[] rows = null;
if (s.contains(rowDelimiter)) {
rows = s.split(rowDelimiter);
} else {
rows = new String[]{s};
}
array = new double[rows.length][];
for (int i = 0; i < rows.length; i++) {
String[] cols = rows[i].split(columnDelimiter);
array[i] = new double[cols.length];
for (int j = 0; j < cols.length; j++) {
try {
array[i][j] = Double.parseDouble(cols[j]);
} catch (NumberFormatException e) {
array[i][j] = Double.NaN;
}
}
}
return array;
}
public static int[][] readStringInt(String s) {
return readStringInt(s, defaultColumnDelimiter, defaultRowDelimiter);
}
public static int[][] readStringInt(String s, String columnDelimiter, String rowDelimiter) {
int[][] array;
String[] rows = s.split(rowDelimiter);
array = new int[rows.length][];
for (int i = 0; i < rows.length; i++) {
String[] cols = rows[i].split(columnDelimiter);
array[i] = new int[cols.length];
for (int j = 0; j < cols.length; j++) {
try {
array[i][j] = Integer.parseInt(cols[j]);
} catch (NumberFormatException e) {
array[i][j] = Integer.MAX_VALUE;
}
}
}
return array;
}
}

View file

@ -1,288 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io.stream;
import org.xbib.graphics.graph.jmathplot.io.littleendian.LEDataInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;
/**
* BSD License
*
* @author Yann RICHET
*/
public class BinaryInputStream extends InputStream {
private final InputStream stream;
public static String LITTLE_ENDIAN = "LITTLE_ENDIAN";
public static String BIG_ENDIAN = "BIG_ENDIAN";
protected boolean bigEndian;
public BinaryInputStream(InputStream in, String endian) {
bigEndian = isBigEndian(endian);
stream = in;
}
public BinaryInputStream(InputStream in, boolean endian) {
bigEndian = endian;
stream = in;
}
private boolean isBigEndian(String endian) {
boolean be;
if (endian.equals(LITTLE_ENDIAN)) {
be = false;
} else if (endian.equals(BIG_ENDIAN)) {
be = true;
} else {
throw new IllegalArgumentException(
"The Endian type : "
+ endian
+ "is unknown. You must specify LITTLE_ENDIAN or BIG_ENDIAN.");
}
return be;
}
public static double[] readDoubleArray(InputStream in, String endian) {
BinaryInputStream bi = new BinaryInputStream(in, endian);
return bi.readDoubleArray();
}
public static float[] readFloatArray(InputStream in, String endian) {
BinaryInputStream bi = new BinaryInputStream(in, endian);
return bi.readFloatArray();
}
public static int[] readIntArray(InputStream in, String endian) {
BinaryInputStream bi = new BinaryInputStream(in, endian);
return bi.readIntArray();
}
/**
* Read a binary File
*
* @return int[]
*/
public int[] readIntArray() {
try {
DataInput dis;
if (bigEndian) {
dis = new DataInputStream(stream);
} else {
dis = new LEDataInputStream(stream);
}
Vector<Integer> intV = new Vector<Integer>();
try {
while (true) {
int i = dis.readInt();
intV.add(new Integer(i));
}
} catch (EOFException eof) {
stream.close();
}
int[] array = new int[intV.size()];
for (int i = 0; i < array.length; i++) {
array[i] = intV.get(i).intValue();
}
return array;
} catch (IOException e) {
throw new IllegalArgumentException("InputStream is unreadable : "
+ e.toString());
}
}
/**
* Read a binary File
*
* @return float[]
*/
public float[] readFloatArray() {
try {
DataInput dis;
if (bigEndian) {
dis = new DataInputStream(stream);
} else {
dis = new LEDataInputStream(stream);
}
Vector<Float> floatV = new Vector<Float>();
try {
while (true) {
float f = dis.readFloat();
floatV.add(new Float(f));
}
} catch (EOFException eof) {
stream.close();
}
float[] array = new float[floatV.size()];
for (int i = 0; i < array.length; i++) {
array[i] = floatV.get(i).floatValue();
}
return array;
} catch (IOException e) {
throw new IllegalArgumentException("InputStream is unreadable : "
+ e.toString());
}
}
/**
* Read a binary File
*
* @return double[]
*/
public double[] readDoubleArray() {
try {
DataInput dis;
if (bigEndian) {
dis = new DataInputStream(stream);
} else {
dis = new LEDataInputStream(stream);
}
Vector<Double> doubleV = new Vector<Double>();
try {
while (true) {
double f = dis.readDouble();
doubleV.add(new Double(f));
}
} catch (EOFException eof) {
stream.close();
}
double[] array = new double[doubleV.size()];
for (int i = 0; i < array.length; i++) {
array[i] = doubleV.get(i).doubleValue();
}
return array;
} catch (IOException e) {
throw new IllegalArgumentException("InputStream is unreadable : "
+ e.toString());
}
}
/**
* Read a binary File
*
* @return double[]
*/
public double[] readDoubleArray(int n1, int n2) {
try {
DataInput dis;
if (bigEndian) {
dis = new DataInputStream(stream);
} else {
dis = new LEDataInputStream(stream);
}
double[] array = new double[n2 - n1];
dis.skipBytes(n1 * 4);
for (int i = 0; i < array.length; i++) {
array[i] = dis.readDouble();
}
return array;
} catch (IOException e) {
throw new IllegalArgumentException("InputStream is unreadable : "
+ e.toString());
}
}
/**
* Read a binary File
*
* @return byte[]
*/
public byte[] readByteArray() {
try {
DataInput dis;
if (bigEndian) {
dis = new DataInputStream(stream);
} else {
dis = new LEDataInputStream(stream);
}
Vector<Byte> bytesV = new Vector<Byte>();
try {
while (true) {
byte b = dis.readByte();
bytesV.add(new Byte(b));
}
} catch (EOFException eof) {
stream.close();
}
byte[] bytes = new byte[bytesV.size()];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = bytesV.get(i).byteValue();
}
return bytes;
} catch (IOException e) {
throw new IllegalArgumentException("InputStream is unreadable : "
+ e.toString());
}
}
/**
* Read a binary File
*
* @return int
*/
public int readInt() {
return readIntArray()[0];
}
/**
* Read a binary File
*
* @return float
*/
public float readFloat() {
return readFloatArray()[0];
}
/**
* Read a binary File
*
* @return double
*/
public double readDouble() {
return readDoubleArray()[0];
}
/**
* Read a binary File
*
* @return byte
*/
public byte readByte() {
return readByteArray()[0];
}
/**
* Read a binary File
*
* @return byte
*/
public int read() {
return readInt();
}
}

View file

@ -1,222 +0,0 @@
package org.xbib.graphics.graph.jmathplot.io.stream;
import org.xbib.graphics.graph.jmathplot.io.littleendian.LEDataOutputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* BSD License
*
* @author Yann RICHET
*/
public class BinaryOutputStream extends OutputStream {
private final OutputStream stream;
public static String LITTLE_ENDIAN = "LITTLE_ENDIAN";
public static String BIG_ENDIAN = "BIG_ENDIAN";
protected boolean bigEndian;
public BinaryOutputStream(OutputStream out, String endian) {
bigEndian = isBigEndian(endian);
stream = out;
}
public BinaryOutputStream(OutputStream out, boolean endian) {
bigEndian = endian;
stream = out;
}
private boolean isBigEndian(String endian) {
boolean be;
if (endian.equals(LITTLE_ENDIAN)) {
be = false;
} else if (endian.equals(BIG_ENDIAN)) {
be = true;
} else {
throw new IllegalArgumentException(
"The Endian type : " + endian + "is unknown. You must specify LITTLE_ENDIAN or BIG_ENDIAN.");
}
return be;
}
public static void writeDoubleArray(OutputStream out, double[] array,
String endian) {
BinaryOutputStream bs = new BinaryOutputStream(out, endian);
bs.writeDoubleArray(array, false);
}
public static void appendDoubleArray(OutputStream out, double[] array,
String endian) {
BinaryOutputStream bs = new BinaryOutputStream(out, endian);
bs.writeDoubleArray(array, true);
}
public static void writeFloatArray(OutputStream out, float[] array,
String endian) {
BinaryOutputStream bs = new BinaryOutputStream(out, endian);
bs.writeFloatArray(array, false);
}
public static void appendFloatArray(OutputStream out, float[] array,
String endian) {
BinaryOutputStream bs = new BinaryOutputStream(out, endian);
bs.writeFloatArray(array, true);
}
public static void writeIntArray(OutputStream out, int[] array,
String endian) {
BinaryOutputStream bs = new BinaryOutputStream(out, endian);
bs.writeIntArray(array, false);
}
public static void appendIntArray(OutputStream out, int[] array,
String endian) {
BinaryOutputStream bs = new BinaryOutputStream(out, endian);
bs.writeIntArray(array, true);
}
/**
* Write an int array in a binary File
*
* @param array int[]
* @param append boolean
*/
public void writeIntArray(int[] array, boolean append) {
try {
DataOutput dos;
if (bigEndian) {
dos = new DataOutputStream(stream);
} else {
dos = new LEDataOutputStream(stream);
}
for (int i = 0; i < array.length; i++) {
dos.writeInt(array[i]);
}
stream.close();
} catch (IOException e) {
throw new IllegalArgumentException("InputStream is unwritable : " + e.toString());
}
}
/**
* Write a float array in a binary File
*
* @param array float[]
* @param append boolean
*/
public void writeFloatArray(float[] array, boolean append) {
try {
DataOutput dos;
if (bigEndian) {
dos = new DataOutputStream(stream);
} else {
dos = new LEDataOutputStream(stream);
}
for (int i = 0; i < array.length; i++) {
dos.writeFloat(array[i]);
}
stream.close();
} catch (IOException e) {
throw new IllegalArgumentException("InputStream is unwritable : " + e.toString());
}
}
/**
* Write a double array in a binary File
*
* @param array float[]
* @param append boolean
*/
public void writeDoubleArray(double[] array, boolean append) {
try {
DataOutput dos;
if (bigEndian) {
dos = new DataOutputStream(stream);
} else {
dos = new LEDataOutputStream(stream);
}
for (int i = 0; i < array.length; i++) {
dos.writeDouble(array[i]);
}
stream.close();
} catch (IOException e) {
throw new IllegalArgumentException("InputStream is unwritable : " + e.toString());
}
}
/**
* Write a text in a binary File
*
* @param bytes byte[]
* @param append boolean
*/
public void writeByteArray(byte[] bytes, boolean append) {
try {
DataOutputStream dos = new DataOutputStream(stream);
dos.write(bytes);
stream.close();
} catch (IOException e) {
throw new IllegalArgumentException("InputStream is unwritable : " + e.toString());
}
}
/**
* Write an int in a binary File
*
* @param i int
* @param append boolean
*/
public void writeInt(int i, boolean append) {
writeIntArray(new int[]{i}, append);
}
/**
* Write a float in a binary File
*
* @param f float
* @param append boolean
*/
public void writeFloat(float f, boolean append) {
writeFloatArray(new float[]{f}, append);
}
/**
* Write a double in a binary File
*
* @param d double
* @param append boolean
*/
public void writeDouble(double d, boolean append) {
writeDoubleArray(new double[]{d}, append);
}
/**
* Write a text in a binary File
*
* @param b byte
* @param append boolean
*/
public void writeByte(byte b, boolean append) {
writeByteArray(new byte[]{b}, append);
}
/**
* Write an int in a binary File
*
* @param i int
*/
public void write(int i) {
writeInt(i, false);
}
}

View file

@ -1,77 +0,0 @@
package org.xbib.graphics.graph.jmathplot.panel;
import org.xbib.graphics.graph.jmathplot.io.ClipBoardPrintable;
import org.xbib.graphics.graph.jmathplot.io.FilePrintable;
import org.xbib.graphics.graph.jmathplot.io.StringPrintable;
import org.xbib.graphics.graph.jmathplot.frame.DataToolBar;
import java.awt.BorderLayout;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.io.File;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/**
* BSD License
*
* @author Yann RICHET
*/
public abstract class DataPanel extends JPanel implements ComponentListener, FilePrintable, ClipBoardPrintable, StringPrintable {
protected DataToolBar toolBar;
protected JScrollPane scrollPane;
public static int[] dimension = new int[]{400, 400};
public DataPanel() {
setLayout(new BorderLayout());
initToolBar();
init();
}
protected void initToolBar() {
toolBar = new DataToolBar(this);
add(toolBar, BorderLayout.NORTH);
toolBar.setFloatable(false);
}
protected void initSize() {
if (scrollPane != null) {
scrollPane.setSize(this.getSize());
}
// scrollPane.setPreferredSize(this.getSize());
}
protected void init() {
// initSize();
addComponentListener(this);
}
public void update() {
// this.remove(scrollPane);
toWindow();
repaint();
}
protected abstract void toWindow();
public abstract void toClipBoard();
public abstract void toASCIIFile(File file);
public void componentHidden(ComponentEvent e) {
}
public void componentMoved(ComponentEvent e) {
}
public void componentResized(ComponentEvent e) {
/*
* dimension = new int[] { (int) (this.getSize().getWidth()), (int)
* (this.getSize().getHeight()) };
*/
initSize();
}
public void componentShown(ComponentEvent e) {
}
}

View file

@ -1,827 +0,0 @@
/*
* Created on 6 juil. 07 by richet
*/
package org.xbib.graphics.graph.jmathplot.panel;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.util.LinkedList;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
* Panel designed to select a given number of columns in a multi columns matrix.
* Useful to provide a 3d plot view of Nd data matrix.
*/
public class DataSelectPanel extends JPanel {
private static final long serialVersionUID = 419181752327223313L;
ParameterRow[] rows;
private Object[][] _data, _selecteddata;
private LinkedList<Object[]> _tmpselecteddata;
boolean dataUpdated = false;
private int[] _tmpselectedIndex;
private int _nbselected;
private int[] _selectedindex;
private final String[] _parametersNames;
//boolean Zselected = false;
int _dimension;
void autoSelectVariableParam() {
int d = 0;
for (int i = 0; i < _data[0].length; i++) {
boolean constant = true;
String val = _data[0][i].toString();
for (int j = 1; j < _data.length; j++) {
if (!_data[j][i].toString().equals(val)) {
//System.err.println(_data[j][i] + " != " + val);
constant = false;
break;
}
}
if (!constant && _dimension > d) {
if (d == 0) {
selectAsX(i);
d++;
continue;
} else if (d == 1) {
selectAsY(i);
d++;
continue;
} else if (d == 2) {
selectAsZ(i);
break;
}
}
}
}
public DataSelectPanel(Object[][] data, int dimension, String... parametersNames) {
_data = data;
_dimension = dimension;
_parametersNames = parametersNames;
if (_dimension > parametersNames.length) {
throw new IllegalArgumentException("Number of parameters must be > to dimension=" + _dimension);
}
setLayout(new GridLayout(_parametersNames.length /*+ 1*/, 1));
//JPanel title = new JPanel();
//title.setLayout(new GridLayout(1, 2));
//title.add(new JLabel("Variable"));
//title.add(new JLabel("Axis / Parameter"));
//add(title);
if (_dimension == 0) {
buildRows();
} else if (_dimension == 1) {
buildRows(0);
} else if (_dimension == 2) {
buildRows(0, 1);
} else if (_dimension == 3) {
buildRows(0, 1, 2);
}
fireSelectedDataChanged("init");
}
void buildRows(int... selectedaxis) {
ButtonGroup xgrp = new ButtonGroup();
ButtonGroup ygrp = new ButtonGroup();
ButtonGroup zgrp = new ButtonGroup();
rows = new ParameterRow[_parametersNames.length];
for (int i = 0; i < _parametersNames.length; i++) {
rows[i] = new ParameterRow(_parametersNames[i], getColumn(i, _data));
if (selectedaxis != null && selectedaxis.length > 0) {
if (selectedaxis.length >= 1) {
rows[i].xaxis.setSelected(selectedaxis[0] == i);
}
if (selectedaxis.length >= 2) {
rows[i].yaxis.setSelected(selectedaxis[1] == i);
}
if (selectedaxis.length == 3) {
rows[i].zaxis.setSelected(selectedaxis[2] == i);
}
}
xgrp.add(rows[i].xaxis);
ygrp.add(rows[i].yaxis);
zgrp.add(rows[i].zaxis);
add(rows[i]);
}
setPreferredSize(new Dimension(row_width, row_height * _parametersNames.length));
setSize(new Dimension(row_width, row_height * _parametersNames.length));
autoSelectVariableParam();
updateSelectedData();
}
public void setData(Object[][] data) {
if (data[0].length != _data[0].length) {
throw new IllegalArgumentException("new data dimension is not consistent with previous one.");
}
_data = data;
int[] selectedaxis = new int[_dimension];
for (int i = 0; i < rows.length; i++) {
if (selectedaxis.length >= 1) {
if (rows[i].xaxis.isSelected()) {
selectedaxis[0] = i;
}
}
if (selectedaxis.length >= 2) {
if (rows[i].yaxis.isSelected()) {
selectedaxis[1] = i;
}
}
if (selectedaxis.length == 3) {
if (rows[i].zaxis.isSelected()) {
selectedaxis[2] = i;
}
}
remove(rows[i]);
}
dataUpdated = false;
buildRows(selectedaxis);
fireSelectedDataChanged("set");
}
void updateSelectedData() {
if (dataUpdated) {
return;
}
for (ParameterRow row : rows) {
boolean isaxis = row.xaxis.isSelected() || row.yaxis.isSelected() || row.zaxis.isSelected();
if (row._isNumber) {
row.min.setEnabled(!isaxis);
row.max.setEnabled(!isaxis);
} else {
row.list.setEnabled(!isaxis);
}
if (!isaxis) {
if (row._isNumber) {
row.name.setText(row._paramName + "=[" + row._kernelDoubleValues[row.min.getValue() - 1] + "," + row._kernelDoubleValues[row.max.getValue() - 1] + "]");
} else {
row.name.setText(row._paramName + "={" + Array.cat(row.list.getSelectedValues()) + "}");
}
} else {
row.name.setText(row._paramName);
}
}
_tmpselectedIndex = new int[_data.length];
_nbselected = 0;
_tmpselecteddata = new LinkedList<Object[]>();
for (int i = 0; i < _data.length; i++) {
boolean sel = true;
for (int j = 0; j < rows.length; j++) {
ParameterRow row = rows[j];
if (!row.xaxis.isSelected() && !row.yaxis.isSelected() && !row.zaxis.isSelected() && !row.check(_data[i][j])) {
sel = false;
}
}
if (sel) {
_tmpselecteddata.add(_data[i]);
_tmpselectedIndex[_nbselected] = i;
_nbselected++;
/*System.out.print("OK:");
for (int j = 0; j < _tmpselecteddata.getLast().length; j++)
System.out.print(_tmpselecteddata.getLast()[j]+",");
System.out.println("");*/
}
}
dataUpdated = true;
}
/**
* Method to override if you want to link to any gui component (for instance, a plotpanel).
*/
public void fireSelectedDataChanged(String from) {
System.err.println("fireSelectedDataChanged from " + from);
Object[][] sel = getSelectedFullData();
System.err.println("selected full data :");
System.err.println(Array.cat(_parametersNames));
if (sel.length > 0) {
System.err.println(Array.cat(getSelectedFullData()));
}
sel = getSelectedProjectedData();
System.err.println("selected projected data :");
switch (_dimension) {
case 0:
System.err.println("No axis selected");
break;
case 1:
System.err.println(Array.cat(new String[]{getSelectedXAxis()}));
break;
case 2:
System.err.println(Array.cat(new String[]{getSelectedXAxis(), getSelectedYAxis()}));
break;
case 3:
System.err.println(Array.cat(new String[]{getSelectedXAxis(), getSelectedYAxis(), getSelectedZAxis()}));
break;
}
if (sel.length > 0) {
System.err.println(Array.cat(sel));
}
System.err.println("Done.");
}
/**
* return selected data
*/
public int[] getSelectedDataIndex() {
updateSelectedData();
_selectedindex = new int[_nbselected];
for (int i = 0; i < _nbselected; i++) {
_selectedindex[i] = _tmpselectedIndex[i];
}
return _selectedindex;
}
/**
* return selected data
*/
public Object[][] getSelectedFullData() {
updateSelectedData();
_selecteddata = new Object[_tmpselecteddata.size()][_data[0].length];
for (int i = 0; i < _selecteddata.length; i++) {
for (int j = 0; j < _selecteddata[i].length; j++) {
_selecteddata[i][j] = _tmpselecteddata.get(i)[j];
}
}
return _selecteddata;
}
/**
* return selected data projected on axis selected
*/
public Object[][] getSelectedProjectedData() {
//updateSelectedData();
/*if (_dimension == 0) {
return getSelectedFullData();
}*/
int[] selectedaxis = getSelectedAxisIndex();
_selecteddata = new Object[_tmpselecteddata.size()][_dimension];
for (int i = 0; i < _selecteddata.length; i++) {
for (int j = 0; j < _dimension; j++) {
_selecteddata[i][j] = _tmpselecteddata.get(i)[selectedaxis[j]];
}
}
return _selecteddata;
}
public int[] getSelectedAxisIndex() {
int[] selectedaxis = new int[_dimension];
updateSelectedData();
for (int i = 0; i < rows.length; i++) {
if (rows[i].xaxis.isSelected()) {
//System.out.println("selextedaxis[0] =" + i);
selectedaxis[0] = i;
}
if (rows[i].yaxis.isSelected()) {
//System.out.println("selextedaxis[1] =" + i);
selectedaxis[1] = i;
}
if (rows[i].zaxis.isSelected()) {
//System.out.println("selextedaxis[2] =" + i);
selectedaxis[2] = i;
}
}
return selectedaxis;
}
/**
* return selected X axis name
*/
public String getSelectedXAxis() {
updateSelectedData();
for (ParameterRow row : rows) {
if (row.xaxis.isSelected()) {
return row._paramName;
}
}
return null;
}
/**
* return selected Y axis name
*/
public String getSelectedYAxis() {
updateSelectedData();
for (ParameterRow row : rows) {
if (row.yaxis.isSelected()) {
return row._paramName;
}
}
return null;
}
/**
* return selected Z axis name
*/
public String getSelectedZAxis() {
updateSelectedData();
for (ParameterRow row : rows) {
if (row.zaxis.isSelected()) {
return row._paramName;
}
}
return null;
}
static Object[] getColumn(int j, Object[][] mat) {
Object[] col = new Object[mat.length];
for (int i = 0; i < col.length; i++) {
col[i] = mat[i][j];
}
return col;
}
public Font font = new Font("Arial", Font.PLAIN, 10);
public int row_height = 60;
public int row_width = 300;
public void selectAsX(int row) {
rows[row].selectAsX();
}
public void selectAsY(int row) {
rows[row].selectAsY();
}
public void selectAsZ(int row) {
rows[row].selectAsZ();
}
class ParameterRow extends JPanel {
String _paramName;
JLabel name;
JRadioButton xaxis, yaxis, zaxis;
JComponent parameter;
JSlider min, max;
JCheckBox linkminmax;
JList list;
//Object[] _values;
Vector<Object> _kernelStringValues;
boolean _isNumber;
//double[] _dvalues;
double[] _kernelDoubleValues;
/**
* Quick Sort algoritm.
* <p>
* Allows to sort a column quickly, Using a generic version of C.A.R Hoare's
* Quick Sort algorithm.
* <p>
*/
public class Sorting {
/*
* ------------------------ Class variables ------------------------
*/
/**
* Array for internal storage of the matrix to sort.
*/
private final double[] A;
/**
* Array for internal storage of the order.
*/
private final int[] order;
/*
* ------------------------ Constructors ------------------------
*/
/**
* Construct an ascending order.
*
* @param array Array to sort.
* @param copyArray Specify if the sort is made directly : true -> array is
* modified (usefull for big arrays !), false -> array is copied
* and not modified (more memory used).
*/
public Sorting(double[] array, boolean copyArray) {
if (copyArray) {
A = new double[array.length];
System.arraycopy(array, 0, A, 0, array.length);
// for (int i = 0; i < A.length; i++) {
// A[i] = array[i];
// }
} else {
A = array;
}
order = new int[A.length];
for (int i = 0; i < A.length; i++) {
order[i] = i;
}
sort(A);
}
/*
* ------------------------ Public Methods ------------------------
*/
public int[] invertIndex(int[] ind) {
int[] invind = new int[ind.length];
for (int i = 0; i < ind.length; i++) {
invind[ind[i]] = i;
}
return invind;
}
/**
* Get the ascending order of one line.
*
* @param i Line number.
* @return Ascending order of the line.
*/
public int getIndex(int i) {
return order[i];
}
/**
* Get the ascending order of all lines.
*
* @return Ascending order of lines.
*/
public int[] getIndex() {
return order;
}
/*
* ------------------------ Private Methods ------------------------
*/
/**
* This is a generic version of C.A.R Hoare's Quick Sort algorithm. This
* will handle arrays that are already sorted, and arrays with duplicate
* keys. <BR>
* <p>
* If you think of a one dimensional array as going from the lowest index on
* the left to the highest index on the right then the parameters to this
* function are lowest index or left and highest index or right. The first
* time you call this function it will be with the parameters 0, a.length -
* 1.
*
* @param a A double array.
* @param lo0 Int.
* @param hi0 Int.
*/
private void QuickSort(double[] a, int lo0, int hi0) {
int lo = lo0;
int hi = hi0;
double mid;
if (hi0 > lo0) {
// Arbitrarily establishing partition element as the midpoint of the
// array.
mid = a[(lo0 + hi0) / 2];
// loop through the array until indices cross
while (lo <= hi) {
// find the first element that is greater than or equal to the
// partition element starting from the left Index.
while ((lo < hi0) && (a[lo] < mid)) {
++lo;
}
// find an element that is smaller than or equal to the
// partition element starting from the right Index.
while ((hi > lo0) && (a[hi] > mid)) {
--hi;
}
// if the indexes have not crossed, swap
if (lo <= hi) {
swap(a, lo, hi);
++lo;
--hi;
}
}
// If the right index has not reached the left side of array must
// now sort the left partition.
if (lo0 < hi) {
QuickSort(a, lo0, hi);
// If the left index has not reached the right side of array
// must now sort the right partition.
}
if (lo < hi0) {
QuickSort(a, lo, hi0);
}
}
}
/**
* Swap two positions.
*
* @param a Array.
* @param i Line number.
* @param j Line number.
*/
private void swap(double[] a, int i, int j) {
double T;
T = a[i];
a[i] = a[j];
a[j] = T;
int t;
t = order[i];
order[i] = order[j];
order[j] = t;
}
private void sort(double[] a) {
QuickSort(a, 0, a.length - 1);
}
}
public void selectAsX() {
xaxis.setSelected(true);
yaxis.setSelected(false);
zaxis.setSelected(false);
for (ParameterRow r : rows) {
if (!r._paramName.equals(_paramName)) {
r.xaxis.setSelected(false);
}
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " xaxis");
}
public void selectAsY() {
xaxis.setSelected(false);
yaxis.setSelected(true);
zaxis.setSelected(false);
for (ParameterRow r : rows) {
if (!r._paramName.equals(_paramName)) {
r.yaxis.setSelected(false);
}
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " yaxis");
}
public void selectAsZ() {
xaxis.setSelected(false);
yaxis.setSelected(false);
zaxis.setSelected(true);
for (ParameterRow r : rows) {
if (!r._paramName.equals(_paramName)) {
r.zaxis.setSelected(false);
}
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " zaxis");
}
public ParameterRow(String paramName, Object[] values) {
_paramName = paramName;
_isNumber = Array.isDouble(values[0].toString());
if (!_isNumber) {
_kernelStringValues = new Vector<Object>(values.length);
for (int i = 0; i < values.length; i++) {
if (!_kernelStringValues.contains(values[i])) {
_kernelStringValues.add(values[i]);
}
}
} else {
Vector<Double> _tmpdvalues = new Vector<Double>(values.length);
for (int i = 0; i < values.length; i++) {
if (!_tmpdvalues.contains(Double.valueOf(values[i].toString()))) {
_tmpdvalues.add(Double.valueOf(values[i].toString()));
}
}
_kernelDoubleValues = new double[_tmpdvalues.size()];
for (int i = 0; i < _kernelDoubleValues.length; i++) {
_kernelDoubleValues[i] = _tmpdvalues.get(i);
}
new Sorting(_kernelDoubleValues, false);
}
setLayout(new GridLayout(1, 2));
name = new JLabel(_paramName);
name.setFont(font);
JPanel left = new JPanel(new BorderLayout());
left.add(name, BorderLayout.CENTER);
add(left, 0);
JPanel right = new JPanel(new BorderLayout());
JPanel XYZ = new JPanel();
if (_dimension > 0) {
XYZ = new JPanel(new GridLayout(_dimension, 1));
}
xaxis = new JRadioButton("X");
xaxis.setFont(font);
xaxis.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
selectAsX();
}
});
if (_dimension >= 1) {
XYZ.add(xaxis);
}
yaxis = new JRadioButton("Y");
yaxis.setFont(font);
yaxis.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
selectAsY();
}
});
if (_dimension >= 2) {
XYZ.add(yaxis);
}
zaxis = new JRadioButton("Z");
zaxis.setFont(font);
zaxis.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
selectAsZ();
}
});
if (_dimension == 3) {
XYZ.add(zaxis);
}
left.add(XYZ, BorderLayout.EAST);
if (_isNumber) {
parameter = new JPanel();
parameter.setLayout(new GridLayout(2, 1));
min = new JSlider(1, _kernelDoubleValues.length, 1);
min.setFont(font);
min.setMinorTickSpacing(1);
min.setSnapToTicks(true);
min.setPaintTicks(true);
max = new JSlider(1, _kernelDoubleValues.length, _kernelDoubleValues.length);
max.setFont(font);
max.setMinorTickSpacing(1);
max.setSnapToTicks(true);
max.setPaintTicks(true);
min.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (max.getValue() < min.getValue()) {
max.setValue(min.getValue());
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " min");
}
});
max.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (max.getValue() < min.getValue()) {
min.setValue(max.getValue());
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " max");
}
});
parameter.add(min, 0);
parameter.add(max, 1);
} else {
list = new JList(_kernelStringValues);
list.setFont(font);
list.setSelectedIndices(buildIntSeq(0, _kernelStringValues.size() - 1));
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
dataUpdated = false;
fireSelectedDataChanged(_paramName + " list");
}
});
parameter = new JScrollPane(list);
}
right.add(parameter, BorderLayout.CENTER);
add(right, 1);
setBorder(BorderFactory.createEtchedBorder());
setPreferredSize(new Dimension(row_width, row_height));
setSize(new Dimension(row_width, row_height));
}
int[] buildIntSeq(int min, int max) {
int[] seq = new int[max - min + 1];
for (int i = 0; i < seq.length; i++) {
seq[i] = min + i;
}
return seq;
}
boolean check(Object value) {
if (_isNumber) {
double dval = Double.valueOf(value.toString());
return (dval >= _kernelDoubleValues[min.getValue() - 1] && dval <= _kernelDoubleValues[max.getValue() - 1]);
} else {
for (int i = 0; i < list.getSelectedIndices().length; i++) {
if (_kernelStringValues.get(list.getSelectedIndices()[i]).equals(value)) {
return true;
}
}
return false;
}
}
}
public static void main(String[] args) {
final PlotPanel pp = new Plot3DPanel(PlotPanel.WEST);
pp.setPreferredSize(new Dimension(400, 400));
new FrameView(pp).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object[][] data = {{1, 3, 4, 5, "a0"}, {1, 3, 1, 1, "a1"}, {1, 3, 2, 2, "a2"}, {1, 3, 3, 3, "a5"}, {1, 3, 3, 3, "a3"}, {1.5, 3.5, 3, 4, "a2"}};
DataSelectPanel dsp3 = new DataSelectPanel(data, 3, "x1", "x2", "x3", "x4", "x5") {
private static final long serialVersionUID = 1L;
@Override
public void fireSelectedDataChanged(String from) {
super.fireSelectedDataChanged(from);
pp.setAxisLabel(0, getSelectedXAxis());
pp.setAxisLabel(1, getSelectedYAxis());
pp.setAxisLabel(2, getSelectedZAxis());
System.err.println("plotting ...");
if (pp.getPlots().size() == 0) {
System.err.println(" new");
pp.addPlot("SCATTER", "data", pp.mapData(getSelectedProjectedData()));
} else {
System.err.println(" existing");
if (from != null && from.endsWith("axis")) {
pp.resetMapData();
pp.removeAllPlots();
pp.addPlot("SCATTER", "data", pp.mapData(getSelectedProjectedData()));
} else {
pp.getPlot(0).setData(pp.mapData(getSelectedProjectedData()));
}
}
//System.out.println(Array.cat(pp.getAxesScales()));
}
};
JFrame f3 = new JFrame("Test mat editor 3");
f3.setContentPane(dsp3);
f3.pack();
f3.setVisible(true);
f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/*try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Object[][] data2 = { { 0, 0, 0, 0, "a0" }, { 1, 1, 1, 1, "a1" }, { 2, 2, 2, 2, "a2" }, { 3, 3, 3, 3, "a3" }, { 4, 3, 3, 3, "a3" },
{ 5, 3, 3, 3, "a4" }, { 5, 4, 3, 3, "a4" } };
dsp.setData(data2);*/
}
}

View file

@ -1,720 +0,0 @@
/*
* Created on 6 juil. 07 by richet
*/
package org.xbib.graphics.graph.jmathplot.panel;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.util.LinkedList;
import java.util.Vector;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
/**
* Panel designed to select a given number of columns in a multi columns matrix.
* Useful to provide a 3d plot view of Nd data matrix.
*/
public class DataSelectTable extends JPanel {
private static final long serialVersionUID = 41918175232722331L;
LinkedList<ParameterRow> rows;
private Object[][] _data, _selecteddata;
private LinkedList<Object[]> _tmpselecteddata;
boolean dataUpdated = false;
private int[] _tmpselectedIndex;
private int _nbselected;
private int[] _selectedindex;
private final String[] _parametersNames;
private JTable _table;
int _dimension;
public DataSelectTable(Object[][] data, int dimension, String... parametersNames) {
_data = data;
_dimension = dimension;
_parametersNames = parametersNames;
if (_dimension > parametersNames.length) {
throw new IllegalArgumentException("Number of parameters must be > to dimension=" + _dimension);
}
if (_dimension == 1) {
buildRows(0);
} else if (_dimension == 2) {
buildRows(0, 1);
} else if (_dimension == 3) {
buildRows(0, 1, 2);
}
add(new JScrollPane(_table));
}
LinkedList<String> header;
LinkedList<Class<?>> columnclasses;
class Model implements TableModel {
public Model(int... selectedaxis) {
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
// TODO Auto-generated method stub
}
public void removeTableModelListener(TableModelListener l) {
// TODO Auto-generated method stub
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
// TODO Auto-generated method stub
return false;
}
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
return _parametersNames[rowIndex];
}
if (columnIndex == _dimension - 2) {
return rows.get(rowIndex).xaxis;
}
if (columnIndex == _dimension - 1) {
return rows.get(rowIndex).yaxis;
}
if (columnIndex == _dimension) {
return rows.get(rowIndex).zaxis;
}
return null;
}
public int getRowCount() {
return _parametersNames.length;
}
public String getColumnName(int columnIndex) {
return header.get(columnIndex);
}
public int getColumnCount() {
return header.size();
}
public Class<?> getColumnClass(int columnIndex) {
return columnclasses.get(columnIndex);
}
public void addTableModelListener(TableModelListener l) {
// TODO Auto-generated method stub
}
}
void buildRows(int... selectedaxis) {
header = new LinkedList<String>();
header.add("Parameter");
if (_dimension <= 1) {
header.add("X");
}
if (_dimension <= 2) {
header.add("Y");
}
if (_dimension <= 3) {
header.add("Z");
}
header.add("min");
header.add("<>");
header.add("=");
header.add("<>");
header.add("max");
columnclasses = new LinkedList<Class<?>>();
columnclasses.add(String.class);
if (_dimension <= 1) {
columnclasses.add(Boolean.class);
}
if (_dimension <= 2) {
columnclasses.add(Boolean.class);
}
if (_dimension <= 3) {
columnclasses.add(Boolean.class);
}
columnclasses.add(Double.class);
columnclasses.add(JSlider.class);
columnclasses.add(Boolean.class);
columnclasses.add(JSlider.class);
columnclasses.add(Double.class);
ButtonGroup xgrp = new ButtonGroup();
ButtonGroup ygrp = new ButtonGroup();
ButtonGroup zgrp = new ButtonGroup();
rows = new LinkedList<ParameterRow>();
for (int i = 0; i < _parametersNames.length; i++) {
rows.add(new ParameterRow(_parametersNames[i], getColumn(i, _data)));
rows.get(i).xaxis.setSelected(selectedaxis[0] == i);
if (selectedaxis.length >= 2) {
rows.get(i).yaxis.setSelected(selectedaxis[1] == i);
}
if (selectedaxis.length == 3) {
rows.get(i).zaxis.setSelected(selectedaxis[2] == i);
}
xgrp.add(rows.get(i).xaxis);
ygrp.add(rows.get(i).yaxis);
zgrp.add(rows.get(i).zaxis);
}
updateSelectedData();
}
public void setData(Object[][] data) {
if (data[0].length != _data[0].length) {
throw new IllegalArgumentException("new data dimension is not consistent with previous one.");
}
_data = data;
int[] selectedaxis = new int[_dimension];
for (int i = 0; i < rows.size(); i++) {
if (rows.get(i).xaxis.isSelected()) {
selectedaxis[0] = i;
}
if (selectedaxis.length >= 2) {
if (rows.get(i).yaxis.isSelected()) {
selectedaxis[1] = i;
}
}
if (selectedaxis.length == 3) {
if (rows.get(i).zaxis.isSelected()) {
selectedaxis[2] = i;
}
}
rows.remove(i);
}
dataUpdated = false;
buildRows(selectedaxis);
fireSelectedDataChanged("setData");
}
void updateSelectedData() {
if (dataUpdated) {
return;
}
for (ParameterRow row : rows) {
boolean isaxis = row.xaxis.isSelected() || row.yaxis.isSelected() || row.zaxis.isSelected();
if (row._isNumber) {
row.min.setEnabled(!isaxis);
row.max.setEnabled(!isaxis);
} else {
row.list.setEnabled(!isaxis);
}
/*if (!isaxis)
if (row._isNumber)
row.name.setText(row._paramName + "=[" + row._kernelDoubleValues[row.min.getValue() - 1] + ","
+ row._kernelDoubleValues[row.max.getValue() - 1] + "]");
else
row.name.setText(row._paramName + "={" + Array.cat(row.list.getSelectedValues()) + "}");
else
row.name.setText(row._paramName);*/
}
_tmpselectedIndex = new int[_data.length];
_nbselected = 0;
_tmpselecteddata = new LinkedList<Object[]>();
for (int i = 0; i < _data.length; i++) {
boolean sel = true;
/*for (int j = 0; j < rows.length; j++) {
ParameterRow row = rows[j];
if (!row.xaxis.isSelected() && !row.yaxis.isSelected() && !row.zaxis.isSelected() && !row.check(_data[i][j]))
sel = false;
}*/
if (sel) {
_tmpselecteddata.add(_data[i]);
_tmpselectedIndex[_nbselected] = i;
_nbselected++;
/*System.out.print("OK:");
for (int j = 0; j < _tmpselecteddata.getLast().length; j++)
System.out.print(_tmpselecteddata.getLast()[j]+",");
System.out.println("");*/
}
}
dataUpdated = true;
}
/**
* Method to override if you want to link to any gui component (for instance, a plotpanel).
*/
public void fireSelectedDataChanged(String from) {
System.out.println("fireSelectedDataChanged from " + from);
Object[][] sel = getSelectedFullData();
System.out.println("selected full data :");
System.out.println(Array.cat(_parametersNames));
if (sel.length > 0) {
System.out.println(Array.cat(getSelectedFullData()));
}
sel = getSelectedProjectedData();
System.out.println("selected projected data :");
switch (_dimension) {
case 1:
System.out.println(Array.cat(new String[]{getSelectedXAxis()}));
break;
case 2:
System.out.println(Array.cat(new String[]{getSelectedXAxis(), getSelectedYAxis()}));
break;
case 3:
System.out.println(Array.cat(new String[]{getSelectedXAxis(), getSelectedYAxis(), getSelectedZAxis()}));
break;
}
if (sel.length > 0) {
System.out.println(Array.cat(getSelectedProjectedData()));
}
}
/**
* return selected data
*/
public int[] getSelectedDataIndex() {
updateSelectedData();
_selectedindex = new int[_nbselected];
for (int i = 0; i < _nbselected; i++) {
_selectedindex[i] = _tmpselectedIndex[i];
}
return _selectedindex;
}
/**
* return selected data
*/
public Object[][] getSelectedFullData() {
updateSelectedData();
_selecteddata = new Object[_tmpselecteddata.size()][_data[0].length];
for (int i = 0; i < _selecteddata.length; i++) {
for (int j = 0; j < _selecteddata[i].length; j++) {
_selecteddata[i][j] = _tmpselecteddata.get(i)[j];
}
}
return _selecteddata;
}
/**
* return selected data projected on axis selected
*/
public Object[][] getSelectedProjectedData() {
updateSelectedData();
int[] selextedaxis = getSelectedAxisIndex();
_selecteddata = new Object[_tmpselecteddata.size()][_dimension];
for (int i = 0; i < _selecteddata.length; i++) {
for (int j = 0; j < _dimension; j++) {
_selecteddata[i][j] = _tmpselecteddata.get(i)[selextedaxis[j]];
}
}
return _selecteddata;
}
public int[] getSelectedAxisIndex() {
int[] selextedaxis = new int[_dimension];
updateSelectedData();
/*for (int i = 0; i < rows.length; i++) {
if (rows[i].xaxis.isSelected()) {
//System.out.println("selextedaxis[0] =" + i);
selextedaxis[0] = i;
}
if (rows[i].yaxis.isSelected()) {
//System.out.println("selextedaxis[1] =" + i);
selextedaxis[1] = i;
}
if (rows[i].zaxis.isSelected()) {
//System.out.println("selextedaxis[2] =" + i);
selextedaxis[2] = i;
}
}*/
return selextedaxis;
}
/**
* return selected X axis name
*/
public String getSelectedXAxis() {
updateSelectedData();
for (ParameterRow row : rows) {
if (row.xaxis.isSelected()) {
return row._paramName;
}
}
return null;
}
/**
* return selected Y axis name
*/
public String getSelectedYAxis() {
updateSelectedData();
for (ParameterRow row : rows) {
if (row.yaxis.isSelected()) {
return row._paramName;
}
}
return null;
}
/**
* return selected Z axis name
*/
public String getSelectedZAxis() {
updateSelectedData();
for (ParameterRow row : rows) {
if (row.zaxis.isSelected()) {
return row._paramName;
}
}
return null;
}
static Object[] getColumn(int j, Object[][] mat) {
Object[] col = new Object[mat.length];
for (int i = 0; i < col.length; i++) {
col[i] = mat[i][j];
}
return col;
}
class ParameterRow /*extends JPanel */ {
//private static final long serialVersionUID = -7301434647336910071L;
String _paramName;
//JLabel name;
JRadioButton xaxis, yaxis, zaxis;
JComponent parameter;
JSlider min, max;
JCheckBox linkminmax;
JList list;
//Object[] _values;
Vector<Object> _kernelStringValues;
boolean _isNumber;
//double[] _dvalues;
double[] _kernelDoubleValues;
public ParameterRow(String paramName, Object[] values) {
_paramName = paramName;
_isNumber = Array.isDouble(values[0].toString());
if (!_isNumber) {
_kernelStringValues = new Vector<Object>(values.length);
for (int i = 0; i < values.length; i++) {
if (!_kernelStringValues.contains(values[i])) {
_kernelStringValues.add(values[i]);
}
}
} else {
Vector<Double> _tmpdvalues = new Vector<Double>(values.length);
for (int i = 0; i < values.length; i++) {
if (!_tmpdvalues.contains(Double.valueOf(values[i].toString()))) {
_tmpdvalues.add(Double.valueOf(values[i].toString()));
}
}
_kernelDoubleValues = new double[_tmpdvalues.size()];
for (int i = 0; i < _kernelDoubleValues.length; i++) {
_kernelDoubleValues[i] = _tmpdvalues.get(i);
}
}
setLayout(new GridLayout(1, 2));
//name = new JLabel(_paramName);
//add(name, 0);
JPanel type = new JPanel(new BorderLayout());
JPanel XYZ = new JPanel(new GridLayout(_dimension, 1));
xaxis = new JRadioButton("X");
xaxis.addActionListener(new Action() {
public void actionPerformed(ActionEvent e) {
yaxis.setSelected(false);
zaxis.setSelected(false);
for (ParameterRow r : rows) {
if (!r._paramName.equals(_paramName)) {
r.xaxis.setSelected(false);
}
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " xaxis");
}
public void setEnabled(boolean b) {
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
}
public void putValue(String key, Object value) {
}
public boolean isEnabled() {
return true;
}
public Object getValue(String key) {
return null;
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
}
});
XYZ.add(xaxis);
yaxis = new JRadioButton("Y");
yaxis.addActionListener(new Action() {
public void actionPerformed(ActionEvent e) {
xaxis.setSelected(false);
zaxis.setSelected(false);
for (ParameterRow r : rows) {
if (!r._paramName.equals(_paramName)) {
r.yaxis.setSelected(false);
}
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " yaxis");
}
public void setEnabled(boolean b) {
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
}
public void putValue(String key, Object value) {
}
public boolean isEnabled() {
return true;
}
public Object getValue(String key) {
return null;
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
}
});
if (_dimension >= 2) {
XYZ.add(yaxis);
}
zaxis = new JRadioButton("Z");
zaxis.addActionListener(new Action() {
public void actionPerformed(ActionEvent e) {
xaxis.setSelected(false);
yaxis.setSelected(false);
for (ParameterRow r : rows) {
if (!r._paramName.equals(_paramName)) {
r.zaxis.setSelected(false);
}
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " zaxis");
}
public void setEnabled(boolean b) {
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
}
public void putValue(String key, Object value) {
}
public boolean isEnabled() {
return true;
}
public Object getValue(String key) {
return null;
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
}
});
if (_dimension == 3) {
XYZ.add(zaxis);
}
type.add(XYZ, BorderLayout.WEST);
if (_isNumber) {
parameter = new JPanel();
parameter.setLayout(new GridLayout(2, 1));
min = new JSlider(1, _kernelDoubleValues.length, 1);
min.setMinorTickSpacing(1);
min.setSnapToTicks(true);
min.setPaintTicks(true);
max = new JSlider(1, _kernelDoubleValues.length, _kernelDoubleValues.length);
max.setMinorTickSpacing(1);
max.setSnapToTicks(true);
max.setPaintTicks(true);
min.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (max.getValue() < min.getValue()) {
max.setValue(min.getValue());
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " min");
}
});
max.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (max.getValue() < min.getValue()) {
min.setValue(max.getValue());
}
dataUpdated = false;
fireSelectedDataChanged(_paramName + " max");
}
});
parameter.add(min, 0);
parameter.add(max, 1);
} else {
list = new JList(_kernelStringValues);
list.setSelectedIndices(buildIntSeq(0, _kernelStringValues.size() - 1));
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
dataUpdated = false;
fireSelectedDataChanged(_paramName + " list");
}
});
parameter = new JScrollPane(list);
}
type.add(parameter, BorderLayout.CENTER);
add(type, 1);
setBorder(BorderFactory.createEtchedBorder());
setPreferredSize(new Dimension(400, 60));
}
int[] buildIntSeq(int min, int max) {
int[] seq = new int[max - min + 1];
for (int i = 0; i < seq.length; i++) {
seq[i] = min + i;
}
return seq;
}
boolean check(Object value) {
if (_isNumber) {
double dval = Double.valueOf(value.toString());
return (dval >= _kernelDoubleValues[min.getValue() - 1] && dval <= _kernelDoubleValues[max.getValue() - 1]);
} else {
for (int i = 0; i < list.getSelectedIndices().length; i++) {
if (_kernelStringValues.get(list.getSelectedIndices()[i]).equals(value)) {
return true;
}
}
return false;
}
}
}
public static void main(String[] args) {
final PlotPanel pp = new Plot3DPanel(PlotPanel.WEST);
pp.setPreferredSize(new Dimension(400, 400));
new FrameView(pp).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object[][] data = {{0, 0, 0, 0, "a0"}, {1, 1, 1, 1, "a1"}, {2, 2, 2, 2, "a2"}, {3, 3, 3, 3, "a3"}, {4, 3, 3, 3, "a3"}, {5, 3, 3, 3, "a4"}};
DataSelectTable dsp = new DataSelectTable(data, 3, "x1", "x2", "x3", "x4", "x5") {
private static final long serialVersionUID = 1L;
@Override
public void fireSelectedDataChanged(String from) {
super.fireSelectedDataChanged(from);
pp.setAxisLabel(0, getSelectedXAxis());
pp.setAxisLabel(1, getSelectedYAxis());
pp.setAxisLabel(2, getSelectedZAxis());
if (pp.getPlots().size() == 0) {
pp.addPlot("SCATTER", "data", pp.mapData(getSelectedProjectedData()));
} else {
if (from.endsWith("axis")) {
pp.resetMapData();
pp.removeAllPlots();
pp.addPlot("SCATTER", "data", pp.mapData(getSelectedProjectedData()));
} else {
pp.getPlot(0).setData(pp.mapData(getSelectedProjectedData()));
}
}
//System.out.println(Array.cat(pp.getAxesScales()));
}
};
new FrameView(dsp).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/*try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Object[][] data2 = { { 0, 0, 0, 0, "a0" }, { 1, 1, 1, 1, "a1" }, { 2, 2, 2, 2, "a2" }, { 3, 3, 3, 3, "a3" }, { 4, 3, 3, 3, "a3" },
{ 5, 3, 3, 3, "a4" }, { 5, 4, 3, 3, "a4" } };
dsp.setData(data2);*/
}
}

View file

@ -1,66 +0,0 @@
package org.xbib.graphics.graph.jmathplot.panel;
import org.xbib.graphics.graph.jmathplot.canvas.Plot2DCanvas;
import org.xbib.graphics.graph.jmathplot.canvas.Plot3DCanvas;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* BSD License
*
* @author Yann RICHET
*/
public class FrameView extends JFrame {
private static final long serialVersionUID = 1L;
public FrameView(Plot2DCanvas... canvas) {
JPanel panel = new JPanel();
for (int i = 0; i < canvas.length; i++) {
panel.add(new Plot2DPanel(canvas[i]));
}
setContentPane(panel);
pack();
setSize(600, 600);
setVisible(true);
}
public FrameView(Plot3DCanvas... canvas) {
JPanel panel = new JPanel();
for (int i = 0; i < canvas.length; i++) {
panel.add(new Plot3DPanel(canvas[i]));
}
setContentPane(panel);
pack();
setSize(600, 600);
setVisible(true);
}
public FrameView(String title, JComponent panel) {
super(title);
setContentPane(panel);
pack();
setSize(600, 600);
setVisible(true);
}
public FrameView(JComponent... panels) {
JPanel panel = new JPanel();
for (int i = 0; i < panels.length; i++) {
panel.add(panels[i]);
}
setContentPane(panel);
pack();
setSize(600, 600);
setVisible(true);
}
public FrameView(JPanel panel) {
setContentPane(panel);
pack();
setSize(600, 600);
setVisible(true);
}
}

View file

@ -1,159 +0,0 @@
package org.xbib.graphics.graph.jmathplot.panel;
import org.xbib.graphics.graph.jmathplot.io.files.ASCIIFile;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.io.File;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
/**
* BSD License
*
* @author Yann RICHET
*/
public class MatrixTablePanel extends DataPanel {
private static final long serialVersionUID = 1L;
private JTable table;
private TableModel model;
private Object[][] M;
private boolean viewHeaders = false;
private String[] headers;
public MatrixTablePanel(Object[][] m) {
this(m, null);
}
public MatrixTablePanel(Object[][] m, String[] headers) {
super();
M = m;
if (headers == null) {
if (M.length == 0) {
this.headers = new String[0];
} else {
this.headers = new String[M[0].length];
}
} else {
viewHeaders = true;
this.headers = headers;
}
setModel();
toWindow();
}
public void addSelectionListener(ListSelectionListener lsitener) {
ListSelectionModel listSelectionModel = table.getSelectionModel();
listSelectionModel.addListSelectionListener(lsitener);
}
public void removeSelectionListener(ListSelectionListener lsitener) {
ListSelectionModel listSelectionModel = table.getSelectionModel();
listSelectionModel.removeListSelectionListener(lsitener);
}
public void toClipBoard() {
try {
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(Array.cat(M)), null);
} catch (IllegalStateException e) {
JOptionPane.showConfirmDialog(null, "Copy to clipboard failed : " + e.getMessage(), "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
}
}
public String getText() {
return M.toString();
}
public void toASCIIFile(File file) {
try {
ASCIIFile.write(file, Array.cat(M));
} catch (NullPointerException e) {
// System.out.println("File not saved");
}
}
private void setModel() {
/*Double[][] array = null;
if (M.length != 0) {
array = new Double[M.length][M[0].length];
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j] = new Double(M[i][j]);
}
}
} else
array = new Double[0][0];*/
model = new DefaultTableModel(M, headers) {
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
}
public void setHeaders(String[] h) {
if (M.length != 0) {
if (h.length != M[0].length) {
throw new IllegalArgumentException("Headers of the table must have " + M[0].length + " elements.");
}
}
headers = h;
viewHeaders = true;
update();
}
public void update() {
setModel();
super.update();
}
public void setMatrix(Object[][] m) {
M = m;
if (M.length == 0) {
headers = new String[0];
} else {
headers = new String[M[0].length];
}
update();
}
public void toWindow() {
table = new JTable(model);
if (!viewHeaders) {
table.setTableHeader(null);
}
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setRowSelectionAllowed(true);
table.setEnabled(true);
scrollPane = new JScrollPane(table);
/*
* scrollPane.setPreferredSize(getSize());
* scrollPane.setSize(getSize());
*/
add(scrollPane, BorderLayout.CENTER);
}
public Object[][] getMatrix() {
return M;
}
}

View file

@ -1,189 +0,0 @@
package org.xbib.graphics.graph.jmathplot.panel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/**
* BSD License
*
* @author Yann RICHET
*/
public class ParametersPanel extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
private Dimension defaultSize;
private final String[] paramLabels;
private final String[] paramValues;
private final boolean[] isList;
private final int[] paramValuesIndex;
private final String[][] paramChoices;
private JLabel[] labels;
private JComboBox[] fields;
private Runnable action;
public ParametersPanel(String[] lab, String[] val) {
this(lab, new int[lab.length], new String[][]{val});
}
public ParametersPanel(String[] lab) {
this(lab, new String[lab.length]);
}
public ParametersPanel(String[] lab, int[] selected, String[][] ch) {
paramLabels = lab;
isList = new boolean[paramLabels.length];
for (int i = 0; i < isList.length; i++) {
isList[i] = true;
}
paramValuesIndex = selected;
paramChoices = ch;
paramValues = new String[paramLabels.length];
for (int i = 0; i < paramChoices.length; i++) {
paramValues[i] = paramChoices[i][paramValuesIndex[i]];
}
setComponents();
setAppearence();
draw();
}
public ParametersPanel(String[] lab, String[][] ch) {
this(lab, new int[lab.length], ch);
}
private void setComponents() {
labels = new JLabel[paramLabels.length];
fields = new JComboBox[paramLabels.length];
for (int i = 0; i < paramLabels.length; i++) {
labels[i] = new JLabel(paramLabels[i], JLabel.RIGHT);
if (isList[i]) {
fields[i] = new JComboBox(paramChoices[i]);
} else {
fields[i] = new JComboBox();
}
fields[i].setEditable(!isList[i]);
}
defaultSize = new Dimension(400, paramLabels.length * 30);
}
private void setAppearence() {
setPreferredSize(defaultSize);
setSize(defaultSize);
}
private void update() {
updateValues();
updateValuesIndex();
}
private void updateValues() {
for (int i = 0; i < paramLabels.length; i++) {
paramValues[i] = (String) (fields[i].getSelectedItem());
}
}
private void updateValuesIndex() {
for (int i = 0; i < paramLabels.length; i++) {
if (isList[i]) {
paramValuesIndex[i] = fields[i].getSelectedIndex();
}
}
}
public void actionPerformed(ActionEvent e) {
update();
new Thread(action, "PanelParameters " + this.toString() + " selection").start();
}
public int getValueIndex(int i) {
if (!isList[i]) {
throw new IllegalArgumentException("This PanelParameter element is not set to give an Index.");
}
update();
return paramValuesIndex[i];
}
public int[] getValuesIndex() {
update();
return paramValuesIndex;
}
public String[] getValues() {
update();
return paramValues;
}
public String getValue(int i) {
update();
return paramValues[i];
}
public void setAction(Runnable t) {
action = t;
}
private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) {
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
}
private void draw() {
JPanel panel = new JPanel();
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
panel.setLayout(gbl);
for (int i = 0; i < paramLabels.length; i++) {
fields[i].addActionListener(this);
// Ajout du panel de la chaine
buildConstraints(c, 0, i, 1, 1, 50, 20);
c.anchor = GridBagConstraints.EAST;
gbl.setConstraints(labels[i], c);
panel.add(labels[i]);
// Ajout du panel de la chaine
buildConstraints(c, 1, i, 1, 1, 50, 20);
c.fill = GridBagConstraints.HORIZONTAL;
gbl.setConstraints(fields[i], c);
panel.add(fields[i]);
}
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setPreferredSize(getSize());
scrollPane.setSize(getSize());
setLayout(new BorderLayout());
add(scrollPane, BorderLayout.CENTER);
}
}

View file

@ -1,412 +0,0 @@
package org.xbib.graphics.graph.jmathplot.panel;
import org.xbib.graphics.graph.jmathplot.canvas.Plot2DCanvas;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import java.awt.Color;
/**
* BSD License
*
* @author Yann RICHET
*/
/**
* Class suitable for plotting 2D data on a panel, to be added to a swing
* container.
* <p>
* Class for ascending compatibility
*
* @author Yann Richet
*/
public class Plot2DPanel extends PlotPanel {
private static final long serialVersionUID = 1L;
/**
* Constructor for Plot2DPanel.
* Create a new blank instance of Plot2DPanel, to be added to a swing
* component.
*/
public Plot2DPanel() {
super(new Plot2DCanvas());
}
public Plot2DPanel(double[] min, double[] max, String[] axesScales, String[] axesLabels) {
super(new Plot2DCanvas(min, max, axesScales, axesLabels));
}
public Plot2DPanel(PlotCanvas _canvas, String legendOrientation) {
super(_canvas, legendOrientation);
}
public Plot2DPanel(PlotCanvas _canvas) {
super(_canvas);
}
public Plot2DPanel(String legendOrientation) {
super(new Plot2DCanvas(), legendOrientation);
}
/**
* Adds a scatter plot (each data point is plotted as a single dot
* marker) to the current plot panel.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XY Pairs of array of double. First one contains the X position
* of the data points, second contains Y position.
* <br>
* Each array of the pair
* must be of the same length; if not a ArrayIndexOutOfBoundsException
* exception will be thrown.
* <br>
* Each data set must come in <b>pair</b> of
* array of double; if not a ArrayIndexOutOfBoundsException exception
* will be thrown.
* @return the index of the plot in the panel (int).
* @see #addLinePlot(String, Color, double[]...)
* @see #addBarPlot(String, Color, double[]...)
* @see #addBoxPlot(String, Color, double[][], double[][])
* @see #addHistogramPlot(String, Color, double[][], double[])
* @see #addStaircasePlot(String, Color, double[]...)
*/
public int addScatterPlot(String name, Color color, double[][] XY) {
return ((Plot2DCanvas) plotCanvas).addScatterPlot(name, color, XY);
}
public int addScatterPlot(String name, Color color, double[] Y) {
return ((Plot2DCanvas) plotCanvas).addScatterPlot(name, color, Y);
}
public int addScatterPlot(String name, Color color, double[] X, double[] Y) {
return ((Plot2DCanvas) plotCanvas).addScatterPlot(name, color, X, Y);
}
public int addScatterPlot(String name, double[][] XY) {
return addScatterPlot(name, getNewColor(), XY);
}
public int addScatterPlot(String name, double[] Y) {
return addScatterPlot(name, getNewColor(), Y);
}
public int addScatterPlot(String name, double[] X, double[] Y) {
return addScatterPlot(name, getNewColor(), X, Y);
}
/**
* Adds a line plot (each data point is connected to the next one by a
* solid line) to the current plot panel.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XY Pairs of array of double. First one contains the X position
* of the data points, second contains Y position.
* <br>
* Each array of the pair
* must be of the same length; if not a ArrayIndexOutOfBoundsException
* exception will be thrown.
* <br>
* Each data set must come in <b>pair</b> of
* array of double; if not a ArrayIndexOutOfBoundsException exception
* will be thrown.
* @return the index of the plot in the panel (int).
* @see #addScatterPlot(String, Color, double[]...)
* @see #addBarPlot(String, Color, double[]...)
* @see #addBoxPlot(String, Color, double[]...)
* @see #addHistogramPlot(String, Color, double[]...)
* @see #addStaircasePlot(String, Color, double[]...)
*/
public int addLinePlot(String name, Color color, double[][] XY) {
return ((Plot2DCanvas) plotCanvas).addLinePlot(name, color, XY);
}
public int addLinePlot(String name, Color color, double[] Y) {
return ((Plot2DCanvas) plotCanvas).addLinePlot(name, color, Y);
}
public int addLinePlot(String name, Color color, double[] X, double[] Y) {
return ((Plot2DCanvas) plotCanvas).addLinePlot(name, color, X, Y);
}
public int addLinePlot(String name, double[][] XY) {
return addLinePlot(name, getNewColor(), XY);
}
public int addLinePlot(String name, double[] Y) {
return addLinePlot(name, getNewColor(), Y);
}
public int addLinePlot(String name, double[] X, double[] Y) {
return addLinePlot(name, getNewColor(), X, Y);
}
/**
* Adds a bar plot (each data point is shown as a dot marker connected to
* the horizontal axis by a vertical line) to the current plot panel.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XY Pairs of array of double. First one contains the X position
* of the data points, second contains Y position.
* <br>
* Each array of the pair
* must be of the same length; if not a ArrayIndexOutOfBoundsException
* exception will be thrown.
* <br>
* Each data set must come in <b>pair</b> of
* array of double; if not a ArrayIndexOutOfBoundsException exception
* will be thrown.
* @return the index of the plot in the panel (int).
* @see #addScatterPlot(String, Color, double[]...)
* @see #addLinePlot(String, Color, double[]...)
* @see #addBoxPlot(String, Color, double[]...)
* @see #addHistogramPlot(String, Color, double[]...)
* @see #addStaircasePlot(String, Color, double[]...)
*/
public int addBarPlot(String name, Color color, double[][] XY) {
return ((Plot2DCanvas) plotCanvas).addBarPlot(name, color, XY);
}
public int addBarPlot(String name, Color color, double[] Y) {
return ((Plot2DCanvas) plotCanvas).addBarPlot(name, color, Y);
}
public int addBarPlot(String name, Color color, double[] X, double[] Y) {
return ((Plot2DCanvas) plotCanvas).addBarPlot(name, color, X, Y);
}
public int addBarPlot(String name, double[][] XY) {
return addBarPlot(name, getNewColor(), XY);
}
public int addBarPlot(String name, double[] Y) {
return addBarPlot(name, getNewColor(), Y);
}
public int addBarPlot(String name, double[] X, double[] Y) {
return addBarPlot(name, getNewColor(), X, Y);
}
/**
* Adds a staircase plot (each data point is connected to the following
* one by a horizontal line then a vertical line) to the current plot panel.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XY Pairs of array of double. First one contains the X position
* of the data points, second contains Y position.
* <br>
* Each array of the pair
* must be of the same length; if not a ArrayIndexOutOfBoundsException
* exception will be thrown.
* <br>
* Each data set must come in <b>pair</b> of
* array of double; if not a ArrayIndexOutOfBoundsException exception
* will be thrown.
* @return the index of the plot in the panel (int).
* @see #addScatterPlot(String, Color, double[]...)
* @see #addBarPlot(String, Color, double[]...)
* @see #addBoxPlot(String, Color, double[][], double[][])
* @see #addHistogramPlot(String, Color, double[][], double[])
* @see #addLinePlot(String, Color, double[]...)
*/
public int addStaircasePlot(String name, Color color, double[][] XY) {
return ((Plot2DCanvas) plotCanvas).addStaircasePlot(name, color, XY);
}
public int addStaircasePlot(String name, Color color, double[] Y) {
return ((Plot2DCanvas) plotCanvas).addStaircasePlot(name, color, Y);
}
public int addStaircasePlot(String name, Color color, double[] X, double[] Y) {
return ((Plot2DCanvas) plotCanvas).addStaircasePlot(name, color, X, Y);
}
public int addStaircasePlot(String name, double[][] XY) {
return addStaircasePlot(name, getNewColor(), XY);
}
public int addStaircasePlot(String name, double[] Y) {
return addStaircasePlot(name, getNewColor(), Y);
}
public int addStaircasePlot(String name, double[] X, double[] Y) {
return addStaircasePlot(name, getNewColor(), X, Y);
}
/**
* Adds a box plot to the current plot panel. Each data point is plotted
* as a dot marker at the center of a rectangle.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XY m*2 array of array of double. Contains the x,y coordinates of the
* m boxes' center (m lines, 2 rows).
* @param dXdY m*2 array of array of double. Contains the width and heigth of the
* m boxes (m lines, 2 rows).
* @return the index of the plot in the panel (int).
* @see #addScatterPlot(String, Color, double[]...)
* @see #addBarPlot(String, Color, double[]...)
* @see #addStaircasePlot(String, Color, double[]...)
* @see #addHistogramPlot(String, Color, double[][], double[])
* @see #addLinePlot(String, Color, double[]...)
*/
public int addBoxPlot(String name, Color color, double[][] XY, double[][] dXdY) {
return ((Plot2DCanvas) plotCanvas).addBoxPlot(name, color, XY, dXdY);
}
public int addBoxPlot(String name, double[][] XY, double[][] dXdY) {
return addBoxPlot(name, getNewColor(), XY, dXdY);
}
/**
* Adds a box plot to the current plot panel. Each data point is plotted
* as a dot marker at the center of a rectangle.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XYdXdY m*4 array of array of double. Contains the x,y coordinates of the
* m boxes' center and the boxes width and heigth (m lines, 4 rows).
* @return the index of the plot in the panel (int).
* @see #addScatterPlot(String, Color, double[]...)
* @see #addBarPlot(String, Color, double[]...)
* @see #addStaircasePlot(String, Color, double[]...)
* @see #addHistogramPlot(String, Color, double[][], double[])
* @see #addLinePlot(String, Color, double[]...)
*/
public int addBoxPlot(String name, Color color, double[][] XYdXdY) {
return ((Plot2DCanvas) plotCanvas).addBoxPlot(name, color, XYdXdY);
}
public int addBoxPlot(String name, double[][] XYdXdY) {
return addBoxPlot(name, getNewColor(), XYdXdY);
}
/**
* Adds a histogram plot to the current plot panel. Each data point is as
* vertical bar which width can be set.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XY m*2 array of array of double. Contains the x coordinate and
* the heigth of each bar (m lines, 2 rows).
* @param dX Array of double. Contains the width each bar (m lines).
* @return the index of the plot in the panel (int).
* @see #addScatterPlot(String, Color, double[]...)
* @see #addBarPlot(String, Color, double[]...)
* @see #addStaircasePlot(String, Color, double[]...)
* @see #addBoxPlot(String, Color, double[][])
* @see #addLinePlot(String, Color, double[]...)
*/
public int addHistogramPlot(String name, Color color, double[][] XY, double[] dX) {
return ((Plot2DCanvas) plotCanvas).addHistogramPlot(name, color, XY, dX);
}
public int addHistogramPlot(String name, double[][] XY, double[] dX) {
return addHistogramPlot(name, getNewColor(), XY, dX);
}
public int addHistogramPlot(String name, Color color, double[][] XYdX) {
return ((Plot2DCanvas) plotCanvas).addHistogramPlot(name, color, XYdX);
}
/**
* Adds a histogram plot to the current plot panel. Each data point is as
* vertical bar which width can be set.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param XYdX m*3 array of array of double. Contains the x coordinate,
* the heigth of each bar and the width of each bar (m lines, 3 rows).
* @return the index of the plot in the panel (int).
* @see #addScatterPlot(String, Color, double[]...)
* @see #addBarPlot(String, Color, double[]...)
* @see #addStaircasePlot(String, Color, double[]...)
* @see #addBoxPlot(String, Color, double[][])
* @see #addLinePlot(String, Color, double[]...)
*/
public int addHistogramPlot(String name, double[][] XYdX) {
return addHistogramPlot(name, getNewColor(), XYdX);
}
/**
* Adds a plot of the statistical repartition of a sample, as a histogram.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param sample Array of double containing the data which statistics will be plotted.
* @param n Bin number for the statistics (int).
* @return the index of the plot in the panel (int).
*/
public int addHistogramPlot(String name, Color color, double[] sample, int n) {
return ((Plot2DCanvas) plotCanvas).addHistogramPlot(name, color, sample, n);
}
public int addHistogramPlot(String name, double[] X, int n) {
return addHistogramPlot(name, getNewColor(), X, n);
}
/**
* Adds a plot of the statistical repartition of a sample, as a histogram.
* The bins' limits can be set.
*
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param sample Array of double containing the data which statistics will be plotted.
* @param bounds Specify the limits for the bins' boundaries.
* @return the index of the plot in the panel (int).
*/
public int addHistogramPlot(String name, Color color, double[] sample, double... bounds) {
return ((Plot2DCanvas) plotCanvas).addHistogramPlot(name, color, sample, bounds);
}
public int addHistogramPlot(String name, double[] X, double... bounds) {
return addHistogramPlot(name, getNewColor(), X, bounds);
}
public int addHistogramPlot(String name, Color color, double[] X, double min, double max, int n) {
return ((Plot2DCanvas) plotCanvas).addHistogramPlot(name, color, X, min, max, n);
}
public int addHistogramPlot(String name, double[] X, double min, double max, int n) {
return addHistogramPlot(name, getNewColor(), X, min, max, n);
}
public int addCloudPlot(String name, Color color, double[][] sampleXY, int nX, int nY) {
return ((Plot2DCanvas) plotCanvas).addCloudPlot(name, color, sampleXY, nX, nY);
}
public int addCloudPlot(String name, double[][] sampleXY, int nX, int nY) {
return addCloudPlot(name, getNewColor(), sampleXY, nX, nY);
}
@Override
public int addPlot(String type, String name, Color color, double[]... XY) {
if (type.equalsIgnoreCase(SCATTER)) {
return addScatterPlot(name, color, XY);
} else if (type.equalsIgnoreCase(LINE)) {
return addLinePlot(name, color, XY);
} else if (type.equalsIgnoreCase(BAR)) {
return addBarPlot(name, color, XY);
} else if (type.equalsIgnoreCase(STAIRCASE)) {
return addStaircasePlot(name, color, XY);
} else if (type.equalsIgnoreCase(HISTOGRAM)) {
return addHistogramPlot(name, color, XY);
} else if (type.equalsIgnoreCase(BOX)) {
return addBoxPlot(name, color, XY);
} else {
throw new IllegalArgumentException("Plot type is unknown : " + type);
}
}
}

View file

@ -1,249 +0,0 @@
package org.xbib.graphics.graph.jmathplot.panel;
import org.xbib.graphics.graph.jmathplot.canvas.Plot3DCanvas;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
public class Plot3DPanel extends PlotPanel {
public void setDefaultZoom(double zoom_factor) {
((Plot3DCanvas) plotCanvas).setDefaultZoom(zoom_factor);
repaint();
}
public Plot3DPanel() {
super(new Plot3DCanvas());
}
public Plot3DPanel(double[] min, double[] max, String[] axesScales, String[] axesLabels) {
super(new Plot3DCanvas(min, max, axesScales, axesLabels));
}
public Plot3DPanel(PlotCanvas _canvas, String legendOrientation) {
super(_canvas, legendOrientation);
}
public Plot3DPanel(PlotCanvas _canvas) {
super(_canvas);
}
public Plot3DPanel(String legendOrientation) {
super(new Plot3DCanvas(), legendOrientation);
}
/**
* Adds a scatter plot (each data point is plotted as a single dot
* marker) to the current plot panel.
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XY Array of triple double. For each triple, first one contains the X position
* of the data points, second contains Y position, third contains Z position.
* <br>
* Each array of the triple
* must be of the same length; if not a ArrayIndexOutOfBoundsException
* exception will be thrown.
* <br>
* Each data set must come in
* array of <b>triple</b> of double; if not a ArrayIndexOutOfBoundsException exception
* will be thrown.
* @return the index of the plot in the panel (int).
* @see #addLinePlot(String, Color, double[]...)
* @see #addBarPlot(String, Color, double[]...)
* @see #addBoxPlot(String, Color, double[][], double[][])
*/
public int addScatterPlot(String name, Color color, double[][] XY) {
return ((Plot3DCanvas) plotCanvas).addScatterPlot(name, color, XY);
}
public int addScatterPlot(String name, Color color, double[] X, double[] Y, double[] Z) {
return ((Plot3DCanvas) plotCanvas).addScatterPlot(name, color, X, Y, Z);
}
public int addScatterPlot(String name, double[][] XY) {
return addScatterPlot(name, getNewColor(), XY);
}
public int addScatterPlot(String name, double[] X, double[] Y, double[] Z) {
return addScatterPlot(name, getNewColor(), X, Y, Z);
}
/**
* Adds a line plot (each data point is connected to the next one by a
* solid line) to the current plot panel.
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XY Array of triple double. For each triple, first one contains the X position
* of the data points, second contains Y position, third contains Z position.
* <br>
* Each array of the triple
* must be of the same length; if not a ArrayIndexOutOfBoundsException
* exception will be thrown.
* <br>
* Each data set must come in
* array of <b>triple</b> of double; if not a ArrayIndexOutOfBoundsException exception
* will be thrown.
* @return the index of the plot in the panel (int).
* @see #addScatterPlot(String, Color, double[]...)
* @see #addBarPlot(String, Color, double[]...)
* @see #addBoxPlot(String, Color, double[]...)
*/
public int addLinePlot(String name, Color color, double[][] XY) {
return ((Plot3DCanvas) plotCanvas).addLinePlot(name, color, XY);
}
public int addLinePlot(String name, Color color, double[] X, double[] Y, double[] Z) {
return ((Plot3DCanvas) plotCanvas).addLinePlot(name, color, X, Y, Z);
}
public int addLinePlot(String name, double[][] XY) {
return addLinePlot(name, getNewColor(), XY);
}
public int addLinePlot(String name, double[] X, double[] Y, double[] Z) {
return addLinePlot(name, getNewColor(), X, Y, Z);
}
/**
* Adds a bar plot (each data point is shown as a dot marker connected to
* the horizontal axis by a vertical line) to the current plot panel.
* @param name Name for the plot, which will be used in the legend.
* (String)
* @param color Plot color. (Color)
* @param XY Array of triple double. For each triple, first one contains the X position
* of the data points, second contains Y position, third contains Z position.
* <br>
* Each array of the triple
* must be of the same length; if not a ArrayIndexOutOfBoundsException
* exception will be thrown.
* <br>
* Each data set must come in
* array of <b>triple</b> of double; if not a ArrayIndexOutOfBoundsException exception
* will be thrown.
* @return the index of the plot in the panel (int).
* @see #addScatterPlot(String, Color, double[]...)
* @see #addLinePlot(String, Color, double[]...)
* @see #addBoxPlot(String, Color, double[]...)
*/
public int addBarPlot(String name, Color color, double[][] XY) {
return ((Plot3DCanvas) plotCanvas).addBarPlot(name, color, XY);
}
public int addBarPlot(String name, Color color, double[] X, double[] Y, double[] Z) {
return ((Plot3DCanvas) plotCanvas).addBarPlot(name, color, X, Y, Z);
}
public int addBarPlot(String name, double[][] XY) {
return addBarPlot(name, getNewColor(), XY);
}
public int addBarPlot(String name, double[] X, double[] Y, double[] Z) {
return addBarPlot(name, getNewColor(), X, Y, Z);
}
public int addBoxPlot(String name, Color c, double[][] XY, double[][] dX) {
return ((Plot3DCanvas) plotCanvas).addBoxPlot(name, c, XY, dX);
}
public int addBoxPlot(String name, double[][] XY, double[][] dX) {
return addBoxPlot(name, getNewColor(), XY, dX);
}
public int addBoxPlot(String name, Color c, double[][] XYdX) {
return ((Plot3DCanvas) plotCanvas).addBoxPlot(name, c, Array.getColumnsRangeCopy(XYdX, 0, 2), Array.getColumnsRangeCopy(XYdX, 3, 5));
}
public int addBoxPlot(String name, double[][] XYdX) {
return addBoxPlot(name, getNewColor(), XYdX);
}
public int addHistogramPlot(String name, Color c, double[][] XY, double[][] dX) {
return ((Plot3DCanvas) plotCanvas).addHistogramPlot(name, c, XY, dX);
}
public int addHistogramPlot(String name, double[][] XY, double[][] dX) {
return addHistogramPlot(name, getNewColor(), XY, dX);
}
public int addHistogramPlot(String name, Color c, double[][] XYdX) {
return ((Plot3DCanvas) plotCanvas).addHistogramPlot(name, c, Array.getColumnsRangeCopy(XYdX, 0, 2), Array.getColumnsRangeCopy(XYdX, 3, 4));
}
public int addHistogramPlot(String name, double[][] XYdX) {
return addHistogramPlot(name, getNewColor(), XYdX);
}
public int addHistogramPlot(String name, Color c, double[][] XY, int nX, int nY) {
return ((Plot3DCanvas) plotCanvas).addHistogramPlot(name, c, XY, nX, nY);
}
public int addHistogramPlot(String name, double[][] XY, int nX, int nY) {
return addHistogramPlot(name, getNewColor(), XY, nX, nY);
}
public int addHistogramPlot(String name, Color c, double[][] XY, double[] boundsX, double[] boundsY) {
return ((Plot3DCanvas) plotCanvas).addHistogramPlot(name, c, XY, boundsX, boundsY);
}
public int addHistogramPlot(String name, double[][] XY, double[] boundsX, double[] boundsY) {
return addHistogramPlot(name, getNewColor(), XY, boundsX, boundsY);
}
public int addHistogramPlot(String name, Color c, double[][] XY, double minX, double maxX, int nX, double minY, double maxY, int nY) {
return ((Plot3DCanvas) plotCanvas).addHistogramPlot(name, c, XY, minX, maxX, nX, minY, maxY, nY);
}
public int addHistogramPlot(String name, double[][] XY, double minX, double maxX, int nX, double minY, double maxY, int nY) {
return addHistogramPlot(name, getNewColor(), XY, minX, maxX, nX, minY, maxY, nY);
}
public int addGridPlot(String name, Color c, double[] X, double[] Y, double[][] Z) {
return ((Plot3DCanvas) plotCanvas).addGridPlot(name, c, X, Y, Z);
}
public int addGridPlot(String name, double[] X, double[] Y, double[][] Z) {
return addGridPlot(name, getNewColor(), X, Y, Z);
}
public int addGridPlot(String name, Color c, double[][] XYZMatrix) {
return ((Plot3DCanvas) plotCanvas).addGridPlot(name, c, XYZMatrix);
}
public int addGridPlot(String name, double[][] XYZMatrix) {
return addGridPlot(name, getNewColor(), XYZMatrix);
}
public int addCloudPlot(String name, Color color, double[][] sampleXYZ, int nX, int nY, int nZ) {
return ((Plot3DCanvas) plotCanvas).addCloudPlot(name, color, sampleXYZ, nX, nY, nZ);
}
public int addCloudPlot(String name, double[][] sampleXYZ, int nX, int nY, int nZ) {
return addCloudPlot(name, getNewColor(), sampleXYZ, nX, nY, nZ);
}
@Override
public int addPlot(String type, String name, Color c, double[]... XY) {
if (type.equalsIgnoreCase(SCATTER)) {
return addScatterPlot(name, c, XY);
} else if (type.equalsIgnoreCase(LINE)) {
return addLinePlot(name, c, XY);
} else if (type.equalsIgnoreCase(BAR)) {
return addBarPlot(name, c, XY);
} else if (type.equalsIgnoreCase(HISTOGRAM)) {
return addHistogramPlot(name, c, XY);
} else if (type.equalsIgnoreCase(BOX)) {
return addBoxPlot(name, c, XY);
} else if (type.equalsIgnoreCase(GRID)) {
return addGridPlot(name, c, XY);
} else {
throw new IllegalArgumentException("Plot type is unknown : " + type);
}
}
public void rotate(double theta, double phi) {
((Plot3DCanvas) plotCanvas).rotate(theta, phi);
repaint();
}
}

View file

@ -1,696 +0,0 @@
package org.xbib.graphics.graph.jmathplot.panel;
import org.xbib.graphics.graph.jmathplot.io.files.ASCIIFile;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.frame.LegendPanel;
import org.xbib.graphics.graph.jmathplot.frame.PlotToolBar;
import org.xbib.graphics.graph.jmathplot.Axis;
import org.xbib.graphics.graph.jmathplot.Plotable;
import org.xbib.graphics.graph.jmathplot.Plot;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* BSD License
*
* @author Yann RICHET
*/
public abstract class PlotPanel extends JPanel {
private static final long serialVersionUID = 1L;
public PlotToolBar plotToolBar;
public PlotCanvas plotCanvas;
public LegendPanel plotLegend;
public final static String EAST = BorderLayout.EAST;
public final static String SOUTH = BorderLayout.SOUTH;
public final static String NORTH = BorderLayout.NORTH;
public final static String WEST = BorderLayout.WEST;
public final static String INVISIBLE = "INVISIBLE";
public final static String SCATTER = "SCATTER";
public final static String LINE = "LINE";
public final static String BAR = "BAR";
public final static String HISTOGRAM = "HISTOGRAM";
public final static String BOX = "BOX";
public final static String STAIRCASE = "STAIRCASE";
public final static String GRID = "GRID";
public final static Color[] COLORLIST = {Color.BLUE, Color.RED, Color.GREEN, Color.YELLOW, Color.ORANGE, Color.PINK, Color.CYAN, Color.MAGENTA};
private Font font = new Font("Arial", Font.PLAIN, 10);
public PlotPanel(PlotCanvas _canvas, String legendOrientation) {
plotCanvas = _canvas;
setBackground(Color.WHITE);
setLayout(new BorderLayout());
addPlotToolBar(NORTH);
addLegend(legendOrientation);
add(plotCanvas, BorderLayout.CENTER);
}
public PlotPanel(PlotCanvas _canvas) {
this(_canvas, INVISIBLE);
}
/**
* Defines where the legend of the plot should be added to the plot
* panel.
*
* @param location Location where should be put the legend (String).
* location can have the following values (case insensitive): EAST,
* SOUTH, WEST, NORTH, INVISIBLE (legend will be hidden in this case).
* Any other value will be ignored and an error message will be sent to
* the error output.
*/
public void addLegend(String location) {
if (location.equalsIgnoreCase(EAST)) {
plotLegend = new LegendPanel(this, LegendPanel.VERTICAL);
add(plotLegend, EAST);
} else if (location.equalsIgnoreCase(SOUTH)) {
plotLegend = new LegendPanel(this, LegendPanel.HORIZONTAL);
add(plotLegend, SOUTH);
} else if (location.equalsIgnoreCase(WEST)) {
plotLegend = new LegendPanel(this, LegendPanel.VERTICAL);
add(plotLegend, WEST);
} else if (location.equalsIgnoreCase(NORTH)) {
plotLegend = new LegendPanel(this, LegendPanel.HORIZONTAL);
add(plotLegend, NORTH);
} else if (location.equalsIgnoreCase(INVISIBLE)) {
plotLegend = new LegendPanel(this, LegendPanel.INVISIBLE);
// add(legends, BorderLayout.NORTH);
} else {
System.err.println("Orientation " + location + " is unknown.");
}
}
/**
* Removes the current legend from the plot panel.
*/
public void removeLegend() {
remove(plotLegend);
}
/**
* Moves the legend to the specified location.
*
* @param location Location where should be put the legend (String).
* location can have the following values (case insensitive): EAST,
* SOUTH, WEST, NORTH, INVISIBLE (legend will be hidden in this case).
* Any other value will be ignored and an error message will be sent to
* the error output.
*/
public void setLegendOrientation(String location) {
removeLegend();
addLegend(location);
}
/**
* Adds a new plot toolbar to the specified location. The previous toolbar
* is deleted.
*
* @param location Location where should be put the toolbar (String).
* location can have the following values (case insensitive): EAST,
* SOUTH, WEST, NORTH.
* Any other value will be ignored and an error message will be sent to
* the error output.
*/
public void addPlotToolBar(String location) {
if (location.equalsIgnoreCase(EAST)) {
removePlotToolBar();
plotToolBar = new PlotToolBar(this);
plotToolBar.setFloatable(false);
add(plotToolBar, EAST);
} else if (location.equalsIgnoreCase(SOUTH)) {
removePlotToolBar();
plotToolBar = new PlotToolBar(this);
plotToolBar.setFloatable(false);
add(plotToolBar, SOUTH);
} else if (location.equalsIgnoreCase(WEST)) {
removePlotToolBar();
plotToolBar = new PlotToolBar(this);
plotToolBar.setFloatable(false);
add(plotToolBar, WEST);
} else if (location.equalsIgnoreCase(NORTH)) {
removePlotToolBar();
plotToolBar = new PlotToolBar(this);
plotToolBar.setFloatable(false);
add(plotToolBar, NORTH);
}
}
/**
* Removes the plot toolbar from the panel.
*/
public void removePlotToolBar() {
if (plotToolBar == null) {
return;
}
remove(plotToolBar);
}
/**
* Moves the plot toolbar to the specified location.
*
* @param location Location where should be put the toolbar (String).
* location can have the following values (case insensitive): EAST,
* SOUTH, WEST, NORTH.
* Any other value will be ignored and an error message will be sent to
* the error output.
*/
public void setPlotToolBarOrientation(String location) {
addPlotToolBar(location);
}
public PlotToolBar getPlotToolBar() {
return plotToolBar;
}
public void setAdjustBounds(boolean adjust) {
plotCanvas.setAdjustBounds(adjust);
if (plotToolBar != null) {
plotToolBar.ajustBoundsChanged();
}
}
// ///////////////////////////////////////////
// ////// set actions ////////////////////////
// ///////////////////////////////////////////
public void setActionMode(int am) {
plotCanvas.setActionMode(am);
}
public void setNoteCoords(boolean b) {
plotCanvas.setNoteCoords(b);
}
public void setEditable(boolean b) {
plotCanvas.setEditable(b);
}
public boolean getEditable() {
return plotCanvas.getEditable();
}
public void setNotable(boolean b) {
plotCanvas.setNotable(b);
}
public boolean getNotable() {
return plotCanvas.getNotable();
}
// ///////////////////////////////////////////
// ////// set/get elements ///////////////////
// ///////////////////////////////////////////
public LinkedList<Plot> getPlots() {
return plotCanvas.getPlots();
}
public Plot getPlot(int i) {
return plotCanvas.getPlot(i);
}
public int getPlotIndex(Plot p) {
return plotCanvas.getPlotIndex(p);
}
public LinkedList<Plotable> getPlotables() {
return plotCanvas.getPlotables();
}
public Plotable getPlotable(int i) {
return plotCanvas.getPlotable(i);
}
/**
* Return the axis specified in parameter.
*
* @param i Axis number. 0 for X, 1 for Y, 2 for Z.
* @return The axis which number is given in parameter.
*/
public Axis getAxis(int i) {
return plotCanvas.getGrid().getAxis(i);
}
/**
* Returns the scaling for all of the axis of the plot.
*
* @return An array of String
*/
public String[] getAxisScales() {
return plotCanvas.getAxisScales();
}
// TODO axes labels are rested after addPlot... correct this.
/**
* Sets the name of the axis, in this order: X, Y and Z.
*
* @param labels One to three strings containing the name of each axis.
*/
public void setAxisLabels(String... labels) {
plotCanvas.setAxisLabels(labels);
}
/**
* Sets the name of the axis specified in parameter.
*
* @param axe Axis number. 0 for X, 1 for Y, 2 for Z.
* @param label Name to be given.
*/
public void setAxisLabel(int axe, String label) {
plotCanvas.setAxisLabel(axe, label);
}
/**
* Sets the scale of the axes, linear or logarithm, in this order: X,Y,Z.
*
* @param scales Strings containing the scaling, LOG or LIN (case insensitive) for the axes.
*/
public void setAxisScales(String... scales) {
plotCanvas.setAxisScales(scales);
}
/**
* Sets the scaling of the specified axis.
*
* @param axe Axis number. 0 for X, 1 for Y, 2 for Z.
* @param scale String specifying the scaling. LIN or LOG, case insensitive.
*/
public void setAxisScale(int axe, String scale) {
plotCanvas.setAxiScale(axe, scale);
}
/**
* Sets the boundaries for each axis.
*
* @param min Array of at most 3 doubles specifying the min bound of each axis, in this order: X,Y,Z.
* @param max Array of at most 3 doubles specifying the max bound of each axis, in this order: X,Y,Z.
*/
public void setFixedBounds(double[] min, double[] max) {
plotCanvas.setFixedBounds(min, max);
}
/**
* Sets the boundaries for the specified axis.
*
* @param axe Axis number to modify. 0 for X, 1 for Y, 2 for Z.
* @param min Min bound of the axis.
* @param max Max bound of the axis.
*/
public void setFixedBounds(int axe, double min, double max) {
plotCanvas.setFixedBounds(axe, min, max);
}
/**
* Modify bounds of the axes so as to include the point given in parameter.
*
* @param into Coords of the point to include in bounds.
*/
public void includeInBounds(double... into) {
plotCanvas.includeInBounds(into);
}
/**
* Modify axes boundaries so as to include all the points of a given plot.
*
* @param plot Plot to include.
*/
public void includeInBounds(Plot plot) {
plotCanvas.includeInBounds(plot);
}
/**
* Set bounds automatically.
*/
public void setAutoBounds() {
plotCanvas.setAutoBounds();
}
/**
* Set bounds automatically for one axis.
*
* @param axe Number of the axis to modify. 0 for X, 1 for Y, 2 for Z.
*/
public void setAutoBounds(int axe) {
plotCanvas.setAutoBounds(axe);
}
public double[][] mapData(Object[][] stringdata) {
return plotCanvas.mapData(stringdata);
}
public void resetMapData() {
plotCanvas.resetMapData();
}
// ///////////////////////////////////////////
// ////// add/remove elements ////////////////
// ///////////////////////////////////////////
public void addLabel(String text, Color c, double... where) {
plotCanvas.addLabel(text, c, where);
}
public void addBaseLabel(String text, Color c, double... where) {
plotCanvas.addBaseLabel(text, c, where);
}
public void addPlotable(Plotable p) {
plotCanvas.addPlotable(p);
}
public void removePlotable(Plotable p) {
plotCanvas.removePlotable(p);
}
public void removePlotable(int i) {
plotCanvas.removePlotable(i);
}
public void removeAllPlotables() {
plotCanvas.removeAllPlotables();
}
public int addPlot(Plot newPlot) {
return plotCanvas.addPlot(newPlot);
}
protected Color getNewColor() {
return COLORLIST[plotCanvas.plots.size() % COLORLIST.length];
}
public int addPlot(String type, String name, double[]... v) {
return addPlot(type, name, getNewColor(), v);
}
public abstract int addPlot(String type, String name, Color c, double[]... v);
public void setPlot(int I, Plot p) {
plotCanvas.setPlot(I, p);
}
public void changePlotData(int I, double[]... XY) {
plotCanvas.changePlotData(I, XY);
}
public void changePlotName(int I, String name) {
plotCanvas.changePlotName(I, name);
}
public void changePlotColor(int I, Color c) {
plotCanvas.changePlotColor(I, c);
}
public void removePlot(int I) {
plotCanvas.removePlot(I);
}
public void removePlot(Plot p) {
plotCanvas.removePlot(p);
}
public void removeAllPlots() {
plotCanvas.removeAllPlots();
}
public void addVectortoPlot(int numPlot, double[][] v) {
plotCanvas.addVectortoPlot(numPlot, v);
}
public void addQuantiletoPlot(int numPlot, int numAxe, double rate, boolean symetric, double[] q) {
plotCanvas.addQuantiletoPlot(numPlot, numAxe, rate, symetric, q);
}
public void addQuantiletoPlot(int numPlot, int numAxe, double rate, boolean symetric, double q) {
plotCanvas.addQuantiletoPlot(numPlot, numAxe, rate, symetric, q);
}
public void addQuantilestoPlot(int numPlot, int numAxe, double[][] q) {
plotCanvas.addQuantilestoPlot(numPlot, numAxe, q);
}
public void addQuantilestoPlot(int numPlot, int numAxe, double[] q) {
plotCanvas.addQuantilestoPlot(numPlot, numAxe, q);
}
public void addGaussQuantilestoPlot(int numPlot, int numAxe, double[] s) {
plotCanvas.addGaussQuantilestoPlot(numPlot, numAxe, s);
}
public void addGaussQuantilestoPlot(int numPlot, int numAxe, double s) {
plotCanvas.addGaussQuantilestoPlot(numPlot, numAxe, s);
}
public void toGraphicFile(File file) throws IOException {
// otherwise toolbar appears
plotToolBar.setVisible(false);
Image image = createImage(getWidth(), getHeight());
paint(image.getGraphics());
image = new ImageIcon(image).getImage();
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = bufferedImage.createGraphics();
g.drawImage(image, 0, 0, Color.WHITE, null);
g.dispose();
// make it reappear
plotToolBar.setVisible(true);
try {
ImageIO.write(bufferedImage, "PNG", file);
} catch (IllegalArgumentException ex) {
}
}
public static void main(String[] args) {
String man = "Usage: jplot.<sh|bat> <-2D|-3D> [-l <INVISIBLE|NORTH|SOUTH|EAST|WEST>] [options] <ASCII file (n rows, m columns)> [[options] other ASCII file]\n" + "[-l <INVISIBLE|NORTH|SOUTH|EAST|WEST>] giving the legend position\n" + "[options] are:\n" + " -t <SCATTER|LINE|BAR|HISTOGRAM2D(<integer h>)|HISTOGRAM3D(<integer h>,<integer k>)|GRID3D|CLOUD2D(<integer h>,<integer k>)|CLOUD3D(<integer h>,<integer k>,<integer l>)> type of the plot\n" + " SCATTER|LINE|BAR: each line of the ASCII file contains coordinates of one point.\n" + " HISTOGRAM2D(<integer h>): ASCII file contains the 1D sample (i.e. m=1) to split in h slices.\n" + " HISTOGRAM3D(<integer h>,<integer k>): ASCII file contains the 2D sample (i.e. m=2) to split in h*k slices (h slices on X axis and k slices on Y axis).\n" + " GRID3D: ASCII file is a matrix, first row gives n X grid values, first column gives m Y grid values, other values are Z values.\n" + " CLOUD2D(<integer h>,<integer k>): ASCII file contains the 2D sample (i.e. m=2) to split in h*k slices (h slices on X axis and k slices on Y axis), density of cloud corresponds to frequency of X-Y slice in given 2D sample.\n" + " CLOUD3D(<integer h>,<integer k>,<integer l>): ASCII file contains the 3D sample (i.e. m=3) to split in h*k*l slices (h slices on X axis, k slices on Y axis, l slices on Y axis), density of cloud corresponds to frequency of X-Y-Z slice in given 3D sample.\n" + " -n name name of the plot\n" + " -v <ASCII file (n,3|2)> vector data to add to the plot\n" + " -q<X|Y|Z>(<float Q>) <ASCII file (n,1)> Q-quantile to add to the plot on <X|Y|Z> axis. Each line of the given ASCII file contains the value of quantile for probvability Q.\n" + " -qP<X|Y|Z> <ASCII file (n,p)> p-quantiles density to add to the plot on <X|Y|Z> axis. Each line of the given ASCII file contains p values.\n" + " -qN<X|Y|Z> <ASCII file (n,1)> Gaussian density to add to the plot on <X|Y|Z> axis. Each line of the given ASCII file contains a standard deviation.";
if (args.length == 0) {
double[][] data = new double[20][];
for (int i = 0; i < data.length; i++) {
data[i] = new double[]{Math.random(), Math.random(), Math.random()};
}
ASCIIFile.writeDoubleArray(new File("tmp.dat"), data);
args = new String[]{"-3D", "-l", "SOUTH", "-t", "SCATTER", "tmp.dat"};
System.out.println(man);
System.out.println("\nExample: jplot.<sh|bat> " + Array.cat(args));
}
PlotPanel p = null;
if (args[0].equals("-2D")) {
p = new Plot2DPanel();
} else if (args[0].equals("-3D")) {
p = new Plot3DPanel();
} else {
System.out.println(man);
}
try {
String leg = "INVISIBLE";
String type = SCATTER;
String name = "";
double[][] v = null;
double[] qX = null;
double[] qY = null;
double[] qZ = null;
double qXp = 0;
double qYp = 0;
double qZp = 0;
double[][] qPX = null;
double[][] qPY = null;
double[][] qPZ = null;
double[] qNX = null;
double[] qNY = null;
double[] qNZ = null;
for (int i = 1; i < args.length; i++) {
//System.out.println("<" + args[i] + ">");
if (args[i].equals("-l")) {
leg = args[i + 1];
i++;
} else if (args[i].equals("-t")) {
type = args[i + 1];
i++;
} else if (args[i].equals("-n")) {
name = args[i + 1];
i++;
} else if (args[i].equals("-v")) {
v = ASCIIFile.readDoubleArray(new File(args[i + 1]));
i++;
} else if (args[i].startsWith("-qX(")) {
qX = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
qXp = Double.parseDouble(args[i].substring(4, args[i].length() - 1));
i++;
} else if (args[i].startsWith("-qY(")) {
qY = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
qYp = Double.parseDouble(args[i].substring(4, args[i].length() - 1));
i++;
} else if (args[i].startsWith("-qZ(")) {
qZ = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
qZp = Double.parseDouble(args[i].substring(4, args[i].length() - 1));
i++;
} else if (args[i].equals("-qPX")) {
qPX = ASCIIFile.readDoubleArray(new File(args[i + 1]));
i++;
} else if (args[i].equals("-qPY")) {
qPY = ASCIIFile.readDoubleArray(new File(args[i + 1]));
i++;
} else if (args[i].equals("-qPZ")) {
qPZ = ASCIIFile.readDoubleArray(new File(args[i + 1]));
i++;
} else if (args[i].equals("-qNX")) {
qNX = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
i++;
} else if (args[i].equals("-qNY")) {
qNY = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
i++;
} else if (args[i].equals("-qNZ")) {
qNZ = ASCIIFile.readDouble1DArray(new File(args[i + 1]));
i++;
} else {
File input_file = new File(args[i]);
int n = 0;
if (input_file.exists()) {
if (name.length() == 0) {
name = input_file.getName();
}
if (p instanceof Plot2DPanel) {
Plot2DPanel p2d = (Plot2DPanel) p;
if (type.equals("SCATTER")) {
n = p2d.addScatterPlot(name, ASCIIFile.readDoubleArray(input_file));
} else if (type.equals("LINE")) {
n = p2d.addLinePlot(name, ASCIIFile.readDoubleArray(input_file));
} else if (type.equals("BAR")) {
n = p2d.addBarPlot(name, ASCIIFile.readDoubleArray(input_file));
} else if (type.startsWith("HISTOGRAM2D(")) {
n = p2d.addHistogramPlot(name, ASCIIFile.readDouble1DArray(input_file), Integer.parseInt(type.substring(12, type.length() - 1)));
} else if (type.startsWith("CLOUD2D(")) {
n = p2d.addCloudPlot(name, ASCIIFile.readDoubleArray(input_file), Integer.parseInt(type.substring(8, type.indexOf(","))),
Integer.parseInt(type.substring(type.indexOf(",") + 1, type.length() - 1)));
} else {
p2d.addPlot(type, name, ASCIIFile.readDoubleArray(input_file));
}
} else {
Plot3DPanel p3d = (Plot3DPanel) p;
if (type.equals("SCATTER")) {
n = p3d.addScatterPlot(name, ASCIIFile.readDoubleArray(input_file));
} else if (type.equals("LINE")) {
n = p3d.addLinePlot(name, ASCIIFile.readDoubleArray(input_file));
} else if (type.equals("BAR")) {
n = p3d.addBarPlot(name, ASCIIFile.readDoubleArray(input_file));
} else if (type.startsWith("HISTOGRAM3D(")) {
n = p3d.addHistogramPlot(name, ASCIIFile.readDoubleArray(input_file), Integer.parseInt(type.substring(12, type.indexOf(","))),
Integer.parseInt(type.substring(type.indexOf(",") + 1, type.length() - 1)));
} else if (type.equals("GRID3D")) {
n = p3d.addGridPlot(name, ASCIIFile.readDoubleArray(input_file));
} else if (type.startsWith("CLOUD3D(")) {
n = p3d.addCloudPlot(name, ASCIIFile.readDoubleArray(input_file), Integer.parseInt(type.substring(8, type.indexOf(","))),
Integer.parseInt(type.substring(type.indexOf(",") + 1, type.indexOf(",", type.indexOf(",") + 1))), Integer.parseInt(type.substring(type.indexOf(",", type.indexOf(",") + 1) + 1, type.length() - 1)));
} else {
p3d.addPlot(type, name, ASCIIFile.readDoubleArray(input_file));
}
}
if (v != null) {
p.addVectortoPlot(n, v);
}
if (qX != null) {
p.addQuantiletoPlot(n, 0, qXp, false, qX);
}
if (qY != null) {
p.addQuantiletoPlot(n, 1, qYp, false, qY);
}
if (qZ != null) {
p.addQuantiletoPlot(n, 2, qZp, false, qZ);
}
if (qPX != null) {
p.addQuantilestoPlot(n, 0, qPX);
}
if (qPY != null) {
p.addQuantilestoPlot(n, 1, qPY);
}
if (qPZ != null) {
p.addQuantilestoPlot(n, 2, qPZ);
}
if (qNX != null) {
p.addGaussQuantilestoPlot(n, 0, qNX);
}
if (qNY != null) {
p.addGaussQuantilestoPlot(n, 1, qNY);
}
if (qNZ != null) {
p.addGaussQuantilestoPlot(n, 2, qNZ);
}
type = "SCATTER";
leg = "SOUTH";
name = "";
qX = null;
qY = null;
qZ = null;
qXp = 0;
qYp = 0;
qZp = 0;
v = null;
qPX = null;
qPY = null;
qPZ = null;
qNX = null;
qNY = null;
qNZ = null;
} else {
System.out.println("File " + args[i] + " unknown.");
System.out.println(man);
}
}
}
p.setLegendOrientation(leg);
FrameView f = new FrameView(p);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} catch (Exception e) {
e.printStackTrace();
System.err.println("\n" + man);
}
}
/**
* @return the font
*/
public Font getFont() {
return font;
}
/**
* @param font the font to set
*/
public void setFont(Font font) {
this.font = font;
}
}

View file

@ -1,509 +0,0 @@
/*
* Created on 31 mai 2005 by richet
* Changed on 6/13/2014 by Jerry Dietrich
* Contact info ballooninternet@cox.net
*/
package org.xbib.graphics.graph.jmathplot.render;
import static java.lang.Math.PI;
import static java.lang.Math.abs;
import static java.lang.Math.acos;
import static java.lang.Math.atan;
import static java.lang.Math.cos;
import static java.lang.Math.signum;
import static java.lang.Math.sqrt;
import static java.lang.Math.tan;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.utils.FastMath;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Image;
import java.awt.Stroke;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
public abstract class AWTDrawer extends AbstractDrawer {
public Projection projection;
public AWTDrawer(PlotCanvas _canvas) {
super(_canvas);
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#resetProjection()
*/
public void resetBaseProjection() {
projection.initBaseCoordsProjection(true);
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#setColor(java.awt.Color)
*/
public void setColor(Color c) {
comp2D.setColor(c);
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#setGradient
*/
public void setGradient(double[] xy0, Color c0, double[] xy1, Color c1) {
int[] s0 = project(xy0);
int[] s1 = project(xy1);
comp2D.setPaint(new GradientPaint(s0[0], s0[1], c0, s1[0], s1[1], c1));
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#setFont(java.awt.Font)
*/
public void setFont(Font f) {
comp2D.setFont(f);
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#getColor()
*/
public Color getColor() {
return comp2D.getColor();
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#getFont()
*/
public Font getFont() {
return comp2D.getFont();
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#project(double[])
*/
public int[] project(double... pC) {
return projection.screenProjection(pC);
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#projectRatio(double[])
*/
public int[] projectBase(double... rC) {
return projection.screenProjectionBase(rC);
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#translate(int[])
*/
public void translate(int... t) {
projection.translate(t);
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#dilate(int[], double[])
*/
public void dilate(int[] screenOrigin, double[] screenRatio) {
projection.dilate(screenOrigin, screenRatio);
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#drawString(java.lang.String,
* double[], double, double, double)
*/
public void drawText(String label, double... pC) {
int[] sC = projection.screenProjection(pC);
// Corner offset adjustment : Text Offset is used Here
FontRenderContext frc = comp2D.getFontRenderContext();
Font font1 = comp2D.getFont();
int x = sC[0];
int y = sC[1];
double w = font1.getStringBounds(label, frc).getWidth();
double h = font1.getSize2D();
x -= (int) (w * text_Eastoffset);
y += (int) (h * text_Northoffset);
int wc = (int) (w * FastMath.cos(text_angle) + h * FastMath.sin(text_angle));
int hc = (int) (h * FastMath.cos(text_angle) + w * FastMath.sin(text_angle));
if (!comp2D.hitClip(x, y, wc, hc)) {
return;
}
if (text_angle != 0) {
comp2D.rotate(text_angle, x + w / 2, y - h / 2);
}
int tmpY = y;
String[] lines = label.split("\n");
for (int i = 0; i < lines.length; i++) {
comp2D.drawString(lines[i], x, tmpY);
tmpY += h;
}
if (text_angle != 0) {
comp2D.rotate(-text_angle, x + w / 2, y - h / 2);
}
}
public void drawShadowedText(String label, float alpha, double... pC) {
int[] sC = projection.screenProjection(pC);
// Corner offset adjustment : Text Offset is used Here
FontRenderContext frc = comp2D.getFontRenderContext();
Font font1 = comp2D.getFont();
int x = sC[0];
int y = sC[1];
double w = font1.getStringBounds(label, frc).getWidth();
double h = font1.getSize2D();
x -= (int) (w * text_Eastoffset);
y += (int) (h * text_Northoffset);
int wc = (int) (w * FastMath.cos(text_angle) + h * FastMath.sin(text_angle));
int hc = (int) (h * FastMath.cos(text_angle) + w * FastMath.sin(text_angle));
if (!comp2D.hitClip(x, y, wc, hc)) {
return;
}
if (text_angle != 0) {
comp2D.rotate(text_angle, x + w / 2, y - h / 2);
}
Composite cs = comp2D.getComposite();
Color c = comp2D.getColor();
String[] lines = label.split("\n");
for (int i = 0; i < lines.length; i++) {
comp2D.setColor(Color.white);
comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
comp2D.fillRect(x, y - (int) h, (int) w, (int) h);
comp2D.setComposite(cs);
comp2D.setColor(c);
comp2D.drawString(lines[i], x, y);
y += h;
}
if (text_angle != 0) {
comp2D.rotate(-text_angle, x + w / 2, y - h / 2);
}
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#drawStringRatio(java.lang.String,
* double[], double, double, double)
*/
public void drawTextBase(String label, double... rC) {
int[] sC = projection.screenProjectionBase(rC);
// Corner offset adjustment : Text Offset is used Here
FontRenderContext frc = comp2D.getFontRenderContext();
Font font1 = comp2D.getFont();
int x = sC[0];
int y = sC[1];
double w = font1.getStringBounds(label, frc).getWidth();
double h = font1.getSize2D();
x -= (int) (w * text_Eastoffset);
y += (int) (h * text_Northoffset);
int wc = (int) (w * FastMath.cos(text_angle) + h * FastMath.sin(text_angle));
int hc = (int) (h * FastMath.cos(text_angle) + w * FastMath.sin(text_angle));
if (!comp2D.hitClip(x, y, wc, hc)) {
return;
}
if (text_angle != 0) {
comp2D.rotate(text_angle, x + w / 2, y - h / 2);
}
String[] lines = label.split("\n");
for (int i = 0; i < lines.length; i++) {
comp2D.drawString(lines[i], x, y);
y += h;
}
//comp2D.drawString(label, x, y);
if (text_angle != 0) {
comp2D.rotate(-text_angle, x + w / 2, y - h / 2);
}
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#drawLineRatio(double[],
* double[])
*/
public void drawLineBase(double[]... rC) {
int[][] sC = new int[rC.length][];
for (int i = 0; i < sC.length; i++) {
sC[i] = projection.screenProjectionBase(rC[i]);
}
drawLine(sC);
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#drawLine(double[], double[])
*/
public void drawLine(double[]... pC) {
int[][] sC = new int[pC.length][];
for (int i = 0; i < sC.length; i++) {
sC[i] = projection.screenProjection(pC[i]);
}
drawLine(sC);
}
private void drawLine(int[]... c) {
int minx = c[0][0], miny = c[0][1], maxx = c[0][0] + 1, maxy = c[0][1] + 1;
int[] x = new int[c.length];
for (int i = 0; i < c.length; i++) {
x[i] = c[i][0];
minx = FastMath.min(minx, x[i]);
maxx = FastMath.max(maxx, x[i]);
}
int[] y = new int[c.length];
for (int i = 0; i < c.length; i++) {
y[i] = c[i][1];
miny = FastMath.min(miny, y[i]);
maxy = FastMath.max(maxy, y[i]);
}
if (comp2D.hitClip(minx, miny, maxx - minx, maxy - miny)) {
Stroke s = null;
switch (line_type) {
case CONTINOUS_LINE:
s = new BasicStroke(line_width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);
break;
case DOTTED_LINE:
s = new BasicStroke(line_width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1f, new float[]{2f}, 0f);
break;
}
comp2D.setStroke(s);
comp2D.drawPolyline(x, y, c.length);
}
}
public void drawRoundDot(double... pC) {
int[] sC = projection.screenProjection(pC);
comp2D.fillOval(sC[0] - dot_radius, sC[1] - dot_radius, 2 * dot_radius, 2 * dot_radius);
}
public void drawCrossDot(double... pC) {
int[] sC = projection.screenProjection(pC);
comp2D.drawLine(sC[0] - dot_radius, sC[1] - dot_radius, sC[0] + dot_radius, sC[1] + dot_radius);
comp2D.drawLine(sC[0] + dot_radius, sC[1] - dot_radius, sC[0] - dot_radius, sC[1] + dot_radius);
}
public void drawPatternDot(double... pC) {
int[] sC = projection.screenProjection(pC);
int yoffset = (int) FastMath.ceil(dot_pattern.length / 2.0);
int xoffset = (int) FastMath.ceil(dot_pattern[0].length / 2.0);
for (int i = 0; i < dot_pattern.length; i++) {
for (int j = 0; j < dot_pattern[i].length; j++) {
if (dot_pattern[i][j]) // comp2D.setColor(new Color(getColor())
{
//System.err.println("comp2D.fillRect");
comp2D.fillRect(sC[0] - xoffset + j, sC[1] - yoffset + i, 1, 1);
}
}
}
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#drawPloygon(double[][])
*/
public void drawPolygon(double[]... pC) {
int[][] c = new int[pC.length][2];
for (int i = 0; i < pC.length; i++) {
c[i] = projection.screenProjection(pC[i]);
}
int minx = c[0][0], miny = c[0][1], maxx = c[0][0] + 1, maxy = c[0][1] + 1;
int[] x = new int[c.length];
for (int i = 0; i < c.length; i++) {
x[i] = c[i][0];
minx = FastMath.min(minx, x[i]);
maxx = FastMath.max(maxx, x[i]);
}
int[] y = new int[c.length];
for (int i = 0; i < c.length; i++) {
y[i] = c[i][1];
miny = FastMath.min(miny, y[i]);
maxy = FastMath.max(maxy, y[i]);
}
if (comp2D.hitClip(minx, miny, maxx - minx, maxy - miny)) {
comp2D.drawPolygon(x, y, c.length);
}
}
/*
* (non-Javadoc)
*
* @see org.math.plot.render.AbstractDrawer#fillPloygon(double[][])
*/
public void fillPolygon(float alpha, double[]... pC) {
int[][] c = new int[pC.length][2];
for (int i = 0; i < pC.length; i++) {
c[i] = projection.screenProjection(pC[i]);
}
int minx = c[0][0], miny = c[0][1], maxx = c[0][0] + 1, maxy = c[0][1] + 1;
int[] x = new int[c.length];
for (int i = 0; i < c.length; i++) {
x[i] = c[i][0];
minx = FastMath.min(minx, x[i]);
maxx = FastMath.max(maxx, x[i]);
}
int[] y = new int[c.length];
for (int i = 0; i < c.length; i++) {
y[i] = c[i][1];
miny = FastMath.min(miny, y[i]);
maxy = FastMath.max(maxy, y[i]);
}
if (comp2D.hitClip(minx, miny, maxx - minx, maxy - miny)) {
Composite cs = comp2D.getComposite();
comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
comp2D.fillPolygon(x, y, c.length);
comp2D.setComposite(cs);
}
}
public void drawImage(Image img, float alpha, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) {
Composite cs = comp2D.getComposite();
comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
AffineTransform t = getAffineTransform(img.getWidth(canvas), img.getHeight(canvas), _xyzSW, _xyzSE, _xyzNW);
if (t != null) {
comp2D.drawImage(img, t, canvas);
}
comp2D.setComposite(cs);
}
/*public void drawShape(Shape shape, float alpha, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) {
AffineTransform t = getAffineTransform(shape.getBounds().width,shape.getBounds().height, _xyzSW, _xyzSE, _xyzNW);
Shape t_shape = t.createTransformedShape(shape);
Composite cs = comp2D.getComposite();
comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
comp2D.draw(t_shape);
comp2D.setComposite(cs);
}*/
static boolean isDiff(double[] x, int[] y) {
return abs(x[0] - y[0]) > 1 || abs(x[1] - y[1]) > 1;
}
static double sign(double x) {
if (x != 0) {
return signum(x);
} else {
return 1.0;
}
}
static double sqr(double x) {
return x * x;
}
public AffineTransform getAffineTransform(int width, int height, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) {
int[] cornerNW = projection.screenProjection(_xyzNW);
int[] cornerSE = projection.screenProjection(_xyzSE);
int[] cornerSW = projection.screenProjection(_xyzSW);
double[] vectWE = {(double) cornerSE[0] - (double) cornerSW[0], (double) cornerSE[1] - (double) cornerSW[1]};
double normvectWE = sqrt(sqr(vectWE[0]) + sqr(vectWE[1]));
double[] vectSN = {(double) cornerNW[0] - (double) cornerSW[0], (double) cornerNW[1] - (double) cornerSW[1]};
double normvectSN = sqrt(sqr(vectSN[0]) + sqr(vectSN[1]));
double angleSW = acos((vectWE[0] * vectSN[0] + vectWE[1] * vectSN[1]) / (normvectWE * normvectSN));
if (angleSW == 0.0) {
return null;
}
AffineTransform t = new AffineTransform();
t.translate(cornerNW[0], cornerNW[1]);
t.scale(sign(vectWE[0]), -sign(vectSN[1]));
t.rotate(-atan(vectSN[0] / vectSN[1]));
t.shear(0, 1 / tan(PI - angleSW));
t.scale(normvectWE * cos(angleSW - PI / 2) / (double) width, normvectSN / (double) height);
double[] _cornerSE_tr = new double[2];
double[] _cornerSE = {width, height};
t.transform(_cornerSE, 0, _cornerSE_tr, 0, 1);
if (isDiff(_cornerSE_tr, cornerSE)) {
double[] vectSE_NW_1 = {(double) cornerNW[0] - (double) cornerSE[0], (double) cornerNW[1] - (double) cornerSE[1]};
double[] vectSE_NW_2 = {(double) cornerNW[0] - _cornerSE_tr[0], (double) cornerNW[1] - _cornerSE_tr[1]};
double normvect_1 = sqrt(sqr(vectSE_NW_1[0]) + sqr(vectSE_NW_1[1]));
double normvect_2 = sqrt(sqr(vectSE_NW_1[0]) + sqr(vectSE_NW_1[1]));
double cos_angle = (((vectSE_NW_1[0] * vectSE_NW_2[0] + vectSE_NW_1[1] * vectSE_NW_2[1]) / (normvect_1 * normvect_2)));
double vect = (vectSE_NW_1[0] * vectSE_NW_2[1] - vectSE_NW_1[1] * vectSE_NW_2[0]);
AffineTransform t2 = new AffineTransform();
if (vect < 0) {
t2.rotate(acos(cos_angle), cornerNW[0], cornerNW[1]);
} else {
t2.rotate(-acos(cos_angle), cornerNW[0], cornerNW[1]);
}
t.preConcatenate(t2);
}
// TODO patch for many cases...
/*double[] _cornerSW_tr = new double[2];
double[] _cornerSW = { 0, img.getHeight(canvas) };
t.transform(_cornerSW, 0, _cornerSW_tr, 0, 1);
if (isDiff(_cornerSW_tr, cornerSW)) {
double[] vectSW_NW_1 = { (double) cornerNW[0] - (double) cornerSW[0], (double) cornerNW[1] - (double) cornerSW[1] };
double[] vectSW_NW_2 = { (double) cornerNW[0] - (double) _cornerSW_tr[0], (double) cornerNW[1] - (double) _cornerSW_tr[1] };
double normvect_1 = sqrt(sqr(vectSW_NW_1[0]) + sqr(vectSW_NW_1[1]));
double normvect_2 = sqrt(sqr(vectSW_NW_1[0]) + sqr(vectSW_NW_1[1]));
double cos_angle = (((vectSW_NW_1[0] * vectSW_NW_2[0] + vectSW_NW_1[1] * vectSW_NW_2[1]) / (normvect_1 * normvect_2)));
double vect = (vectSW_NW_1[0] * vectSW_NW_2[1] - vectSW_NW_1[1] * vectSW_NW_2[0]);
System.out.println(cos_angle + " " + vect + " -> " + toDegrees(acos(cos_angle)));
//System.out.println(" "+vectSE_NW_1[0]+","+vectSE_NW_1[1]+" "+vectSE_NW_2[0]+","+vectSE_NW_2[1]);
AffineTransform t2 = new AffineTransform();
if (vect > 0)
t2.rotate(acos(cos_angle), cornerNW[0], cornerNW[1]);
else
t2.rotate(-acos(cos_angle), cornerNW[0], cornerNW[1]);
t.preConcatenate(t2);
}*/
return t;
}
}

View file

@ -1,28 +0,0 @@
package org.xbib.graphics.graph.jmathplot.render;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
public class AWTDrawer2D extends AWTDrawer {
public AWTDrawer2D(PlotCanvas _canvas) {
super(_canvas);
projection = new Projection2D(this);
}
/*// More efficient method for orthogonal display of images
public void drawImage(Image img,float alpha, double[] _xyzSW, double[] _xyzSE,double[] _xyzNW) {
int[] cornerNW = projection.screenProjection(_xyzNW);
int[] cornerSE = projection.screenProjection(_xyzSE);
int[] cornerSW = projection.screenProjection(_xyzSW);
AffineTransform transform = new AffineTransform();
transform.translate(cornerNW[0],cornerNW[1]);
transform.scale((-cornerSW[0]+cornerSE[0])/(double)img.getWidth(canvas),(-cornerNW[1]+cornerSW[1])/(double)img.getHeight(canvas));
Composite cs = comp2D.getComposite();
comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha));
comp2D.drawImage(img, transform,canvas);
comp2D.setComposite(cs);
}*/
}

View file

@ -1,27 +0,0 @@
package org.xbib.graphics.graph.jmathplot.render;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
public class AWTDrawer3D extends AWTDrawer {
public AWTDrawer3D(PlotCanvas _canvas) {
super(_canvas);
projection = new Projection3D(this);
}
public void rotate(int[] t, int[] panelSize) {
((Projection3D) projection).rotate(t, panelSize);
}
public void dilate(int[] screenOrigin, double[] screenRatio) {
super.dilate(screenOrigin, screenRatio);
((Projection3D) projection).updateCoordsCenterScreen();
canvas.repaint();
}
public void translate(int... t) {
super.translate(t);
((Projection3D) projection).updateCoordsCenterScreen();
canvas.repaint();
}
}

View file

@ -1,252 +0,0 @@
package org.xbib.graphics.graph.jmathplot.render;
import org.xbib.graphics.graph.jmathplot.canvas.PlotCanvas;
import org.xbib.graphics.graph.jmathplot.utils.Array;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
public abstract class AbstractDrawer {
public PlotCanvas canvas;
protected Graphics2D comp2D;
public final static int ROUND_DOT = 1;
public final static int CROSS_DOT = 2;
public final static int PATTERN_DOT = 0;
public final static int CONTINOUS_LINE = 1;
public final static int DOTTED_LINE = 2;
public final static int DEFAULT_DOT_RADIUS = 2;
public final static int DEFAULT_LINE_WIDTH = 1;
public final static boolean[][] DOT_TRIANGLE_PATTERN = stringToPattern("_", "___#___", "__#_#__", "__#_#__", "_#___#_", "_#___#_", "#######");
public final static boolean[][] DOT_SQUARE_PATTERN = stringToPattern("_", "######", "#____#", "#____#", "#____#", "#____#", "######");
public final static Font DEFAULT_FONT = new Font("Arial", Font.PLAIN, 10);
public final static Color DEFAULT_COLOR = Color.BLACK;
protected Font font = DEFAULT_FONT;
protected double text_Eastoffset, text_Northoffset;
protected double text_angle;
protected Color color = DEFAULT_COLOR;
protected double[] base_offset;
protected int[] screen_offset;
//protected double alpha;
protected int dot_type = ROUND_DOT;
protected int dot_radius = DEFAULT_DOT_RADIUS;
protected boolean[][] dot_pattern = DOT_TRIANGLE_PATTERN;
protected int line_type = CONTINOUS_LINE;
protected int line_width = DEFAULT_LINE_WIDTH;
//protected boolean[][] line_pattern = DOT_TRIANGLE_PATTERN;
public AbstractDrawer(PlotCanvas _canvas) {
canvas = _canvas;
}
/**
* Method used to initialize drawer to DEFAULT values
*/
public void initGraphics(Graphics2D _comp2D) {
comp2D = _comp2D;
comp2D.setPaintMode();
}
public Graphics2D getGraphics2D() {
return comp2D;
}
/**
* Method used to reinitialize the plot when the base has changed (bounds or
* scale)
*/
public abstract void resetBaseProjection();
public void setColor(Color c) {
color = c;
}
public abstract void setGradient(double[] xy0, Color c0, double[] xy1, Color c1);
public void resetGradient() {
comp2D.setPaint(color);
}
public void setFont(Font f) {
font = f;
}
public void setTextOffset(double _cornerEast, double _cornerNorth) {
text_Eastoffset = _cornerEast;
text_Northoffset = _cornerNorth;
}
public void setTextAngle(double _angle) {
text_angle = _angle;
}
public void setDotType(int _dot_type) {
dot_type = _dot_type;
}
public void setDotRadius(int _dot_radius) {
dot_radius = _dot_radius;
}
public void setDotPattern(boolean[][] _dot_pattern) {
dot_pattern = _dot_pattern;
}
public void setLineType(int _line_type) {
line_type = _line_type;
}
public void setLineWidth(int _line_width) {
line_width = _line_width;
}
public int getLineWidth() {
return line_width;
}
public void setBaseOffset(double... _boffset) {
base_offset = _boffset;
}
public void setScreenOffset(int... _soffset) {
screen_offset = _soffset;
}
/*public void setAlpha(double _alpha) {
alpha = _alpha;
}*/
public Color getColor() {
return color;
}
public Font getFont() {
return font;
}
public double[] getTextOffset() {
return new double[]{text_Eastoffset, text_Northoffset};
}
public double getTextAngle() {
return text_angle;
}
public int getDotType() {
return dot_type;
}
public int getDotRadius() {
return dot_radius;
}
public boolean[][] getDotPattern() {
return dot_pattern;
}
public double[] getBaseOffset() {
return base_offset;
}
public int[] getScreenOffset() {
return screen_offset;
}
/**
* Returns the screen coordinates coresponding to plot coordinates Used to
* test if mouse is pointing on a plot.
*
* @param pC plot ccordinates to project in screen
* @return screen coordinates
*/
public abstract int[] project(double... pC);
/**
* Returns the screen coordinates coresponding to plot coordinates Used to
* test if mouse is pointing on a plot.
*
* @param rC plot ccordinates to project in screen
* @return screen coordinates
*/
public abstract int[] projectBase(double... rC);
/**
* Plot ActionMode : translation of the plot
*
* @param t mouse translation in pixels
*/
public abstract void translate(int... t);
/**
* Plot ActionMode : dilatation of the plot
*
* @param screenOrigin mouse initial position
* @param screenRatio mouse final position relative to plot panel size
*/
public abstract void dilate(int[] screenOrigin, double[] screenRatio);
public void drawCoordinate(double... pC) {
for (int i = 0; i < canvas.base.dimension; i++) {
double[] axeprojection = Array.copy(pC);
axeprojection[i] = canvas.base.baseCoords[0][i];
drawLine(pC, axeprojection);
}
setTextAngle(0);
setTextOffset(0, 0);
//drawText(Label.coordToString(pC), pC);
}
public abstract void drawText(String label, double... pC);
public abstract void drawShadowedText(String label, float alpha, double... pC);
public abstract void drawTextBase(String label, double... rC);
public abstract void drawLineBase(double[]... rC);
public abstract void drawLine(double[]... pC);
public void drawDot(double... pC) {
switch (dot_type) {
case ROUND_DOT:
drawRoundDot(pC);
break;
case CROSS_DOT:
drawCrossDot(pC);
break;
case PATTERN_DOT:
drawPatternDot(pC);
break;
}
}
public abstract void drawRoundDot(double... pC);
public abstract void drawCrossDot(double... pC);
public abstract void drawPatternDot(double... pC);
public abstract void drawPolygon(double[]... pC);
public abstract void fillPolygon(float alpha, double[]... pC);
public abstract void drawImage(Image img, float alpha, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW);
// needs to be discussed... Maybe a geometric addon should be more interesting...
//public abstract void drawShape(Shape shape, float alpha,double[] _xyzSW, double[] _xyzSE,double[] _xyzNW);
public static boolean[][] stringToPattern(String empty, String... c) {
boolean[][] p = new boolean[c.length][];
for (int i = 0; i < p.length; i++) {
p[i] = stringToPattern(empty, c[i]);
}
return p;
}
public static boolean[] stringToPattern(String empty, String c) {
boolean[] p = new boolean[c.length()];
for (int i = 0; i < p.length; i++) {
p[i] = !(c.substring(i, i + 1).equals(empty));
}
return p;
}
}

View file

@ -1,152 +0,0 @@
/*
* Created on 31 mai 2005 by richet
*/
package org.xbib.graphics.graph.jmathplot.render;
import org.xbib.graphics.graph.jmathplot.Base;
import org.xbib.graphics.graph.jmathplot.utils.FastMath;
public abstract class Projection {
protected int[][] baseScreenCoords;
public static double DEFAULT_BORDER = 0.15;
protected double borderCoeff = 1 - 2 * DEFAULT_BORDER;
protected AWTDrawer draw;
public Projection(AWTDrawer _draw) {
draw = _draw;
}
public void initBaseCoordsProjection(boolean reset) {
// System.out.println("Projection.initBaseCoordsProjection");
if (baseScreenCoords == null) {
baseScreenCoords = new int[draw.canvas.base.baseCoords.length][2];
}
if (reset) {
totalScreenRatio[0] = 1;
totalScreenRatio[1] = 1;
}
for (int i = 0; i < draw.canvas.base.dimension + 1; i++) {
// Compute the basis extremity coordinates in the normed-centered screen (ie [-0.5,0.5]x[-0.5,0.5] screen)
double[] ratio = new double[]{1, 1};
if (draw.canvas.base.baseCoords != null) {
ratio = baseCoordsScreenProjectionRatio(draw.canvas.base.baseCoords[i]);
}
// Compute the basis extremity coordinates in the true screen (ie in px: [0,400]x[0,400])
baseScreenCoords[i][0] = (int) (draw.canvas.getWidth() * (.5 + (borderCoeff * ratio[0] / totalScreenRatio[0])));
baseScreenCoords[i][1] = (int) (draw.canvas.getHeight() * (.5 - (borderCoeff * ratio[1] / totalScreenRatio[1])));
}
//System.err.println("\n" + Array.toString(baseScreenCoords));
}
// ///////////////////////////////////////////
// ////// move methods ///////////////////////
// ///////////////////////////////////////////
public void translate(int[] screenTranslation) {
for (int i = 0; i < draw.canvas.base.dimension + 1; i++) {
baseScreenCoords[i][0] = baseScreenCoords[i][0] + screenTranslation[0];
baseScreenCoords[i][1] = baseScreenCoords[i][1] + screenTranslation[1];
}
}
// This stores the whole zooming ratio along all dilate calls.
public double[] totalScreenRatio = new double[]{1, 1};
public double[] maxScreenRatio = new double[]{1, 1};
public double[] minScreenRatio = new double[]{.01, .01};
public void dilate(int[] screenOrigin, double[] screenRatio) {
// System.out.println("screenOrigin = "+screenOrigin[0]+" ,
// "+screenOrigin[1]);
// System.out.println("screenRatio = "+screenRatio[0]+" ,
// "+screenRatio[1]);
// Update the zooming ratio history
if (totalScreenRatio[0] * screenRatio[0] > maxScreenRatio[0]) {
screenRatio[0] = maxScreenRatio[0] / totalScreenRatio[0];
}
if (totalScreenRatio[1] * screenRatio[1] > maxScreenRatio[1]) {
screenRatio[1] = maxScreenRatio[1] / totalScreenRatio[1];
}
if (totalScreenRatio[0] * screenRatio[0] < minScreenRatio[0]) {
screenRatio[0] = minScreenRatio[0] / totalScreenRatio[0];
}
if (totalScreenRatio[1] * screenRatio[1] < minScreenRatio[1]) {
screenRatio[1] = minScreenRatio[1] / totalScreenRatio[1];
}
for (int i = 0; i < draw.canvas.base.dimension + 1; i++) {
// System.out.println("baseScreenCoords["+i+"] =
// "+baseScreenCoords[i][0]+" , "+baseScreenCoords[i][1]);
baseScreenCoords[i][0] = (int) ((baseScreenCoords[i][0] - screenOrigin[0]) / screenRatio[0]);
baseScreenCoords[i][1] = (int) ((baseScreenCoords[i][1] - screenOrigin[1]) / screenRatio[1]);
// System.out.println(" -> baseScreenCoords["+i+"] =
// "+baseScreenCoords[i][0]+" , "+baseScreenCoords[i][1]);
}
// Update the zooming ratio history
totalScreenRatio[0] = totalScreenRatio[0] * screenRatio[0];
totalScreenRatio[1] = totalScreenRatio[1] * screenRatio[1];
}
// ///////////////////////////////////////////
// ////// projection method //////////////////
// ///////////////////////////////////////////
public int[] screenProjection(double... pC) {
// System.out.println("Projection.screenProjection("+Array.toString(pC)+")");
double[] sC = new double[2];
sC[0] = baseScreenCoords[0][0];
sC[1] = baseScreenCoords[0][1];
for (int i = 0; i < draw.canvas.base.dimension; i++) {
double normdist_pC_baseCoords = 0;
if (draw.canvas.base.axesScales[i].equalsIgnoreCase(Base.LOGARITHM)) {
normdist_pC_baseCoords = ((FastMath.log(pC[i]) - FastMath.log(draw.canvas.base.baseCoords[0][i])) / (FastMath.log(draw.canvas.base.baseCoords[i + 1][i]) - FastMath.log(draw.canvas.base.baseCoords[0][i])));
} else if (draw.canvas.base.axesScales[i].equalsIgnoreCase(Base.LINEAR) || draw.canvas.base.axesScales[i].equalsIgnoreCase(Base.STRINGS)) {
if (pC != null && draw.canvas.base.baseCoords != null && draw.canvas.base.baseCoords[i + 1] != null) {
normdist_pC_baseCoords = ((pC[i] - draw.canvas.base.baseCoords[0][i]) / (draw.canvas.base.baseCoords[i + 1][i] - draw.canvas.base.baseCoords[0][i]));
}
}
sC[0] += normdist_pC_baseCoords * (baseScreenCoords[i + 1][0] - baseScreenCoords[0][0]);
sC[1] += normdist_pC_baseCoords * (baseScreenCoords[i + 1][1] - baseScreenCoords[0][1]);
}
if (draw.base_offset != null) {
for (int i = 0; i < draw.canvas.base.dimension; i++) {
sC[0] += draw.base_offset[i] * (baseScreenCoords[i + 1][0] - baseScreenCoords[0][0]);
sC[1] += draw.base_offset[i] * (baseScreenCoords[i + 1][1] - baseScreenCoords[0][1]);
}
}
if (draw.screen_offset != null) {
sC[0] += draw.screen_offset[0];
sC[1] += draw.screen_offset[1];
}
return new int[]{(int) sC[0], (int) sC[1]};
}
public int[] screenProjectionBase(double... rC) {
double[] sC = new double[2];
sC[0] = baseScreenCoords[0][0];
sC[1] = baseScreenCoords[0][1];
for (int i = 0; i < draw.canvas.base.dimension; i++) {
sC[0] += rC[i] * (baseScreenCoords[i + 1][0] - baseScreenCoords[0][0]);
sC[1] += rC[i] * (baseScreenCoords[i + 1][1] - baseScreenCoords[0][1]);
}
if (draw.base_offset != null) {
for (int i = 0; i < draw.canvas.base.dimension; i++) {
sC[0] += draw.base_offset[i] * (baseScreenCoords[i + 1][0] - baseScreenCoords[0][0]);
sC[1] += draw.base_offset[i] * (baseScreenCoords[i + 1][1] - baseScreenCoords[0][1]);
}
}
if (draw.screen_offset != null) {
sC[0] += draw.screen_offset[0];
sC[1] += draw.screen_offset[1];
}
return new int[]{(int) sC[0], (int) sC[1]};
}
protected abstract double[] baseCoordsScreenProjectionRatio(double[] xyz);
}

View file

@ -1,23 +0,0 @@
package org.xbib.graphics.graph.jmathplot.render;
/**
* BSD License
*
* @author Yann RICHET
*/
public class Projection2D extends Projection {
public Projection2D(AWTDrawer _draw) {
super(_draw);
initBaseCoordsProjection(true);
}
protected double[] baseCoordsScreenProjectionRatio(double[] xy) {
double[] sC = new double[2];
sC[0] = -0.5 + (xy[0] - draw.canvas.base.roundXmin[0]) / (draw.canvas.base.roundXmax[0] - draw.canvas.base.roundXmin[0]);
sC[1] = -0.5 + (xy[1] - draw.canvas.base.roundXmin[1]) / (draw.canvas.base.roundXmax[1] - draw.canvas.base.roundXmin[1]);
// System.out.println("(" + xy[0] +"," + xy[1] + ") -> (" + sC[0] + ","
// + sC[1] + ")");
return sC;
}
}

View file

@ -1,141 +0,0 @@
package org.xbib.graphics.graph.jmathplot.render;
import org.xbib.graphics.graph.jmathplot.utils.FastMath;
/**
* BSD License
*
* @author Yann RICHET
*/
public class Projection3D extends Projection {
public double theta;
public double phi;
// protected boolean useRoundTrigonometry = false;
public Projection3D(AWTDrawer _draw) {
super(_draw);
theta(Math.PI / 4);
phi(Math.PI / 4);
initBaseCoordsProjection(true);
}
public double factor = 1.4;
public double x0, y0, z0;
public double cos_phi, sin_phi, tan_phi, cos_theta, sin_theta, tan_theta;
static double pi = Math.PI;
private void theta(double theta) {
if (theta == this.theta) {
//System.err.println("o");
return;
}
this.theta = theta;
cos_theta = cos(theta);
sin_theta = sin(theta);
tan_theta = tan(theta);
}
private void phi(double phi) {
if (phi == this.phi) {
//System.err.println(".");
return;
}
this.phi = phi;
cos_phi = cos(phi);
sin_phi = sin(phi);
tan_phi = tan(phi);
}
public void initBaseCoordsProjection(boolean reset) {
if (reset) {
x0 = (draw.canvas.base.roundXmax[0] + draw.canvas.base.roundXmin[0]) / 2;
y0 = (draw.canvas.base.roundXmax[1] + draw.canvas.base.roundXmin[1]) / 2;
z0 = (draw.canvas.base.roundXmax[2] + draw.canvas.base.roundXmin[2]) / 2;
}
super.initBaseCoordsProjection(reset);
}
// search for (x0,y0,z0) , matching center of the screen [.5,.5] and closest to the center (.5,.5,.5) of the plot
protected void updateCoordsCenterScreen() {
double dx0 = (draw.canvas.getWidth() * .5 - baseScreenCoords[0][0]) / (baseScreenCoords[1][0] - baseScreenCoords[0][0]);
double dy0 = (draw.canvas.getWidth() * .5 - baseScreenCoords[0][0]) / (baseScreenCoords[2][0] - baseScreenCoords[0][0]);
double dz0 = (draw.canvas.getHeight() * .5 - baseScreenCoords[0][1]) / (baseScreenCoords[3][1] - baseScreenCoords[0][1]);
double dx, dy, dz = 0;
if ((theta - pi / 4) % pi > pi / 2) {
dx = (.5 * (sin_theta + cos_theta) - tan_theta * dy0) / (sin_theta * sin_theta + cos_theta);
dy = tan_theta * dx + dy0;
} else {
dy = (.5 * (sin_theta + cos_theta) - cos_theta * dx0) / (cos_theta / tan_theta + sin_theta);
dx = 1 / tan_theta * dy + dx0;
}
dz = dz0 + .5 * tan_phi;
// uuuhhh :) I've always dreamed to speak perl...
dx = (dx < 0 ? 0 : (dx > 1 ? 1 : dx));
dy = (dy < 0 ? 0 : (dy > 1 ? 1 : dy));
dz = (dz < 0 ? 0 : (dz > 1 ? 1 : dz));
x0 = draw.canvas.base.roundXmin[0] + (draw.canvas.base.roundXmax[0] - draw.canvas.base.roundXmin[0]) * dx;
y0 = draw.canvas.base.roundXmin[1] + (draw.canvas.base.roundXmax[1] - draw.canvas.base.roundXmin[1]) * dy;
z0 = draw.canvas.base.roundXmin[2] + (draw.canvas.base.roundXmax[2] - draw.canvas.base.roundXmin[2]) * dz;
//System.err.println("(x0,y0,z0) = " + x0 + " " + y0 + " " + z0);
}
protected double[] baseCoordsScreenProjectionRatio(double[] xyz) {
double normdist_xyz_x0 = ((xyz[0] - x0) / (draw.canvas.base.roundXmax[0] - draw.canvas.base.roundXmin[0]));
double normdist_xyz_y0 = ((xyz[1] - y0) / (draw.canvas.base.roundXmax[1] - draw.canvas.base.roundXmin[1]));
double normdist_xyz_z0 = ((xyz[2] - z0) / (draw.canvas.base.roundXmax[2] - draw.canvas.base.roundXmin[2]));
double[] sC = new double[2];
sC[0] = (cos_theta * normdist_xyz_y0
- sin_theta * normdist_xyz_x0)
/ factor;
sC[1] = (cos_phi * normdist_xyz_z0
- sin_phi * cos_theta * normdist_xyz_x0
- sin_phi * sin_theta * normdist_xyz_y0)
/ factor;
//System.out.println("Theta = " + theta + " Phi = " + phi);
// System.err.println("(" + xyz[0] +"," + xyz[1] +"," + xyz[2] + ") -> (" + sC[0] + "," + sC[1] + ")");
return sC;
}
// TODO test efficiceny of an approximation of cos and sin fuctions.
/*
* private final static double _2PI = 2 * Math.PI;
*
* private final static int N = 100;
*
* private final static double[] COS =
* DoubleArray.f(DoubleArray.increment(N, 0, 2 * Math.PI / (N - 1)), new
* Function() { public double f(double x) { return Math.cos(x); } });
*
* private final static double[] SIN =
* DoubleArray.f(DoubleArray.increment(N, 0, 2 * Math.PI / (N - 1)), new
* Function() { public double f(double x) { return Math.sin(x); } });
*/
private double cos(double x) {
return FastMath.cos(x);
}
private double tan(double x) {
return FastMath.tan(x);
}
private double sin(double x) {
return FastMath.sin(x);
}
public void rotate(double _theta, double _phi) {
theta(_theta);
phi(_phi);
initBaseCoordsProjection(false);
}
public void rotate(int[] screenTranslation, int[] dimension) {
theta(theta - ((double) screenTranslation[0]) / 100);
phi(phi + ((double) screenTranslation[1]) / 100);
initBaseCoordsProjection(false);
}
}

View file

@ -1,622 +0,0 @@
package org.xbib.graphics.graph.jmathplot.utils;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
/**
* BSD License
*
* @author Yann RICHET
*/
public class Array {
public static HashMap<Double, String> reverseStringMap(HashMap<String, Double> map) {
if (map == null) {
return null;
}
HashMap<Double, String> reverseMap = new HashMap<Double, String>();
for (String key : map.keySet()) {
reverseMap.put(map.get(key), key);
}
return reverseMap;
}
private static HashMap<String, Double> mapStringArray(double minvalue, double step, List<String> array) {
if (array == null) {
return null;
}
Collections.sort(array);
HashMap<String, Double> map = new HashMap<String, Double>(array.size());
double v = minvalue;
for (String string : array) {
if (!map.containsKey(string)) {
map.put(string, v);
v += step;
}
}
return map;
}
public static boolean equals(double[] x, double[] y) {
if (x.length != y.length) {
return false;
}
for (int i = 0; i < y.length; i++) {
if (x[i] != y[i]) {
return false;
}
}
return true;
}
public static String toString(HashMap hash) {
StringBuffer sb = new StringBuffer();
for (Object key : hash.keySet()) {
sb.append(key + " > " + hash.get(key) + "\n");
}
return sb.toString();
}
public static boolean isDouble(String s) {
try {
Double.parseDouble(s);
} catch (NumberFormatException ne) {
return false;
}
return true;
}
public static HashMap<String, Double> mapStringArray(List<String> array) {
return mapStringArray(0, 1, array);
}
// Create methods
public static String cat(Object[] array) {
return cat(" ", array);
}
public static String cat(String separator, Object[] array) {
String o = "";
for (int i = 0; i < array.length - 1; i++) {
o += array[i].toString() + separator;
}
o += array[array.length - 1].toString();
return o;
}
public static String cat(String separator, double[] array) {
String o = "";
for (int i = 0; i < array.length - 1; i++) {
o += array[i] + separator;
}
o += array[array.length - 1];
return o;
}
public static String cat(String columnsSeparator, String rowsSeparator, Object[][] array) {
String o = "";
for (int i = 0; i < array.length - 1; i++) {
o += cat(columnsSeparator, array[i]) + rowsSeparator;
}
o += cat(columnsSeparator, array[array.length - 1]);
return o;
}
public static String cat(Object[][] array) {
return cat(" ", "\n", array);
}
/*public static String cat(List<Object> array, String rowsSeparator) {
String o = "";
for (int i = 0; i < array.size() - 1; i++)
o += array.get(i) + rowsSeparator;
o += array.get(array.size() - 1);
return o;
}
public static String cat(List <Object>array) {
return cat(array, " ");
}*/
public static String[] duplicate(int m, String c) {
String[] o = new String[m];
for (int i = 0; i < o.length; i++) {
o[i] = c;
}
return o;
}
public static int[] duplicate(int m, int c) {
int[] o = new int[m];
for (int i = 0; i < o.length; i++) {
o[i] = c;
}
return o;
}
public static double[][] one(int m, int n) {
return one(m, n, 1.0);
}
public static double[][] one(int m, int n, double c) {
double[][] o = new double[m][n];
for (int i = 0; i < o.length; i++) {
for (int j = 0; j < o[i].length; j++) {
o[i][j] = c;
}
}
return o;
}
public static double[] one(int m) {
return one(m, 1.0);
}
public static double[] one(int m, double c) {
double[] o = new double[m];
for (int i = 0; i < o.length; i++) {
o[i] = c;
}
return o;
}
public static double[][] increment(int m, int n, double begin, double pitch) {
double[][] array = new double[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
array[i][j] = begin + i * pitch;
}
}
return array;
}
public static double[] increment(int m, double begin, double pitch) {
double[] array = new double[m];
for (int i = 0; i < m; i++) {
array[i] = begin + i * pitch;
}
return array;
}
// Modify rows & colmumns methods
public static double[] copy(double[] M) {
double[] array = new double[M.length];
System.arraycopy(M, 0, array, 0, M.length);
return array;
}
public static double[][] copy(double[][] M) {
double[][] array = new double[M.length][M[0].length];
for (int i = 0; i < array.length; i++) {
System.arraycopy(M[i], 0, array[i], 0, M[i].length);
}
return array;
}
public static double[][] getSubMatrixRangeCopy(double[][] M, int i1, int i2, int j1, int j2) {
double[][] array = new double[i2 - i1 + 1][j2 - j1 + 1];
for (int i = 0; i < i2 - i1 + 1; i++) {
System.arraycopy(M[i + i1], j1, array[i], 0, j2 - j1 + 1);
}
return array;
}
public static double[][] getColumnsRangeCopy(double[][] M, int j1, int j2) {
double[][] array = new double[M.length][j2 - j1 + 1];
for (int i = 0; i < M.length; i++) {
System.arraycopy(M[i], j1, array[i], 0, j2 - j1 + 1);
}
return array;
}
public static double[][] getColumnsCopy(double[][] M, int... J) {
double[][] array = new double[M.length][J.length];
for (int i = 0; i < M.length; i++) {
for (int j = 0; j < J.length; j++) {
array[i][j] = M[i][J[j]];
}
}
return array;
}
public static double[] getColumnCopy(double[][] M, int j) {
double[] array = new double[M.length];
for (int i = 0; i < M.length; i++) {
array[i] = M[i][j];
}
return array;
}
public static double[] getColumnCopy(double[][][] M, int j, int k) {
double[] array = new double[M.length];
for (int i = 0; i < M.length; i++) {
array[i] = M[i][j][k];
}
return array;
}
public static double[][] getRowsCopy(double[][] M, int... I) {
double[][] array = new double[I.length][M[0].length];
for (int i = 0; i < I.length; i++) {
System.arraycopy(M[I[i]], 0, array[i], 0, M[I[i]].length);
}
return array;
}
public static double[] getRowCopy(double[][] M, int i) {
double[] array = new double[M[0].length];
System.arraycopy(M[i], 0, array, 0, M[i].length);
return array;
}
public static double[][] getRowsRangeCopy(double[][] M, int i1, int i2) {
double[][] array = new double[i2 - i1 + 1][M[0].length];
for (int i = 0; i < i2 - i1 + 1; i++) {
System.arraycopy(M[i + i1], 0, array[i], 0, M[i + i1].length);
}
return array;
}
public static double[] getRangeCopy(double[] M, int j1, int j2) {
double[] array = new double[j2 - j1 + 1];
System.arraycopy(M, j1, array, 0, j2 - j1 + 1);
return array;
}
public static double[] getCopy(double[] M, int... I) {
double[] array = new double[I.length];
for (int i = 0; i < I.length; i++) {
array[i] = M[I[i]];
}
return array;
}
public static int getColumnDimension(double[][] M, int i) {
return M[i].length;
}
public static double[][] mergeRows(double[]... x) {
double[][] array = new double[x.length][];
for (int i = 0; i < array.length; i++) {
array[i] = new double[x[i].length];
System.arraycopy(x[i], 0, array[i], 0, array[i].length);
}
return array;
}
public static double[][] mergeColumns(double[]... x) {
double[][] array = new double[x[0].length][x.length];
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j] = x[j][i];
}
}
return array;
}
public static double[] merge(double[]... x) {
int[] xlength_array = new int[x.length];
xlength_array[0] = x[0].length;
for (int i = 1; i < x.length; i++) {
xlength_array[i] = x[i].length + xlength_array[i - 1];
}
double[] array = new double[xlength_array[x.length - 1]];
System.arraycopy(x[0], 0, array, 0, x[0].length);
for (int i = 1; i < x.length; i++) {
System.arraycopy(x[i], 0, array, xlength_array[i - 1], x[i].length);
}
return array;
}
public static double[][] insertColumns(double[][] x, double[][] y, int J) {
double[][] array = new double[x.length][x[0].length + y[0].length];
for (int i = 0; i < array.length; i++) {
System.arraycopy(x[i], 0, array[i], 0, J);
System.arraycopy(y[i], 0, array[i], J, y[i].length);
System.arraycopy(x[i], J, array[i], J + y[i].length, x[i].length - J);
}
return array;
}
public static double[][] insertColumn(double[][] x, double[] y, int J) {
double[][] array = new double[x.length][x[0].length + 1];
for (int i = 0; i < array.length; i++) {
System.arraycopy(x[i], 0, array[i], 0, J);
array[i][J] = y[i];
System.arraycopy(x[i], J, array[i], J + 1, x[i].length - J);
}
return array;
}
public static double[][] insertRows(double[][] x, double[][] y, int I) {
double[][] array = new double[x.length + y.length][x[0].length];
for (int i = 0; i < I; i++) {
System.arraycopy(x[i], 0, array[i], 0, x[i].length);
}
for (int i = 0; i < y.length; i++) {
System.arraycopy(y[i], 0, array[i + I], 0, y[i].length);
}
for (int i = 0; i < x.length - I; i++) {
System.arraycopy(x[i + I], 0, array[i + I + y.length], 0, x[i].length);
}
return array;
}
public static double[][] insertRow(double[][] x, double[] y, int I) {
double[][] array = new double[x.length + 1][x[0].length];
for (int i = 0; i < I; i++) {
System.arraycopy(x[i], 0, array[i], 0, x[i].length);
}
System.arraycopy(y, 0, array[I], 0, y.length);
for (int i = 0; i < x.length - I; i++) {
System.arraycopy(x[i + I], 0, array[i + I + 1], 0, x[i].length);
}
return array;
}
public static double[] insert(double[] x, int I, double... y) {
double[] array = new double[x.length + y.length];
System.arraycopy(x, 0, array, 0, I);
System.arraycopy(y, 0, array, I, y.length);
System.arraycopy(x, I, array, I + y.length, x.length - I);
return array;
}
public static double[][] deleteColumnsRange(double[][] x, int J1, int J2) {
double[][] array = new double[x.length][x[0].length - (J2 - J1 + 1)];
for (int i = 0; i < array.length; i++) {
System.arraycopy(x[i], 0, array[i], 0, J1);
System.arraycopy(x[i], J2 + 1, array[i], J1, x[i].length - (J2 + 1));
}
return array;
}
public static double[][] deleteColumns(double[][] x, int... J) {
double[][] array = new double[x.length][x[0].length - J.length];
for (int i = 0; i < array.length; i++) {
System.arraycopy(x[i], 0, array[i], 0, J[0]);
for (int j = 0; j < J.length - 1; j++) {
System.arraycopy(x[i], J[j] + 1, array[i], J[j] - j, J[j + 1] - J[j] - 1);
}
System.arraycopy(x[i], J[J.length - 1] + 1, array[i], J[J.length - 1] - J.length + 1, x[i].length - J[J.length - 1] - 1);
}
return array;
}
public static double[][] deleteRowsRange(double[][] x, int I1, int I2) {
double[][] array = new double[x.length - (I2 - I1 + 1)][x[0].length];
for (int i = 0; i < I1; i++) {
System.arraycopy(x[i], 0, array[i], 0, x[i].length);
}
for (int i = 0; i < x.length - I2 - 1; i++) {
System.arraycopy(x[i + I2 + 1], 0, array[i + I1], 0, x[i].length);
}
return array;
}
public static double[][] deleteRows(double[][] x, int... I) {
double[][] array = new double[x.length - I.length][x[0].length];
for (int i = 0; i < I[0]; i++) {
System.arraycopy(x[i], 0, array[i], 0, x[i].length);
}
for (int j = 0; j < I.length - 1; j++) {
for (int i = I[j] + 1; i < I[j + 1]; i++) {
System.arraycopy(x[i], 0, array[i - j], 0, x[i].length);
}
}
for (int i = I[I.length - 1] + 1; i < x.length; i++) {
System.arraycopy(x[i], 0, array[i - I.length], 0, x[i].length);
}
return array;
}
public static double[] deleteRange(double[] x, int J1, int J2) {
double[] array = new double[x.length - (J2 - J1 + 1)];
System.arraycopy(x, 0, array, 0, J1);
System.arraycopy(x, J2 + 1, array, J1, x.length - (J2 + 1));
return array;
}
public static double[] delete(double[] x, int... J) {
double[] array = new double[x.length - J.length];
System.arraycopy(x, 0, array, 0, J[0]);
for (int j = 0; j < J.length - 1; j++) {
System.arraycopy(x, J[j] + 1, array, J[j] - j, J[j + 1] - J[j] - 1);
}
System.arraycopy(x, J[J.length - 1] + 1, array, J[J.length - 1] - J.length + 1, x.length - J[J.length - 1] - 1);
return array;
}
public static double[][] buildXY(double Xmin, double Xmax, double[] Y) {
int n = Y.length;
double[][] XY = new double[n][2];
for (int i = 0; i < n; i++) {
XY[i][0] = Xmin + (Xmax - Xmin) * (double) i / (double) (n - 1);
XY[i][1] = Y[i];
}
return XY;
}
public static double[][] buildXY(double[] X, double[] Y) {
return mergeColumns(X, Y);
}
// min/max methods
public static double[] min(double[][] M) {
double[] min = new double[M[0].length];
for (int j = 0; j < min.length; j++) {
min[j] = M[0][j];
for (int i = 1; i < M.length; i++) {
if (!Double.isNaN(M[i][j])) {
min[j] = FastMath.min(min[j], M[i][j]);
}
}
}
return min;
}
public static int min(int... M) {
int min = M[0];
for (int i = 1; i < M.length; i++) {
min = FastMath.min(min, M[i]);
}
return min;
}
public static int max(int... M) {
int max = M[0];
for (int i = 1; i < M.length; i++) {
max = FastMath.max(max, M[i]);
}
return max;
}
public static double min(double... M) {
double min = M[0];
for (int i = 1; i < M.length; i++) {
if (!Double.isNaN(M[i])) {
min = FastMath.min(min, M[i]);
}
}
return min;
}
public static double[] max(double[][] M) {
double[] max = new double[M[0].length];
for (int j = 0; j < max.length; j++) {
max[j] = M[0][j];
for (int i = 1; i < M.length; i++) {
if (!Double.isNaN(M[i][j])) {
max[j] = FastMath.max(max[j], M[i][j]);
}
}
}
return max;
}
public static double max(double... M) {
double max = M[0];
for (int i = 1; i < M.length; i++) {
if (!Double.isNaN(M[i])) {
max = FastMath.max(max, M[i]);
}
}
return max;
}
public static int[] minIndex(double[][] M) {
int[] minI = new int[M[0].length];
for (int j = 0; j < minI.length; j++) {
minI[j] = 0;
for (int i = 1; i < M.length; i++) {
if (M[i][j] < M[minI[j]][j]) {
minI[j] = i;
}
}
}
return minI;
}
public static int minIndex(double... M) {
int minI = 0;
for (int i = 1; i < M.length; i++) {
if (M[i] < M[minI]) {
minI = i;
}
}
return minI;
}
public static int[] maxIndex(double[][] M) {
int[] maxI = new int[M[0].length];
for (int j = 0; j < maxI.length; j++) {
maxI[j] = 0;
for (int i = 1; i < M.length; i++) {
if (M[i][j] > M[maxI[j]][j]) {
maxI[j] = i;
}
}
}
return maxI;
}
public static int maxIndex(double... M) {
int maxI = 0;
for (int i = 1; i < M.length; i++) {
if (M[i] > M[maxI]) {
maxI = i;
}
}
return maxI;
}
// print methods
public static String toString(double[]... v) {
StringBuffer str = new StringBuffer();
for (int i = 0; i < v.length; i++) {
for (int j = 0; j < v[i].length; j++) {
str.append(v[i][j] + " ");
}
if (i < v.length - 1) {
str.append("\n");
}
}
return str.toString();
}
public static String toString(int[]... v) {
StringBuffer str = new StringBuffer();
for (int i = 0; i < v.length; i++) {
for (int j = 0; j < v[i].length; j++) {
str.append(v[i][j] + " ");
}
if (i < v.length - 1) {
str.append("\n");
}
}
return str.toString();
}
// check methods
public static void throwError(String msg) {
throw new IllegalArgumentException(msg);
}
public static void checkColumnDimension(double[][] M, int n) {
for (int i = 0; i < M.length; i++) {
if (M[i].length != n) {
throwError("row " + i + " have " + M[i].length + " columns instead of " + n + " columns expected.");
}
}
}
public static boolean isColumnDimension(double[][] M, int n) {
for (int i = 0; i < M.length; i++) {
if (M[i].length != n) {
return false;
}
}
return true;
}
public static void checkRowDimension(double[][] M, int m) {
if (M.length != m) {
throwError("columns have " + M.length + " rows instead of " + m + " rows expected.");
}
}
public static boolean isRowDimension(double[][] M, int m) {
return M.length == m;
}
public static void checkLength(double[] M, int n) {
if (M.length != n) {
throwError("row have " + M.length + " elements instead of " + n + " elements expected.");
}
}
public static boolean isLength(double[] M, int n) {
return M.length == n;
}
}

View file

@ -1,195 +0,0 @@
/*
* Created on 21 juil. 2005 by richet
*/
package org.xbib.graphics.graph.jmathplot.utils;
import static org.xbib.graphics.graph.jmathplot.utils.Array.getColumnCopy;
import static org.xbib.graphics.graph.jmathplot.utils.Array.insertColumn;
import static org.xbib.graphics.graph.jmathplot.utils.Array.max;
import static org.xbib.graphics.graph.jmathplot.utils.Array.mergeColumns;
import static org.xbib.graphics.graph.jmathplot.utils.Array.min;
public class Histogram {
// histograms functions
public static double[][] histogram_classes(double[] values, double[] bounds) {
return mergeColumns(centers(bounds), histogram(values, bounds));
}
public static double[][] histogram_classes(double[] values, double min, double max, int n) {
double[] bounds = bounds(values, min, max, n);
return mergeColumns(centers(bounds), histogram(values, bounds));
}
public static double[][] histogram_classes(double[] values, int n) {
double[] bounds = bounds(values, n);
return mergeColumns(centers(bounds), histogram(values, bounds));
}
public static double[] histogram(double[] values, double[] bounds) {
double[] h = new double[bounds.length - 1];
for (int i = 0; i < values.length; i++) {
for (int j = 0; j < h.length; j++) {
if (((bounds[j + 1] - values[i]) * (bounds[j] - values[i]) <= 0) || ((bounds[j] == values[i]))) {
h[j]++;
break;
}
}
}
return h;
}
public static double[] histogram(double[] values, double min, double max, int n) {
double[] bounds = bounds(values, min, max, n);
return histogram(values, bounds);
}
public static double[] histogram(double[] values, int n) {
return histogram(values, n);
}
private static double[] bounds(double[] values, int n) {
double min = min(values);
double max = max(values);
return bounds(values, min, max, n);
}
private static double[] bounds(double[] values, double min, double max, int n) {
double[] bounds = new double[n + 1];
for (int i = 0; i < bounds.length; i++) {
bounds[i] = min + (max - min) * i / (double) n;
}
return bounds;
}
private static double[] centers(double[] bounds) {
double[] center = new double[bounds.length - 1];
for (int i = 0; i < center.length; i++) {
center[i] = (bounds[i] + bounds[i + 1]) / 2;
}
return center;
}
// histograms 2D functions
public static double[][] histogram_classes_2D(double[][] values, double[] boundsX, double[] boundsY) {
return insertColumn(centers_2D(boundsX, boundsY), histogram_2D(values, boundsX, boundsY), 2);
}
public static double[][] histogram_classes_2D(double[][] values, double minX, double maxX, int nX, double minY, double maxY, int nY) {
double[] valuesX = getColumnCopy(values, 0);
double[] valuesY = getColumnCopy(values, 1);
double[] boundsX = bounds(valuesX, minX, maxX, nX);
double[] boundsY = bounds(valuesY, minY, maxY, nY);
return insertColumn(centers_2D(boundsX, boundsY), histogram_2D(values, boundsX, boundsY), 2);
}
public static double[][] histogram_classes_2D(double[][] values, int nX, int nY) {
double[] valuesX = getColumnCopy(values, 0);
double[] valuesY = getColumnCopy(values, 1);
double[] boundsX = bounds(valuesX, nX);
double[] boundsY = bounds(valuesY, nY);
return insertColumn(centers_2D(boundsX, boundsY), histogram_2D(values, boundsX, boundsY), 2);
}
public static double[] histogram_2D(double[][] values, double[] boundsX, double[] boundsY) {
double[] h = new double[(boundsX.length - 1) * (boundsY.length - 1)];
for (int n = 0; n < values.length; n++) {
for (int i = 0; i < boundsX.length - 1; i++) {
for (int j = 0; j < boundsY.length - 1; j++) {
if ((((boundsX[i + 1] - values[n][0]) * (boundsX[i] - values[n][0]) < 0) || ((boundsX[i] == values[n][0])))
&& (((boundsY[j + 1] - values[n][1]) * (boundsY[j] - values[n][1]) < 0) || ((boundsY[j] == values[n][1])))) {
h[index2(i, j, boundsX.length - 1)]++;
}
}
}
}
return h;
}
public static double[] histogram_2D(double[][] values, double minX, double maxX, int nX, double minY, double maxY, int nY) {
double[] valuesX = getColumnCopy(values, 0);
double[] valuesY = getColumnCopy(values, 1);
double[] boundsX = bounds(valuesX, minX, maxX, nX);
double[] boundsY = bounds(valuesY, minY, maxY, nY);
return histogram_2D(values, boundsX, boundsY);
}
public static double[] histogram_2D(double[][] values, int nX, int nY) {
double[] valuesX = getColumnCopy(values, 0);
double[] valuesY = getColumnCopy(values, 1);
double[] boundsX = bounds(valuesX, nX);
double[] boundsY = bounds(valuesY, nY);
return histogram_2D(values, boundsX, boundsY);
}
private static double[][] centers_2D(double[] boundsX, double[] boundsY) {
int nb_centers = (boundsX.length - 1) * (boundsY.length - 1);
double[][] center = new double[nb_centers][2];
for (int i = 0; i < boundsX.length - 1; i++) {
for (int j = 0; j < boundsY.length - 1; j++) {
int k = index2(i, j, boundsX.length - 1);
center[k][0] = (boundsX[i] + boundsX[i + 1]) / 2;
center[k][1] = (boundsY[j] + boundsY[j + 1]) / 2;
}
}
return center;
}
private static int index2(int i, int j, int imax) {
return i + imax * j;
}
// histograms 3D functions
public static double[][] histogram_classes_3D(double[][] values, int nX, int nY, int nZ) {
double[] valuesX = getColumnCopy(values, 0);
double[] valuesY = getColumnCopy(values, 1);
double[] valuesZ = getColumnCopy(values, 2);
double[] boundsX = bounds(valuesX, nX);
double[] boundsY = bounds(valuesY, nY);
double[] boundsZ = bounds(valuesZ, nZ);
return insertColumn(centers_3D(boundsX, boundsY, boundsZ), histogram_3D(values, boundsX, boundsY, boundsZ), 3);
}
public static double[] histogram_3D(double[][] values, double[] boundsX, double[] boundsY, double[] boundsZ) {
double[] h = new double[(boundsX.length - 1) * (boundsY.length - 1) * (boundsZ.length - 1)];
for (int n = 0; n < values.length; n++) {
for (int i = 0; i < boundsX.length - 1; i++) {
for (int j = 0; j < boundsY.length - 1; j++) {
for (int k = 0; k < boundsZ.length - 1; k++) {
if ((((boundsX[i + 1] - values[n][0]) * (boundsX[i] - values[n][0]) < 0) || ((boundsX[i] == values[n][0])))
&& (((boundsY[j + 1] - values[n][1]) * (boundsY[j] - values[n][1]) < 0) || ((boundsY[j] == values[n][1]))) && (((boundsZ[k + 1] - values[n][2]) * (boundsZ[k] - values[n][2]) < 0) || ((boundsZ[k] == values[n][2])))) {
h[index3(i, j, k, boundsX.length - 1, boundsY.length - 1)]++;
}
}
}
}
}
return h;
}
private static double[][] centers_3D(double[] boundsX, double[] boundsY, double[] boundsZ) {
int nb_centers = (boundsX.length - 1) * (boundsY.length - 1) * (boundsZ.length - 1);
double[][] center = new double[nb_centers][3];
for (int i = 0; i < boundsX.length - 1; i++) {
for (int j = 0; j < boundsY.length - 1; j++) {
for (int k = 0; k < boundsZ.length - 1; k++) {
int l = index3(i, j, k, boundsX.length - 1, boundsY.length - 1);
center[l][0] = (boundsX[i] + boundsX[i + 1]) / 2;
center[l][1] = (boundsY[j] + boundsY[j + 1]) / 2;
center[l][2] = (boundsZ[k] + boundsZ[k + 1]) / 2;
}
}
}
return center;
}
private static int index3(int i, int j, int k, int imax, int jmax) {
return i + imax * j + imax * jmax * k;
}
}

View file

@ -1,25 +0,0 @@
package org.xbib.graphics.graph.jmathplot.test;
import org.junit.jupiter.api.Test;
import org.xbib.graphics.graph.jmathplot.panel.FrameView;
import org.xbib.graphics.graph.jmathplot.panel.Plot2DPanel;
import javax.swing.JFrame;
public class QuantileLayerPlotTest {
@Test
public void test() throws InterruptedException {
Plot2DPanel p2 = new Plot2DPanel();
for (int i = 0; i < 1; i++) {
double[][] XYZ = new double[10][2];
for (int j = 0; j < XYZ.length; j++) {
XYZ[j][0] = /*1 + */Math.random();
XYZ[j][1] = /*100 * */Math.random();
}
p2.addScatterPlot("toto" + i, XYZ);
}
p2.addQuantiletoPlot(0, 1, 1.0, true, 0.2);
new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Thread.sleep(10000);
}
}

View file

@ -11,4 +11,3 @@ include 'graphics-pdfbox-layout'
include 'graphics-pdfbox-groovy'
include 'graphics-pdfbox-print'
include 'graphics-graph-gral'
include 'graphics-graph-jmathplot'