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

com.panayotis.gnuplot.layout.LayoutMetrics Maven / Gradle / Ivy

Go to download

This JavaPlot library has not been written by me (the author of the PA-Toolbox project). See the given URL for the original JavaPlot project. These files have been extracted from the download JavaPlot-0.5.0.tar.bz2. It is included here just to resolve external dependencies of other PA-Toolbox submodules.

The newest version!
/* Copyright (c) 2007-2014 by panayotis.com
 *
 * JavaPlot 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, version 2.
 *
 * JavaPlot is free 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 CrossMobile; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package com.panayotis.gnuplot.layout;

import java.io.Serializable;

/**
 * Container of the metrics for a specific graph
 *
 * @author teras
 */
public class LayoutMetrics implements Serializable {

    private float x, y, width, height;
    private float minsize = 0.001f;

    /**
     * Set default position, covering the whole screen
     */
    public LayoutMetrics() {
        this(0, 0, 1, 1);
    }

    /**
     * Set a specific position, in the area of 0,0-1,1 and with a minimum size
     *
     * @param x horizontal position
     * @param y vertical position
     * @param width width
     * @param height height
     */
    public LayoutMetrics(float x, float y, float width, float height) {
        if (width < 0)
            width = minsize;
        if (height < 0)
            height = minsize;
        if (width > 1)
            width = 1;
        if (height > 1)
            height = 1;

        if (x < 0)
            x = 0;
        if (y < 0)
            y = 0;
        if (x > 1)
            x = 1;
        if (y > 1)
            y = 1;

        float x2 = x + width;
        float y2 = y + height;
        if (x2 > 1) {
            x = 1 - minsize;
            width = minsize;
        }
        if (y2 > 1) {
            y = 1 - minsize;
            height = minsize;
        }

        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }

    /**
     * Get horizontal position
     *
     * @return horizontal position
     */
    public float getX() {
        return x;
    }

    /**
     * Get vertical position
     *
     * @return vertical position
     */
    public float getY() {
        return y;
    }

    /**
     * Get width
     *
     * @return width
     */
    public float getWidth() {
        return width;
    }

    /**
     * Get height
     *
     * @return height
     */
    public float getHeight() {
        return height;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy