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 {
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)
* @see eva2.tools.chart2d.DFunction#isDefinedAt(double)
@ -50,10 +55,15 @@ public class Exp extends DFunction {
*/
public double getSourceOf(double target) {
if (target <= 0) {
throw new IllegalArgumentException(
"Can not calculate log on values smaller than or equal 0 --> target = "
+ target);
return Math.log(minValue); // think of a minimal value we want to show in case invalid values are requested
// throw new IllegalArgumentException(
// "Can not calculate log on values smaller than or equal 0 --> target = "
// + 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.DArea;
import eva2.tools.chart2d.DBorder;
import eva2.tools.chart2d.DFunction;
import eva2.tools.chart2d.DPoint;
import eva2.tools.chart2d.DPointIcon;
import eva2.tools.chart2d.DPointSet;
@ -317,6 +318,18 @@ public class FunctionArea extends DArea implements Serializable {
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) {
if (y <= 0.0) {
if (m_log && notifyNegLog) {
@ -821,23 +834,12 @@ public class FunctionArea extends DArea implements Serializable {
this.m_RefPointListener = null;
}
/**
*
*/
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 (m_log)
toggleLog();
// if (m_log) 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);
}
@ -955,6 +957,7 @@ public class FunctionArea extends DArea implements Serializable {
repaint();
}
/**
*
* @param x
@ -962,9 +965,10 @@ public class FunctionArea extends DArea implements Serializable {
* @param 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 (m_log)
toggleLog();
// if (m_log) toggleLog();
}
this.getGraphPointSet(GraphLabel).addDPoint(x, y);
this.getGraphPointSet(GraphLabel).setConnectedMode(false);
@ -1007,17 +1011,20 @@ public class FunctionArea extends DArea implements Serializable {
*/
public void toggleLog() {
// System.out.println("ToggleLog log was: "+m_log);
boolean setMinPos=false;
if (!m_log && !checkLoggable()) {
System.err.println("Cant toggle log with values <= 0!");
return;
System.err.println("Warning: toggling logarithmics scale with values <= 0! Some points will not be displayed.");
setMinPos=true;
}
if (m_log == false) {
setMinRectangle(0.001, 0.001, 1, 1);
// setVisibleRectangle( 0.001, 0.001, 100000, 1000 );
setYScale(new Exp());
m_Border.setSrcdY(Math.log(10));
m_Border.applyPattern(false, "0.###E0");
m_log = true;
setMinRectangle(0.001, 0.001, 1, 1);
//setVisibleRectangle( 0.001, 0.001, 100000, 1000 );
Exp exp = new Exp();
if (setMinPos) exp.setMinValue(getMinimalPositiveYValue());
setYScale(exp);
m_Border.setSrcdY(Math.log(10));
m_Border.applyPattern(false, "0.###E0");
m_log = true;
} else {
m_log = false;
setYScale(null);

View File

@ -798,6 +798,10 @@ public class DArea extends JComponent implements DParent, Printable {
repaint();
}
public DFunction getYScale() {
return measures.y_scale;
}
/**
* 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