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

info.monitorenter.gui.chart.axis.AxisInverse 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!
/*
 *  AAxisInverse.java of project jchart2d, 
 *  an IAxis implementations that inverts the values and shows 
 *  decreasing values (10, 9,... 1).  
 *  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.IAxis;
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.LabeledValue;
import info.monitorenter.util.Range;
import info.monitorenter.util.math.MathUtil;

import java.awt.Graphics;
import java.util.Iterator;
import java.util.List;

/**
 * An {@link AAxis} with inverse display of values.
 * 

* * Labels and values are starting from the highest value and go down to the * lowest one. *

* * @param * Subtypes may be more picky which scale policies the accept to * disallow incorrect scales: This supports it (see * {@link IAxis#setAxisScalePolicy(IAxisScalePolicy)}). * * @author Andrea Plotegher (initial contribution) * * @author Achim Westermann * (adaption for core) * * @version $Revision: 1.20 $ */ public class AxisInverse extends AAxis { /** * * An accessor for the x axis of a chart. *

* * @author getScaleValues(Graphics g2d, IAxis axis) { List ret = axisScalePolicy.getScaleValues(g2d, axis); for (LabeledValue label : ret) { label.setValue(1.0 - label.getValue()); } return ret; } }); } /** * @see info.monitorenter.gui.chart.IAxis#getScaledValue(double) */ public double getScaledValue(final double absolute) { Range range = this.getRange(); double scalerX = range.getExtent(); double result = 1 - ((absolute - range.getMin()) / scalerX); if (!MathUtil.isDouble(result)) { result = 0; } return result; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy