From 95a9f991625f844eb50778e2d2a0cb554c1fa7e2 Mon Sep 17 00:00:00 2001 From: Marcel Kronfeld Date: Wed, 12 May 2010 14:39:04 +0000 Subject: [PATCH] Merging mk branch rev. 528: more generous log scale view --- src/eva2/gui/Exp.java | 16 +++++++-- src/eva2/gui/FunctionArea.java | 55 +++++++++++++++++-------------- src/eva2/tools/chart2d/DArea.java | 4 +++ 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/src/eva2/gui/Exp.java b/src/eva2/gui/Exp.java index f7cfbea3..713541c5 100644 --- a/src/eva2/gui/Exp.java +++ b/src/eva2/gui/Exp.java @@ -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 (y0)) minValue=y; + } } diff --git a/src/eva2/gui/FunctionArea.java b/src/eva2/gui/FunctionArea.java index 0abd7589..746c7849 100644 --- a/src/eva2/gui/FunctionArea.java +++ b/src/eva2/gui/FunctionArea.java @@ -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); diff --git a/src/eva2/tools/chart2d/DArea.java b/src/eva2/tools/chart2d/DArea.java index 0f068718..906397c1 100644 --- a/src/eva2/tools/chart2d/DArea.java +++ b/src/eva2/tools/chart2d/DArea.java @@ -797,6 +797,10 @@ public class DArea extends JComponent implements DParent, Printable { measures.x_scale = x_s; repaint(); } + + public DFunction getYScale() { + return measures.y_scale; + } /** * sets a new scale function to the y-axis That means that not the standard