Merging mk branch rev. 528: more generous log scale view

This commit is contained in:
Marcel Kronfeld 2010-05-12 14:39:04 +00:00
parent 045e6dbb82
commit 95a9f99162
3 changed files with 48 additions and 27 deletions

View File

@ -19,7 +19,12 @@ import eva2.tools.chart2d.DFunction;
* *
*/ */
public class Exp extends DFunction { public class Exp extends DFunction {
private double minValue = 1e-10; // think of a minimal value we want to show in case invalid (<=0) values are requested
public void setMinValue(double v) {
if (v>0) minValue = v;
else System.err.println("Error, minimal value for Exp must be positive!");
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see eva2.tools.chart2d.DFunction#isDefinedAt(double) * @see eva2.tools.chart2d.DFunction#isDefinedAt(double)
@ -50,10 +55,15 @@ public class Exp extends DFunction {
*/ */
public double getSourceOf(double target) { public double getSourceOf(double target) {
if (target <= 0) { if (target <= 0) {
throw new IllegalArgumentException( return Math.log(minValue); // think of a minimal value we want to show in case invalid values are requested
"Can not calculate log on values smaller than or equal 0 --> target = " // throw new IllegalArgumentException(
+ target); // "Can not calculate log on values smaller than or equal 0 --> target = "
// + target);
} }
return Math.log(target); return Math.log(target);
} }
public void updateMinValue(double y) {
if (y<minValue && (y>0)) minValue=y;
}
} }

View File

@ -42,6 +42,7 @@ import eva2.tools.chart2d.Chart2DDPointIconPoint;
import eva2.tools.chart2d.Chart2DDPointIconText; import eva2.tools.chart2d.Chart2DDPointIconText;
import eva2.tools.chart2d.DArea; import eva2.tools.chart2d.DArea;
import eva2.tools.chart2d.DBorder; import eva2.tools.chart2d.DBorder;
import eva2.tools.chart2d.DFunction;
import eva2.tools.chart2d.DPoint; import eva2.tools.chart2d.DPoint;
import eva2.tools.chart2d.DPointIcon; import eva2.tools.chart2d.DPointIcon;
import eva2.tools.chart2d.DPointSet; import eva2.tools.chart2d.DPointSet;
@ -317,6 +318,18 @@ public class FunctionArea extends DArea implements Serializable {
return (minY > 0); return (minY > 0);
} }
protected double getMinimalPositiveYValue() {
double minY = Double.MAX_VALUE;
for (int i = 0; i < m_PointSetContainer.size(); i++) {
DPointSet pSet = (m_PointSetContainer.get(i).getConnectedPointSet());
if (pSet.getSize() > 0) {
double tmpMinY = Math.min(minY, pSet.getMinYVal());
if (tmpMinY>0) minY=tmpMinY;
}
}
return minY;
}
protected boolean checkLogValidYValue(double x, double y, int graphLabel) { protected boolean checkLogValidYValue(double x, double y, int graphLabel) {
if (y <= 0.0) { if (y <= 0.0) {
if (m_log && notifyNegLog) { if (m_log && notifyNegLog) {
@ -821,23 +834,12 @@ public class FunctionArea extends DArea implements Serializable {
this.m_RefPointListener = null; this.m_RefPointListener = null;
} }
/**
*
*/
public void setConnectedPoint(double x, double y, int graphLabel) { public void setConnectedPoint(double x, double y, int graphLabel) {
DFunction scF = getYScale();
if (scF instanceof Exp) ((Exp)scF).updateMinValue(y);
if (!checkLogValidYValue(x, y, graphLabel)) { if (!checkLogValidYValue(x, y, graphLabel)) {
if (m_log) // if (m_log) toggleLog();
toggleLog();
} }
// if (y <= 0.0) {
// // y = Double.MIN_VALUE;
// if (notifyNegLog) {
// System.err.println("Warning: trying to plot value (" + x + "/" + y +
// ") with y <= 0 in logarithmic mode! Setting y to " + 1e-30);
// notifyNegLog = false;
// }
// y = 1e-30;
// }
getGraphPointSet(graphLabel).addDPoint(x, y); getGraphPointSet(graphLabel).addDPoint(x, y);
} }
@ -955,6 +957,7 @@ public class FunctionArea extends DArea implements Serializable {
repaint(); repaint();
} }
/** /**
* *
* @param x * @param x
@ -962,9 +965,10 @@ public class FunctionArea extends DArea implements Serializable {
* @param GraphLabel * @param GraphLabel
*/ */
public void setUnconnectedPoint(double x, double y, int GraphLabel) { public void setUnconnectedPoint(double x, double y, int GraphLabel) {
DFunction scF = getYScale();
if (scF instanceof Exp) ((Exp)scF).updateMinValue(y);
if (!checkLogValidYValue(x, y, GraphLabel)) { if (!checkLogValidYValue(x, y, GraphLabel)) {
if (m_log) // if (m_log) toggleLog();
toggleLog();
} }
this.getGraphPointSet(GraphLabel).addDPoint(x, y); this.getGraphPointSet(GraphLabel).addDPoint(x, y);
this.getGraphPointSet(GraphLabel).setConnectedMode(false); this.getGraphPointSet(GraphLabel).setConnectedMode(false);
@ -1007,17 +1011,20 @@ public class FunctionArea extends DArea implements Serializable {
*/ */
public void toggleLog() { public void toggleLog() {
// System.out.println("ToggleLog log was: "+m_log); // System.out.println("ToggleLog log was: "+m_log);
boolean setMinPos=false;
if (!m_log && !checkLoggable()) { if (!m_log && !checkLoggable()) {
System.err.println("Cant toggle log with values <= 0!"); System.err.println("Warning: toggling logarithmics scale with values <= 0! Some points will not be displayed.");
return; setMinPos=true;
} }
if (m_log == false) { if (m_log == false) {
setMinRectangle(0.001, 0.001, 1, 1); setMinRectangle(0.001, 0.001, 1, 1);
// setVisibleRectangle( 0.001, 0.001, 100000, 1000 ); //setVisibleRectangle( 0.001, 0.001, 100000, 1000 );
setYScale(new Exp()); Exp exp = new Exp();
m_Border.setSrcdY(Math.log(10)); if (setMinPos) exp.setMinValue(getMinimalPositiveYValue());
m_Border.applyPattern(false, "0.###E0"); setYScale(exp);
m_log = true; m_Border.setSrcdY(Math.log(10));
m_Border.applyPattern(false, "0.###E0");
m_log = true;
} else { } else {
m_log = false; m_log = false;
setYScale(null); setYScale(null);

View File

@ -798,6 +798,10 @@ public class DArea extends JComponent implements DParent, Printable {
repaint(); repaint();
} }
public DFunction getYScale() {
return measures.y_scale;
}
/** /**
* sets a new scale function to the y-axis That means that not the standard * sets a new scale function to the y-axis That means that not the standard
* linear scale is shown but the image of the linear scale under the given * linear scale is shown but the image of the linear scale under the given