Improved the FunctionArea: Now a color can be set directly for a certain plot.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
||||
package eva2.gui;
|
||||
|
||||
/*
|
||||
* Title: EvA2
|
||||
* Description:
|
||||
@@ -13,15 +14,18 @@ package eva2.gui;
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import eva2.tools.chart2d.*;
|
||||
import eva2.tools.chart2d.DArea;
|
||||
import eva2.tools.chart2d.DMeasures;
|
||||
import eva2.tools.chart2d.DPoint;
|
||||
import eva2.tools.chart2d.DPointIcon;
|
||||
import eva2.tools.chart2d.DPointSet;
|
||||
import eva2.tools.math.Mathematics;
|
||||
|
||||
/*==========================================================================*
|
||||
* CLASS DECLARATION
|
||||
*==========================================================================*/
|
||||
@@ -46,6 +50,7 @@ public class GraphPointSet {
|
||||
private int m_CacheSize = 0;
|
||||
private double[] m_cachex;
|
||||
private double[] m_cachey;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -82,20 +87,45 @@ public class GraphPointSet {
|
||||
initGraph(Area);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
private Color indexToColor(int index) {
|
||||
Color c = Color.black;
|
||||
int k = index % 10;
|
||||
switch (k) {
|
||||
case 0: c = Color.black; break;
|
||||
case 1: c = Color.red; break;
|
||||
case 2: c = Color.blue; break;
|
||||
case 3: c = Color.pink; break;
|
||||
case 4: c = Color.green; break;
|
||||
case 5: c = Color.gray; break;
|
||||
case 6: c = Color.magenta; break;
|
||||
case 7: c = Color.cyan; break;
|
||||
case 8: c = Color.orange; break;
|
||||
case 9: c = Color.darkGray; break;
|
||||
case 0:
|
||||
c = Color.black;
|
||||
break;
|
||||
case 1:
|
||||
c = Color.red;
|
||||
break;
|
||||
case 2:
|
||||
c = Color.blue;
|
||||
break;
|
||||
case 3:
|
||||
c = Color.pink;
|
||||
break;
|
||||
case 4:
|
||||
c = Color.green;
|
||||
break;
|
||||
case 5:
|
||||
c = Color.gray;
|
||||
break;
|
||||
case 6:
|
||||
c = Color.magenta;
|
||||
break;
|
||||
case 7:
|
||||
c = Color.cyan;
|
||||
break;
|
||||
case 8:
|
||||
c = Color.orange;
|
||||
break;
|
||||
case 9:
|
||||
c = Color.darkGray;
|
||||
break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
@@ -114,6 +144,8 @@ public class GraphPointSet {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param size
|
||||
* @param GraphLabel
|
||||
*/
|
||||
private GraphPointSet(int size, int GraphLabel) {
|
||||
m_GraphLabel = GraphLabel;
|
||||
@@ -151,43 +183,57 @@ public class GraphPointSet {
|
||||
m_ConnectedPointSet.setColor(m_Color);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DPointSet printPoints() {
|
||||
for (int i = 0; i < m_ConnectedPointSet.getSize(); i++) {
|
||||
DPoint p = m_ConnectedPointSet.getDPoint(i);
|
||||
double x = p.x;
|
||||
double y = p.y;
|
||||
//System.out.println("point "+i+ " x= "+x+"y= "+y);
|
||||
System.out.println("point " + i + " x = " + x + "y = " + y);
|
||||
}
|
||||
return m_ConnectedPointSet.getDPointSet();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Color getColor() {
|
||||
return m_ConnectedPointSet.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param c
|
||||
*/
|
||||
public void setColor(Color c) {
|
||||
m_Color = c;
|
||||
m_ConnectedPointSet.setColor(m_Color);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DPointSet getConnectedPointSet() {
|
||||
return m_ConnectedPointSet.getDPointSet();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DPointSetMultiIcon getReference2ConnectedPointSet() {
|
||||
return m_ConnectedPointSet;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Area
|
||||
*/
|
||||
public void initGraph(DArea Area) {
|
||||
m_Area = Area;
|
||||
@@ -211,20 +257,24 @@ public class GraphPointSet {
|
||||
// public DBorder getDBorder(){ return new DBorder(4, 4, 4, 4); }
|
||||
// };
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p
|
||||
* @return
|
||||
*/
|
||||
public DPoint getNearestDPoint(DPoint p) {
|
||||
return m_ConnectedPointSet.getNearestDPoint(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the PointSet to interupt the connected painting at the
|
||||
* current position.
|
||||
* Causes the PointSet to interupt the connected painting at the current
|
||||
* position.
|
||||
*/
|
||||
public void jump() {
|
||||
m_ConnectedPointSet.jump();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -234,8 +284,11 @@ public class GraphPointSet {
|
||||
// m_PointSet_2.removeAllPoints();
|
||||
// m_PointSet_3.removeAllPoints();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
public void addDPoint(double x, double y) {
|
||||
// System.out.println(" "+x+" "+y);
|
||||
@@ -245,15 +298,16 @@ public class GraphPointSet {
|
||||
}
|
||||
m_ConnectedPointSet.addDPoint(x, y);
|
||||
m_CacheIndex = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
m_cachex[m_CacheIndex] = x;
|
||||
m_cachey[m_CacheIndex] = y;
|
||||
m_CacheIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p
|
||||
*/
|
||||
public void addDPoint(DPoint p) {
|
||||
m_ConnectedPointSet.addDPoint(p);
|
||||
@@ -261,19 +315,24 @@ public class GraphPointSet {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p
|
||||
*/
|
||||
public void setIcon(DPointIcon p) {
|
||||
this.m_Icon = p;
|
||||
this.m_ConnectedPointSet.setIcon(p);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p
|
||||
*/
|
||||
public void setConnectedMode(boolean p) {
|
||||
m_ConnectedPointSet.setConnected(p);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isStatisticsGraph() {
|
||||
return m_isStatisticsGraph;
|
||||
@@ -281,6 +340,7 @@ public class GraphPointSet {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getPointCount() {
|
||||
return m_ConnectedPointSet.getSize();
|
||||
@@ -288,12 +348,15 @@ public class GraphPointSet {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PointSet getPointSet() {
|
||||
return new PointSet(this.m_ConnectedPointSet.getDPointSet());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public void removePoint(DPoint x) {
|
||||
System.out.println("removePoint " + x.x + " " + x.y);
|
||||
@@ -312,17 +375,22 @@ public class GraphPointSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a graph to another one forming a statistics graph if it isnt one already.
|
||||
* Add a graph to another one forming a statistics graph if it isnt one
|
||||
* already.
|
||||
*
|
||||
* @param set
|
||||
* @param measures
|
||||
* @param useForce forces the add even if point counts mismatch, maybe losing some data points
|
||||
* @param useForce
|
||||
* forces the add even if point counts mismatch, maybe losing
|
||||
* some data points
|
||||
*/
|
||||
public void addGraph(GraphPointSet set, DMeasures measures, boolean useForce) {
|
||||
if (set.m_ConnectedPointSet.getSize()!=m_ConnectedPointSet.getSize() &&
|
||||
m_ConnectedPointSet.getSize()!=0 && !useForce) {
|
||||
System.err.println("WARNING addGraph not possible, lost last graph");
|
||||
System.err.println(" m_ConnectedPointSet.getSize() "+ m_ConnectedPointSet.getSize());
|
||||
if (set.m_ConnectedPointSet.getSize() != m_ConnectedPointSet.getSize()
|
||||
&& m_ConnectedPointSet.getSize() != 0 && !useForce) {
|
||||
System.err
|
||||
.println("WARNING addGraph not possible, lost last graph");
|
||||
System.err.println(" m_ConnectedPointSet.getSize() "
|
||||
+ m_ConnectedPointSet.getSize());
|
||||
return;
|
||||
}
|
||||
if (set.getPointSet().getSize() == 0) {
|
||||
@@ -338,23 +406,35 @@ public class GraphPointSet {
|
||||
int[] GraphSize = new int[m_PointSetContainer.size()];
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++) {
|
||||
GraphSize[i] = ((PointSet) m_PointSetContainer.get(i)).getSize();
|
||||
if (GraphSize[i]<=0) System.err.println("Warning: invalid graph size of " + GraphSize[i] + " at " + i + "! (GraphPointSet.addGraph)");
|
||||
if (GraphSize[i] <= 0)
|
||||
System.err.println("Warning: invalid graph size of "
|
||||
+ GraphSize[i] + " at " + i
|
||||
+ "! (GraphPointSet.addGraph)");
|
||||
}
|
||||
if (Mathematics.sum(GraphSize) == 0) {
|
||||
System.err.println("Error: not adding empty graphs... (GraphPointSet.addGraph)");
|
||||
System.err
|
||||
.println("Error: not adding empty graphs... (GraphPointSet.addGraph)");
|
||||
return;
|
||||
}
|
||||
boolean allSetsHaveMorePoints = true;
|
||||
double nextXValue;
|
||||
double[] y = new double[m_PointSetContainer.size()];
|
||||
while ( allSetsHaveMorePoints ) { // Loop over all point sets, add them up and calc. mean
|
||||
// this is a bit more complicated because it is allowed that the point sets are asynchronouos
|
||||
// in the sense that the x values do not have to match - y values for any x value found are averaged
|
||||
// over all points. However curves may look strange if this happens, since they consist of
|
||||
while (allSetsHaveMorePoints) { // Loop over all point sets, add them up
|
||||
// and calc. mean
|
||||
// this is a bit more complicated because it is allowed that the
|
||||
// point sets are asynchronouos
|
||||
// in the sense that the x values do not have to match - y values
|
||||
// for any x value found are averaged
|
||||
// over all points. However curves may look strange if this happens,
|
||||
// since they consist of
|
||||
// heterogenous points.
|
||||
nextXValue = m_PointSetContainer.get(0).m_X[index[0]];
|
||||
// System.out.println("m_PointSetContainer.size()"+m_PointSetContainer.size());
|
||||
for (int i = 1;i<m_PointSetContainer.size();i++) { // search for smalles x value at next index
|
||||
for (int i = 1; i < m_PointSetContainer.size(); i++) { // search for
|
||||
// smalles x
|
||||
// value at
|
||||
// next
|
||||
// index
|
||||
// System.out.println("i="+i);
|
||||
if (nextXValue > m_PointSetContainer.get(i).m_X[index[i]]) {
|
||||
nextXValue = m_PointSetContainer.get(i).m_X[index[i]];
|
||||
@@ -362,18 +442,30 @@ public class GraphPointSet {
|
||||
}
|
||||
// Stelle nextXValue wird gezeichnet. jetzt alle y werte dazu finden
|
||||
int numberofpoints = 0;
|
||||
for (int i = 0;i<m_PointSetContainer.size();i++) { // collect all points at next x-value
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++) { // collect
|
||||
// all
|
||||
// points at
|
||||
// next
|
||||
// x-value
|
||||
if (nextXValue == m_PointSetContainer.get(i).m_X[index[i]]) {
|
||||
y[i] = m_PointSetContainer.get(i).m_Y[index[i]];
|
||||
index[i]++;
|
||||
numberofpoints++;
|
||||
} else y[i]=0;
|
||||
} else
|
||||
y[i] = 0;
|
||||
}
|
||||
double ymean = Mathematics.sum(y) / numberofpoints;
|
||||
// compute median double median = getMedian(y);
|
||||
addDPoint(nextXValue,ymean);// System.out.println("ymean "+ymean+" y.length "+ y.length);
|
||||
//addDPoint(minx,median);// System.out.println("ymean "+ymean+" y.length "+ y.length);
|
||||
for (int i=0;i<m_PointSetContainer.size();i++) { // Stop if one of the point sets has no more points
|
||||
addDPoint(nextXValue, ymean);// System.out.println("ymean "+ymean+" y.length "+
|
||||
// y.length);
|
||||
// addDPoint(minx,median);//
|
||||
// System.out.println("ymean "+ymean+" y.length "+ y.length);
|
||||
for (int i = 0; i < m_PointSetContainer.size(); i++) { // Stop if
|
||||
// one of
|
||||
// the point
|
||||
// sets has
|
||||
// no more
|
||||
// points
|
||||
if (GraphSize[i] <= index[i]) {
|
||||
allSetsHaveMorePoints = false;
|
||||
break;
|
||||
@@ -381,22 +473,15 @@ public class GraphPointSet {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private double getMedian(double[] in) {
|
||||
double[] x = (double[]) in.clone();
|
||||
double ret = 0;
|
||||
Arrays.sort(x);
|
||||
int m = (int)( x.length/2.0);
|
||||
return x[m];
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getGraphLabel() {
|
||||
return m_GraphLabel;
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
@@ -409,8 +494,11 @@ public class GraphPointSet {
|
||||
public String getInfoString() {
|
||||
return m_InfoString;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param x
|
||||
* @param stroke
|
||||
*/
|
||||
public void setInfoString(String x, float stroke) {
|
||||
m_InfoString = x;
|
||||
@@ -422,11 +510,17 @@ public class GraphPointSet {
|
||||
*
|
||||
*/
|
||||
class PointSet implements Serializable {
|
||||
/**
|
||||
* Generated serial version identifier
|
||||
*/
|
||||
private static final long serialVersionUID = -5863595580492128866L;
|
||||
private double[] m_X;
|
||||
private double[] m_Y;
|
||||
private Color m_Color;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pointset
|
||||
*/
|
||||
public PointSet(DPointSet pointset) {
|
||||
m_Color = pointset.getColor();
|
||||
@@ -438,8 +532,10 @@ public class GraphPointSet {
|
||||
m_Y[i] = point.y;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DPointSet getDPointSet() {
|
||||
DPointSet ret = new DPointSet(100);
|
||||
@@ -448,8 +544,10 @@ public class GraphPointSet {
|
||||
ret.addDPoint(m_X[i], m_Y[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getSize() {
|
||||
return m_X.length;
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user