All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.monitorenter.gui.chart.axis.AAxisTransformation Maven / Gradle / Ivy

Go to download

JChart2D is an easy to use component for displaying two- dimensional traces in a coordinate system written in Java.

The newest version!
/*
 *  AAxisTransformation.java of project jchart2d, 
 *  base class for Axis implementations that transform the scale 
 *  for changed display.  
 *  Copyright (C) 2007 -2011 Achim Westermann, created on 20:33:13.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *  
 *  If you modify or optimize the code in a useful way please let me know.
 *  [email protected]
 *
 */
package info.monitorenter.gui.chart.axis;

import info.monitorenter.gui.chart.Chart2D;
import info.monitorenter.gui.chart.IAxisLabelFormatter;
import info.monitorenter.gui.chart.IAxisScalePolicy;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.gui.chart.ITracePoint2D;
import info.monitorenter.gui.chart.axis.scalepolicy.AxisScalePolicyTransformation;
import info.monitorenter.util.Range;
import info.monitorenter.util.math.MathUtil;

import java.awt.event.MouseEvent;
import java.util.Iterator;

/**
 * Base class for Axis implementations that transform the scale for changed
 * display.
 * 

* * Note that instances of this implementations will only accept subtypes of * {@link AxisScalePolicyTransformation} for the method * {@link #setAxisScalePolicy(IAxisScalePolicy)}. *

* * * @param * Used to enforce that this instance only accepts * {@link AxisScalePolicyTransformation} and subtypes. * * @author Achim Westermann * * @version $Revision: 1.32 $ */ public abstract class AAxisTransformation extends AAxis { /** * An accessor for the x axis of a chart. *

* * @author * * @return the transformed max with additional error treatment in case of * empty traces. * * @see info.monitorenter.gui.chart.axis.AAxis#getMax() */ public double getMaxTransformed() { double result = 1.0; try { result = this.transform(super.getMax()); } catch (IllegalArgumentException e) { // nop } return result; } /** * Returns the transformed min with additional error treatment in case of * empty traces. *

* * @return the transformed min with additional error treatment in case of * empty traces. * * @see info.monitorenter.gui.chart.axis.AAxis#getMin() */ public double getMinTransformed() { double result = 0.0; try { result = this.transform(super.getMin()); } catch (IllegalArgumentException e) { // nop } return result; } /** * @see info.monitorenter.gui.chart.IAxis#getScaledValue(double) */ public final double getScaledValue(final double absolute) { double result; Range range = new Range(this.getMinTransformed(), this.getMaxTransformed()); try { result = (AAxisTransformation.this.transform(absolute) - range.getMin()); double scaler = range.getExtent(); result = result / scaler; if (!MathUtil.isDouble(result)) { result = 0; } } catch (IllegalArgumentException e) { long tstamp = System.currentTimeMillis(); if (tstamp - this.m_outputErrorTstamp > AAxisTransformation.OUTPUT_ERROR_THRESHHOLD) { System.out.println(e.getLocalizedMessage()); this.m_outputErrorTstamp = tstamp; } result = 0; } return result; } /** * Overridden to incorporate transformation. *

* * @see info.monitorenter.gui.chart.IAxis#scaleTrace(info.monitorenter.gui.chart.ITrace2D) */ @Override public void scaleTrace(final ITrace2D trace) { final Range range = new Range(this.getMinTransformed(), this.getMaxTransformed()); this.m_accessor.scaleTrace(trace, range); } /** * Template method for performing the axis transformation. *

* The argument should not be negative, so only normalized values (no chart * values but their scaled values or pixel values) should be given here. *

* * @param in * the value to transform. * * @return the transformed value. * * @throws IllegalArgumentException * if scaling is impossible (due to some mathematical transformation * in implementations like * {@link info.monitorenter.gui.chart.axis.AxisLog10} */ public abstract double transform(final double in) throws IllegalArgumentException; /** * @see info.monitorenter.gui.chart.axis.AAxis#translateMousePosition(java.awt.event.MouseEvent) */ @Override public final double translateMousePosition(final MouseEvent mouseEvent) throws IllegalArgumentException { return this.untransform(this.getAccessor().translateMousePosition(mouseEvent)); } /** * @see info.monitorenter.gui.chart.axis.AAxis#translatePxToValue(int) */ @Override public double translatePxToValue(final int pixel) { return this.untransform(this.m_accessor.translatePxToValue(pixel)); } /** * Template method for performing the reverse axis transformation. *

* This is the counterpart to {@link #transform(double)}. *

* * @param in * the transformed value. * @return the normal value; */ public abstract double untransform(final double in); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy