    001/* ===========================================================
    002 * Orson Charts : a 3D chart library for the Java(tm) platform
    003 * ===========================================================
    004 *
    005 * (C)opyright 2013-2022, by David Gilbert.  All rights reserved.
    006 *
    007 * https://github.com/jfree/orson-charts
    008 *
    009 * This program is free software: you can redistribute it and/or modify
    010 * it under the terms of the GNU General Public License as published by
    011 * the Free Software Foundation, either version 3 of the License, or
    012 * (at your option) any later version.
    013 *
    014 * This program is distributed in the hope that it will be useful,
    015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    017 * GNU General Public License for more details.
    018 *
    019 * You should have received a copy of the GNU General Public License
    020 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    021 *
    022 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    023 * Other names may be trademarks of their respective owners.]
    024 *
    025 * If you do not wish to be bound by the terms of the GPL, an alternative
    026 * commercial license can be purchased.  For details, please see visit the
    027 * Orson Charts home page:
    028 *
    029 * http://www.object-refinery.com/orsoncharts/index.html
    030 *
    031 */
    032
    033package org.jfree.chart3d.axis;
    034
    035import java.awt.geom.Point2D;
    036import org.jfree.chart3d.internal.Args;
    037
    038/**
    039 * Data related to the tick marks and labels on a chart.
    040 */
    041public class TickData {
    042
    043    /** The position along the axis as a percentage. */
    044    private final double pos;
    045
    046    /** The key for the tick (used for CategoryAxis3D, null otherwise). */
    047    private final Comparable<?> key;
    048
    049    /**
    050     * The label used for the category key (used for CategoryAxis3D, null
    051     * otherwise).
    052     */
    053    private final String keyLabel;
    054
    055    /** The data value (used for ValueAxis3D). */
    056    private final double dataValue;
    057
    058    /** The vertex in the ChartBox that is the anchor point for this tick. */
    059    private int vertexIndex;
    060
    061    /** The anchor point. */
    062    private Point2D anchorPt;
    063
    064    /**
    065     * Creates a new instance.  This constructor is used for category axes.
    066     *
    067     * @param pos  the position along the axis as a percentage of the range.
    068     * @param key  the key.
    069     * @param keyLabel  the key label.
    070     */
    071    public TickData(double pos, Comparable<?> key, String keyLabel) {
    072        this.pos = pos;
    073        this.key = key;
    074        this.keyLabel = keyLabel;
    075        this.dataValue = Double.NaN;
    076        this.vertexIndex = -1;
    077        this.anchorPt = null;
    078    }
    079
    080    /**
    081     * Creates a new instance.  This constructor is used for numerical axes.
    082     *
    083     * @param pos  the position along the axis as a percentage of the range.
    084     * @param dataValue  the data value.
    085     */
    086    public TickData(double pos, double dataValue) {
    087        this.pos = pos;
    088        this.dataValue = dataValue;
    089        this.key = null;
    090        this.keyLabel = null;
    091        this.vertexIndex = -1;
    092        this.anchorPt = null;
    093    }
    094
    095    /**
    096     * Creates a new instance by copying an existing instance but altering
    097     * the vertex index.
    098     *
    099     * @param source  a source to copy ({@code null} not permitted).
    100     * @param vertexIndex  the vertex index.
    101     */
    102    public TickData(TickData source, int vertexIndex) {
    103        Args.nullNotPermitted(source, "source");
    104        this.pos = source.pos;
    105        this.dataValue = source.dataValue;
    106        this.key = source.key;
    107        this.keyLabel = source.keyLabel;
    108        this.anchorPt = source.anchorPt;
    109        this.vertexIndex = vertexIndex;
    110    }
    111
    112    /**
    113     * Returns the position of the tick, as a percentage along the axis (for
    114     * example, 0.5 is halfway along the axis).
    115     *
    116     * @return The position.
    117     */
    118    public double getPos() {
    119        return this.pos;
    120    }
    121
    122    /**
    123     * Returns the key when the tick data is for a {@link CategoryAxis3D},
    124     * and {@code null} otherwise.
    125     *
    126     * @return The key (possibly {@code null}).
    127     */
    128    public Comparable<?> getKey() {
    129        return this.key;
    130    }
    131
    132    /**
    133     * Returns the key label.
    134     *
    135     * @return The key label (possibly {@code null}).
    136     *
    137     * @since 1.2
    138     */
    139    public String getKeyLabel() {
    140        return this.keyLabel;
    141    }
    142
    143    /**
    144     * Returns the data value when the tick data is for a {@link NumberAxis3D},
    145     * and {@code Double.NaN} otherwise.
    146     *
    147     * @return The data value.
    148     */
    149    public double getDataValue() {
    150        return this.dataValue;
    151    }
    152
    153    /**
    154     * Returns the vertex index that is the anchor point for the tick mark.
    155     *
    156     * @return The vertex index.
    157     */
    158    public int getVertexIndex() {
    159        return this.vertexIndex;
    160    }
    161
    162    /**
    163     * Sets the vertex index.  The vertex is a point in 3D space that is
    164     * the anchor point for the tick mark, after this is projected to
    165     * 2D space we have a reference point for the tick mark.
    166     *
    167     * @param index  the index.
    168     */
    169    public void setVertexIndex(int index) {
    170        this.vertexIndex = index;
    171    }
    172
    173    /**
    174     * Returns the anchor point.
    175     *
    176     * @return The anchor point.
    177     */
    178    public Point2D getAnchorPt() {
    179        return this.anchorPt;
    180    }
    181
    182    /**
    183     * Sets the anchor point.  This is the projected point in 2D space of the
    184     * vertex we track in 3D space.
    185     *
    186     * @param anchorPt  the anchor point.
    187     */
    188    public void setAnchorPt(Point2D anchorPt) {
    189        this.anchorPt = anchorPt;
    190    }
    191}